Search in sources :

Example 86 with TransactionLegacy

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();
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) ResourceCountVO(com.cloud.configuration.ResourceCountVO) ResourceType(com.cloud.configuration.Resource.ResourceType) DB(com.cloud.utils.db.DB)

Example 87 with TransactionLegacy

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();
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) Map(java.util.Map) HashMap(java.util.HashMap)

Example 88 with TransactionLegacy

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();
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy)

Example 89 with TransactionLegacy

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;
}
Also used : AlertVO(com.cloud.alert.AlertVO) TransactionLegacy(com.cloud.utils.db.TransactionLegacy)

Example 90 with TransactionLegacy

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);
    }
}
Also used : SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) TransactionLegacy(com.cloud.utils.db.TransactionLegacy) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ResultSet(java.sql.ResultSet)

Aggregations

TransactionLegacy (com.cloud.utils.db.TransactionLegacy)368 PreparedStatement (java.sql.PreparedStatement)174 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)149 SQLException (java.sql.SQLException)133 ResultSet (java.sql.ResultSet)102 ArrayList (java.util.ArrayList)98 DB (com.cloud.utils.db.DB)95 ConfigurationException (javax.naming.ConfigurationException)54 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)35 Date (java.util.Date)34 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)31 HashMap (java.util.HashMap)29 URISyntaxException (java.net.URISyntaxException)28 AccountVO (com.cloud.user.AccountVO)21 CloudException (com.cloud.exception.CloudException)20 Account (com.cloud.user.Account)20 Field (java.lang.reflect.Field)19 MockVolumeVO (com.cloud.simulator.MockVolumeVO)18 AgentManager (com.cloud.agent.AgentManager)13 IPAddressDao (com.cloud.network.dao.IPAddressDao)13