use of org.h2.jaqu.Db in project h2database by h2database.
the class AnnotationsTest method testCreateTableIfRequiredAnnotation.
private void testCreateTableIfRequiredAnnotation() {
// tests JQTable.createTableIfRequired=false
Db noCreateDb = null;
try {
noCreateDb = Db.open("jdbc:h2:mem:", "sa", "sa");
noCreateDb.insertAll(ProductNoCreateTable.getList());
noCreateDb.close();
} catch (RuntimeException r) {
SQLException s = (SQLException) r.getCause();
assertEquals(ErrorCode.TABLE_OR_VIEW_NOT_FOUND_1, s.getErrorCode());
}
if (noCreateDb != null) {
JdbcUtils.closeSilently(noCreateDb.getConnection());
}
}
use of org.h2.jaqu.Db in project h2database by h2database.
the class TestLob method testLobCompression.
private void testLobCompression(boolean compress) throws Exception {
deleteDb("lob");
Connection conn;
conn = reconnect(null);
if (compress) {
conn.createStatement().execute("SET COMPRESS_LOB LZF");
} else {
conn.createStatement().execute("SET COMPRESS_LOB NO");
}
conn.createStatement().execute("CREATE TABLE TEST(ID INT PRIMARY KEY, C CLOB)");
PreparedStatement prep = conn.prepareStatement("INSERT INTO TEST VALUES(?, ?)");
long time = System.nanoTime();
int len = getSize(10, 40);
if (config.networked && config.big) {
len = 5;
}
StringBuilder buff = new StringBuilder();
for (int i = 0; i < 1000; i++) {
buff.append(StringUtils.xmlNode("content", null, "This is a test " + i));
}
String xml = buff.toString();
for (int i = 0; i < len; i++) {
prep.setInt(1, i);
prep.setString(2, xml + i);
prep.execute();
}
for (int i = 0; i < len; i++) {
ResultSet rs = conn.createStatement().executeQuery("SELECT * FROM TEST");
while (rs.next()) {
if (i == 0) {
assertEquals(xml + rs.getInt(1), rs.getString(2));
} else {
Reader r = rs.getCharacterStream(2);
String result = IOUtils.readStringAndClose(r, -1);
assertEquals(xml + rs.getInt(1), result);
}
}
}
time = System.nanoTime() - time;
trace("time: " + TimeUnit.NANOSECONDS.toMillis(time) + " compress: " + compress);
conn.close();
if (!config.memory) {
long length = new File(getBaseDir() + "/lob.h2.db").length();
trace("len: " + length + " compress: " + compress);
}
}
use of org.h2.jaqu.Db in project h2database by h2database.
the class TestMultiThread method testConcurrentLobAdd.
private void testConcurrentLobAdd() throws Exception {
String db = getTestName();
deleteDb(db);
final String url = getURL(db + ";MULTI_THREADED=1", true);
try (Connection conn = getConnection(url)) {
Statement stat = conn.createStatement();
stat.execute("create table test(id identity, data clob)");
Task[] tasks = new Task[2];
for (int i = 0; i < tasks.length; i++) {
Task t = new Task() {
@Override
public void call() throws Exception {
try (Connection c2 = getConnection(url)) {
PreparedStatement p2 = c2.prepareStatement("insert into test(data) values(?)");
while (!stop) {
p2.setCharacterStream(1, new StringReader(new String(new char[10 * 1024])));
p2.execute();
}
}
}
};
tasks[i] = t;
t.execute();
}
Thread.sleep(500);
for (Task t : tasks) {
t.get();
}
}
}
use of org.h2.jaqu.Db in project h2database by h2database.
the class TestMultiThread method testConcurrentView.
private void testConcurrentView() throws Exception {
if (config.mvcc || config.mvStore) {
return;
}
String db = getTestName();
deleteDb(db);
final String url = getURL(db + ";MULTI_THREADED=1", true);
final Random r = new Random();
try (Connection conn = getConnection(url)) {
Statement stat = conn.createStatement();
StringBuilder buff = new StringBuilder();
buff.append("create table test(id int");
final int len = 3;
for (int i = 0; i < len; i++) {
buff.append(", x" + i + " int");
}
buff.append(")");
stat.execute(buff.toString());
stat.execute("create view test_view as select * from test");
stat.execute("insert into test(id) select x from system_range(1, 2)");
Task t = new Task() {
@Override
public void call() throws Exception {
Connection c2 = getConnection(url);
while (!stop) {
c2.prepareStatement("select * from test_view where x" + r.nextInt(len) + "=1");
}
c2.close();
}
};
t.execute();
SynchronizedVerifier.setDetect(SmallLRUCache.class, true);
for (int i = 0; i < 1000; i++) {
conn.prepareStatement("select * from test_view where x" + r.nextInt(len) + "=1");
}
t.get();
SynchronizedVerifier.setDetect(SmallLRUCache.class, false);
}
}
use of org.h2.jaqu.Db in project jdbi by jdbi.
the class TestMixinInterfaces method setUp.
@Before
public void setUp() throws Exception {
JdbcDataSource ds = new JdbcDataSource();
ds.setURL(String.format("jdbc:h2:mem:%s;MVCC=TRUE", UUID.randomUUID()));
db = Jdbi.create(ds);
db.installPlugin(new SqlObjectPlugin());
handle = db.open();
handle.execute("create table something (id int primary key, name varchar(100))");
}
Aggregations