本文整理匯總了Java中com.cloud.utils.db.TransactionCallback類的典型用法代碼示例。如果您正苦於以下問題:Java TransactionCallback類的具體用法?Java TransactionCallback怎麽用?Java TransactionCallback使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
TransactionCallback類屬於com.cloud.utils.db包,在下文中一共展示了TransactionCallback類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: markIpAsUnavailable
import com.cloud.utils.db.TransactionCallback; //導入依賴的package包/類
@DB
@Override
public IPAddressVO markIpAsUnavailable(final long addrId) {
final IPAddressVO ip = _ipAddressDao.findById(addrId);
if (ip.getAllocatedToAccountId() == null && ip.getAllocatedTime() == null) {
s_logger.trace("Ip address id=" + addrId + " is already released");
return ip;
}
if (ip.getState() != State.Releasing) {
return Transaction.execute(new TransactionCallback<IPAddressVO>() {
@Override
public IPAddressVO doInTransaction(final TransactionStatus status) {
if (updateIpResourceCount(ip)) {
_resourceLimitMgr.decrementResourceCount(_ipAddressDao.findById(addrId).getAllocatedToAccountId(), ResourceType.public_ip);
}
return _ipAddressDao.markAsUnavailable(addrId);
}
});
}
return ip;
}
示例2: deleteAccountFromProject
import com.cloud.utils.db.TransactionCallback; //導入依賴的package包/類
@Override
@DB
public boolean deleteAccountFromProject(final long projectId, final long accountId) {
return Transaction.execute(new TransactionCallback<Boolean>() {
@Override
public Boolean doInTransaction(final TransactionStatus status) {
boolean success;
//remove account
final ProjectAccountVO projectAccount = _projectAccountDao.findByProjectIdAccountId(projectId, accountId);
success = _projectAccountDao.remove(projectAccount.getId());
//remove all invitations for account
if (success) {
s_logger.debug("Removed account " + accountId + " from project " + projectId + " , cleaning up old invitations for account/project...");
final ProjectInvitation invite = _projectInvitationDao.findByAccountIdProjectId(accountId, projectId);
if (invite != null) {
success = success && _projectInvitationDao.remove(invite.getId());
}
}
return success;
}
});
}
示例3: addResourceMetaData
import com.cloud.utils.db.TransactionCallback; //導入依賴的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;
}
});
}
示例4: savePublicIPRange
import com.cloud.utils.db.TransactionCallback; //導入依賴的package包/類
@DB
protected boolean savePublicIPRange(final String startIP, final String endIP, final long zoneId, final long vlanDbId, final long sourceNetworkid, final long
physicalNetworkId) {
final long startIPLong = NetUtils.ip2Long(startIP);
final long endIPLong = NetUtils.ip2Long(endIP);
final List<String> problemIps = Transaction.execute(new TransactionCallback<List<String>>() {
@Override
public List<String> doInTransaction(final TransactionStatus status) {
final IPRangeConfig config = new IPRangeConfig();
return config.savePublicIPRange(TransactionLegacy.currentTxn(), startIPLong, endIPLong, zoneId, vlanDbId, sourceNetworkid, physicalNetworkId);
}
});
return problemIps != null && problemIps.size() == 0;
}
示例5: getUsageRecordsPendingQuotaAggregation
import com.cloud.utils.db.TransactionCallback; //導入依賴的package包/類
public Pair<List<? extends UsageVO>, Integer> getUsageRecordsPendingQuotaAggregation(final long accountId, final long domainId) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Getting usage records for account: " + accountId + ", domainId: " + domainId);
}
return Transaction.execute(TransactionLegacy.USAGE_DB, new TransactionCallback<Pair<List<? extends UsageVO>, Integer>>() {
@Override
public Pair<List<? extends UsageVO>, Integer> doInTransaction(final TransactionStatus status) {
Pair<List<UsageVO>, Integer> usageRecords = new Pair<List<UsageVO>, Integer>(new ArrayList<UsageVO>(), 0);
Filter usageFilter = new Filter(UsageVO.class, "startDate", true, 0L, Long.MAX_VALUE);
QueryBuilder<UsageVO> qb = QueryBuilder.create(UsageVO.class);
if (accountId != -1) {
qb.and(qb.entity().getAccountId(), SearchCriteria.Op.EQ, accountId);
}
if (domainId != -1) {
qb.and(qb.entity().getDomainId(), SearchCriteria.Op.EQ, domainId);
}
qb.and(qb.entity().getQuotaCalculated(), SearchCriteria.Op.NEQ, 1);
qb.and(qb.entity().getRawUsage(), SearchCriteria.Op.GT, 0);
if (s_logger.isDebugEnabled()) {
s_logger.debug("Getting usage records" + usageFilter.getOrderBy());
}
usageRecords = searchAndCountAllRecords(qb.create(), usageFilter);
return new Pair<List<? extends UsageVO>, Integer>(usageRecords.first(), usageRecords.second());
}
});
}
示例6: updateResourceCountForAccount
import com.cloud.utils.db.TransactionCallback; //導入依賴的package包/類
@DB
protected boolean updateResourceCountForAccount(final long accountId, final ResourceType type, final boolean increment, final long delta) {
if(s_logger.isDebugEnabled()) {
s_logger.debug("Updating resource Type = " + type + " count for Account = " + accountId +
" Operation = " + (increment ? "increasing" : "decreasing") + " Amount = " + delta);
}
try {
return Transaction.execute(new TransactionCallback<Boolean>() {
@Override
public Boolean doInTransaction(TransactionStatus status) {
boolean result = true;
List<ResourceCountVO> rowsToUpdate = lockAccountAndOwnerDomainRows(accountId, type);
for (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 (Exception ex) {
s_logger.error("Failed to update resource count for account id=" + accountId);
return false;
}
}
示例7: assignNicsToNewPhysicalNetwork
import com.cloud.utils.db.TransactionCallback; //導入依賴的package包/類
@Override
public void assignNicsToNewPhysicalNetwork(Network srcNetwork, Network networkInNewPhysicalNet) {
List<NicVO> nics = _nicDao.listByNetworkId(srcNetwork.getId());
final CallContext cctx = CallContext.current();
final ReservationContext context = new ReservationContextImpl(null, null, cctx.getCallingUser(), cctx.getCallingAccount());
final DataCenter dc = _entityMgr.findById(DataCenter.class, networkInNewPhysicalNet.getDataCenterId());
//For each nic in the old network check if the nic belongs to a guest vm and migrate it to the new network.
for (NicVO originalNic : nics) {
if (originalNic.getVmType() != VirtualMachine.Type.User) {
continue;
}
Transaction.execute((TransactionCallback<Boolean>)
(status) -> migrateNicsInDB(originalNic, networkInNewPhysicalNet, dc, context));
}
//Now that nics are migrated we can migrate the static nats on those nics
reapplyPublicIps(srcNetwork, networkInNewPhysicalNet);
}
示例8: deleteAccountFromProject
import com.cloud.utils.db.TransactionCallback; //導入依賴的package包/類
@Override
@DB
public boolean deleteAccountFromProject(final long projectId, final long accountId) {
return Transaction.execute(new TransactionCallback<Boolean>() {
@Override
public Boolean doInTransaction(TransactionStatus status) {
boolean success = true;
//remove account
ProjectAccountVO projectAccount = _projectAccountDao.findByProjectIdAccountId(projectId, accountId);
success = _projectAccountDao.remove(projectAccount.getId());
//remove all invitations for account
if (success) {
s_logger.debug("Removed account " + accountId + " from project " + projectId + " , cleaning up old invitations for account/project...");
ProjectInvitation invite = _projectInvitationDao.findByAccountIdProjectId(accountId, projectId);
if (invite != null) {
success = success && _projectInvitationDao.remove(invite.getId());
}
}
return success;
}
});
}
示例9: moveUser
import com.cloud.utils.db.TransactionCallback; //導入依賴的package包/類
private boolean moveUser(UserVO user, long newAccountId) {
if(newAccountId == user.getAccountId()) {
// could do a not silent fail but the objective of the user is reached
return true; // no need to create a new user object for this user
}
return Transaction.execute(new TransactionCallback<Boolean>() {
@Override
public Boolean doInTransaction(TransactionStatus status) {
UserVO newUser = new UserVO(user);
user.setExternalEntity(user.getUuid());
user.setUuid(UUID.randomUUID().toString());
_userDao.update(user.getId(),user);
newUser.setAccountId(newAccountId);
boolean success = _userDao.remove(user.getId());
UserVO persisted = _userDao.persist(newUser);
return success && persisted.getUuid().equals(user.getExternalEntity());
}
});
}
示例10: addResourceMetaData
import com.cloud.utils.db.TransactionCallback; //導入依賴的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(TransactionStatus status) {
for (String key : details.keySet()) {
String value = details.get(key);
if (value == null || value.isEmpty()) {
throw new InvalidParameterValueException("Value for the key " + key + " is either null or empty");
}
DetailDaoHelper newDetailDaoHelper = new DetailDaoHelper(resourceType);
newDetailDaoHelper.addDetail(_taggedResourceMgr.getResourceId(resourceId, resourceType), key, value, forDisplay);
}
return true;
}
});
}
示例11: findCredits
import com.cloud.utils.db.TransactionCallback; //導入依賴的package包/類
@Override
public List<QuotaCreditsVO> findCredits(final long accountId, final long domainId, final Date startDate, final Date endDate) {
return Transaction.execute(TransactionLegacy.USAGE_DB, new TransactionCallback<List<QuotaCreditsVO>>() {
@Override
public List<QuotaCreditsVO> doInTransaction(final TransactionStatus status) {
if ((startDate != null) && (endDate != null) && startDate.before(endDate)) {
Filter filter = new Filter(QuotaCreditsVO.class, "updatedOn", true, 0L, Long.MAX_VALUE);
QueryBuilder<QuotaCreditsVO> qb = QueryBuilder.create(QuotaCreditsVO.class);
qb.and(qb.entity().getAccountId(), SearchCriteria.Op.EQ, accountId);
qb.and(qb.entity().getDomainId(), SearchCriteria.Op.EQ, domainId);
qb.and(qb.entity().getUpdatedOn(), SearchCriteria.Op.BETWEEN, startDate, endDate);
return search(qb.create(), filter);
} else {
return Collections.<QuotaCreditsVO> emptyList();
}
}
});
}
示例12: findServiceOffering
import com.cloud.utils.db.TransactionCallback; //導入依賴的package包/類
@Override
public ServiceOfferingVO findServiceOffering(final Long vmId, final long serviceOfferingId) {
return Transaction.execute(TransactionLegacy.CLOUD_DB, new TransactionCallback<ServiceOfferingVO>() {
@Override
public ServiceOfferingVO doInTransaction(final TransactionStatus status) {
ServiceOfferingVO offering = findById(serviceOfferingId);
if (offering.isDynamic()) {
if (vmId == null) {
throw new CloudRuntimeException("missing argument vmId");
}
offering.setDynamicFlag(true);
Map<String, String> dynamicOffering = userVmDetailsDao.listDetailsKeyPairs(vmId);
return getcomputeOffering(offering, dynamicOffering);
}
return offering;
}
});
}
示例13: getcomputeOffering
import com.cloud.utils.db.TransactionCallback; //導入依賴的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;
}
});
}
示例14: findLastQuotaUsageEntry
import com.cloud.utils.db.TransactionCallback; //導入依賴的package包/類
@Override
public QuotaUsageVO findLastQuotaUsageEntry(final Long accountId, final Long domainId, final Date beforeThis) {
return Transaction.execute(TransactionLegacy.USAGE_DB, new TransactionCallback<QuotaUsageVO>() {
@Override
public QuotaUsageVO doInTransaction(final TransactionStatus status) {
List<QuotaUsageVO> quotaUsageEntries = new ArrayList<>();
Filter filter = new Filter(QuotaUsageVO.class, "startDate", false, 0L, 1L);
QueryBuilder<QuotaUsageVO> qb = QueryBuilder.create(QuotaUsageVO.class);
qb.and(qb.entity().getAccountId(), SearchCriteria.Op.EQ, accountId);
qb.and(qb.entity().getDomainId(), SearchCriteria.Op.EQ, domainId);
qb.and(qb.entity().getStartDate(), SearchCriteria.Op.LT, beforeThis);
quotaUsageEntries = search(qb.create(), filter);
return !quotaUsageEntries.isEmpty() ? quotaUsageEntries.get(0) : null;
}
});
}
示例15: findLastBalanceEntry
import com.cloud.utils.db.TransactionCallback; //導入依賴的package包/類
@Override
public QuotaBalanceVO findLastBalanceEntry(final Long accountId, final Long domainId, final Date beforeThis) {
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", false, 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.LT, beforeThis);
quotaBalanceEntries = search(qb.create(), filter);
return !quotaBalanceEntries.isEmpty() ? quotaBalanceEntries.get(0) : null;
}
});
}