Search in sources :

Example 51 with TransactionLegacy

use of com.cloud.utils.db.TransactionLegacy in project cloudstack by apache.

the class HostDetailsDaoImpl method persist.

@Override
public void persist(long hostId, Map<String, String> details) {
    final String InsertOrUpdateSql = "INSERT INTO `cloud`.`host_details` (host_id, name, value) VALUES (?,?,?) ON DUPLICATE KEY UPDATE value=?";
    TransactionLegacy txn = TransactionLegacy.currentTxn();
    txn.start();
    for (Map.Entry<String, String> detail : details.entrySet()) {
        String value = detail.getValue();
        if ("password".equals(detail.getKey())) {
            value = DBEncryptionUtil.encrypt(value);
        }
        try {
            PreparedStatement pstmt = txn.prepareAutoCloseStatement(InsertOrUpdateSql);
            pstmt.setLong(1, hostId);
            pstmt.setString(2, detail.getKey());
            pstmt.setString(3, value);
            pstmt.setString(4, value);
            pstmt.executeUpdate();
        } catch (SQLException e) {
            throw new CloudRuntimeException("Unable to persist the host_details key: " + detail.getKey() + " for host id: " + hostId, e);
        }
    }
    txn.commit();
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) SQLException(java.sql.SQLException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PreparedStatement(java.sql.PreparedStatement) HashMap(java.util.HashMap) Map(java.util.Map)

Example 52 with TransactionLegacy

use of com.cloud.utils.db.TransactionLegacy in project cloudstack by apache.

the class EngineDataCenterDaoImpl method remove.

@Override
public boolean remove(Long id) {
    TransactionLegacy txn = TransactionLegacy.currentTxn();
    txn.start();
    EngineDataCenterVO zone = createForUpdate();
    zone.setName(null);
    update(id, zone);
    boolean result = super.remove(id);
    txn.commit();
    return result;
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) EngineDataCenterVO(org.apache.cloudstack.engine.datacenter.entity.api.db.EngineDataCenterVO)

Example 53 with TransactionLegacy

use of com.cloud.utils.db.TransactionLegacy in project cloudstack by apache.

the class EngineHostPodDaoImpl method remove.

@Override
public boolean remove(Long id) {
    TransactionLegacy txn = TransactionLegacy.currentTxn();
    txn.start();
    EngineHostPodVO pod = createForUpdate();
    pod.setName(null);
    update(id, pod);
    boolean result = super.remove(id);
    txn.commit();
    return result;
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) EngineHostPodVO(org.apache.cloudstack.engine.datacenter.entity.api.db.EngineHostPodVO)

Example 54 with TransactionLegacy

use of com.cloud.utils.db.TransactionLegacy in project cloudstack by apache.

the class TestNGAop method intercept.

@Override
public List<IMethodInstance> intercept(List<IMethodInstance> methods, ITestContext context) {
    for (IMethodInstance methodIns : methods) {
        ITestNGMethod method = methodIns.getMethod();
        ConstructorOrMethod meth = method.getConstructorOrMethod();
        Method m = meth.getMethod();
        if (m != null) {
            DB db = m.getAnnotation(DB.class);
            if (db != null) {
                TransactionLegacy txn = TransactionLegacy.open(m.getName());
            }
        }
    }
    // TODO Auto-generated method stub
    return methods;
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) ITestNGMethod(org.testng.ITestNGMethod) IMethodInstance(org.testng.IMethodInstance) ITestNGMethod(org.testng.ITestNGMethod) Method(java.lang.reflect.Method) ConstructorOrMethod(org.testng.internal.ConstructorOrMethod) DB(com.cloud.utils.db.DB) ConstructorOrMethod(org.testng.internal.ConstructorOrMethod)

Example 55 with TransactionLegacy

use of com.cloud.utils.db.TransactionLegacy in project cloudstack by apache.

the class SAMLTokenDaoImpl method expireTokens.

@Override
public void expireTokens() {
    TransactionLegacy txn = TransactionLegacy.currentTxn();
    try {
        txn.start();
        String sql = "DELETE FROM `saml_token` WHERE `created` < (NOW() - INTERVAL 1 HOUR)";
        PreparedStatement pstmt = txn.prepareAutoCloseStatement(sql);
        pstmt.executeUpdate();
        txn.commit();
    } catch (Exception e) {
        txn.rollback();
        throw new CloudRuntimeException("Unable to flush old SAML tokens due to exception", e);
    }
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PreparedStatement(java.sql.PreparedStatement) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

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