use of org.h2.engine.Database in project siena by mandubian.
the class FullText method reindex.
/**
* Re-creates the full text index for this database. Calling this method is
* usually not needed, as the index is kept up-to-date automatically.
*
* @param conn the connection
*/
public static void reindex(Connection conn) throws SQLException {
init(conn);
removeAllTriggers(conn, TRIGGER_PREFIX);
FullTextSettings setting = FullTextSettings.getInstance(conn);
setting.getWordList().clear();
Statement stat = conn.createStatement();
stat.execute("TRUNCATE TABLE " + SCHEMA + ".WORDS");
stat.execute("TRUNCATE TABLE " + SCHEMA + ".ROWS");
stat.execute("TRUNCATE TABLE " + SCHEMA + ".MAP");
ResultSet rs = stat.executeQuery("SELECT * FROM " + SCHEMA + ".FT_INDEXES");
while (rs.next()) {
String schema = rs.getString("SCHEMA");
String table = rs.getString("TABLE");
createTrigger(conn, schema, table);
indexExistingRows(conn, schema, table);
}
}
use of org.h2.engine.Database in project frostwire by frostwire.
the class FullTextLucene2 method indexExistingRows.
/**
* Add the existing data to the index.
*
* @param conn the database connection
* @param schema the schema name
* @param table the table name
*/
protected static void indexExistingRows(Connection conn, String schema, String table) throws SQLException {
FullTextLucene2.FullTextTrigger existing = new FullTextLucene2.FullTextTrigger();
existing.init(conn, schema, null, table, false, Trigger.INSERT);
String sql = "SELECT * FROM " + StringUtils.quoteIdentifier(schema) + "." + StringUtils.quoteIdentifier(table);
ResultSet rs = conn.createStatement().executeQuery(sql);
int columnCount = rs.getMetaData().getColumnCount();
while (rs.next()) {
Object[] row = new Object[columnCount];
for (int i = 0; i < columnCount; i++) {
row[i] = rs.getObject(i + 1);
}
// existing.fire(conn, null, row);
existing.insert(row, false);
}
existing.commitIndex();
}
use of org.h2.engine.Database in project frostwire by frostwire.
the class FullTextLucene2 method getIndexPath.
/**
* Get the path of the Lucene index for this database.
*
* @param conn the database connection
* @return the path
*/
protected static String getIndexPath(Connection conn) throws SQLException {
Statement stat = conn.createStatement();
ResultSet rs = stat.executeQuery("CALL DATABASE_PATH()");
rs.next();
String path = rs.getString(1);
if (path == null) {
throw throwException("Fulltext search for in-memory databases is not supported.");
}
int index = path.lastIndexOf(':');
// position 1 means a windows drive letter is used, ignore that
if (index > 1) {
path = path.substring(index + 1);
}
rs.close();
return path;
}
use of org.h2.engine.Database in project rxjava2-jdbc by davidmoten.
the class DatabaseTest method testSelectConcurrencyTest.
@Test(timeout = 5000)
public void testSelectConcurrencyTest() throws InterruptedException, TimeoutException {
debug();
try {
try (Database db = db(1)) {
Scheduler scheduler = Schedulers.from(Executors.newFixedThreadPool(2));
int n = 2;
CountDownLatch latch = new CountDownLatch(n);
AtomicInteger count = new AtomicInteger();
for (int i = 0; i < n; i++) {
//
db.select("select score from person where name=?").parameters("FRED", //
"JOSEPH").getAs(//
Integer.class).subscribeOn(//
scheduler).toList().doOnSuccess(x -> {
if (!x.equals(Lists.newArrayList(21, 34))) {
throw new RuntimeException("run broken");
}
}).doOnSuccess(x -> {
count.incrementAndGet();
latch.countDown();
}).doOnError(//
x -> latch.countDown()).subscribe();
log.info("submitted " + i);
}
if (!latch.await(5000, TimeUnit.SECONDS)) {
throw new TimeoutException("timeout");
}
assertEquals(n, count.get());
}
} finally {
debug();
}
}
use of org.h2.engine.Database in project rxjava2-jdbc by davidmoten.
the class DatabaseTest method testDelayedCallsAreNonBlocking.
@Test
public void testDelayedCallsAreNonBlocking() throws InterruptedException {
List<String> list = new CopyOnWriteArrayList<String>();
try (Database db = db(1)) {
//
//
db.select("select score from person where name=?").parameter(//
"FRED").getAs(//
Integer.class).doOnNext(//
x -> Thread.sleep(1000)).subscribeOn(//
Schedulers.io()).subscribe();
Thread.sleep(100);
CountDownLatch latch = new CountDownLatch(1);
//
db.select("select score from person where name=?").parameter(//
"FRED").getAs(//
Integer.class).doOnNext(//
x -> list.add("emitted")).doOnNext(//
x -> log.debug("emitted on " + Thread.currentThread().getName())).doOnNext(//
x -> latch.countDown()).subscribe();
list.add("subscribed");
assertTrue(latch.await(TIMEOUT_SECONDS, TimeUnit.SECONDS));
assertEquals(Arrays.asList("subscribed", "emitted"), list);
}
}
Aggregations