clean up transation code

This commit is contained in:
anthony 2011-04-12 18:56:30 -07:00
parent 80fe0b584d
commit e0ba2a2fa6
5 changed files with 9 additions and 15 deletions

View File

@ -28,6 +28,7 @@ import javax.ejb.Local;
import org.apache.log4j.Logger;
import com.cloud.domain.DomainVO;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.GlobalLock;
import com.cloud.utils.db.SearchBuilder;
@ -133,7 +134,8 @@ public class DomainDaoImpl extends GenericDaoBase<DomainVO, Long> implements Dom
}
}
@Override
@Override
@DB
public boolean remove(Long id) {
// check for any active users / domains assigned to the given domain id and don't remove the domain if there are any
if (id != null && id.longValue() == DomainVO.ROOT_DOMAIN) {
@ -162,20 +164,17 @@ public class DomainDaoImpl extends GenericDaoBase<DomainVO, Long> implements Dom
DomainVO parentDomain = super.lockRow(domain.getParent(), true);
if(parentDomain == null) {
s_logger.error("Unable to load parent domain: " + domain.getParent());
txn.commit();
return false;
}
PreparedStatement stmt = txn.prepareAutoCloseStatement(sql);
ResultSet rs = stmt.executeQuery();
if (rs.next()) {
txn.commit();
return false;
}
stmt = txn.prepareAutoCloseStatement(sql1);
rs = stmt.executeQuery();
if (rs.next()) {
txn.commit();
return false;
}

View File

@ -817,7 +817,6 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
@DB
public List<NetworkVO> setupNetwork(Account owner, NetworkOfferingVO offering, Network predefined, DeploymentPlan plan, String name, String displayText, boolean isShared, boolean isDefault,
boolean errorIfAlreadySetup, Long domainId) throws ConcurrentOperationException {
Transaction.currentTxn();
Account locked = _accountDao.acquireInLockTable(owner.getId());
if (locked == null) {
throw new ConcurrentOperationException("Unable to acquire lock on " + owner);

View File

@ -74,6 +74,7 @@ public class OvsWorkDaoImpl extends GenericDaoBase<OvsWorkVO, Long> implements
}
@Override
@DB
public OvsWorkVO take(long serverId) {
final Transaction txn = Transaction.currentTxn();
try {
@ -85,7 +86,6 @@ public class OvsWorkDaoImpl extends GenericDaoBase<OvsWorkVO, Long> implements
txn.start();
final List<OvsWorkVO> vos = lockRows(sc, filter, true);
if (vos.size() == 0) {
txn.commit();
return null;
}
OvsWorkVO work = null;
@ -97,7 +97,6 @@ public class OvsWorkDaoImpl extends GenericDaoBase<OvsWorkVO, Long> implements
}
}
if (work == null) {
txn.commit();
return null;
}
work.setServerId(serverId);
@ -128,7 +127,6 @@ public class OvsWorkDaoImpl extends GenericDaoBase<OvsWorkVO, Long> implements
final List<OvsWorkVO> vos = lockRows(sc, filter, true);
if (vos.size() == 0) {
txn.commit();
return;
}
OvsWorkVO work = vos.get(0);
@ -147,13 +145,13 @@ public class OvsWorkDaoImpl extends GenericDaoBase<OvsWorkVO, Long> implements
}
@Override
@DB
public void updateStep(Long workId, Step step) {
final Transaction txn = Transaction.currentTxn();
txn.start();
OvsWorkVO work = lockRow(workId, true);
if (work == null) {
txn.commit();
return;
}
work.setStep(step);

View File

@ -26,6 +26,7 @@ import javax.ejb.Local;
import com.cloud.ha.HaWorkVO;
import com.cloud.network.security.SecurityGroupWorkVO;
import com.cloud.network.security.SecurityGroupWorkVO.Step;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.Filter;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.SearchBuilder;
@ -93,6 +94,7 @@ public class SecurityGroupWorkDaoImpl extends GenericDaoBase<SecurityGroupWorkVO
}
@Override
@DB
public SecurityGroupWorkVO take(long serverId) {
final Transaction txn = Transaction.currentTxn();
try {
@ -104,7 +106,6 @@ public class SecurityGroupWorkDaoImpl extends GenericDaoBase<SecurityGroupWorkVO
txn.start();
final List<SecurityGroupWorkVO> vos = lockRows(sc, filter, true);
if (vos.size() == 0) {
txn.commit();
return null;
}
SecurityGroupWorkVO work = null;
@ -116,7 +117,6 @@ public class SecurityGroupWorkDaoImpl extends GenericDaoBase<SecurityGroupWorkVO
}
}
if (work == null) {
txn.commit();
return null;
}
work.setServerId(serverId);
@ -135,6 +135,7 @@ public class SecurityGroupWorkDaoImpl extends GenericDaoBase<SecurityGroupWorkVO
}
@Override
@DB
public void updateStep(Long vmId, Long logSequenceNumber, Step step) {
final Transaction txn = Transaction.currentTxn();
txn.start();
@ -146,7 +147,6 @@ public class SecurityGroupWorkDaoImpl extends GenericDaoBase<SecurityGroupWorkVO
final List<SecurityGroupWorkVO> vos = lockRows(sc, filter, true);
if (vos.size() == 0) {
txn.commit();
return;
}
SecurityGroupWorkVO work = vos.get(0);
@ -165,13 +165,13 @@ public class SecurityGroupWorkDaoImpl extends GenericDaoBase<SecurityGroupWorkVO
}
@Override
@DB
public void updateStep(Long workId, Step step) {
final Transaction txn = Transaction.currentTxn();
txn.start();
SecurityGroupWorkVO work = lockRow(workId, true);
if (work == null) {
txn.commit();
return;
}
work.setStep(step);

View File

@ -1928,7 +1928,6 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
// set the pool state to prepare for maintenance
primaryStorage.setStatus(StoragePoolStatus.PrepareForMaintenance);
_storagePoolDao.update(primaryStorageId, primaryStorage);
txn.commit();
// check to see if other ps exist
// if they do, then we can migrate over the system vms to them
@ -2148,7 +2147,6 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
primaryStorage.setStatus(StoragePoolStatus.CancelMaintenance);
_storagePoolDao.update(primaryStorageId, primaryStorage);
txn.commit();
txn.close();
// 2. Get a list of pending work for this queue
List<StoragePoolWorkVO> pendingWork = _storagePoolWorkDao.listPendingWorkForCancelMaintenanceByPoolId(primaryStorageId);