Search in sources :

Example 41 with DatabaseAccessException

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

the class DbWriteAccess method startTestCase.

public int startTestCase(String suiteName, String scenarioName, String scenarioDescription, String testcaseName, long timestamp, int suiteId, boolean closeConnection) throws DatabaseAccessException {
    final String errMsg = "Unable to start testcase with name " + testcaseName;
    // start a new test case
    final int indexRowsInserted = 7;
    final int indexTestcaseId = 8;
    CallableStatement callableStatement = null;
    try {
        refreshInternalConnection();
        callableStatement = connection.prepareCall("{ call sp_start_testcase(?, ?, ?, ?, ?, ?, ?, ?) }");
        callableStatement.setInt(1, suiteId);
        callableStatement.setString(2, suiteName);
        callableStatement.setString(3, scenarioName);
        callableStatement.setString(4, scenarioDescription);
        callableStatement.setString(5, testcaseName);
        callableStatement.setTimestamp(6, new Timestamp(timestamp));
        callableStatement.registerOutParameter(indexRowsInserted, Types.INTEGER);
        callableStatement.registerOutParameter(indexTestcaseId, Types.INTEGER);
        callableStatement.execute();
        if (callableStatement.getInt(indexRowsInserted) != 1) {
            throw new DatabaseAccessException(errMsg);
        } else {
            if (callableStatement.getInt(indexTestcaseId) == 0) {
                throw new DatabaseAccessException(errMsg + " - testcase id returned was 0");
            }
        }
        // get the result
        return callableStatement.getInt(indexTestcaseId);
    } 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 42 with DatabaseAccessException

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

the class DbWriteAccess method clearScenarioMetainfo.

/**
     * Clear all meta info about an existing test scenario.
     * Intended to be called prior to adding meta data about a scenario.
     *
     * @param scenarioId
     * @param closeConnection
     * @throws DatabaseAccessException
     */
public void clearScenarioMetainfo(int scenarioId, boolean closeConnection) throws DatabaseAccessException {
    final String errMsg = "Unable to clear scenario meta info for scenario with id " + scenarioId;
    final int indexRowsDeleted = 2;
    CallableStatement callableStatement = null;
    try {
        refreshInternalConnection();
        callableStatement = connection.prepareCall("{ call sp_clear_scenario_metainfo(?, ?) }");
        callableStatement.setInt(1, scenarioId);
        callableStatement.registerOutParameter(indexRowsDeleted, Types.INTEGER);
        callableStatement.execute();
    } 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) SQLException(java.sql.SQLException) DatabaseAccessException(com.axway.ats.log.autodb.exceptions.DatabaseAccessException)

Example 43 with DatabaseAccessException

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

the class DbWriteAccess method insertSuiteMessage.

public boolean insertSuiteMessage(String message, int level, boolean escapeHtml, String machineName, String threadName, long timestamp, int suiteId, boolean closeConnection) throws DatabaseAccessException {
    String dbVersionString = getDatabaseVersion();
    int dbVersion = Integer.parseInt(dbVersionString.replace(".", ""));
    if (dbVersion < 350) {
        return false;
    } else {
        Connection currentConnection;
        if (!isBatchMode) {
            currentConnection = refreshInternalConnection();
        } else {
            currentConnection = dbEventsCache.connection;
        }
        CallableStatement insertMessageStatement = insertFactory.getInsertSuiteMessageStatement(currentConnection, message, level, escapeHtml, machineName, threadName, timestamp, suiteId);
        if (isBatchMode) {
            // schedule this event for batch execution
            return dbEventsCache.addInsertSuiteMessageEventToBatch(insertMessageStatement);
        } else {
            // execute this event now
            final String errMsg = "Unable to insert suite message '" + message + "'";
            final int indexRowsInserted = 8;
            try {
                insertMessageStatement.execute();
                if (insertMessageStatement.getInt(indexRowsInserted) < 1) {
                    throw new DatabaseAccessException(errMsg);
                }
            } catch (SQLException e) {
                throw new DatabaseAccessException(errMsg, e);
            } finally {
                if (closeConnection) {
                    DbUtils.close(connection, insertMessageStatement);
                } else {
                    DbUtils.closeStatement(insertMessageStatement);
                }
            }
            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 44 with DatabaseAccessException

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

the class DbWriteAccess method startCheckpoint.

public CheckpointInfo startCheckpoint(String name, String threadName, long startTimestamp, String transferUnit, int loadQueueId, boolean closeConnection) throws DatabaseAccessException {
    final String errMsg = "Unable to start checkpoint '" + name + "' for thread '" + threadName + "' in load queue " + loadQueueId;
    final int indexCheckpointSummaryId = 6;
    final int indexCheckpointId = 7;
    CallableStatement callableStatement = null;
    try {
        refreshInternalConnection();
        callableStatement = connection.prepareCall("{ call sp_start_checkpoint(?, ?, ?, ?, ?, ?, ?) }");
        callableStatement.setInt(1, loadQueueId);
        callableStatement.setString(2, threadName);
        callableStatement.setString(3, name);
        callableStatement.setInt(4, checkpointLogLevel.toInt());
        callableStatement.setString(5, transferUnit);
        callableStatement.registerOutParameter(indexCheckpointSummaryId, Types.INTEGER);
        callableStatement.registerOutParameter(indexCheckpointId, Types.INTEGER);
        callableStatement.execute();
        // we always update the checkpoint summary table
        if (callableStatement.getInt(indexCheckpointSummaryId) == 0) {
            throw new DatabaseAccessException(errMsg + " - checkpoint summary ID returned was 0");
        }
        // we update the checkpoint table only in FULL mode
        if (checkpointLogLevel == CheckpointLogLevel.FULL && callableStatement.getInt(indexCheckpointId) == 0) {
            throw new DatabaseAccessException(errMsg + " - checkpoint ID returned was 0");
        }
        int checkpointSummaryId = callableStatement.getInt(indexCheckpointSummaryId);
        int checkpointId = callableStatement.getInt(indexCheckpointId);
        return new CheckpointInfo(name, checkpointSummaryId, checkpointId, startTimestamp);
    } 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 45 with DatabaseAccessException

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

the class DbWriteAccess method startRun.

/**
     * Insert a new run in the database
     *
     * @param runName
     *            name of the run
     * @param osName
     *            name of the OS
     * @param productName
     *            name of the product
     * @param versionName
     *            version of the product
     * @param buildName
     *            build version
     * @param timestamp
     * @param hostName
     *            name/IP of the machine , from which the run was started
     * @return
     */
public int startRun(String runName, String osName, String productName, String versionName, String buildName, long timestamp, String hostName, boolean closeConnection) throws DatabaseAccessException {
    final String errMsg = "Unable to insert run with name " + runName;
    // then start the run
    final int indexRowsInserted = 8;
    final int indexRunId = 9;
    CallableStatement callableStatement = null;
    try {
        refreshInternalConnection();
        callableStatement = connection.prepareCall("{ call sp_start_run(?, ?, ?, ?, ?, ?, ?, ? ,?) }");
        callableStatement.setString(1, productName);
        callableStatement.setString(2, versionName);
        callableStatement.setString(3, buildName);
        callableStatement.setString(4, runName);
        callableStatement.setString(5, osName);
        callableStatement.setTimestamp(6, new Timestamp(timestamp));
        callableStatement.setString(7, hostName);
        callableStatement.registerOutParameter(indexRowsInserted, Types.INTEGER);
        callableStatement.registerOutParameter(indexRunId, Types.INTEGER);
        callableStatement.execute();
        if (callableStatement.getInt(indexRowsInserted) == 1) {
            // check if the run ID is correct
            if (callableStatement.getInt(indexRunId) == 0) {
                throw new DatabaseAccessException(errMsg + " - run ID returned was 0");
            }
        } else {
            throw new DatabaseAccessException(errMsg);
        }
        // get the result
        return callableStatement.getInt(indexRunId);
    } 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

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