Search in sources :

Example 26 with DatabaseAccessException

use of com.axway.ats.log.autodb.exceptions.DatabaseAccessException 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 27 with DatabaseAccessException

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

the class ReportExtactor method extractRunEntities.

/**
     * extract the runs
     * 
     * @param runIds
     * @return
     */
private List<RunWrapper> extractRunEntities(int[] runIds) {
    StringBuilder whereClause = new StringBuilder();
    whereClause.append(" WHERE runId IN (");
    for (int runId : runIds) {
        whereClause.append(runId).append(", ");
    }
    whereClause.setLength(whereClause.lastIndexOf(","));
    whereClause.append(")");
    List<Run> dbRuns;
    try {
        dbRuns = dbReadAccess.getRuns(0, 10000, whereClause.toString(), "runId", true);
    } catch (DatabaseAccessException e) {
        throw new ReportExtractorException("Error loading runs " + whereClause, e);
    }
    List<RunWrapper> runs = new ArrayList<RunWrapper>();
    for (Run dbRun : dbRuns) {
        // load this run's suites
        List<Suite> suites;
        try {
            suites = dbReadAccess.getSuites(0, 10000, "WHERE runId=" + dbRun.runId, "suiteId", true, false);
        } catch (DatabaseAccessException e) {
            throw new ReportExtractorException("Error loading suites for run with id " + dbRun.runId, e);
        }
        RunWrapper run = new RunWrapper(dbRun, suites);
        runs.add(run);
    }
    return runs;
}
Also used : Suite(com.axway.ats.log.autodb.entities.Suite) ReportExtractorException(com.axway.ats.log.report.exceptions.ReportExtractorException) ArrayList(java.util.ArrayList) Run(com.axway.ats.log.autodb.entities.Run) DatabaseAccessException(com.axway.ats.log.autodb.exceptions.DatabaseAccessException)

Example 28 with DatabaseAccessException

use of com.axway.ats.log.autodb.exceptions.DatabaseAccessException 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)

Example 29 with DatabaseAccessException

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

the class DbWriteAccess method startSuite.

public int startSuite(String packageName, String suiteName, long timestamp, int runId, boolean closeConnection) throws DatabaseAccessException {
    final String errMsg = "Unable to start suite with name " + suiteName;
    // create a new suite
    CallableStatement callableStatement = null;
    try {
        refreshInternalConnection();
        // TODO : remove me after 3.6.0
        String dbVersionString = getDatabaseVersion();
        int dbVersion = Integer.parseInt(dbVersionString.replace(".", ""));
        if (dbVersion >= 350) {
            callableStatement = connection.prepareCall("{ call sp_start_suite(?, ?, ?, ?, ?, ?) }");
            if (packageName == null) {
                packageName = "";
            }
            callableStatement.setString("@package", packageName);
        } else {
            callableStatement = connection.prepareCall("{ call sp_start_suite(?, ?, ?, ?, ?) }");
        }
        callableStatement.setString("@suiteName", suiteName);
        callableStatement.setInt("@runId", runId);
        callableStatement.setTimestamp("@dateStart", new Timestamp(timestamp));
        callableStatement.registerOutParameter("@RowsInserted", Types.INTEGER);
        callableStatement.registerOutParameter("@suiteId", Types.INTEGER);
        callableStatement.execute();
        if (callableStatement.getInt("@RowsInserted") != 1) {
            throw new DatabaseAccessException(errMsg);
        } else {
            if (callableStatement.getInt("@suiteId") == 0) {
                throw new DatabaseAccessException(errMsg + " - suite ID returned was 0");
            }
        }
        // get the result
        return callableStatement.getInt("@suiteId");
    } 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 30 with DatabaseAccessException

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

the class DbWriteAccess method isRunPresent.

public boolean isRunPresent(int runId) throws DatabaseAccessException {
    Connection connection = getConnection();
    PreparedStatement statement = null;
    ResultSet rs = null;
    try {
        statement = connection.prepareStatement("SELECT COUNT(*) FROM tRuns WHERE runId = " + runId);
        rs = statement.executeQuery();
        if (rs.next()) {
            return 1 == rs.getInt(1);
        }
    } catch (Exception e) {
        throw new DatabaseAccessException("Error checking whether run with id " + runId + " exists", e);
    } finally {
        DbUtils.closeResultSet(rs);
        DbUtils.close(connection, statement);
    }
    return false;
}
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) SQLException(java.sql.SQLException) DatabaseAccessException(com.axway.ats.log.autodb.exceptions.DatabaseAccessException)

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