提交 b9283ea4 authored 作者: Thomas Mueller Graf's avatar Thomas Mueller Graf

Formatting / Javadocs

上级 2134953d
......@@ -54,11 +54,13 @@ class Optimizer {
}
/**
* @return {@code true} If join reordering is enabled (it can be disabled by hint).
* Whether join reordering is enabled (it can be disabled by hint).
*
* @return {@code true} if yes
*/
private static boolean isJoinReorderingEnabled() {
OptimizerHints hints = OptimizerHints.get();
return hints == null || hints.joinReorderEnabled;
return hints == null || hints.getJoinReorderEnabled();
}
/**
......
......@@ -6,23 +6,26 @@
package org.h2.command.dml;
/**
* Thread local hints for H2 query optimizer. All the ongoing queries in the current thread
* will run with respect to these hints, so if they are needed only for a single
* operation it is preferable to setup and drop them in try-finally block.
* Thread local hints for H2 query optimizer. All the ongoing queries in the
* current thread will run with respect to these hints, so if they are needed
* only for a single operation it is preferable to setup and drop them in
* try-finally block.
*
* Currently works only in embedded mode.
*
* @author Sergi Vladykin
*/
public class OptimizerHints {
private static final ThreadLocal<OptimizerHints> HINTS = new ThreadLocal<OptimizerHints>();
boolean joinReorderEnabled = true;
private static final ThreadLocal<OptimizerHints> HINTS =
new ThreadLocal<OptimizerHints>();
private boolean joinReorderEnabled = true;
/**
* Set thread local hints or {@code null} to drop any existing hints.
*
* @param hints
* @param hints the hints
*/
public static void set(OptimizerHints hints) {
if (hints != null) {
......@@ -33,19 +36,25 @@ public class OptimizerHints {
}
/**
* @return Current thread local hints or {@code null} if none.
* Get the current thread local hints or {@code null} if none.
*
* @return the hints
*/
public static OptimizerHints get() {
return HINTS.get();
}
/**
* Set whether reordering of tables (or anything else in the {@code FROM} clause) is enabled.
* By default is {@code true}.
* Set whether reordering of tables (or anything else in the {@code FROM}
* clause) is enabled. By default is {@code true}.
*
* @param joinReorderEnabled Flag value.
*/
public void setJoinReorderEnabled(boolean joinReorderEnabled) {
this.joinReorderEnabled = joinReorderEnabled;
}
public boolean getJoinReorderEnabled() {
return joinReorderEnabled;
}
}
......@@ -49,7 +49,8 @@ public class TestMvcc4 extends TestBase {
+ "entity_id VARCHAR(100) NOT NULL PRIMARY KEY, "
+ "lastUpdated TIMESTAMP NOT NULL)");
PreparedStatement ps = setup.prepareStatement("INSERT INTO test (entity_id, lastUpdated) VALUES (?, ?)");
PreparedStatement ps = setup.prepareStatement(
"INSERT INTO test (entity_id, lastUpdated) VALUES (?, ?)");
for (int i = 0; i < 2; i++) {
String id = "" + i;
ps.setString(1, id);
......@@ -72,7 +73,8 @@ public class TestMvcc4 extends TestBase {
Connection c2 = getConnection("mvcc4");
c2.setAutoCommit(false);
PreparedStatement ps = c2.prepareStatement("SELECT * FROM test WHERE entity_id = ? FOR UPDATE");
PreparedStatement ps = c2.prepareStatement(
"SELECT * FROM test WHERE entity_id = ? FOR UPDATE");
ps.setString(1, "1");
ps.executeQuery().next();
......@@ -93,32 +95,32 @@ public class TestMvcc4 extends TestBase {
} catch (InterruptedException e) {
}
{
//Execute an update. This should initially fail, and enter the waiting for lock case.
// Execute an update. This should initially fail, and enter the waiting
// for lock case.
PreparedStatement ps = c1.prepareStatement("UPDATE test SET lastUpdated = ?");
ps.setTimestamp(1, new Timestamp(System.currentTimeMillis()));
ps.executeUpdate();
}
c1.commit();
c1.close();
Connection verify = getConnection("mvcc4");
{
verify.setAutoCommit(false);
PreparedStatement ps = verify.prepareStatement("SELECT COUNT(*) FROM test");
ps = verify.prepareStatement("SELECT COUNT(*) FROM test");
ResultSet rs = ps.executeQuery();
assertTrue(rs.next());
assertTrue(rs.getInt(1) == 2);
verify.commit();
verify.close();
}
setup.close();
}
private static void waitForThreadToBlockOnDB(Thread t) {
while (true) {
// TODO must not use getAllStackTraces, as the method names are
// implementation details
Map<Thread, StackTraceElement[]> threadMap = Thread.getAllStackTraces();
StackTraceElement[] elements = threadMap.get(t);
if (elements != null
......
......@@ -777,4 +777,4 @@ bradmesserle dan incorporated keegan industries tagtraum cyr israels rafel
dance schedule hitting reverted youngest footers inliner deadlocked reorder nger
nullid syspublic sysibmts sysibminternal syscat sysfun sysstat systools sysibmadm
sysproc jcc expecting gpg showed unreferenced activating cvf stephane lacoin
centrale umr ecole nantes sticc lab
centrale umr ecole nantes sticc lab reordering preferable
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论