Search in sources :

Example 1 with LoadQueue

use of com.axway.ats.log.autodb.entities.LoadQueue in project ats-framework by Axway.

the class DbReadAccess method getLoadQueues.

public List<LoadQueue> getLoadQueues(String whereClause, String sortColumn, boolean ascending, boolean dateFormatNoYear) throws DatabaseAccessException {
    List<LoadQueue> loadQueues = new ArrayList<LoadQueue>();
    String sqlLog = new SqlRequestFormatter().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_loadqueues(?, ?, ?) }");
        callableStatement.setString(1, "where " + whereClause);
        callableStatement.setString(2, sortColumn);
        callableStatement.setString(3, (ascending ? "ASC" : "DESC"));
        rs = callableStatement.executeQuery();
        int numberRecords = 0;
        while (rs.next()) {
            LoadQueue loadQueue = new LoadQueue();
            loadQueue.loadQueueId = rs.getInt("loadQueueId");
            loadQueue.name = rs.getString("name");
            loadQueue.sequence = rs.getInt("sequence");
            loadQueue.hostsList = rs.getString("hostsList");
            loadQueue.threadingPattern = rs.getString("threadingPattern");
            loadQueue.numberThreads = rs.getInt("numberThreads");
            if (loadQueue.threadingPattern != null) {
                loadQueue.threadingPattern = loadQueue.threadingPattern.replace("<number_threads>", String.valueOf(loadQueue.numberThreads));
            }
            if (dateFormatNoYear) {
                loadQueue.dateStart = formatDateNoYear(rs.getTimestamp("dateStart"));
                loadQueue.dateEnd = formatDateNoYear(rs.getTimestamp("dateEnd"));
            } else {
                loadQueue.dateStart = formatDate(rs.getTimestamp("dateStart"));
                loadQueue.dateEnd = formatDate(rs.getTimestamp("dateEnd"));
            }
            int duration = rs.getInt("duration");
            if (duration < 0) {
                // this may happen when the load queue is not ended and the time of the log server
                // is behind with the time of the test executor host
                duration = 0;
            }
            loadQueue.duration = formatTimeDiffereceFromSecondsToString(duration);
            loadQueue.result = rs.getInt("result");
            /*
                 *   -- 0 FAILED
                 *   -- 1 PASSED
                 *   -- 2 SKIPPED
                 *   -- 4 RUNNING
                 */
            switch(loadQueue.result) {
                case 0:
                    loadQueue.state = "FAILED";
                    break;
                case 1:
                    loadQueue.state = "PASSED";
                    break;
                case 2:
                    loadQueue.state = "SKIPPED";
                    break;
                case 4:
                    loadQueue.state = "RUNNING";
                    break;
                default:
                    //TODO: add warning
                    loadQueue.state = "unknown";
            }
            loadQueues.add(loadQueue);
            numberRecords++;
        }
        logQuerySuccess(sqlLog, "loadqueues", numberRecords);
    } catch (Exception e) {
        throw new DatabaseAccessException("Error when " + sqlLog, e);
    } finally {
        DbUtils.closeResultSet(rs);
        DbUtils.close(connection, callableStatement);
    }
    return loadQueues;
}
Also used : CallableStatement(java.sql.CallableStatement) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) DbConnection(com.axway.ats.core.dbaccess.DbConnection) ResultSet(java.sql.ResultSet) LoadQueue(com.axway.ats.log.autodb.entities.LoadQueue) 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)

Aggregations

DbConnection (com.axway.ats.core.dbaccess.DbConnection)1 Checkpoint (com.axway.ats.log.autodb.entities.Checkpoint)1 LoadQueue (com.axway.ats.log.autodb.entities.LoadQueue)1 DatabaseAccessException (com.axway.ats.log.autodb.exceptions.DatabaseAccessException)1 CallableStatement (java.sql.CallableStatement)1 Connection (java.sql.Connection)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1