Skip to content

Instantly share code, notes, and snippets.

@marcelo-ochoa
Created August 24, 2020 17:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcelo-ochoa/6c1af8bf1445c12961006908259a2d56 to your computer and use it in GitHub Desktop.
Save marcelo-ochoa/6c1af8bf1445c12961006908259a2d56 to your computer and use it in GitHub Desktop.
package com.dom.benchmarking.swingbench.testcollection;
import com.dom.benchmarking.swingbench.event.JdbcTaskEvent;
import com.dom.benchmarking.swingbench.kernel.SwingBenchException;
import com.dom.benchmarking.swingbench.kernel.SwingBenchTask;
import com.dom.util.RandomUtilities;
import java.sql.Connection;
import java.sql.Timestamp;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Map;
import oracle.jdbc.OraclePreparedStatement;
public final class StressTestInsert extends StressTest {
public StressTestInsert() {
}
public void execute(Map parameters) throws SwingBenchException {
Connection connection = (Connection) parameters.get(SwingBenchTask.JDBC_CONNECTION);
PreparedStatement insPs = null;
boolean success = true;
initJdbcTask();
long executeStart = System.nanoTime();
try {
insPs = connection.prepareStatement("INSERT /*+ memoptimize_write */ INTO TESTCOLLECTION VALUES (?,?,?,?,?)");
((OraclePreparedStatement) insPs).setExecuteBatch(100);
for (int i=0;i<=100;i++) {
insPs.setString(1, RandomUtilities.randomAlpha(32, 32)); // 8937136EF68A435A95A39F27AC4BFB2C
insPs.setTimestamp(2,new Timestamp(System.currentTimeMillis())); // systimestamp
insPs.setTimestamp(3,new Timestamp(System.currentTimeMillis())); // systimestamp
insPs.setString(4, RandomUtilities.randomAlpha(32, 32)); // DAF3015E8A2A4B84AE7F4B5988E1E1EB
insPs.setString(5, "{\"name\": \"todd\", \"is_cool\": true, \"age\": 43}");
insPs.execute();
}
((OraclePreparedStatement) insPs).sendBatch ();
connection.commit();
addInsertStatements(1);
addCommitStatements(1);
} catch (SQLException ex) {
success = false;
System.out.println(ex);
} finally {
try {
insPs.close();
} catch (SQLException e) {
}
processTransactionEvent(new JdbcTaskEvent(this, getId(), (System.nanoTime() -
executeStart), success, getSelectStatements(), getInsertStatements(), getUpdateStatements(), getDeleteStatements(), getCommitStatements(), getRollbackStatements()));
}
}
public void close() {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment