use of org.h2.jaqu.Db in project h2database by h2database.
the class MVTableEngine method createTable.
@Override
public TableBase createTable(CreateTableData data) {
Database db = data.session.getDatabase();
Store store = init(db);
MVTable table = new MVTable(data, store);
table.init(data.session);
store.tableMap.put(table.getMapName(), table);
return table;
}
use of org.h2.jaqu.Db in project h2database by h2database.
the class MVTableEngine method init.
/**
* Initialize the MVStore.
*
* @param db the database
* @return the store
*/
public static Store init(final Database db) {
Store store = db.getMvStore();
if (store != null) {
return store;
}
byte[] key = db.getFileEncryptionKey();
String dbPath = db.getDatabasePath();
MVStore.Builder builder = new MVStore.Builder();
store = new Store();
boolean encrypted = false;
if (dbPath != null) {
String fileName = dbPath + Constants.SUFFIX_MV_FILE;
MVStoreTool.compactCleanUp(fileName);
builder.fileName(fileName);
builder.pageSplitSize(db.getPageSize());
if (db.isReadOnly()) {
builder.readOnly();
} else {
// possibly create the directory
boolean exists = FileUtils.exists(fileName);
if (exists && !FileUtils.canWrite(fileName)) {
// read only
} else {
String dir = FileUtils.getParent(fileName);
FileUtils.createDirectories(dir);
}
}
if (key != null) {
encrypted = true;
char[] password = new char[key.length / 2];
for (int i = 0; i < password.length; i++) {
password[i] = (char) (((key[i + i] & 255) << 16) | ((key[i + i + 1]) & 255));
}
builder.encryptionKey(password);
}
if (db.getSettings().compressData) {
builder.compress();
// use a larger page split size to improve the compression ratio
builder.pageSplitSize(64 * 1024);
}
builder.backgroundExceptionHandler(new UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread t, Throwable e) {
db.setBackgroundException(DbException.convert(e));
}
});
}
store.open(db, builder, encrypted);
db.setMvStore(store);
return store;
}
use of org.h2.jaqu.Db in project h2database by h2database.
the class TestRecoverKillLoop method runTest.
private void runTest(int count) throws Exception {
FileUtils.deleteRecursive("data/db", false);
Random random = new Random(1);
for (int i = 0; i < count; i++) {
String[] procDef = { "java", "-cp", getClassPath(), "-Dtest.dir=data/db", TestRecover.class.getName() };
Process p = Runtime.getRuntime().exec(procDef);
InputStream in = p.getInputStream();
OutputCatcher catcher = new OutputCatcher(in);
catcher.start();
while (true) {
String s = catcher.readLine(60 * 1000);
// System.out.println("> " + s);
if (s == null) {
fail("No reply from process");
} else if (s.startsWith("testing...")) {
int sleep = random.nextInt(10000);
Thread.sleep(sleep);
printTime("killing");
p.destroy();
p.waitFor();
break;
} else if (s.startsWith("error!")) {
fail("Failed: " + s);
}
}
}
}
use of org.h2.jaqu.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.jaqu.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();
}
Aggregations