use of java.sql.CallableStatement in project voltdb by VoltDB.
the class TestJDBCSecurityEnabled method execUserProc.
private boolean execUserProc(String userProc) throws SQLException {
CallableStatement stmt = myconn.prepareCall("{call " + userProc + "(?) }");
stmt.setLong(1, 2);
try {
stmt.execute();
} catch (SQLException e) {
return false;
}
return true;
}
use of java.sql.CallableStatement in project voltdb by VoltDB.
the class TestJDBCSecurityEnabled method execDefaultProc.
private boolean execDefaultProc() throws SQLException {
CallableStatement stmt = myconn.prepareCall("{call T.upsert(?,?,?) }");
stmt.setInt(1, 1);
stmt.setDouble(2, 3.0);
stmt.setDouble(3, 4.0);
try {
stmt.execute();
} catch (SQLException e) {
return false;
}
return true;
}
use of java.sql.CallableStatement in project voltdb by VoltDB.
the class JDBCBenchmark method main.
// Application entry point
public static void main(String[] args) {
try {
KVConfig config = new KVConfig();
config.parse(JDBCBenchmark.class.getName(), args);
System.out.println(config.getConfigDumpString());
// ---------------------------------------------------------------------------------------------------------------------------------------------------
// We need only do this once, to "hot cache" the JDBC driver reference so the JVM may realize it's there.
Class.forName("org.voltdb.jdbc.Driver");
// Prepare the JDBC URL for the VoltDB driver
String url = "jdbc:voltdb://" + config.servers;
// Get a client connection - we retry for a while in case the server hasn't started yet
System.out.printf("Connecting to: %s\n", url);
int sleep = 1000;
while (true) {
try {
Con = DriverManager.getConnection(url, "", "");
break;
} catch (Exception e) {
System.err.printf("Connection failed - retrying in %d second(s).\n", sleep / 1000);
try {
Thread.sleep(sleep);
} catch (Exception tie) {
}
if (sleep < 8000)
sleep += sleep;
}
}
// Statistics manager objects from the connection, used to generate latency histogram
ClientStatsContext fullStatsContext = ((IVoltDBConnection) Con).createStatsContext();
periodicStatsContext = ((IVoltDBConnection) Con).createStatsContext();
System.out.println("Connected. Starting benchmark.");
// Get a payload generator to create random Key-Value pairs to store in the database and process (uncompress) pairs retrieved from the database.
final PayloadProcessor processor = new PayloadProcessor(config.keysize, config.minvaluesize, config.maxvaluesize, config.entropy, config.poolsize, config.usecompression);
// Initialize the store
if (config.preload) {
System.out.print("Initializing data store... ");
final PreparedStatement removeCS = Con.prepareStatement("DELETE FROM store;");
final CallableStatement putCS = Con.prepareCall("{call STORE.upsert(?,?)}");
for (int i = 0; i < config.poolsize; i++) {
if (i == 0) {
removeCS.execute();
}
putCS.setString(1, String.format(processor.KeyFormat, i));
putCS.setBytes(2, processor.generateForStore().getStoreValue());
putCS.execute();
}
System.out.println(" Done.");
}
// start the stats
fullStatsContext.fetchAndResetBaseline();
periodicStatsContext.fetchAndResetBaseline();
benchmarkStartTS = System.currentTimeMillis();
// ---------------------------------------------------------------------------------------------------------------------------------------------------
// Create a Timer task to display performance data on the operating procedures
Timer timer = new Timer();
TimerTask statsPrinting = new TimerTask() {
@Override
public void run() {
printStatistics();
}
};
timer.scheduleAtFixedRate(statsPrinting, config.displayinterval * 1000l, config.displayinterval * 1000l);
// ---------------------------------------------------------------------------------------------------------------------------------------------------
// Create multiple processing threads
ArrayList<Thread> threads = new ArrayList<Thread>();
for (int i = 0; i < config.threads; i++) threads.add(new Thread(new ClientThread(url, processor, config.duration, config.getputratio)));
// Start threads
for (Thread thread : threads) thread.start();
// Wait for threads to complete
for (Thread thread : threads) thread.join();
// ---------------------------------------------------------------------------------------------------------------------------------------------------
// We're done - stop the performance statistics display task
timer.cancel();
// ---------------------------------------------------------------------------------------------------------------------------------------------------
// Now print application results:
// stop and fetch the stats
ClientStats stats = fullStatsContext.fetch().getStats();
// 1. Store statistics as tracked by the application (ops counts, payload traffic)
System.out.printf("\n-------------------------------------------------------------------------------------\n" + " Store Results\n" + "-------------------------------------------------------------------------------------\n\n" + "A total of %,d operations was posted...\n" + " - GETs: %,9d Operations (%,9d Misses/Failures)\n" + " %,9d MB in compressed store data\n" + " %,9d MB in uncompressed application data\n" + " Network Throughput: %6.3f Gbps*\n\n" + " - PUTs: %,9d Operations (%,9d Failures)\n" + " %,9d MB in compressed store data\n" + " %,9d MB in uncompressed application data\n" + " Network Throughput: %6.3f Gbps*\n\n" + " - Total Network Throughput: %6.3f Gbps*\n\n" + "* Figure includes key & value traffic but not database protocol overhead.\n" + "\n" + "-------------------------------------------------------------------------------------\n", GetStoreResults.get(0) + GetStoreResults.get(1) + PutStoreResults.get(0) + PutStoreResults.get(1), GetStoreResults.get(0), GetStoreResults.get(1), GetCompressionResults.get(0) / 1048576l, GetCompressionResults.get(1) / 1048576l, ((double) GetCompressionResults.get(0) + (GetStoreResults.get(0) + GetStoreResults.get(1)) * config.keysize) / (134217728d * config.duration), PutStoreResults.get(0), PutStoreResults.get(1), PutCompressionResults.get(0) / 1048576l, PutCompressionResults.get(1) / 1048576l, ((double) PutCompressionResults.get(0) + (PutStoreResults.get(0) + PutStoreResults.get(1)) * config.keysize) / (134217728d * config.duration), ((double) GetCompressionResults.get(0) + (GetStoreResults.get(0) + GetStoreResults.get(1)) * config.keysize) / (134217728d * config.duration) + ((double) PutCompressionResults.get(0) + (PutStoreResults.get(0) + PutStoreResults.get(1)) * config.keysize) / (134217728d * config.duration));
System.out.println("\n\n-------------------------------------------------------------------------------------\n" + " Client Latency Statistics\n" + "-------------------------------------------------------------------------------------\n\n");
System.out.printf("Average latency: %,9.2f ms\n", stats.getAverageLatency());
System.out.printf("10th percentile latency: %,9.2f ms\n", stats.kPercentileLatencyAsDouble(.1));
System.out.printf("25th percentile latency: %,9.2f ms\n", stats.kPercentileLatencyAsDouble(.25));
System.out.printf("50th percentile latency: %,9.2f ms\n", stats.kPercentileLatencyAsDouble(.5));
System.out.printf("75th percentile latency: %,9.2f ms\n", stats.kPercentileLatencyAsDouble(.75));
System.out.printf("90th percentile latency: %,9.2f ms\n", stats.kPercentileLatencyAsDouble(.9));
System.out.printf("95th percentile latency: %,9.2f ms\n", stats.kPercentileLatencyAsDouble(.95));
System.out.printf("99th percentile latency: %,9.2f ms\n", stats.kPercentileLatencyAsDouble(.99));
System.out.printf("99.5th percentile latency: %,9.2f ms\n", stats.kPercentileLatencyAsDouble(.995));
System.out.printf("99.9th percentile latency: %,9.2f ms\n", stats.kPercentileLatencyAsDouble(.999));
System.out.println("\n\n" + stats.latencyHistoReport());
// Dump statistics to a CSV file
Con.unwrap(IVoltDBConnection.class).saveStatistics(stats, config.statsfile);
Con.close();
// ---------------------------------------------------------------------------------------------------------------------------------------------------
} catch (Exception x) {
System.out.println("Exception: " + x);
x.printStackTrace();
}
}
use of java.sql.CallableStatement in project ats-framework by Axway.
the class DbReadAccess method getCheckpointStatistics.
public List<Statistic> getCheckpointStatistics(float timeOffset, String testcaseIds, String actionNames, Set<String> expectedSingleActionUIDs, Set<String> expectedCombinedActionUIDs) throws DatabaseAccessException {
List<Statistic> allStatistics = new ArrayList<Statistic>();
String sqlLog = new SqlRequestFormatter().add("fdate", formatDateFromEpoch(timeOffset)).add("testcase ids", testcaseIds).add("checkpoint names", actionNames).format();
Map<String, Integer> fakeStatisticIds = new HashMap<String, Integer>();
/*
* The DB does not contain combined statistics, so we must create them.
*
* All statistics with same name are combined in one statistic(no matter how many queues are).
* In cases when there are more than one hits at same timestamp, we do not sum the values, but we
* pass the same number of statistics for this timestamp - users see balloon marker on Test Explorer
*/
Map<String, Statistic> combinedStatistics = new HashMap<String, Statistic>();
Map<String, Integer> combinedStatisticHitsAtSameTimestamp = new HashMap<String, Integer>();
Connection connection = getConnection();
CallableStatement callableStatement = null;
ResultSet rs = null;
try {
callableStatement = connection.prepareCall("{ call sp_get_checkpoint_statistics(?, ?, ?) }");
callableStatement.setString(1, formatDateFromEpoch(timeOffset));
callableStatement.setString(2, testcaseIds);
callableStatement.setString(3, actionNames);
int numberRecords = 0;
rs = callableStatement.executeQuery();
while (rs.next()) {
// add new statistic
Statistic statistic = new Statistic();
statistic.name = rs.getString("statsName");
statistic.parentName = rs.getString("queueName");
statistic.unit = "ms";
statistic.value = rs.getFloat("value");
statistic.timestamp = rs.getLong("statsAxisTimestamp");
// Checkpoints will be collected and displayed for testcase
statistic.machineId = 0;
statistic.testcaseId = rs.getInt("testcaseId");
statistic.statisticTypeId = getStatisticFakeId(START_FAKE_ID_VALUE_FOR_CHECKPOINTS, fakeStatisticIds, statistic);
// add to single statistics
if (expectedSingleActionUIDs.contains(statistic.getUid())) {
allStatistics.add(statistic);
}
// add to combined statistics
if (expectedCombinedActionUIDs.contains(statistic.getCombinedStatisticUid())) {
String statisticKey = statistic.timestamp + "->" + statistic.name;
Integer timesHaveThisStatisticAtThisTimestamp = combinedStatisticHitsAtSameTimestamp.get(statisticKey);
Statistic combinedStatistic;
if (timesHaveThisStatisticAtThisTimestamp == null) {
// create a new combined statistic
combinedStatistic = new Statistic();
combinedStatistic.name = statistic.name;
combinedStatistic.parentName = Statistic.COMBINED_STATISTICS_CONTAINER;
combinedStatistic.unit = statistic.unit;
combinedStatistic.timestamp = statistic.timestamp;
combinedStatistic.machineId = statistic.machineId;
combinedStatistic.testcaseId = statistic.testcaseId;
// this is the first such statistic at this timestamp
timesHaveThisStatisticAtThisTimestamp = 1;
} else {
// create another copy of this statistic
combinedStatistic = combinedStatistics.get(statisticKey + "->" + timesHaveThisStatisticAtThisTimestamp).newInstance();
// we already had such statistic at this timestamp
timesHaveThisStatisticAtThisTimestamp++;
}
combinedStatistic.value = statistic.value;
combinedStatistic.statisticTypeId = getStatisticFakeId(START_FAKE_ID_VALUE_FOR_CHECKPOINTS, fakeStatisticIds, combinedStatistic);
// remember how many times we got same statistic at same timestamp
combinedStatisticHitsAtSameTimestamp.put(statisticKey, timesHaveThisStatisticAtThisTimestamp);
// Remember this statistic in the list
// The way we create the map key assures the proper time ordering
combinedStatistics.put(statisticKey + "->" + timesHaveThisStatisticAtThisTimestamp, combinedStatistic);
}
numberRecords++;
}
if (combinedStatistics.size() > 0) {
// sort the combined statistics by their timestamps
List<Statistic> sortedStatistics = new ArrayList<Statistic>(combinedStatistics.values());
Collections.sort(sortedStatistics, new Comparator<Statistic>() {
@Override
public int compare(Statistic stat1, Statistic stat2) {
return (int) (stat1.timestamp - stat2.timestamp);
}
});
// add the combined statistics to the others
allStatistics.addAll(sortedStatistics);
}
logQuerySuccess(sqlLog, "action response statistics", numberRecords);
} catch (Exception e) {
throw new DatabaseAccessException("Error when " + sqlLog, e);
} finally {
DbUtils.closeResultSet(rs);
DbUtils.close(connection, callableStatement);
}
return allStatistics;
}
use of java.sql.CallableStatement in project ats-framework by Axway.
the class DbReadAccess method getSystemStatisticDescriptions.
public List<StatisticDescription> getSystemStatisticDescriptions(float timeOffset, String testcaseIds, Map<String, String> testcaseAliases) throws DatabaseAccessException {
List<StatisticDescription> statisticDescriptions = new ArrayList<StatisticDescription>();
String sqlLog = new SqlRequestFormatter().add("fdate", formatDateFromEpoch(timeOffset)).add("testcase ids", testcaseIds).format();
Connection connection = getConnection();
CallableStatement callableStatement = null;
ResultSet rs = null;
try {
callableStatement = connection.prepareCall("{ call sp_get_system_statistic_descriptions(?, ?) }");
callableStatement.setString(1, formatDateFromEpoch(timeOffset));
callableStatement.setString(2, testcaseIds);
rs = callableStatement.executeQuery();
int numberRecords = 0;
while (rs.next()) {
StatisticDescription statisticDescription = new StatisticDescription();
statisticDescription.testcaseId = rs.getInt("testcaseId");
// if user has provided testcase alias - use it instead the original testcase name
if (testcaseAliases != null) {
statisticDescription.testcaseName = testcaseAliases.get(String.valueOf(statisticDescription.testcaseId));
}
if (statisticDescription.testcaseName == null) {
statisticDescription.testcaseName = rs.getString("testcaseName");
}
statisticDescription.testcaseStarttime = rs.getInt("testcaseStarttime");
statisticDescription.machineId = rs.getInt("machineId");
statisticDescription.machineName = rs.getString("machineName");
statisticDescription.statisticTypeId = rs.getInt("statsTypeId");
statisticDescription.statisticName = rs.getString("name");
statisticDescription.unit = rs.getString("units");
statisticDescription.params = rs.getString("params");
statisticDescription.parent = rs.getString("parentName");
statisticDescription.internalName = rs.getString("internalName");
statisticDescription.numberMeasurements = rs.getInt("statsNumberMeasurements");
statisticDescription.minValue = rs.getFloat("statsMinValue");
statisticDescription.maxValue = rs.getFloat("statsMaxValue");
statisticDescription.avgValue = rs.getFloat("statsAvgValue");
statisticDescriptions.add(statisticDescription);
numberRecords++;
}
logQuerySuccess(sqlLog, "system statistic descriptions", numberRecords);
} catch (Exception e) {
throw new DatabaseAccessException("Error when " + sqlLog, e);
} finally {
DbUtils.closeResultSet(rs);
DbUtils.close(connection, callableStatement);
}
return statisticDescriptions;
}
Aggregations