当前位置: 首页>>代码示例>>Java>>正文


Java Transaction.execute方法代码示例

本文整理汇总了Java中com.cloud.utils.db.Transaction.execute方法的典型用法代码示例。如果您正苦于以下问题:Java Transaction.execute方法的具体用法?Java Transaction.execute怎么用?Java Transaction.execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.cloud.utils.db.Transaction的用法示例。


在下文中一共展示了Transaction.execute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: removeVmSecondaryIpsOfNic

import com.cloud.utils.db.Transaction; //导入方法依赖的package包/类
private boolean removeVmSecondaryIpsOfNic(final long nicId) {
    Transaction.execute(new TransactionCallbackNoReturn() {
        @Override
        public void doInTransactionWithoutResult(final TransactionStatus status) {
            final List<NicSecondaryIpVO> ipList = _nicSecondaryIpDao.listByNicId(nicId);
            if (ipList != null) {
                for (final NicSecondaryIpVO ip : ipList) {
                    _nicSecondaryIpDao.remove(ip.getId());
                }
                s_logger.debug("Revoving nic secondary ip entry ...");
            }
        }
    });

    return true;
}
 
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:17,代码来源:NetworkOrchestrator.java

示例2: resetHostPowerStateTracking

import com.cloud.utils.db.Transaction; //导入方法依赖的package包/类
@Override
@DB
public void resetHostPowerStateTracking(final long hostId) {
    Transaction.execute(new TransactionCallbackNoReturn() {
        @Override
        public void doInTransactionWithoutResult(final TransactionStatus status) {
            final SearchCriteria<VMInstanceVO> sc = createSearchCriteria();
            sc.addAnd("powerHostId", SearchCriteria.Op.EQ, hostId);

            final VMInstanceVO instance = createForUpdate();
            instance.setPowerStateUpdateCount(0);
            instance.setPowerStateUpdateTime(DateUtil.currentGMTTime());

            update(instance, sc);
        }
    });
}
 
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:18,代码来源:VMInstanceDaoImpl.java

示例3: addResourceMetaData

import com.cloud.utils.db.Transaction; //导入方法依赖的package包/类
@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_RESOURCE_DETAILS_CREATE, eventDescription = "creating resource meta data")
public boolean addResourceMetaData(final String resourceId, final ResourceObjectType resourceType, final Map<String, String> details, final boolean forDisplay) {
    return Transaction.execute(new TransactionCallback<Boolean>() {
        @Override
        public Boolean doInTransaction(final TransactionStatus status) {
            for (final String key : details.keySet()) {
                final String value = details.get(key);

                if (value == null || value.isEmpty()) {
                    throw new InvalidParameterValueException("Value for the key " + key + " is either null or empty");
                }

                final DetailDaoHelper newDetailDaoHelper = new DetailDaoHelper(resourceType);
                newDetailDaoHelper.addDetail(_taggedResourceMgr.getResourceId(resourceId, resourceType), key, value, forDisplay);
            }

            return true;
        }
    });
}
 
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:23,代码来源:ResourceMetaDataManagerImpl.java

示例4: affinityGroupService

import com.cloud.utils.db.Transaction; //导入方法依赖的package包/类
@Bean
public AffinityGroupService affinityGroupService() {
    AffinityGroupService mock = Mockito.mock(AffinityGroupService.class);
    try {
        final AffinityGroupVO gmock = new AffinityGroupVO("grp1", "grp-type", "affinity group", 1, Account.ACCOUNT_ID_SYSTEM, ControlledEntity.ACLType.Account);
        Transaction.execute(new TransactionCallbackNoReturn() {
            @Override
            public void doInTransactionWithoutResult(TransactionStatus status) {
                _affinityGroupDao.persist(gmock);
            }
        });
        Mockito.when(
            mock.createAffinityGroup(Matchers.any(String.class), Matchers.any(Long.class), Matchers.any(Long.class), Matchers.any(String.class), Matchers.any(String.class),
                Matchers.any(String.class))).thenReturn(gmock);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return mock;
}
 
开发者ID:apache,项目名称:cloudstack,代码行数:20,代码来源:IntegrationTestConfiguration.java

示例5: findLaterBalanceEntry

import com.cloud.utils.db.Transaction; //导入方法依赖的package包/类
@Override
public QuotaBalanceVO findLaterBalanceEntry(final Long accountId, final Long domainId, final Date afterThis) {
    return Transaction.execute(TransactionLegacy.USAGE_DB, new TransactionCallback<QuotaBalanceVO>() {
        @Override
        public QuotaBalanceVO doInTransaction(final TransactionStatus status) {
            List<QuotaBalanceVO> quotaBalanceEntries = new ArrayList<>();
            Filter filter = new Filter(QuotaBalanceVO.class, "updatedOn", true, 0L, 1L);
            QueryBuilder<QuotaBalanceVO> qb = QueryBuilder.create(QuotaBalanceVO.class);
            qb.and(qb.entity().getAccountId(), SearchCriteria.Op.EQ, accountId);
            qb.and(qb.entity().getDomainId(), SearchCriteria.Op.EQ, domainId);
            qb.and(qb.entity().getCreditsId(), SearchCriteria.Op.EQ, 0);
            qb.and(qb.entity().getUpdatedOn(), SearchCriteria.Op.GT, afterThis);
            quotaBalanceEntries = search(qb.create(), filter);
            return quotaBalanceEntries.size() > 0 ? quotaBalanceEntries.get(0) : null;
        }
    });
}
 
开发者ID:apache,项目名称:cloudstack,代码行数:18,代码来源:QuotaBalanceDaoImpl.java

示例6: getcomputeOffering

import com.cloud.utils.db.Transaction; //导入方法依赖的package包/类
private ServiceOfferingVO getcomputeOffering(final ServiceOfferingVO serviceOffering, final Map<String, String> customParameters) {
    return Transaction.execute(TransactionLegacy.CLOUD_DB, new TransactionCallback<ServiceOfferingVO>() {
        @Override
        public ServiceOfferingVO doInTransaction(final TransactionStatus status) {
            ServiceOfferingVO dummyoffering = new ServiceOfferingVO(serviceOffering);
            dummyoffering.setDynamicFlag(true);
            if (customParameters.containsKey(UsageEventVO.DynamicParameters.cpuNumber.name())) {
                dummyoffering.setCpu(Integer.parseInt(customParameters.get(UsageEventVO.DynamicParameters.cpuNumber.name())));
            }
            if (customParameters.containsKey(UsageEventVO.DynamicParameters.cpuSpeed.name())) {
                dummyoffering.setSpeed(Integer.parseInt(customParameters.get(UsageEventVO.DynamicParameters.cpuSpeed.name())));
            }
            if (customParameters.containsKey(UsageEventVO.DynamicParameters.memory.name())) {
                dummyoffering.setRamSize(Integer.parseInt(customParameters.get(UsageEventVO.DynamicParameters.memory.name())));
            }
            return dummyoffering;
        }
    });
}
 
开发者ID:apache,项目名称:cloudstack,代码行数:20,代码来源:ServiceOfferingDaoImpl.java

示例7: findCreditBalance

import com.cloud.utils.db.Transaction; //导入方法依赖的package包/类
@Override
public List<QuotaBalanceVO> findCreditBalance(final Long accountId, final Long domainId, final Date lastbalancedate, final Date beforeThis) {
    return Transaction.execute(TransactionLegacy.USAGE_DB, new TransactionCallback<List<QuotaBalanceVO>>() {
        @Override
        public List<QuotaBalanceVO> doInTransaction(final TransactionStatus status) {
            if ((lastbalancedate != null) && (beforeThis != null) && lastbalancedate.before(beforeThis)) {
                Filter filter = new Filter(QuotaBalanceVO.class, "updatedOn", true, 0L, Long.MAX_VALUE);
                QueryBuilder<QuotaBalanceVO> qb = QueryBuilder.create(QuotaBalanceVO.class);
                qb.and(qb.entity().getAccountId(), SearchCriteria.Op.EQ, accountId);
                qb.and(qb.entity().getDomainId(), SearchCriteria.Op.EQ, domainId);
                qb.and(qb.entity().getCreditsId(), SearchCriteria.Op.GT, 0);
                qb.and(qb.entity().getUpdatedOn(), SearchCriteria.Op.BETWEEN, lastbalancedate, beforeThis);
                return search(qb.create(), filter);
            } else {
                return new ArrayList<QuotaBalanceVO>();
            }
        }
    });
}
 
开发者ID:apache,项目名称:cloudstack,代码行数:20,代码来源:QuotaBalanceDaoImpl.java

示例8: getNextTopologyUpdateSequenceNumber

import com.cloud.utils.db.Transaction; //导入方法依赖的package包/类
private long getNextTopologyUpdateSequenceNumber(final long vpcId) {

        try {
            return  Transaction.execute(new TransactionCallback<Long>() {
                @Override
                public Long doInTransaction(TransactionStatus status) {
                    VpcDistributedRouterSeqNoVO seqVo = _vpcDrSeqNoDao.findByVpcId(vpcId);
                    if (seqVo == null) {
                        seqVo = new VpcDistributedRouterSeqNoVO(vpcId);
                        _vpcDrSeqNoDao.persist(seqVo);
                    }
                    seqVo = _vpcDrSeqNoDao.lockRow(seqVo.getId(), true);
                    seqVo.incrTopologyUpdateSequenceNo();
                    _vpcDrSeqNoDao.update(seqVo.getId(), seqVo);
                    return seqVo.getTopologyUpdateSequenceNo();
                }
            });
        } finally {

        }
    }
 
开发者ID:apache,项目名称:cloudstack,代码行数:22,代码来源:OvsTunnelManagerImpl.java

示例9: attachIAMPolicyToAccounts

import com.cloud.utils.db.Transaction; //导入方法依赖的package包/类
@Override
public void attachIAMPolicyToAccounts(final Long policyId, final List<Long> acctIds) {
    IAMPolicy policy = _aclPolicyDao.findById(policyId);
    if (policy == null) {
        throw new InvalidParameterValueException("Unable to find acl policy: " + policyId
                + "; failed to add policy to account.");
    }

    Transaction.execute(new TransactionCallbackNoReturn() {
        @Override
        public void doInTransactionWithoutResult(TransactionStatus status) {
            // add entries in acl_group_policy_map table
            for (Long acctId : acctIds) {
                IAMAccountPolicyMapVO acctMap = _aclAccountPolicyMapDao.findByAccountAndPolicy(acctId, policyId);
                if (acctMap == null) {
                    // not there already
                    acctMap = new IAMAccountPolicyMapVO(acctId, policyId);
                    _aclAccountPolicyMapDao.persist(acctMap);
                }
            }
        }
    });

    invalidateIAMCache();
}
 
开发者ID:apache,项目名称:cloudstack,代码行数:26,代码来源:IAMServiceImpl.java

示例10: activeInviteExists

import com.cloud.utils.db.Transaction; //导入方法依赖的package包/类
@DB
public boolean activeInviteExists(final Project project, final Long accountId, final String email) {
    return Transaction.execute(new TransactionCallback<Boolean>() {
        @Override
        public Boolean doInTransaction(final TransactionStatus status) {
            //verify if the invitation was already generated
            ProjectInvitationVO invite = null;
            if (accountId != null) {
                invite = _projectInvitationDao.findByAccountIdProjectId(accountId, project.getId());
            } else if (email != null) {
                invite = _projectInvitationDao.findByEmailAndProjectId(email, project.getId());
            }

            if (invite != null) {
                if (invite.getState() == ProjectInvitation.State.Completed ||
                        (invite.getState() == ProjectInvitation.State.Pending && _projectInvitationDao.isActive(invite.getId(), _invitationTimeOut))) {
                    return true;
                } else {
                    if (invite.getState() == ProjectInvitation.State.Pending) {
                        expireInvitation(invite);
                    }
                    //remove the expired/declined invitation
                    if (accountId != null) {
                        s_logger.debug("Removing invitation in state " + invite.getState() + " for account id=" + accountId + " to project " + project);
                    } else if (email != null) {
                        s_logger.debug("Removing invitation in state " + invite.getState() + " for email " + email + " to project " + project);
                    }

                    _projectInvitationDao.expunge(invite.getId());
                }
            }

            return false;
        }
    });
}
 
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:37,代码来源:ProjectManagerImpl.java

示例11: updatePowerState

import com.cloud.utils.db.Transaction; //导入方法依赖的package包/类
@Override
public boolean updatePowerState(final long instanceId, final long powerHostId, final VirtualMachine.PowerState powerState) {
    return Transaction.execute(new TransactionCallback<Boolean>() {
        @Override
        public Boolean doInTransaction(final TransactionStatus status) {
            boolean needToUpdate = false;
            final VMInstanceVO instance = findById(instanceId);
            if (instance != null) {
                final Long savedPowerHostId = instance.getPowerHostId();
                if (instance.getPowerState() != powerState || savedPowerHostId == null
                        || savedPowerHostId.longValue() != powerHostId) {
                    instance.setPowerState(powerState);
                    instance.setPowerHostId(powerHostId);
                    instance.setPowerStateUpdateCount(1);
                    instance.setPowerStateUpdateTime(DateUtil.currentGMTTime());
                    needToUpdate = true;
                    update(instanceId, instance);
                } else {
                    // to reduce DB updates, consecutive same state update for more than 3 times
                    if (instance.getPowerStateUpdateCount() < MAX_CONSECUTIVE_SAME_STATE_UPDATE_COUNT) {
                        instance.setPowerStateUpdateCount(instance.getPowerStateUpdateCount() + 1);
                        instance.setPowerStateUpdateTime(DateUtil.currentGMTTime());
                        needToUpdate = true;
                        update(instanceId, instance);
                    }
                }
            }
            return needToUpdate;
        }
    });
}
 
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:32,代码来源:VMInstanceDaoImpl.java

示例12: createAffinityGroup

import com.cloud.utils.db.Transaction; //导入方法依赖的package包/类
private AffinityGroupVO createAffinityGroup(final AffinityGroupProcessor processor, final Account owner, final ACLType aclType, final String affinityGroupName, final String
        affinityGroupType, final String description, boolean domainLevel, Long domainId) {

    Long domainIdBasedOnDomainLevel = owner.getDomainId();
    if (domainLevel) {
        domainIdBasedOnDomainLevel = domainId;
    }
    final Long affinityGroupDomainId = domainIdBasedOnDomainLevel;

    return Transaction.execute(new TransactionCallback<AffinityGroupVO>() {
        @Override
        public AffinityGroupVO doInTransaction(final TransactionStatus status) {
            final AffinityGroupVO group =
                    new AffinityGroupVO(affinityGroupName, affinityGroupType, description, owner.getDomainId(), owner.getId(), aclType);
            _affinityGroupDao.persist(group);

            if (aclType == ACLType.Domain) {
                boolean subDomainAccess;
                subDomainAccess = processor.subDomainAccess();
                AffinityGroupDomainMapVO domainMap = new AffinityGroupDomainMapVO(group.getId(), affinityGroupDomainId, subDomainAccess);
                _affinityGroupDomainMapDao.persist(domainMap);
            }

            return group;
        }
    });
}
 
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:28,代码来源:AffinityGroupServiceImpl.java

示例13: updateResourceCountForAccount

import com.cloud.utils.db.Transaction; //导入方法依赖的package包/类
@DB
protected boolean updateResourceCountForAccount(final long accountId, final ResourceType type, final boolean increment, final long delta) {
    try {
        return Transaction.execute(new TransactionCallback<Boolean>() {
            @Override
            public Boolean doInTransaction(final TransactionStatus status) {
                boolean result = true;
                final Set<Long> rowsToLock = _resourceCountDao.listAllRowsToUpdate(accountId, ResourceOwnerType.Account, type);

                // Lock rows first
                final SearchCriteria<ResourceCountVO> sc = ResourceCountSearch.create();
                sc.setParameters("id", rowsToLock.toArray());
                final List<ResourceCountVO> rowsToUpdate = _resourceCountDao.lockRows(sc, null, true);

                for (final ResourceCountVO rowToUpdate : rowsToUpdate) {
                    if (!_resourceCountDao.updateById(rowToUpdate.getId(), increment, delta)) {
                        s_logger.trace("Unable to update resource count for the row " + rowToUpdate);
                        result = false;
                    }
                }

                return result;
            }
        });
    } catch (final Exception ex) {
        s_logger.error("Failed to update resource count for account id=" + accountId);
        return false;
    }
}
 
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:30,代码来源:ResourceLimitManagerImpl.java

示例14: releaseHostReservation

import com.cloud.utils.db.Transaction; //导入方法依赖的package包/类
@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_HOST_RESERVATION_RELEASE, eventDescription = "releasing host reservation", async = true)
public boolean releaseHostReservation(final Long hostId) {
    return Transaction.execute(new TransactionCallback<Boolean>() {
        @Override
        public Boolean doInTransaction(final TransactionStatus status) {
            final PlannerHostReservationVO reservationEntry = _plannerHostReserveDao.findByHostId(hostId);
            if (reservationEntry != null) {
                final long id = reservationEntry.getId();
                final PlannerHostReservationVO hostReservation = _plannerHostReserveDao.lockRow(id, true);
                if (hostReservation == null) {
                    if (s_logger.isDebugEnabled()) {
                        s_logger.debug("Host reservation for host: " + hostId + " does not even exist.  Release reservartion call is ignored.");
                    }
                    return false;
                }
                hostReservation.setResourceUsage(null);
                _plannerHostReserveDao.persist(hostReservation);
                return true;
            }

            if (s_logger.isDebugEnabled()) {
                s_logger.debug("Host reservation for host: " + hostId + " does not even exist.  Release reservartion call is ignored.");
            }

            return false;
        }
    });
}
 
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:31,代码来源:ResourceManagerImpl.java

示例15: queue

import com.cloud.utils.db.Transaction; //导入方法依赖的package包/类
@Override
@DB
public SyncQueueVO queue(final String syncObjType, final long syncObjId, final String itemType, final long itemId, final long queueSizeLimit) {
    try {
        return Transaction.execute(new TransactionCallback<SyncQueueVO>() {
            @Override
            public SyncQueueVO doInTransaction(final TransactionStatus status) {
                _syncQueueDao.ensureQueue(syncObjType, syncObjId);
                final SyncQueueVO queueVO = _syncQueueDao.find(syncObjType, syncObjId);
                if (queueVO == null) {
                    throw new CloudRuntimeException("Unable to queue item into DB, DB is full?");
                }

                queueVO.setQueueSizeLimit(queueSizeLimit);
                _syncQueueDao.update(queueVO.getId(), queueVO);

                final Date dt = DateUtil.currentGMTTime();
                final SyncQueueItemVO item = new SyncQueueItemVO();
                item.setQueueId(queueVO.getId());
                item.setContentType(itemType);
                item.setContentId(itemId);
                item.setCreated(dt);

                _syncQueueItemDao.persist(item);
                return queueVO;
            }
        });
    } catch (final Exception e) {
        s_logger.error("Unexpected exception: ", e);
    }
    return null;
}
 
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:33,代码来源:SyncQueueManagerImpl.java


注:本文中的com.cloud.utils.db.Transaction.execute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。