use of com.cloud.utils.db.TransactionLegacy in project cloudstack by apache.
the class ResourceCountDaoImpl method createResourceCounts.
@Override
@DB
public void createResourceCounts(long ownerId, ResourceLimit.ResourceOwnerType ownerType) {
TransactionLegacy txn = TransactionLegacy.currentTxn();
txn.start();
ResourceType[] resourceTypes = Resource.ResourceType.values();
for (ResourceType resourceType : resourceTypes) {
if (!resourceType.supportsOwner(ownerType)) {
continue;
}
ResourceCountVO resourceCountVO = new ResourceCountVO(resourceType, 0, ownerId, ownerType);
persist(resourceCountVO);
}
txn.commit();
}
use of com.cloud.utils.db.TransactionLegacy in project cloudstack by apache.
the class ClusterDetailsDaoImpl method persist.
@Override
public void persist(long clusterId, Map<String, String> details) {
TransactionLegacy txn = TransactionLegacy.currentTxn();
txn.start();
SearchCriteria<ClusterDetailsVO> sc = ClusterSearch.create();
sc.setParameters("clusterId", clusterId);
expunge(sc);
for (Map.Entry<String, String> detail : details.entrySet()) {
String value = detail.getValue();
if ("password".equals(detail.getKey())) {
value = DBEncryptionUtil.encrypt(value);
}
ClusterDetailsVO vo = new ClusterDetailsVO(clusterId, detail.getKey(), value);
persist(vo);
}
txn.commit();
}
use of com.cloud.utils.db.TransactionLegacy in project cloudstack by apache.
the class ClusterDetailsDaoImpl method persist.
@Override
public void persist(long clusterId, String name, String value) {
TransactionLegacy txn = TransactionLegacy.currentTxn();
txn.start();
SearchCriteria<ClusterDetailsVO> sc = DetailSearch.create();
sc.setParameters("clusterId", clusterId);
sc.setParameters("name", name);
expunge(sc);
ClusterDetailsVO vo = new ClusterDetailsVO(clusterId, name, value);
persist(vo);
txn.commit();
}
use of com.cloud.utils.db.TransactionLegacy in project cloudstack by apache.
the class AlertDaoImpl method archiveAlert.
@Override
public boolean archiveAlert(List<Long> ids, String type, Date startDate, Date endDate, Long zoneId) {
SearchCriteria<AlertVO> sc = AlertSearchByIdsAndType.create();
if (ids != null) {
sc.setParameters("id", ids.toArray(new Object[ids.size()]));
}
if (type != null) {
sc.setParameters("type", type);
}
if (zoneId != null) {
sc.setParameters("data_center_id", zoneId);
}
if (startDate != null && endDate != null) {
sc.setParameters("createdDateB", startDate, endDate);
} else if (endDate != null) {
sc.setParameters("createdDateL", endDate);
}
sc.setParameters("archived", false);
boolean result = true;
;
List<AlertVO> alerts = listBy(sc);
if (ids != null && alerts.size() < ids.size()) {
result = false;
return result;
}
if (alerts != null && !alerts.isEmpty()) {
TransactionLegacy txn = TransactionLegacy.currentTxn();
txn.start();
for (AlertVO alert : alerts) {
alert = lockRow(alert.getId(), true);
alert.setArchived(true);
update(alert.getId(), alert);
txn.commit();
}
txn.close();
}
return result;
}
use of com.cloud.utils.db.TransactionLegacy in project cloudstack by apache.
the class CapacityDaoImpl method findByClusterPodZone.
@Override
public List<SummedCapacity> findByClusterPodZone(Long zoneId, Long podId, Long clusterId) {
TransactionLegacy txn = TransactionLegacy.currentTxn();
PreparedStatement pstmt = null;
List<SummedCapacity> result = new ArrayList<SummedCapacity>();
StringBuilder sql = new StringBuilder(LIST_CAPACITY_GROUP_BY_CAPACITY_PART1);
List<Long> resourceIdList = new ArrayList<Long>();
if (zoneId != null) {
sql.append(" AND capacity.data_center_id = ?");
resourceIdList.add(zoneId);
}
if (podId != null) {
sql.append(" AND capacity.pod_id = ?");
resourceIdList.add(podId);
}
if (clusterId != null) {
sql.append(" AND capacity.cluster_id = ?");
resourceIdList.add(clusterId);
}
sql.append(LIST_CAPACITY_GROUP_BY_CAPACITY_PART2);
try {
pstmt = txn.prepareAutoCloseStatement(sql.toString());
for (int i = 0; i < resourceIdList.size(); i++) {
pstmt.setLong(i + 1, resourceIdList.get(i));
}
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
SummedCapacity summedCapacity = new SummedCapacity(rs.getLong(1), rs.getLong(2), rs.getLong(3), (short) rs.getLong(5), null, null, rs.getLong(6));
result.add(summedCapacity);
}
return result;
} catch (SQLException e) {
throw new CloudRuntimeException("DB Exception on: " + sql, e);
} catch (Throwable e) {
throw new CloudRuntimeException("Caught: " + sql, e);
}
}
Aggregations