use of org.h2.test.db.Db in project h2database by h2database.
the class ModelsTest method testModelGeneration.
private void testModelGeneration() {
DbInspector inspector = new DbInspector(db);
List<String> models = inspector.generateModel(null, "SupportedTypes", "org.h2.test.jaqu", true, true);
assertEquals(1, models.size());
// a poor test, but a start
assertEquals(1364, models.get(0).length());
}
use of org.h2.test.db.Db in project h2database by h2database.
the class AliasMapTest method test.
@Override
public void test() throws Exception {
Db db = Db.open("jdbc:h2:mem:", "sa", "sa");
db.insertAll(Product.getList());
Product p = new Product();
List<Product> products = db.from(p).where(p.unitsInStock).is(9).orderBy(p.productId).select();
assertEquals("[]", products.toString());
db.close();
}
use of org.h2.test.db.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.test.db.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.test.db.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();
}
}
}
Aggregations