use of org.h2.jdbc.JdbcSQLException in project h2database by h2database.
the class TestMultiThread method testViews.
private void testViews() throws Exception {
// currently the combination of LOCK_MODE=0 and MULTI_THREADED
// is not supported
deleteDb("lockMode");
final String url = getURL("lockMode;MULTI_THREADED=1", true);
// create some common tables and views
ExecutorService executor = Executors.newFixedThreadPool(8);
Connection conn = getConnection(url);
try {
Statement stat = conn.createStatement();
stat.execute("CREATE TABLE INVOICE(INVOICE_ID INT PRIMARY KEY, AMOUNT DECIMAL)");
stat.execute("CREATE VIEW INVOICE_VIEW as SELECT * FROM INVOICE");
stat.execute("CREATE TABLE INVOICE_DETAIL(DETAIL_ID INT PRIMARY KEY, " + "INVOICE_ID INT, DESCRIPTION VARCHAR)");
stat.execute("CREATE VIEW INVOICE_DETAIL_VIEW as SELECT * FROM INVOICE_DETAIL");
stat.close();
// create views that reference the common views in different threads
ArrayList<Future<Void>> jobs = new ArrayList<>();
for (int i = 0; i < 1000; i++) {
final int j = i;
jobs.add(executor.submit(new Callable<Void>() {
@Override
public Void call() throws Exception {
try (Connection conn2 = getConnection(url)) {
Statement stat2 = conn2.createStatement();
stat2.execute("CREATE VIEW INVOICE_VIEW" + j + " as SELECT * FROM INVOICE_VIEW");
// the following query intermittently results in a
// NullPointerException
stat2.execute("CREATE VIEW INVOICE_DETAIL_VIEW" + j + " as SELECT DTL.* FROM INVOICE_VIEW" + j + " INV JOIN INVOICE_DETAIL_VIEW DTL " + "ON INV.INVOICE_ID = DTL.INVOICE_ID" + " WHERE DESCRIPTION='TEST'");
ResultSet rs = stat2.executeQuery("SELECT * FROM INVOICE_VIEW" + j);
rs.next();
rs.close();
rs = stat2.executeQuery("SELECT * FROM INVOICE_DETAIL_VIEW" + j);
rs.next();
rs.close();
stat2.close();
}
return null;
}
}));
}
// check for exceptions
for (Future<Void> job : jobs) {
try {
job.get();
} catch (ExecutionException ex) {
// trying to test
if (!(ex.getCause() instanceof JdbcSQLException) || ((JdbcSQLException) ex.getCause()).getErrorCode() != ErrorCode.LOCK_TIMEOUT_1) {
throw ex;
}
}
}
} finally {
IOUtils.closeSilently(conn);
executor.shutdown();
executor.awaitTermination(20, TimeUnit.SECONDS);
}
deleteDb("lockMode");
}
Aggregations