use of com.cloud.utils.db.TransactionLegacy in project cloudstack by apache.
the class HighAvailabilityDaoImpl method take.
@Override
public HaWorkVO take(final long serverId) {
final TransactionLegacy txn = TransactionLegacy.currentTxn();
try {
final SearchCriteria<HaWorkVO> sc = TBASearch.create();
sc.setParameters("time", System.currentTimeMillis() >> 10);
sc.setParameters("step", Step.Done, Step.Cancelled);
final Filter filter = new Filter(HaWorkVO.class, null, true, 0l, 1l);
txn.start();
final List<HaWorkVO> vos = lockRows(sc, filter, true);
if (vos.size() == 0) {
txn.commit();
return null;
}
final HaWorkVO work = vos.get(0);
work.setServerId(serverId);
work.setDateTaken(new Date());
update(work.getId(), work);
txn.commit();
return work;
} catch (final Throwable e) {
throw new CloudRuntimeException("Unable to execute take", e);
}
}
use of com.cloud.utils.db.TransactionLegacy in project cloudstack by apache.
the class VmRulesetLogDaoImpl method createOrUpdateUsingBatch.
protected int createOrUpdateUsingBatch(Set<Long> workItems) {
TransactionLegacy txn = TransactionLegacy.currentTxn();
PreparedStatement stmtInsert = null;
int[] queryResult = null;
int count = 0;
boolean success = true;
try {
stmtInsert = txn.prepareAutoCloseStatement(InsertOrUpdateSQl);
txn.start();
for (Long vmId : workItems) {
stmtInsert.setLong(1, vmId);
stmtInsert.addBatch();
count++;
if (count % 16 == 0) {
queryResult = stmtInsert.executeBatch();
stmtInsert.clearBatch();
}
}
queryResult = stmtInsert.executeBatch();
txn.commit();
if (s_logger.isTraceEnabled())
s_logger.trace("Updated or inserted " + workItems.size() + " log items");
} catch (SQLException e) {
s_logger.warn("Failed to execute batch update statement for ruleset log: ", e);
txn.rollback();
success = false;
}
if (!success && queryResult != null) {
Long[] arrayItems = new Long[workItems.size()];
workItems.toArray(arrayItems);
for (int i = 0; i < queryResult.length; i++) {
if (queryResult[i] < 0) {
s_logger.debug("Batch query update failed for vm " + arrayItems[i]);
}
}
}
return count;
}
use of com.cloud.utils.db.TransactionLegacy in project cloudstack by apache.
the class NetworkACLItemCidrsDaoImpl method persist.
/* (non-Javadoc)
* @see com.cloud.network.dao.NetworkAclItemCidrsDao#persist(long, java.util.List)
*/
@Override
public void persist(long networkACLItemId, List<String> cidrs) {
TransactionLegacy txn = TransactionLegacy.currentTxn();
txn.start();
for (String cidr : cidrs) {
NetworkACLItemCidrsVO vo = new NetworkACLItemCidrsVO(networkACLItemId, cidr);
persist(vo);
}
txn.commit();
}
use of com.cloud.utils.db.TransactionLegacy in project cloudstack by apache.
the class IPAddressDaoImpl method countIPs.
@Override
@DB
public int countIPs(long dcId, Long accountId, String vlanId, String vlanGateway, String vlanNetmask) {
TransactionLegacy txn = TransactionLegacy.currentTxn();
int ipCount = 0;
try {
String sql = "SELECT count(*) FROM user_ip_address u INNER JOIN vlan v on (u.vlan_db_id = v.id AND v.data_center_id = ? AND v.vlan_id = ? AND v.vlan_gateway = ? AND v.vlan_netmask = ? AND u.account_id = ?)";
PreparedStatement pstmt = txn.prepareAutoCloseStatement(sql);
pstmt.setLong(1, dcId);
pstmt.setString(2, vlanId);
pstmt.setString(3, vlanGateway);
pstmt.setString(4, vlanNetmask);
pstmt.setLong(5, accountId);
ResultSet rs = pstmt.executeQuery();
if (rs.next()) {
ipCount = rs.getInt(1);
}
} catch (Exception e) {
s_logger.warn("Exception counting IP addresses", e);
}
return ipCount;
}
use of com.cloud.utils.db.TransactionLegacy in project cloudstack by apache.
the class NetworkDaoImpl method persistNetworkServiceProviders.
@Override
@DB
public void persistNetworkServiceProviders(final long networkId, final Map<String, String> serviceProviderMap) {
final TransactionLegacy txn = TransactionLegacy.currentTxn();
txn.start();
for (final String service : serviceProviderMap.keySet()) {
final NetworkServiceMapVO serviceMap = new NetworkServiceMapVO(networkId, Service.getService(service), Provider.getProvider(serviceProviderMap.get(service)));
_ntwkSvcMap.persist(serviceMap);
}
txn.commit();
}
Aggregations