Search in sources :

Example 46 with DatabaseAccessException

use of com.axway.ats.log.autodb.exceptions.DatabaseAccessException in project ats-framework by Axway.

the class DbWriteAccess method insertSystemStatistics.

public void insertSystemStatistics(int testCaseId, String machine, String statisticIds, String statisticValues, long timestamp, boolean closeConnection) throws DatabaseAccessException {
    CallableStatement callableStatement = null;
    try {
        refreshInternalConnection();
        callableStatement = connection.prepareCall("{ call sp_insert_system_statistic_by_ids(?, ?, ?, ?, ?) }");
        callableStatement.setString(3, statisticIds);
        callableStatement.setInt(1, testCaseId);
        callableStatement.setString(2, machine);
        callableStatement.setString(4, statisticValues);
        callableStatement.setTimestamp(5, new Timestamp(timestamp));
        callableStatement.execute();
    } catch (Exception e) {
        String errMsg = "Unable to insert system statistics, statistic IDs '" + statisticIds + "', statistic values '" + statisticValues + "', timestamp " + timestamp;
        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) SQLException(java.sql.SQLException) DatabaseAccessException(com.axway.ats.log.autodb.exceptions.DatabaseAccessException)

Example 47 with DatabaseAccessException

use of com.axway.ats.log.autodb.exceptions.DatabaseAccessException in project ats-framework by Axway.

the class DbWriteAccess method startLoadQueue.

public int startLoadQueue(String name, int sequence, String hostsList, String threadingPattern, int numberThreads, String machine, long timestamp, int testcaseId, boolean closeConnection) throws DatabaseAccessException {
    if (testcaseId < 1) {
        log.warn("Load queue '" + name + "' will not be registered because there is no database connection!");
        return -1;
    }
    final String errMsg = "Unable to start load queue with name " + name;
    // create a new load queue
    final int indexRowsInserted = 9;
    final int indexLoadQueueId = 10;
    CallableStatement callableStatement = null;
    try {
        refreshInternalConnection();
        callableStatement = connection.prepareCall("{ call sp_start_loadqueue(?, ?, ?, ?, ?, ?, ?, ?, ?, ?) }");
        callableStatement.setInt(1, testcaseId);
        callableStatement.setString(2, name);
        callableStatement.setInt(3, sequence);
        callableStatement.setString(4, hostsList);
        callableStatement.setString(5, threadingPattern);
        callableStatement.setInt(6, numberThreads);
        callableStatement.setString(7, machine);
        callableStatement.setTimestamp(8, new Timestamp(timestamp));
        callableStatement.registerOutParameter(indexRowsInserted, Types.INTEGER);
        callableStatement.registerOutParameter(indexLoadQueueId, Types.INTEGER);
        callableStatement.execute();
        if (callableStatement.getInt(indexRowsInserted) != 1) {
            throw new DatabaseAccessException(errMsg);
        } else {
            if (callableStatement.getInt(indexLoadQueueId) == 0) {
                throw new DatabaseAccessException(errMsg + " - load queue id returned was 0");
            }
        }
        // get the result
        return callableStatement.getInt(indexLoadQueueId);
    } 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 48 with DatabaseAccessException

use of com.axway.ats.log.autodb.exceptions.DatabaseAccessException in project ats-framework by Axway.

the class DbWriteAccess method insertCheckpoint.

public boolean insertCheckpoint(String name, String threadName, long startTimestamp, long responseTime, long transferSize, String transferUnit, int result, int loadQueueId, boolean closeConnection) throws DatabaseAccessException {
    Connection currentConnection;
    if (!isBatchMode) {
        currentConnection = refreshInternalConnection();
    } else {
        currentConnection = dbEventsCache.connection;
    }
    CallableStatement insertCheckpointStatement = insertFactory.getInsersCheckpointStatement(currentConnection, name, threadName, responseTime, startTimestamp + responseTime, transferSize, transferUnit, result, checkpointLogLevel, loadQueueId);
    if (isBatchMode) {
        // schedule this event for batch execution
        return dbEventsCache.addInsertCheckpointEventToBatch(insertCheckpointStatement);
    } else {
        // execute this event now
        final String errMsg = "Unable to insert checkpoint '" + name + "'";
        try {
            insertCheckpointStatement.execute();
        //                if( insertCheckpointStatement.getInt( indexRowsInserted ) < 1 ) {
        //                    throw new DatabaseAccessException( errMsg );
        //                }
        } catch (SQLException e) {
            throw new DatabaseAccessException(errMsg, e);
        } finally {
            if (closeConnection) {
                DbUtils.close(connection, insertCheckpointStatement);
            } else {
                DbUtils.closeStatement(insertCheckpointStatement);
            }
        }
        return false;
    }
}
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 49 with DatabaseAccessException

use of com.axway.ats.log.autodb.exceptions.DatabaseAccessException in project ats-framework by Axway.

the class DbWriteAccess method endTestCase.

public void endTestCase(int testcaseResult, long timestamp, int testcaseId, boolean closeConnection) throws DatabaseAccessException {
    final String errMsg = "Unable to end testcase with id " + testcaseId;
    final int indexRowsInserted = 4;
    CallableStatement callableStatement = null;
    try {
        refreshInternalConnection();
        callableStatement = connection.prepareCall("{ call sp_end_testcase(?, ?, ?, ?) }");
        callableStatement.setInt(1, testcaseId);
        callableStatement.setInt(2, testcaseResult);
        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)

Example 50 with DatabaseAccessException

use of com.axway.ats.log.autodb.exceptions.DatabaseAccessException in project ats-framework by Axway.

the class AbstractDbAccess method getDatabaseVersion.

public String getDatabaseVersion() throws DatabaseAccessException {
    if (dbVersion == null) {
        Connection connection = getConnection();
        PreparedStatement statement = null;
        ResultSet rs = null;
        try {
            statement = connection.prepareStatement("SELECT value from tInternal where [key] = 'version'");
            rs = statement.executeQuery();
            // we expect only one record
            if (rs.next()) {
                dbVersion = rs.getString(1);
            } else {
                throw new DatabaseAccessException("Could not fetch the DB version");
            }
        } catch (Exception e) {
            throw new DatabaseAccessException("Error fetching DB version", e);
        } finally {
            DbUtils.closeResultSet(rs);
            DbUtils.close(connection, statement);
        }
    }
    return dbVersion;
}
Also used : Connection(java.sql.Connection) DbConnection(com.axway.ats.core.dbaccess.DbConnection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) DatabaseAccessException(com.axway.ats.log.autodb.exceptions.DatabaseAccessException) DatabaseAccessException(com.axway.ats.log.autodb.exceptions.DatabaseAccessException) DbException(com.axway.ats.core.dbaccess.exceptions.DbException)

Aggregations

DatabaseAccessException (com.axway.ats.log.autodb.exceptions.DatabaseAccessException)57 SQLException (java.sql.SQLException)52 CallableStatement (java.sql.CallableStatement)45 DbConnection (com.axway.ats.core.dbaccess.DbConnection)35 Connection (java.sql.Connection)34 ResultSet (java.sql.ResultSet)28 Checkpoint (com.axway.ats.log.autodb.entities.Checkpoint)23 ArrayList (java.util.ArrayList)18 Timestamp (java.sql.Timestamp)14 PreparedStatement (java.sql.PreparedStatement)7 HashMap (java.util.HashMap)5 Statistic (com.axway.ats.log.autodb.entities.Statistic)4 Message (com.axway.ats.log.autodb.entities.Message)3 SimpleDateFormat (java.text.SimpleDateFormat)3 BackwardCompatibility (com.axway.ats.core.utils.BackwardCompatibility)2 Run (com.axway.ats.log.autodb.entities.Run)2 StatisticDescription (com.axway.ats.log.autodb.entities.StatisticDescription)2 Suite (com.axway.ats.log.autodb.entities.Suite)2 AgentException (com.axway.ats.agent.core.exceptions.AgentException)1 DbException (com.axway.ats.core.dbaccess.exceptions.DbException)1