Search in sources :

Example 16 with DatabaseAccessException

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

the class DbWriteAccess method isTestcasePresent.

public boolean isTestcasePresent(int testcaseId) throws DatabaseAccessException {
    Connection connection = getConnection();
    PreparedStatement statement = null;
    ResultSet rs = null;
    try {
        statement = connection.prepareStatement("SELECT COUNT(*) FROM tTestcases WHERE testcaseId = " + testcaseId);
        rs = statement.executeQuery();
        if (rs.next()) {
            return 1 == rs.getInt(1);
        }
    } catch (Exception e) {
        throw new DatabaseAccessException("Error checking whether testcase with id " + testcaseId + " 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)

Example 17 with DatabaseAccessException

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

the class DbWriteAccess method updateRun.

/**
     * Update the static information about an existing run
     *
     * @param runId
     * @param runName
     * @param osName
     * @param productName
     * @param versionName
     * @param buildName
     * @param userNote
     * @param hostName
     * @throws DatabaseAccessException
     */
public void updateRun(int runId, String runName, String osName, String productName, String versionName, String buildName, String userNote, String hostName, boolean closeConnection) throws DatabaseAccessException {
    final String errMsg = "Unable to update run with name '" + runName + "' and id " + runId;
    // then start the run
    final int indexRowsUpdate = 9;
    CallableStatement callableStatement = null;
    try {
        refreshInternalConnection();
        callableStatement = connection.prepareCall("{ call sp_update_run(?, ?, ?, ?, ?, ?, ?, ?, ?) }");
        callableStatement.setInt(1, runId);
        callableStatement.setString(2, productName);
        callableStatement.setString(3, versionName);
        callableStatement.setString(4, buildName);
        callableStatement.setString(5, runName);
        callableStatement.setString(6, osName);
        callableStatement.setString(7, userNote);
        callableStatement.setString(8, hostName);
        callableStatement.registerOutParameter(indexRowsUpdate, Types.INTEGER);
        callableStatement.execute();
        if (callableStatement.getInt(indexRowsUpdate) != 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 18 with DatabaseAccessException

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

the class DbWriteAccess method insertRunMessage.

public boolean insertRunMessage(String message, int level, boolean escapeHtml, String machineName, String threadName, long timestamp, int runId, 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.getInsertRunMessageStatement(currentConnection, message, level, escapeHtml, machineName, threadName, timestamp, runId);
        if (isBatchMode) {
            // schedule this event for batch execution
            return dbEventsCache.addInsertRunMessageEventToBatch(insertMessageStatement);
        } else {
            // execute this event now
            final String errMsg = "Unable to insert run 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 19 with DatabaseAccessException

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

the class DbWriteAccess method addRunMetainfo.

/**
     * Update meta info about an existing run
     *
     * @param runId
     * @param metaKey
     * @param metaValue
     * @param closeConnection
     * @throws DatabaseAccessException
     */
public void addRunMetainfo(int runId, String metaKey, String metaValue, boolean closeConnection) throws DatabaseAccessException {
    final String errMsg = "Unable to add run meta info '" + metaKey + "=" + metaValue + "' to run with id " + runId;
    final int indexRowsInserted = 4;
    CallableStatement callableStatement = null;
    try {
        refreshInternalConnection();
        callableStatement = connection.prepareCall("{ call sp_add_run_metainfo(?, ?, ?, ?) }");
        callableStatement.setInt(1, runId);
        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 20 with DatabaseAccessException

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

the class DbWriteAccess method insertMessage.

public boolean insertMessage(String message, int level, boolean escapeHtml, String machineName, String threadName, long timestamp, int testCaseId, boolean closeConnection) throws DatabaseAccessException {
    Connection currentConnection;
    if (!isBatchMode) {
        currentConnection = refreshInternalConnection();
    } else {
        currentConnection = dbEventsCache.connection;
    }
    CallableStatement insertMessageStatement = insertFactory.getInsertTestcaseMessageStatement(currentConnection, message, level, escapeHtml, machineName, threadName, timestamp, testCaseId);
    if (isBatchMode) {
        // schedule this event for batch execution
        return dbEventsCache.addInsertTestcaseMessageEventToBatch(insertMessageStatement);
    } else {
        // execute this event now
        final String errMsg = "Unable to insert testcase 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)

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