Java Code Examples for java.sql.CallableStatement.setTimestamp()

The following are Jave code examples for showing how to use setTimestamp() of the java.sql.CallableStatement class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: ats-framework   File: SQLServerDbWriteAccess.java   Source Code and License Vote up 5 votes
/**
 * 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;

    timestamp = inUTC(timestamp);

    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);
        }
    }
}
 
Example 2
Project: ats-framework   File: SQLServerDbWriteAccess.java   Source Code and License Vote up 5 votes
public void endSuite(
                      long timestamp,
                      int suiteId,
                      boolean closeConnection ) throws DatabaseAccessException {

    final String errMsg = "Unable to end suite with id " + suiteId;

    timestamp = inUTC(timestamp);

    final int indexRowsInserted = 3;

    CallableStatement callableStatement = null;
    try {
        refreshInternalConnection();

        callableStatement = connection.prepareCall("{ call sp_end_suite(?, ?, ?) }");
        callableStatement.setInt(1, suiteId);
        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);
        }
    }
}
 
Example 3
Project: ats-framework   File: SQLServerDbWriteAccess.java   Source Code and License Vote up 5 votes
public void endTestCase(
                         int testcaseResult,
                         long timestamp,
                         int testcaseId,
                         boolean closeConnection ) throws DatabaseAccessException {

    final String errMsg = "Unable to end testcase with id " + testcaseId;

    timestamp = inUTC(timestamp);

    final int indexRowsInserted = 4;
    CallableStatement callableStatement = null;
    try {
        refreshInternalConnection();

        callableStatement = connection.prepareCall("{ call sp_end_testcase(?, ?, ?, ?) }");
        callableStatement.setInt(1, testcaseId);
        callableStatement.setInt(2, testcaseResult);
        callableStatement.setTimestamp(3, 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);
        }
    }
}
 
Example 4
Project: ats-framework   File: SQLServerDbWriteAccess.java   Source Code and License Vote up 5 votes
public void endLoadQueue(
                          int result,
                          long timestamp,
                          int loadQueueId,
                          boolean closeConnection ) throws DatabaseAccessException {

    final String errMsg = "Unable to end load queue with id " + loadQueueId;

    timestamp = inUTC(timestamp);

    final int indexRowsInserted = 4;

    CallableStatement callableStatement = null;
    try {
        refreshInternalConnection();

        callableStatement = connection.prepareCall("{ call sp_end_loadqueue(?, ?, ?, ?) }");
        callableStatement.setInt(1, loadQueueId);
        callableStatement.setInt(2, result);
        callableStatement.setTimestamp(3, 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);
        }
    }
}
 
Example 5
Project: ats-framework   File: SQLServerDbWriteAccess.java   Source Code and License Vote up 5 votes
public void insertSystemStatistics(
                                    int testCaseId,
                                    String machine,
                                    String statisticIds,
                                    String statisticValues,
                                    long timestamp,
                                    boolean closeConnection ) throws DatabaseAccessException {

    timestamp = inUTC(timestamp);

    CallableStatement callableStatement = null;
    try {
        refreshInternalConnection();

        callableStatement = connection.prepareCall("{ call sp_insert_system_statistic_by_ids(?, ?, ?, ?, ?) }");
        callableStatement.setString(3, statisticIds);
        callableStatement.setInt(1, testCaseId);
        callableStatement.setString(2, machine);
        callableStatement.setString(4, statisticValues);
        callableStatement.setTimestamp(5, new Timestamp(timestamp));

        callableStatement.execute();

    } catch (Exception e) {
        String errMsg = "Unable to insert system statistics, statistic IDs '" + statisticIds
                        + "', statistic values '" + statisticValues + "', timestamp " + timestamp;
        throw new DatabaseAccessException(errMsg, e);
    } finally {
        if (closeConnection) {
            DbUtils.close(connection, callableStatement);
        } else {
            DbUtils.closeStatement(callableStatement);
        }
    }
}
 
Example 6
Project: ats-framework   File: SQLServerDbWriteAccess.java   Source Code and License Vote up 5 votes
public void insertUserActivityStatistics(
                                          int testCaseId,
                                          String machine,
                                          String statisticIds,
                                          String statisticValues,
                                          long timestamp,
                                          boolean closeConnection ) throws DatabaseAccessException {

    timestamp = inUTC(timestamp);

    CallableStatement callableStatement = null;
    try {
        refreshInternalConnection();

        callableStatement = connection.prepareCall("{ call sp_insert_user_activity_statistic_by_ids(?, ?, ?, ?, ?) }");
        callableStatement.setString(3, statisticIds);
        callableStatement.setInt(1, testCaseId);
        callableStatement.setString(2, machine);
        callableStatement.setString(4, statisticValues);
        callableStatement.setTimestamp(5, new Timestamp(timestamp));

        callableStatement.execute();

    } catch (Exception e) {
        String errMsg = "Unable to insert user activity statistics, statistic IDs '" + statisticIds
                        + "', statistic values '" + statisticValues + "', timestamp " + timestamp;
        throw new DatabaseAccessException(errMsg, e);
    } finally {
        if (closeConnection) {
            DbUtils.close(connection, callableStatement);
        } else {
            DbUtils.closeStatement(callableStatement);
        }
    }
}
 
Example 7
Project: ats-framework   File: PGDbWriteAccess.java   Source Code and License Vote up 5 votes
@Override
public void insertUserActivityStatistics( int testCaseId, String machine, String statisticIds,
                                          String statisticValues, long timestamp,
                                          boolean closeConnection ) throws DatabaseAccessException {

    timestamp = inUTC(timestamp);

    CallableStatement callableStatement = null;
    try {
        refreshInternalConnection();

        callableStatement = connection.prepareCall("{ call sp_insert_user_activity_statistic_by_ids(?, ?, ?, ?, ?) }");
        callableStatement.setInt(1, testCaseId);
        callableStatement.setString(2, machine);
        callableStatement.setString(3, statisticIds);
        callableStatement.setString(4, statisticValues);
        callableStatement.setTimestamp(5, new Timestamp(timestamp));

        callableStatement.execute();

    } catch (Exception e) {
        String errMsg = "Unable to insert user activity statistics, statistic IDs '" + statisticIds
                        + "', statistic values '" + statisticValues + "', timestamp " + timestamp;
        throw new DatabaseAccessException(errMsg, e);
    } finally {
        if (closeConnection) {
            DbUtils.close(connection, callableStatement);
        } else {
            DbUtils.closeStatement(callableStatement);
        }
    }
}
 
Example 8
Project: ats-framework   File: SQLServerDbWriteAccess.java   Source Code and License Vote up 4 votes
/**
 * Insert a new run in the database
 *
 * @param runName
 *            name of the run
 * @param osName
 *            name of the OS
 * @param productName
 *            name of the product
 * @param versionName
 *            version of the product
 * @param buildName
 *            build version
 * @param timestamp
 * @param hostName
 *            name/IP of the machine , from which the run was started
 * @return
 */
public int startRun(
                     String runName,
                     String osName,
                     String productName,
                     String versionName,
                     String buildName,
                     long timestamp,
                     String hostName,
                     boolean closeConnection ) throws DatabaseAccessException {

    final String errMsg = "Unable to insert run with name " + runName;

    timestamp = inUTC(timestamp);

    // then start the run
    final int indexRowsInserted = 8;
    final int indexRunId = 9;

    CallableStatement callableStatement = null;
    try {
        refreshInternalConnection();

        callableStatement = connection.prepareCall("{ call sp_start_run(?, ?, ?, ?, ?, ?, ?, ? ,?) }");
        callableStatement.setString(1, productName);
        callableStatement.setString(2, versionName);
        callableStatement.setString(3, buildName);
        callableStatement.setString(4, runName);
        callableStatement.setString(5, osName);
        callableStatement.setTimestamp(6, new Timestamp(timestamp));
        callableStatement.setString(7, hostName);
        callableStatement.registerOutParameter(indexRowsInserted, Types.INTEGER);
        callableStatement.registerOutParameter(indexRunId, Types.INTEGER);

        callableStatement.execute();
        if (callableStatement.getInt(indexRowsInserted) == 1) {

            // check if the run ID is correct
            if (callableStatement.getInt(indexRunId) == 0) {
                throw new DatabaseAccessException(errMsg + " - run ID returned was 0");
            }
        } else {
            throw new DatabaseAccessException(errMsg);
        }

        // get the result
        return callableStatement.getInt(indexRunId);

    } catch (Exception e) {
        throw new DatabaseAccessException(errMsg, e);
    } finally {
        if (closeConnection) {
            DbUtils.close(connection, callableStatement);
        } else {
            DbUtils.closeStatement(callableStatement);
        }
    }
}
 
Example 9
Project: ats-framework   File: SQLServerDbWriteAccess.java   Source Code and License Vote up 4 votes
public int startSuite(
                       String packageName,
                       String suiteName,
                       long timestamp,
                       int runId,
                       boolean closeConnection ) throws DatabaseAccessException {

    final String errMsg = "Unable to start suite with name " + suiteName;
    // create a new suite

    timestamp = inUTC(timestamp);

    CallableStatement callableStatement = null;
    try {
        refreshInternalConnection();

        // TODO : remove me after 3.6.0
        String dbVersionString = getDatabaseVersion();
        int dbVersion = Integer.parseInt(dbVersionString.replace(".", ""));

        if (dbVersion >= 350) {
            callableStatement = connection.prepareCall("{ call sp_start_suite(?, ?, ?, ?, ?, ?) }");

            if (packageName == null) {
                packageName = "";
            }
            callableStatement.setString("@package", packageName);
        } else {
            callableStatement = connection.prepareCall("{ call sp_start_suite(?, ?, ?, ?, ?) }");
        }
        callableStatement.setString("@suiteName", suiteName);
        callableStatement.setInt("@runId", runId);
        callableStatement.setTimestamp("@dateStart", new Timestamp(timestamp));
        callableStatement.registerOutParameter("@RowsInserted", Types.INTEGER);
        callableStatement.registerOutParameter("@suiteId", Types.INTEGER);

        callableStatement.execute();

        if (callableStatement.getInt("@RowsInserted") != 1) {
            throw new DatabaseAccessException(errMsg);
        } else {
            if (callableStatement.getInt("@suiteId") == 0) {
                throw new DatabaseAccessException(errMsg + " - suite ID returned was 0");
            }
        }
        // get the result
        return callableStatement.getInt("@suiteId");

    } catch (Exception e) {
        throw new DatabaseAccessException(errMsg, e);
    } finally {
        if (closeConnection) {
            DbUtils.close(connection, callableStatement);
        } else {
            DbUtils.closeStatement(callableStatement);
        }
    }
}
 
Example 10
Project: ats-framework   File: SQLServerDbWriteAccess.java   Source Code and License Vote up 4 votes
public int startTestCase(
                          String suiteName,
                          String scenarioName,
                          String scenarioDescription,
                          String testcaseName,
                          long timestamp,
                          int suiteId,
                          boolean closeConnection ) throws DatabaseAccessException {

    final String errMsg = "Unable to start testcase with name " + testcaseName;

    timestamp = inUTC(timestamp);

    // start a new test case
    final int indexRowsInserted = 7;
    final int indexTestcaseId = 8;

    CallableStatement callableStatement = null;
    try {
        refreshInternalConnection();

        callableStatement = connection.prepareCall("{ call sp_start_testcase(?, ?, ?, ?, ?, ?, ?, ?) }");
        callableStatement.setInt(1, suiteId);
        callableStatement.setString(2, suiteName);
        callableStatement.setString(3, scenarioName);
        callableStatement.setString(4, scenarioDescription);
        callableStatement.setString(5, testcaseName);
        callableStatement.setTimestamp(6, new Timestamp(timestamp));
        callableStatement.registerOutParameter(indexRowsInserted, Types.INTEGER);
        callableStatement.registerOutParameter(indexTestcaseId, Types.INTEGER);

        callableStatement.execute();

        if (callableStatement.getInt(indexRowsInserted) != 1) {
            throw new DatabaseAccessException(errMsg);
        } else {
            if (callableStatement.getInt(indexTestcaseId) == 0) {
                throw new DatabaseAccessException(errMsg + " - testcase id returned was 0");
            }
        }

        // get the result
        return callableStatement.getInt(indexTestcaseId);

    } catch (Exception e) {
        throw new DatabaseAccessException(errMsg, e);
    } finally {
        if (closeConnection) {
            DbUtils.close(connection, callableStatement);
        } else {
            DbUtils.closeStatement(callableStatement);
        }
    }
}
 
Example 11
Project: ats-framework   File: SQLServerDbWriteAccess.java   Source Code and License Vote up 4 votes
public void updateTestcase(
                            String suiteFullName,
                            String scenarioName,
                            String scenarioDescription,
                            String testcaseName,
                            String userNote,
                            int testcaseResult,
                            int testcaseId,
                            long timestamp,
                            boolean closeConnection ) throws DatabaseAccessException {

    final String errMsg = "Unable to update testcase with name '" + testcaseName + "' and id " + testcaseId;

    timestamp = inUTC(timestamp);

    final int indexRowsUpdate = 9;

    CallableStatement callableStatement = null;
    try {
        refreshInternalConnection();

        callableStatement = connection.prepareCall("{ call sp_update_testcase(?, ?, ?, ?, ?, ?, ?, ?, ?) }");
        callableStatement.setInt(1, testcaseId);
        callableStatement.setString(2, suiteFullName);
        callableStatement.setString(3, scenarioName);
        callableStatement.setString(4, scenarioDescription);
        callableStatement.setString(5, testcaseName);
        callableStatement.setString(6, userNote);
        callableStatement.setInt(7, testcaseResult);
        callableStatement.setTimestamp(8, new Timestamp(timestamp));
        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);
        }
    }

}
 
Example 12
Project: ats-framework   File: SQLServerDbWriteAccess.java   Source Code and License Vote up 4 votes
public int startLoadQueue(
                           String name,
                           int sequence,
                           String hostsList,
                           String threadingPattern,
                           int numberThreads,
                           String machine,
                           long timestamp,
                           int testcaseId,
                           boolean closeConnection ) throws DatabaseAccessException {

    if (testcaseId < 1) {
        log.getLog4jLogger().warn("Load queue '" + name
                 + "' will not be registered because there is no database connection!");
        return -1;
    }

    timestamp = inUTC(timestamp);

    final String errMsg = "Unable to start load queue with name " + name;

    // create a new load queue
    final int indexRowsInserted = 9;
    final int indexLoadQueueId = 10;

    CallableStatement callableStatement = null;
    try {
        refreshInternalConnection();

        callableStatement = connection.prepareCall("{ call sp_start_loadqueue(?, ?, ?, ?, ?, ?, ?, ?, ?, ?) }");
        callableStatement.setInt(1, testcaseId);
        callableStatement.setString(2, name);
        callableStatement.setInt(3, sequence);
        callableStatement.setString(4, hostsList);
        callableStatement.setString(5, threadingPattern);
        callableStatement.setInt(6, numberThreads);
        callableStatement.setString(7, machine);
        callableStatement.setTimestamp(8, new Timestamp(timestamp));
        callableStatement.registerOutParameter(indexRowsInserted, Types.INTEGER);
        callableStatement.registerOutParameter(indexLoadQueueId, Types.INTEGER);

        callableStatement.execute();

        if (callableStatement.getInt(indexRowsInserted) != 1) {
            throw new DatabaseAccessException(errMsg);
        } else {
            if (callableStatement.getInt(indexLoadQueueId) == 0) {
                throw new DatabaseAccessException(errMsg + " - load queue id returned was 0");
            }
        }

        // get the result
        return callableStatement.getInt(indexLoadQueueId);

    } catch (Exception e) {
        throw new DatabaseAccessException(errMsg, e);
    } finally {
        if (closeConnection) {
            DbUtils.close(connection, callableStatement);
        } else {
            DbUtils.closeStatement(callableStatement);
        }
    }
}
 
Example 13
Project: ats-framework   File: SQLServerDbWriteAccess.java   Source Code and License Vote up 4 votes
public void endCheckpoint(
                           CheckpointInfo runningCheckpointInfo,
                           long endTimestamp,
                           long transferSize,
                           int result,
                           boolean closeConnection ) throws DatabaseAccessException {

    final String errMsg = "Unable to end checkpoint with name '" + runningCheckpointInfo.getName()
                          + "', checkpoint summary id " + runningCheckpointInfo.getCheckpointSummaryId()
                          + ", id " + runningCheckpointInfo.getCheckpointId();

    endTimestamp = inUTC(endTimestamp);

    final int indexRowsInserted = 8;

    CallableStatement callableStatement = null;
    try {
        refreshInternalConnection();

        callableStatement = connection.prepareCall("{ call sp_end_checkpoint(?, ?, ?, ?, ?, ?, ?, ?) }");
        callableStatement.setInt(1, runningCheckpointInfo.getCheckpointSummaryId());
        callableStatement.setInt(2, runningCheckpointInfo.getCheckpointId());
        callableStatement.setInt(3,
                                 (int) (endTimestamp - runningCheckpointInfo.getStartTimestamp()));
        callableStatement.setLong(4, transferSize);
        callableStatement.setInt(5, result);
        callableStatement.setInt(6, checkpointLogLevel.toInt());
        callableStatement.setTimestamp(7, new Timestamp(endTimestamp));
        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);
        }
    }
}
 
Example 14
Project: ats-framework   File: PGDbWriteAccess.java   Source Code and License Vote up 4 votes
@Override
public int startSuite( String packageName, String suiteName, long timestamp, int runId,
                       boolean closeConnection ) throws DatabaseAccessException {

    final String errMsg = "Unable to start suite with name " + suiteName;
    // create a new suite

    timestamp = inUTC(timestamp);

    final int indexRowsInserted = 5;
    final int indexSuiteId = 6;

    CallableStatement callableStatement = null;
    try {
        refreshInternalConnection();

        callableStatement = connection.prepareCall("{ call sp_start_suite(?, ?, ?, ?, ?, ?) }");

        if (packageName == null) {
            packageName = "";
        }
        callableStatement.setString(3, packageName);

        callableStatement.setString(1, suiteName);
        callableStatement.setInt(2, runId);
        callableStatement.setTimestamp(4, new Timestamp(timestamp));
        callableStatement.registerOutParameter(5, Types.INTEGER);
        callableStatement.registerOutParameter(6, Types.INTEGER);

        callableStatement.execute();

        if (callableStatement.getInt(indexRowsInserted) != 1) {
            throw new DatabaseAccessException(errMsg);
        } else {
            if (callableStatement.getInt(indexSuiteId) == 0) {
                throw new DatabaseAccessException(errMsg + " - suite ID returned was 0");
            }
        }
        // get the result
        return callableStatement.getInt(indexSuiteId);

    } catch (Exception e) {
        throw new DatabaseAccessException(errMsg, e);
    } finally {
        if (closeConnection) {
            DbUtils.close(connection, callableStatement);
        } else {
            DbUtils.closeStatement(callableStatement);
        }
    }
}