Search in sources :

Example 51 with DatabaseAccessException

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

the class DbReadAccess method getSystemAggregatedStatistics.

public List<Statistic> getSystemAggregatedStatistics(float timeOffset, String testcaseIds, String machineIds, String statsTypeIds, int interval, int mode) throws DatabaseAccessException {
    List<Statistic> statistics = new ArrayList<Statistic>();
    String sqlLog = new SqlRequestFormatter().add("testcase ids", testcaseIds).add("fdate", formatDateFromEpoch(timeOffset)).add("machine ids", machineIds).add("stats type ids", statsTypeIds).add("inverval (seconds)", interval).add("mode (AVG-0001,SUM-0010,TOTALS-0100,COUNT-1000)", mode).format();
    Connection connection = getConnection();
    CallableStatement callableStatement = null;
    ResultSet rs = null;
    try {
        callableStatement = connection.prepareCall("{ call sp_get_system_aggregated_statistics(?, ?, ?, ?, ?, ?) }");
        callableStatement.setString(1, formatDateFromEpoch(timeOffset));
        callableStatement.setString(2, testcaseIds);
        callableStatement.setString(3, machineIds);
        callableStatement.setString(4, statsTypeIds);
        callableStatement.setInt(5, interval);
        callableStatement.setInt(6, mode);
        rs = callableStatement.executeQuery();
        Map<Integer, Float> totalSumValues = new HashMap<Integer, Float>();
        int numberRecords = 0;
        while (rs.next()) {
            Statistic statistic = new Statistic();
            statistic.statisticTypeId = rs.getInt("statsTypeId");
            statistic.name = rs.getString("statsName");
            statistic.unit = rs.getString("statsUnit");
            statistic.avgValue = rs.getFloat("avgValue");
            statistic.sumValue = rs.getFloat("sumValue");
            statistic.countValue = rs.getFloat("countValue");
            if (StatisticAggregatedType.isTotals(mode)) {
                // total sum value
                float totalSumValue = statistic.sumValue;
                if (totalSumValues.containsKey(statistic.statisticTypeId)) {
                    totalSumValue += totalSumValues.get(statistic.statisticTypeId);
                }
                totalSumValues.put(statistic.statisticTypeId, totalSumValue);
                statistic.totalValue = totalSumValue;
            }
            statistic.timestamp = rs.getInt("timestamp");
            statistic.machineId = rs.getInt("machineId");
            statistic.testcaseId = rs.getInt("testcaseId");
            statistics.add(statistic);
            numberRecords++;
        }
        logQuerySuccess(sqlLog, "system aggregated statistics", numberRecords);
    } catch (Exception e) {
        throw new DatabaseAccessException("Error when " + sqlLog, e);
    } finally {
        DbUtils.closeResultSet(rs);
        DbUtils.close(connection, callableStatement);
    }
    return statistics;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) DbConnection(com.axway.ats.core.dbaccess.DbConnection) Checkpoint(com.axway.ats.log.autodb.entities.Checkpoint) SQLException(java.sql.SQLException) DatabaseAccessException(com.axway.ats.log.autodb.exceptions.DatabaseAccessException) Statistic(com.axway.ats.log.autodb.entities.Statistic) CallableStatement(java.sql.CallableStatement) ResultSet(java.sql.ResultSet) DatabaseAccessException(com.axway.ats.log.autodb.exceptions.DatabaseAccessException)

Example 52 with DatabaseAccessException

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

the class DbReadAccess method getCheckpointsSummary.

public List<CheckpointSummary> getCheckpointsSummary(String whereClause, String sortColumn, boolean ascending) throws DatabaseAccessException {
    List<CheckpointSummary> checkpoints = new ArrayList<CheckpointSummary>();
    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_checkpoints_summary(?, ?, ?) }");
        callableStatement.setString(1, "where " + whereClause);
        callableStatement.setString(2, sortColumn);
        callableStatement.setString(3, (ascending ? "ASC" : "DESC"));
        rs = callableStatement.executeQuery();
        int numberRecords = 0;
        while (rs.next()) {
            CheckpointSummary checkpointSummary = new CheckpointSummary();
            checkpointSummary.checkpointSummaryId = rs.getInt("checkpointSummaryId");
            checkpointSummary.name = rs.getString("name");
            checkpointSummary.numRunning = rs.getInt("numRunning");
            checkpointSummary.numPassed = rs.getInt("numPassed");
            checkpointSummary.numFailed = rs.getInt("numFailed");
            checkpointSummary.numTotal = checkpointSummary.numRunning + checkpointSummary.numPassed + checkpointSummary.numFailed;
            checkpointSummary.minResponseTime = rs.getInt("minResponseTime");
            if (checkpointSummary.minResponseTime == Integer.MAX_VALUE) {
                checkpointSummary.minResponseTime = 0;
            }
            checkpointSummary.avgResponseTime = rs.getFloat("avgResponseTime");
            checkpointSummary.maxResponseTime = rs.getInt("maxResponseTime");
            checkpointSummary.minTransferRate = rs.getFloat("minTransferRate");
            if (checkpointSummary.minTransferRate == Integer.MAX_VALUE) {
                checkpointSummary.minTransferRate = 0.0F;
            }
            checkpointSummary.avgTransferRate = rs.getFloat("avgTransferRate");
            checkpointSummary.maxTransferRate = rs.getFloat("maxTransferRate");
            checkpointSummary.transferRateUnit = rs.getString("transferRateUnit");
            checkpoints.add(checkpointSummary);
            numberRecords++;
        }
        logQuerySuccess(sqlLog, "checkpoints summary", numberRecords);
    } catch (Exception e) {
        throw new DatabaseAccessException("Error when " + sqlLog, e);
    } finally {
        DbUtils.closeResultSet(rs);
        DbUtils.close(connection, callableStatement);
    }
    return checkpoints;
}
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) 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) CheckpointSummary(com.axway.ats.log.autodb.entities.CheckpointSummary)

Example 53 with DatabaseAccessException

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

the class DbReadAccess method getMessagesCount.

public int getMessagesCount(String whereClause) throws DatabaseAccessException {
    String sqlLog = new SqlRequestFormatter().add("where", whereClause).format();
    Connection connection = getConnection();
    CallableStatement callableStatement = null;
    ResultSet rs = null;
    try {
        callableStatement = connection.prepareCall("{ call sp_get_messages_count(?) }");
        callableStatement.setString(1, whereClause);
        rs = callableStatement.executeQuery();
        int messagesCount = 0;
        if (rs.next()) {
            messagesCount = rs.getInt("messagesCount");
        }
        logQuerySuccess(sqlLog, "messages", messagesCount);
        return messagesCount;
    } 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 54 with DatabaseAccessException

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

the class DbReadAccess method getRunMessagesCount.

public int getRunMessagesCount(String whereClause) throws DatabaseAccessException {
    String sqlLog = new SqlRequestFormatter().add("where", whereClause).format();
    Connection connection = getConnection();
    CallableStatement callableStatement = null;
    ResultSet rs = null;
    try {
        callableStatement = connection.prepareCall("{ call sp_get_run_messages_count(?) }");
        callableStatement.setString(1, whereClause);
        rs = callableStatement.executeQuery();
        int messagesCount = 0;
        if (rs.next()) {
            messagesCount = rs.getInt("messagesCount");
        }
        logQuerySuccess(sqlLog, "run messages count", messagesCount);
        return messagesCount;
    } 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 55 with DatabaseAccessException

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

the class DbReadAccess method getSuites.

@BackwardCompatibility
public List<Suite> getSuites(int startRecord, int recordsCount, String whereClause, String sortColumn, boolean ascending, boolean dateFormatNoYear) throws DatabaseAccessException {
    List<Suite> suites = new ArrayList<Suite>();
    Connection connection = getConnection();
    String sqlLog = new SqlRequestFormatter().add("start record", startRecord).add("records", recordsCount).add("where", whereClause).add("sort by", sortColumn).add("asc", ascending).format();
    CallableStatement callableStatement = null;
    ResultSet rs = null;
    try {
        callableStatement = connection.prepareCall("{ call sp_get_suites(?, ?, ?, ?, ?) }");
        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()) {
            Suite suite = new Suite();
            suite.suiteId = rs.getString("suiteId");
            try {
                @BackwardCompatibility int // suite.runId introduced 3.11.0 (internalVersion=3)
                dbInternalVersion = getDatabaseInternalVersion();
                if (dbInternalVersion >= 3) {
                    suite.runId = rs.getString("runId");
                }
            } catch (NumberFormatException nfe) {
                suite.runId = "";
                log.warn("Error parsing dbInternalVersion. ", nfe);
            }
            suite.name = rs.getString("name");
            if (dateFormatNoYear) {
                suite.dateStart = formatDateNoYear(rs.getTimestamp("dateStart"));
                suite.dateEnd = formatDateNoYear(rs.getTimestamp("dateEnd"));
            } else {
                suite.dateStart = formatDate(rs.getTimestamp("dateStart"));
                suite.dateEnd = formatDate(rs.getTimestamp("dateEnd"));
            }
            int duration = rs.getInt("duration");
            if (duration < 0) {
                // this may happen when the suite is not ended and the time of the log server
                // is behind with the time of the test executor host
                duration = 0;
            }
            suite.duration = formatTimeDiffereceFromSecondsToString(duration);
            suite.scenariosTotal = rs.getInt("scenariosTotal");
            suite.scenariosFailed = rs.getInt("scenariosFailed");
            suite.scenariosSkipped = rs.getInt("scenariosSkipped");
            suite.testcasesTotal = rs.getInt("testcasesTotal");
            suite.testcasesFailed = rs.getInt("testcasesFailed");
            suite.testcasesPassedPercent = String.valueOf(rs.getInt("testcasesPassedPercent")) + "%";
            suite.testcaseIsRunning = rs.getBoolean("testcaseIsRunning");
            suite.total = suite.scenariosTotal + "/" + suite.testcasesTotal;
            suite.failed = suite.scenariosFailed + "/" + suite.testcasesFailed;
            suite.userNote = rs.getString("userNote");
            suite.packageName = "";
            try {
                @BackwardCompatibility int // suite.packageName introduced 3.5.0 and internalVersion=1 (in 3.10.0)
                dbInternalVersion = getDatabaseInternalVersion();
                if (dbInternalVersion >= 1) {
                    suite.packageName = rs.getString("package");
                }
            } catch (NumberFormatException nfe) {
                suite.packageName = "";
                log.warn("Error parsing dbInternalVersion. ", nfe);
            }
            suites.add(suite);
            numberRecords++;
        }
        logQuerySuccess(sqlLog, "suites", numberRecords);
    } catch (Exception e) {
        throw new DatabaseAccessException("Error when " + sqlLog, e);
    } finally {
        DbUtils.closeResultSet(rs);
        DbUtils.close(connection, callableStatement);
    }
    return suites;
}
Also used : ArrayList(java.util.ArrayList) Connection(java.sql.Connection) DbConnection(com.axway.ats.core.dbaccess.DbConnection) Checkpoint(com.axway.ats.log.autodb.entities.Checkpoint) SQLException(java.sql.SQLException) DatabaseAccessException(com.axway.ats.log.autodb.exceptions.DatabaseAccessException) Suite(com.axway.ats.log.autodb.entities.Suite) BackwardCompatibility(com.axway.ats.core.utils.BackwardCompatibility) CallableStatement(java.sql.CallableStatement) ResultSet(java.sql.ResultSet) DatabaseAccessException(com.axway.ats.log.autodb.exceptions.DatabaseAccessException) BackwardCompatibility(com.axway.ats.core.utils.BackwardCompatibility)

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