Search in sources :

Example 76 with CallableStatement

use of java.sql.CallableStatement 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 77 with CallableStatement

use of java.sql.CallableStatement 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 78 with CallableStatement

use of java.sql.CallableStatement 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 79 with CallableStatement

use of java.sql.CallableStatement 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)

Example 80 with CallableStatement

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

the class DbWriteAccess method endRun.

/**
     * End a run in the database
     *
     * @param timestamp
     * @param runId
     */
public void endRun(long timestamp, int runId, boolean closeConnection) throws DatabaseAccessException {
    final String errMsg = "Unable to end run with id " + runId;
    final int indexRowsInserted = 3;
    CallableStatement callableStatement = null;
    try {
        refreshInternalConnection();
        callableStatement = connection.prepareCall("{ call sp_end_run(?, ?, ?) }");
        callableStatement.setInt(1, runId);
        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)

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