use of org.h2.jdbc.JdbcSQLNonTransientException in project openmrs-core by openmrs.
the class H2DatabaseIT method dropAllDatabaseObjects.
protected void dropAllDatabaseObjects() throws SQLException {
Connection connection = getConnection();
Statement statement = null;
try {
statement = connection.createStatement();
String query = "DROP ALL OBJECTS";
statement.execute(query);
} catch (JdbcSQLNonTransientException e) {
log.error("connection is already closed, most likely a test method already dropped all database objects");
} finally {
connection.close();
}
}
use of org.h2.jdbc.JdbcSQLNonTransientException in project ma-core-public by infiniteautomation.
the class H2DatabaseTest method test2ExploitLobStorageMap.
// This test may break database
// Needs to be executed as last test for the suite
// https://github.com/h2database/h2database/issues/1808
@Test(timeout = 10 * 1000)
public void test2ExploitLobStorageMap() throws SQLException {
Exception expected = null;
try {
Connection conn1 = Common.getBean(DatabaseProxy.class).getDataSource().getConnection();
String createTable = "CREATE TABLE t1 (id int AUTO_INCREMENT, ver bigint, data text, PRIMARY KEY (id))";
conn1.prepareStatement(createTable).executeUpdate();
String insert = "INSERT INTO t1 (id, ver, data) values (1, 0, ?)";
PreparedStatement insertStmt = conn1.prepareStatement(insert);
String largeData = org.h2.util.StringUtils.pad("", 512, "x", false);
insertStmt.setString(1, largeData);
insertStmt.executeUpdate();
new Thread(() -> {
try {
Connection conn2 = Common.getBean(DatabaseProxy.class).getDataSource().getConnection();
String update = "UPDATE t1 SET ver = ver + 1 WHERE id = 1";
while (!Thread.currentThread().isInterrupted()) {
conn2.prepareStatement(update).executeUpdate();
}
} catch (JdbcSQLSyntaxErrorException ex) {
assertEquals("42S02", ex.getSQLState());
assertEquals("UPDATE t1 SET ver = ver + 1 WHERE id = 1", ex.getSQL());
assertEquals("Table \"T1\" not found", ex.getOriginalMessage());
} catch (SQLException ex) {
throw new RuntimeException(ex);
}
}).start();
while (true) {
conn1.prepareStatement("SELECT * FROM t1").executeQuery();
}
} catch (JdbcSQLNonTransientException ex) {
expected = ex;
assertEquals("HY000", ex.getSQLState());
assertEquals("SELECT * FROM t1", ex.getSQL());
assertEquals("General error: \"java.lang.NullPointerException\"", ex.getOriginalMessage());
}
assertNotNull(expected);
}
Aggregations