use of org.h2.index.Index in project h2database by h2database.
the class TestRecovery method testRunScript.
private void testRunScript() throws SQLException {
DeleteDbFiles.execute(getBaseDir(), "recovery", true);
DeleteDbFiles.execute(getBaseDir(), "recovery2", true);
org.h2.Driver.load();
Connection conn = getConnection("recovery");
Statement stat = conn.createStatement();
stat.execute("create table \"Joe\"\"s Table\" as " + "select 1");
stat.execute("create table test as " + "select * from system_range(1, 100)");
stat.execute("create view \"TEST VIEW OF TABLE TEST\" as " + "select * from test");
stat.execute("create table a(id int primary key) as " + "select * from system_range(1, 100)");
stat.execute("create table b(id int references a(id)) as " + "select * from system_range(1, 100)");
stat.execute("create table lob(c clob, b blob) as " + "select space(10000) || 'end', SECURE_RAND(10000)");
stat.execute("create table d(d varchar) as " + "select space(10000) || 'end'");
stat.execute("alter table a add foreign key(id) references b(id)");
// all rows have the same value - so that SCRIPT can't re-order the rows
stat.execute("create table e(id varchar) as " + "select space(10) from system_range(1, 1000)");
stat.execute("create index idx_e_id on e(id)");
conn.close();
Recover rec = new Recover();
ByteArrayOutputStream buff = new ByteArrayOutputStream();
rec.setOut(new PrintStream(buff));
rec.runTool("-dir", getBaseDir(), "-db", "recovery", "-trace");
String out = new String(buff.toByteArray());
assertContains(out, "Created file");
Connection conn2 = getConnection("recovery2");
Statement stat2 = conn2.createStatement();
String name = "recovery.h2.sql";
stat2.execute("runscript from '" + getBaseDir() + "/" + name + "'");
stat2.execute("select * from test");
conn2.close();
conn = getConnection("recovery");
stat = conn.createStatement();
conn2 = getConnection("recovery2");
stat2 = conn2.createStatement();
assertEqualDatabases(stat, stat2);
conn.close();
conn2.close();
Recover.execute(getBaseDir(), "recovery");
deleteDb("recovery");
deleteDb("recovery2");
FileUtils.delete(getBaseDir() + "/recovery.h2.sql");
String dir = getBaseDir() + "/recovery.lobs.db";
FileUtils.deleteRecursive(dir, false);
}
use of org.h2.index.Index in project h2database by h2database.
the class TableDefinition method mapObject.
void mapObject(Object obj) {
fieldMap.clear();
initObject(obj, fieldMap);
if (clazz.isAnnotationPresent(JQSchema.class)) {
JQSchema schemaAnnotation = clazz.getAnnotation(JQSchema.class);
// setup schema name mapping, if properly annotated
if (!StringUtils.isNullOrEmpty(schemaAnnotation.name())) {
schemaName = schemaAnnotation.name();
}
}
if (clazz.isAnnotationPresent(JQTable.class)) {
JQTable tableAnnotation = clazz.getAnnotation(JQTable.class);
// setup table name mapping, if properly annotated
if (!StringUtils.isNullOrEmpty(tableAnnotation.name())) {
tableName = tableAnnotation.name();
}
// allow control over createTableIfRequired()
createTableIfRequired = tableAnnotation.createIfRequired();
// model version
if (tableAnnotation.version() > 0) {
tableVersion = tableAnnotation.version();
}
// setup the primary index, if properly annotated
List<String> primaryKey = getColumns(tableAnnotation.primaryKey());
if (primaryKey != null) {
setPrimaryKey(primaryKey);
}
}
if (clazz.isAnnotationPresent(JQIndex.class)) {
JQIndex indexAnnotation = clazz.getAnnotation(JQIndex.class);
// setup the indexes, if properly annotated
addIndexes(IndexType.STANDARD, indexAnnotation.standard());
addIndexes(IndexType.UNIQUE, indexAnnotation.unique());
addIndexes(IndexType.HASH, indexAnnotation.hash());
addIndexes(IndexType.UNIQUE_HASH, indexAnnotation.uniqueHash());
}
}
use of org.h2.index.Index in project h2database by h2database.
the class TestAll method run.
private static void run(String... args) throws Exception {
SelfDestructor.startCountdown(4 * 60);
long time = System.nanoTime();
printSystemInfo();
// use lower values, to better test those cases,
// and (for delays) to speed up the tests
System.setProperty("h2.maxMemoryRows", "100");
System.setProperty("h2.check2", "true");
System.setProperty("h2.delayWrongPasswordMin", "0");
System.setProperty("h2.delayWrongPasswordMax", "0");
System.setProperty("h2.useThreadContextClassLoader", "true");
// System.setProperty("h2.modifyOnWrite", "true");
// speedup
// System.setProperty("h2.syncMethod", "");
/*
recovery tests with small freeList pages, page size 64
reopen org.h2.test.unit.TestPageStore
-Xmx1500m -D reopenOffset=3 -D reopenShift=1
power failure test
power failure test: MULTI_THREADED=TRUE
power failure test: larger binaries and additional index.
power failure test with randomly generating / dropping indexes and tables.
drop table test;
create table test(id identity, name varchar(100) default space(100));
@LOOP 10 insert into test select null, null from system_range(1, 100000);
delete from test;
documentation: review package and class level javadocs
documentation: rolling review at main.html
-------------
remove old TODO, move to roadmap
kill a test:
kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
*/
TestAll test = new TestAll();
if (args.length > 0) {
if ("travis".equals(args[0])) {
test.travis = true;
test.testAll();
} else if ("vmlens".equals(args[0])) {
test.vmlens = true;
test.testAll();
} else if ("reopen".equals(args[0])) {
System.setProperty("h2.delayWrongPasswordMin", "0");
System.setProperty("h2.check2", "false");
System.setProperty("h2.analyzeAuto", "100");
System.setProperty("h2.pageSize", "64");
System.setProperty("h2.reopenShift", "5");
FilePathRec.register();
test.reopen = true;
TestReopen reopen = new TestReopen();
reopen.init();
FilePathRec.setRecorder(reopen);
test.runTests();
} else if ("crash".equals(args[0])) {
test.endless = true;
new TestCrashAPI().runTest(test);
} else if ("synth".equals(args[0])) {
new TestSynth().runTest(test);
} else if ("kill".equals(args[0])) {
new TestKill().runTest(test);
} else if ("random".equals(args[0])) {
test.endless = true;
new TestRandomSQL().runTest(test);
} else if ("join".equals(args[0])) {
new TestJoin().runTest(test);
test.endless = true;
} else if ("btree".equals(args[0])) {
new TestBtreeIndex().runTest(test);
} else if ("all".equals(args[0])) {
test.testEverything();
} else if ("codeCoverage".equals(args[0])) {
test.codeCoverage = true;
test.runCoverage();
} else if ("multiThread".equals(args[0])) {
new TestMulti().runTest(test);
} else if ("halt".equals(args[0])) {
new TestHaltApp().runTest(test);
} else if ("timer".equals(args[0])) {
new TestTimer().runTest(test);
}
} else {
test.testAll();
}
System.out.println(TestBase.formatTime(TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - time)) + " total");
}
use of org.h2.index.Index in project h2database by h2database.
the class ValueHashMap method get.
/**
* Get the value for this key. This method returns null if the key was not
* found.
*
* @param key the key
* @return the value for the given key
*/
public V get(Value key) {
int index = getIndex(key);
int plus = 1;
do {
Value k = keys[index];
if (k == null) {
// found an empty record
return null;
} else if (k == ValueNull.DELETED) {
// found a deleted record
} else if (k.equals(key)) {
// found it
return values[index];
}
index = (index + plus++) & mask;
} while (plus <= len);
return null;
}
use of org.h2.index.Index in project h2database by h2database.
the class TestMVTableEngine method testAutoCommit.
private void testAutoCommit() throws SQLException {
Connection conn;
Statement stat;
ResultSet rs;
deleteDb(getTestName());
conn = getConnection(getTestName() + ";MV_STORE=TRUE");
for (int i = 0; i < 2; i++) {
stat = conn.createStatement();
stat.execute("create table test(id int primary key, name varchar)");
stat.execute("create index on test(name)");
conn.setAutoCommit(false);
stat.execute("insert into test values(1, 'Hello')");
stat.execute("insert into test values(2, 'World')");
rs = stat.executeQuery("select count(*) from test");
rs.next();
assertEquals(2, rs.getInt(1));
conn.rollback();
rs = stat.executeQuery("select count(*) from test");
rs.next();
assertEquals(0, rs.getInt(1));
stat.execute("insert into test values(1, 'Hello')");
Savepoint sp = conn.setSavepoint();
stat.execute("insert into test values(2, 'World')");
conn.rollback(sp);
rs = stat.executeQuery("select count(*) from test");
rs.next();
assertEquals(1, rs.getInt(1));
stat.execute("drop table test");
}
conn.close();
}
Aggregations