use of org.h2.engine.Setting in project h2database by h2database.
the class JdbcConnection method setTransactionIsolation.
/**
* Changes the current transaction isolation level. Calling this method will
* commit an open transaction, even if the new level is the same as the old
* one, except if the level is not supported. Internally, this method calls
* SET LOCK_MODE, which affects all connections. The following isolation
* levels are supported:
* <ul>
* <li>Connection.TRANSACTION_READ_UNCOMMITTED = SET LOCK_MODE 0: no locking
* (should only be used for testing).</li>
* <li>Connection.TRANSACTION_SERIALIZABLE = SET LOCK_MODE 1: table level
* locking.</li>
* <li>Connection.TRANSACTION_READ_COMMITTED = SET LOCK_MODE 3: table level
* locking, but read locks are released immediately (default).</li>
* </ul>
* This setting is not persistent. Please note that using
* TRANSACTION_READ_UNCOMMITTED while at the same time using multiple
* connections may result in inconsistent transactions.
*
* @param level the new transaction isolation level:
* Connection.TRANSACTION_READ_UNCOMMITTED,
* Connection.TRANSACTION_READ_COMMITTED, or
* Connection.TRANSACTION_SERIALIZABLE
* @throws SQLException if the connection is closed or the isolation level
* is not supported
*/
@Override
public void setTransactionIsolation(int level) throws SQLException {
try {
debugCodeCall("setTransactionIsolation", level);
checkClosed();
int lockMode;
switch(level) {
case Connection.TRANSACTION_READ_UNCOMMITTED:
lockMode = Constants.LOCK_MODE_OFF;
break;
case Connection.TRANSACTION_READ_COMMITTED:
lockMode = Constants.LOCK_MODE_READ_COMMITTED;
break;
case Connection.TRANSACTION_REPEATABLE_READ:
case Connection.TRANSACTION_SERIALIZABLE:
lockMode = Constants.LOCK_MODE_TABLE;
break;
default:
throw DbException.getInvalidValueException("level", level);
}
commit();
setLockMode = prepareCommand("SET LOCK_MODE ?", setLockMode);
setLockMode.getParameters().get(0).setValue(ValueInt.get(lockMode), false);
setLockMode.executeUpdate(false);
} catch (Exception e) {
throw logAndConvert(e);
}
}
use of org.h2.engine.Setting in project h2database by h2database.
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.clearWordList();
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 + ".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.Setting in project h2database by h2database.
the class FullText method setIgnoreList.
/**
* Change the ignore list. The ignore list is a comma separated list of
* common words that must not be indexed. The default ignore list is empty.
* If indexes already exist at the time this list is changed, reindex must
* be called.
*
* @param conn the connection
* @param commaSeparatedList the list
*/
public static void setIgnoreList(Connection conn, String commaSeparatedList) throws SQLException {
try {
init(conn);
FullTextSettings setting = FullTextSettings.getInstance(conn);
setIgnoreList(setting, commaSeparatedList);
Statement stat = conn.createStatement();
stat.execute("TRUNCATE TABLE " + SCHEMA + ".IGNORELIST");
PreparedStatement prep = conn.prepareStatement("INSERT INTO " + SCHEMA + ".IGNORELIST VALUES(?)");
prep.setString(1, commaSeparatedList);
prep.execute();
} catch (DbException e) {
throw DbException.toSQLException(e);
}
}
use of org.h2.engine.Setting in project h2database by h2database.
the class TestFullText method testMultiThreaded.
private void testMultiThreaded(boolean lucene) throws Exception {
final String prefix = lucene ? "FTL" : "FT";
trace("Testing multithreaded " + prefix);
deleteDb("fullText");
ArrayList<Connection> connList = new ArrayList<>();
try {
int len = 2;
Task[] task = new Task[len];
for (int i = 0; i < len; i++) {
final Connection conn = getConnection("fullText;LOCK_TIMEOUT=60000", connList);
Statement stat = conn.createStatement();
initFullText(stat, lucene);
initFullText(stat, lucene);
final String tableName = "TEST" + i;
stat.execute("CREATE TABLE " + tableName + "(ID INT PRIMARY KEY, DATA VARCHAR)");
stat.execute("CALL " + prefix + "_CREATE_INDEX('PUBLIC', '" + tableName + "', NULL)");
task[i] = new Task() {
@Override
public void call() throws SQLException {
trace("starting thread " + Thread.currentThread());
PreparedStatement prep = conn.prepareStatement("INSERT INTO " + tableName + " VALUES(?, ?)");
Statement stat = conn.createStatement();
Random random = new Random();
int x = 0;
while (!stop) {
trace("stop = " + stop + " for " + Thread.currentThread());
StringBuilder buff = new StringBuilder();
for (int j = 0; j < 1000; j++) {
buff.append(" ").append(random.nextInt(10000));
buff.append(" x").append(j);
buff.append(" ").append(KNOWN_WORDS[j % KNOWN_WORDS.length]);
}
prep.setInt(1, x);
prep.setString(2, buff.toString());
prep.execute();
x++;
for (String knownWord : KNOWN_WORDS) {
trace("searching for " + knownWord + " with " + Thread.currentThread());
ResultSet rs = stat.executeQuery("SELECT * FROM " + prefix + "_SEARCH('" + knownWord + "', 0, 0)");
assertTrue(rs.next());
}
}
trace("closing connection");
if (!config.memory) {
conn.close();
}
trace("completed thread " + Thread.currentThread());
}
};
}
for (Task t : task) {
t.execute();
}
trace("sleeping");
Thread.sleep(1000);
trace("setting stop to true");
for (Task t : task) {
trace("joining " + t);
t.get();
trace("done joining " + t);
}
} finally {
close(connList);
}
}
Aggregations