Search in sources :

Example 11 with DatabaseAccessException

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

the class DbReadAccess method getRunsCount.

public int getRunsCount(String whereClause) throws DatabaseAccessException {
    Connection connection = getConnection();
    String sqlLog = new SqlRequestFormatter().add("where", whereClause).format();
    CallableStatement callableStatement = null;
    ResultSet rs = null;
    try {
        callableStatement = connection.prepareCall("{ call sp_get_runs_count(?) }");
        callableStatement.setString(1, whereClause);
        rs = callableStatement.executeQuery();
        int runsCount = 0;
        while (rs.next()) {
            runsCount = rs.getInt("runsCount");
            logQuerySuccess(sqlLog, "runs", runsCount);
            break;
        }
        return runsCount;
    } catch (Exception e) {
        throw new DatabaseAccessException("Error when " + sqlLog, e);
    } finally {
        DbUtils.closeResultSet(rs);
        DbUtils.close(connection, callableStatement);
    }
}
Also used : CallableStatement(java.sql.CallableStatement) Connection(java.sql.Connection) DbConnection(com.axway.ats.core.dbaccess.DbConnection) ResultSet(java.sql.ResultSet) Checkpoint(com.axway.ats.log.autodb.entities.Checkpoint) SQLException(java.sql.SQLException) DatabaseAccessException(com.axway.ats.log.autodb.exceptions.DatabaseAccessException) DatabaseAccessException(com.axway.ats.log.autodb.exceptions.DatabaseAccessException)

Example 12 with DatabaseAccessException

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

the class DbReadAccess method getMachines.

public List<Machine> getMachines() throws DatabaseAccessException {
    List<Machine> machines = new ArrayList<Machine>();
    Connection connection = getConnection();
    PreparedStatement statement = null;
    ResultSet rs = null;
    try {
        statement = connection.prepareStatement("SELECT * FROM tMachines ORDER BY machineName");
        rs = statement.executeQuery();
        while (rs.next()) {
            Machine machine = new Machine();
            machine.machineId = rs.getInt("machineId");
            machine.name = rs.getString("machineName");
            machine.alias = rs.getString("machineAlias");
            machines.add(machine);
        }
    } catch (Exception e) {
        throw new DatabaseAccessException("Error retrieving machines", e);
    } finally {
        DbUtils.closeResultSet(rs);
        DbUtils.close(connection, statement);
    }
    return machines;
}
Also used : ArrayList(java.util.ArrayList) Connection(java.sql.Connection) DbConnection(com.axway.ats.core.dbaccess.DbConnection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) Machine(com.axway.ats.log.autodb.entities.Machine) SQLException(java.sql.SQLException) DatabaseAccessException(com.axway.ats.log.autodb.exceptions.DatabaseAccessException) DatabaseAccessException(com.axway.ats.log.autodb.exceptions.DatabaseAccessException)

Example 13 with DatabaseAccessException

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

the class DbReadAccess method getSuiteMessages.

public List<Message> getSuiteMessages(int startRecord, int recordsCount, String whereClause, String sortColumn, boolean ascending) throws DatabaseAccessException {
    List<Message> suiteMessages = new ArrayList<Message>();
    SimpleDateFormat dateFormat = new SimpleDateFormat("MMM dd");
    SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm:ss:S");
    String sqlLog = new SqlRequestFormatter().add("start record", startRecord).add("records", recordsCount).add("where", whereClause).add("sort by", sortColumn).add("asc", ascending).format();
    Connection connection = getConnection();
    CallableStatement callableStatement = null;
    ResultSet rs = null;
    try {
        callableStatement = connection.prepareCall("{ call sp_get_suite_messages(?, ?, ?, ?, ?) }");
        callableStatement.setString(1, String.valueOf(startRecord));
        callableStatement.setString(2, String.valueOf(recordsCount));
        callableStatement.setString(3, whereClause);
        callableStatement.setString(4, sortColumn);
        callableStatement.setString(5, (ascending ? "ASC" : "DESC"));
        int numberRecords = 0;
        rs = callableStatement.executeQuery();
        while (rs.next()) {
            Message suiteMessage = new Message();
            suiteMessage.messageId = rs.getInt("suiteMessageId");
            suiteMessage.messageContent = rs.getString("message");
            suiteMessage.messageType = rs.getString("typeName");
            Timestamp timestamp = rs.getTimestamp("timestamp");
            suiteMessage.date = dateFormat.format(timestamp);
            suiteMessage.time = timeFormat.format(timestamp);
            suiteMessage.machineName = rs.getString("machineName");
            suiteMessage.threadName = rs.getString("threadName");
            suiteMessages.add(suiteMessage);
            numberRecords++;
        }
        logQuerySuccess(sqlLog, "suite messages", numberRecords);
    } catch (Exception e) {
        throw new DatabaseAccessException("Error when " + sqlLog, e);
    } finally {
        DbUtils.closeResultSet(rs);
        DbUtils.close(connection, callableStatement);
    }
    return suiteMessages;
}
Also used : Message(com.axway.ats.log.autodb.entities.Message) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) DbConnection(com.axway.ats.core.dbaccess.DbConnection) Timestamp(java.sql.Timestamp) Checkpoint(com.axway.ats.log.autodb.entities.Checkpoint) SQLException(java.sql.SQLException) DatabaseAccessException(com.axway.ats.log.autodb.exceptions.DatabaseAccessException) CallableStatement(java.sql.CallableStatement) ResultSet(java.sql.ResultSet) SimpleDateFormat(java.text.SimpleDateFormat) DatabaseAccessException(com.axway.ats.log.autodb.exceptions.DatabaseAccessException)

Example 14 with DatabaseAccessException

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

the class AbstractClientExecutor method retrieveQueueId.

/**
     * Start performance queue in the database and retrieve its ID
     *
     * @return the started queue ID
     * @throws AgentException 
     */
public int retrieveQueueId(int sequence, String hostsList) throws AgentException {
    int queueId;
    try {
        if (dbAccess == null) {
            dbAccess = new DbAccessFactory().getNewDbWriteAccessObject();
        }
        queueId = dbAccess.startLoadQueue(queueName, sequence, hostsList, threadingPattern.getPatternDescription(), threadingPattern.getThreadCount(), LOCAL_MACHINE, Calendar.getInstance().getTimeInMillis(), ActiveDbAppender.getCurrentInstance().getTestCaseId(), true);
        log.rememberLoadQueueState(queueName, queueId, threadingPattern.getPatternDescription(), threadingPattern.getThreadCount());
    } catch (DatabaseAccessException e) {
        if (ActiveDbAppender.getCurrentInstance() == null) {
            // The log4j DB appender is not attached
            // We assume the user is running a performance test without DB logging
            log.warn("Unable to register a performance queue with name '" + queueName + "' in the loggging database." + " This means the results of running this queue will not be registered in the log DB." + " Check your DB configuration in order to fix this problem.");
            // Return this invalid value will not cause an error on the Test Executor side
            // We also know there will be no error on agent's side as our DB appender will not be present there
            queueId = -1;
        } else {
            throw new AgentException("Unable to register a performance queue with name '" + queueName + "' in the loggging database. This queue will not run at all.", e);
        }
    }
    return queueId;
}
Also used : DbAccessFactory(com.axway.ats.log.autodb.DbAccessFactory) AgentException(com.axway.ats.agent.core.exceptions.AgentException) DatabaseAccessException(com.axway.ats.log.autodb.exceptions.DatabaseAccessException)

Example 15 with DatabaseAccessException

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

the class DbWriteAccess method isSuitePresent.

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