Search in sources :

Example 81 with CallableStatement

use of java.sql.CallableStatement in project ats-framework by Axway.

the class DbWriteAccess method populateSystemStatisticDefinition.

public int populateSystemStatisticDefinition(String name, String parentName, String internalName, String unit, String params) throws DatabaseAccessException {
    if (parentName == null) {
        parentName = "";
    }
    if (internalName == null) {
        internalName = "";
    }
    CallableStatement callableStatement = null;
    Connection con = null;
    boolean useLocalConnection = false;
    try {
        if (connection == null || connection.isClosed()) {
            // connection not set externally so use new connection only for this method invocation
            useLocalConnection = true;
            con = getConnection();
        } else {
            useLocalConnection = false;
            con = connection;
        }
        final int statisticId = 6;
        callableStatement = con.prepareCall("{ call sp_populate_system_statistic_definition(?, ?, ?, ?, ?, ?) }");
        callableStatement.setString(1, parentName);
        callableStatement.setString(2, internalName);
        callableStatement.setString(3, name);
        callableStatement.setString(4, unit);
        callableStatement.setString(5, params);
        callableStatement.registerOutParameter(statisticId, Types.INTEGER);
        callableStatement.execute();
        return callableStatement.getInt(statisticId);
    } catch (Exception e) {
        String errMsg = "Unable to populate statistic '" + name + "' with unit '" + unit + "' and params '" + params + "'";
        throw new DatabaseAccessException(errMsg, e);
    } finally {
        DbUtils.closeStatement(callableStatement);
        if (useLocalConnection) {
            DbUtils.closeConnection(con);
        }
    }
}
Also used : CallableStatement(java.sql.CallableStatement) Connection(java.sql.Connection) DbConnection(com.axway.ats.core.dbaccess.DbConnection) DatabaseAccessException(com.axway.ats.log.autodb.exceptions.DatabaseAccessException) SQLException(java.sql.SQLException) DatabaseAccessException(com.axway.ats.log.autodb.exceptions.DatabaseAccessException)

Example 82 with CallableStatement

use of java.sql.CallableStatement in project ats-framework by Axway.

the class DbWriteAccess method addScenarioMetainfo.

/**
     * Update meta info about an existing test scenario.
     * This data is expected to come from java method annotations
     *
     * @param testcaseId
     * @param metaKey
     * @param metaValue
     * @param closeConnection
     * @throws DatabaseAccessException
     */
public void addScenarioMetainfo(int testcaseId, String metaKey, String metaValue, boolean closeConnection) throws DatabaseAccessException {
    final String errMsg = "Unable to add scenario meta info '" + metaKey + "=" + metaValue + "' to scenario for testcase with id " + testcaseId;
    final int indexRowsInserted = 4;
    CallableStatement callableStatement = null;
    try {
        refreshInternalConnection();
        callableStatement = connection.prepareCall("{ call sp_add_scenario_metainfo(?, ?, ?, ?) }");
        callableStatement.setInt(1, testcaseId);
        callableStatement.setString(2, metaKey);
        callableStatement.setString(3, metaValue);
        callableStatement.registerOutParameter(indexRowsInserted, Types.INTEGER);
        callableStatement.execute();
        if (callableStatement.getInt(indexRowsInserted) != 1) {
            throw new DatabaseAccessException(errMsg);
        }
    } catch (Exception e) {
        throw new DatabaseAccessException(errMsg, e);
    } finally {
        if (closeConnection) {
            DbUtils.close(connection, callableStatement);
        } else {
            DbUtils.closeStatement(callableStatement);
        }
    }
}
Also used : CallableStatement(java.sql.CallableStatement) DatabaseAccessException(com.axway.ats.log.autodb.exceptions.DatabaseAccessException) DatabaseAccessException(com.axway.ats.log.autodb.exceptions.DatabaseAccessException) SQLException(java.sql.SQLException)

Example 83 with CallableStatement

use of java.sql.CallableStatement in project ats-framework by Axway.

the class DbWriteAccess method deleteTestcase.

public void deleteTestcase(List<Object> objectsToDelete) throws DatabaseAccessException {
    StringBuilder testcaseIds = new StringBuilder();
    for (Object obj : objectsToDelete) {
        testcaseIds.append(((Testcase) obj).testcaseId);
        testcaseIds.append(",");
    }
    testcaseIds.delete(testcaseIds.length() - 1, testcaseIds.length());
    final String errMsg = "Unable to delete testcase(s) with id " + testcaseIds;
    Connection connection = getConnection();
    CallableStatement callableStatement = null;
    try {
        callableStatement = connection.prepareCall("{ call sp_delete_testcase(?) }");
        callableStatement.setString(1, testcaseIds.toString());
        callableStatement.execute();
    } catch (SQLException e) {
        throw new DatabaseAccessException(errMsg, e);
    } finally {
        DbUtils.close(connection, callableStatement);
    }
}
Also used : SQLException(java.sql.SQLException) CallableStatement(java.sql.CallableStatement) Connection(java.sql.Connection) DbConnection(com.axway.ats.core.dbaccess.DbConnection) DatabaseAccessException(com.axway.ats.log.autodb.exceptions.DatabaseAccessException)

Example 84 with CallableStatement

use of java.sql.CallableStatement in project ats-framework by Axway.

the class DbWriteAccess method endSuite.

public void endSuite(long timestamp, int suiteId, boolean closeConnection) throws DatabaseAccessException {
    final String errMsg = "Unable to end suite with id " + suiteId;
    final int indexRowsInserted = 3;
    CallableStatement callableStatement = null;
    try {
        refreshInternalConnection();
        callableStatement = connection.prepareCall("{ call sp_end_suite(?, ?, ?) }");
        callableStatement.setInt(1, suiteId);
        callableStatement.setTimestamp(2, new Timestamp(timestamp));
        callableStatement.registerOutParameter(indexRowsInserted, Types.INTEGER);
        callableStatement.execute();
        if (callableStatement.getInt(indexRowsInserted) != 1) {
            throw new DatabaseAccessException(errMsg);
        }
    } catch (Exception e) {
        throw new DatabaseAccessException(errMsg, e);
    } finally {
        if (closeConnection) {
            DbUtils.close(connection, callableStatement);
        } else {
            DbUtils.closeStatement(callableStatement);
        }
    }
}
Also used : CallableStatement(java.sql.CallableStatement) Timestamp(java.sql.Timestamp) DatabaseAccessException(com.axway.ats.log.autodb.exceptions.DatabaseAccessException) DatabaseAccessException(com.axway.ats.log.autodb.exceptions.DatabaseAccessException) SQLException(java.sql.SQLException)

Example 85 with CallableStatement

use of java.sql.CallableStatement in project ats-framework by Axway.

the class DbWriteAccess method endLoadQueue.

public void endLoadQueue(int result, long timestamp, int loadQueueId, boolean closeConnection) throws DatabaseAccessException {
    final String errMsg = "Unable to end load queue with id " + loadQueueId;
    final int indexRowsInserted = 4;
    CallableStatement callableStatement = null;
    try {
        refreshInternalConnection();
        callableStatement = connection.prepareCall("{ call sp_end_loadqueue(?, ?, ?, ?) }");
        callableStatement.setInt(1, loadQueueId);
        callableStatement.setInt(2, result);
        callableStatement.setTimestamp(3, new Timestamp(timestamp));
        callableStatement.registerOutParameter(indexRowsInserted, Types.INTEGER);
        callableStatement.execute();
        if (callableStatement.getInt(indexRowsInserted) != 1) {
            throw new DatabaseAccessException(errMsg);
        }
    } catch (Exception e) {
        throw new DatabaseAccessException(errMsg, e);
    } finally {
        if (closeConnection) {
            DbUtils.close(connection, callableStatement);
        } else {
            DbUtils.closeStatement(callableStatement);
        }
    }
}
Also used : CallableStatement(java.sql.CallableStatement) Timestamp(java.sql.Timestamp) DatabaseAccessException(com.axway.ats.log.autodb.exceptions.DatabaseAccessException) DatabaseAccessException(com.axway.ats.log.autodb.exceptions.DatabaseAccessException) SQLException(java.sql.SQLException)

Aggregations

CallableStatement (java.sql.CallableStatement)273 SQLException (java.sql.SQLException)138 Connection (java.sql.Connection)125 ResultSet (java.sql.ResultSet)60 DatabaseAccessException (com.axway.ats.log.autodb.exceptions.DatabaseAccessException)45 DbConnection (com.axway.ats.core.dbaccess.DbConnection)28 Checkpoint (com.axway.ats.log.autodb.entities.Checkpoint)22 ArrayList (java.util.ArrayList)22 PreparedStatement (java.sql.PreparedStatement)21 CouldntSaveDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException)20 Timestamp (java.sql.Timestamp)18 Test (org.junit.Test)16 CouldntDeleteException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntDeleteException)15 Statement (java.sql.Statement)14 HashMap (java.util.HashMap)10 CConnection (com.google.security.zynamics.binnavi.Database.CConnection)8 MockCallableStatement (com.alibaba.druid.mock.MockCallableStatement)7 MaybeNullException (com.google.security.zynamics.binnavi.Exceptions.MaybeNullException)6 BigInteger (java.math.BigInteger)6 OracleCallableStatement (oracle.jdbc.OracleCallableStatement)6