use of java.sql.CallableStatement in project ats-framework by Axway.
the class DbWriteAccess method populateSystemStatisticDefinition.
public int populateSystemStatisticDefinition(String name, String parentName, String internalName, String unit, String params) throws DatabaseAccessException {
if (parentName == null) {
parentName = "";
}
if (internalName == null) {
internalName = "";
}
CallableStatement callableStatement = null;
Connection con = null;
boolean useLocalConnection = false;
try {
if (connection == null || connection.isClosed()) {
// connection not set externally so use new connection only for this method invocation
useLocalConnection = true;
con = getConnection();
} else {
useLocalConnection = false;
con = connection;
}
final int statisticId = 6;
callableStatement = con.prepareCall("{ call sp_populate_system_statistic_definition(?, ?, ?, ?, ?, ?) }");
callableStatement.setString(1, parentName);
callableStatement.setString(2, internalName);
callableStatement.setString(3, name);
callableStatement.setString(4, unit);
callableStatement.setString(5, params);
callableStatement.registerOutParameter(statisticId, Types.INTEGER);
callableStatement.execute();
return callableStatement.getInt(statisticId);
} catch (Exception e) {
String errMsg = "Unable to populate statistic '" + name + "' with unit '" + unit + "' and params '" + params + "'";
throw new DatabaseAccessException(errMsg, e);
} finally {
DbUtils.closeStatement(callableStatement);
if (useLocalConnection) {
DbUtils.closeConnection(con);
}
}
}
use of java.sql.CallableStatement in project ats-framework by Axway.
the class DbWriteAccess method addScenarioMetainfo.
/**
* Update meta info about an existing test scenario.
* This data is expected to come from java method annotations
*
* @param testcaseId
* @param metaKey
* @param metaValue
* @param closeConnection
* @throws DatabaseAccessException
*/
public void addScenarioMetainfo(int testcaseId, String metaKey, String metaValue, boolean closeConnection) throws DatabaseAccessException {
final String errMsg = "Unable to add scenario meta info '" + metaKey + "=" + metaValue + "' to scenario for testcase with id " + testcaseId;
final int indexRowsInserted = 4;
CallableStatement callableStatement = null;
try {
refreshInternalConnection();
callableStatement = connection.prepareCall("{ call sp_add_scenario_metainfo(?, ?, ?, ?) }");
callableStatement.setInt(1, testcaseId);
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);
}
}
}
use of java.sql.CallableStatement in project ats-framework by Axway.
the class DbWriteAccess method deleteTestcase.
public void deleteTestcase(List<Object> objectsToDelete) throws DatabaseAccessException {
StringBuilder testcaseIds = new StringBuilder();
for (Object obj : objectsToDelete) {
testcaseIds.append(((Testcase) obj).testcaseId);
testcaseIds.append(",");
}
testcaseIds.delete(testcaseIds.length() - 1, testcaseIds.length());
final String errMsg = "Unable to delete testcase(s) with id " + testcaseIds;
Connection connection = getConnection();
CallableStatement callableStatement = null;
try {
callableStatement = connection.prepareCall("{ call sp_delete_testcase(?) }");
callableStatement.setString(1, testcaseIds.toString());
callableStatement.execute();
} catch (SQLException e) {
throw new DatabaseAccessException(errMsg, e);
} finally {
DbUtils.close(connection, callableStatement);
}
}
use of java.sql.CallableStatement in project ats-framework by Axway.
the class DbWriteAccess method endSuite.
public void endSuite(long timestamp, int suiteId, boolean closeConnection) throws DatabaseAccessException {
final String errMsg = "Unable to end suite with id " + suiteId;
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);
}
}
}
use of java.sql.CallableStatement in project ats-framework by Axway.
the class DbWriteAccess method endLoadQueue.
public void endLoadQueue(int result, long timestamp, int loadQueueId, boolean closeConnection) throws DatabaseAccessException {
final String errMsg = "Unable to end load queue with id " + loadQueueId;
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);
}
}
}
Aggregations