提交 8825c9ce authored 作者: Thomas Mueller's avatar Thomas Mueller

Documentation.

上级 9e771b50
...@@ -46,8 +46,8 @@ Other software most likely also works, but is not tested as much. ...@@ -46,8 +46,8 @@ Other software most likely also works, but is not tested as much.
<p> <p>
As this database is written in Java, it can run on many different platforms. As this database is written in Java, it can run on many different platforms.
It is tested with Java 6 and 7. It is tested with Java 6 and 7.
Currently, the database is developed and tested on Windows 8 Currently, the database is developed and tested on Windows 8
and Mac OS X using Java 6, but it also works in many other operating systems and Mac OS X using Java 6, but it also works in many other operating systems
and using other Java runtime environments. and using other Java runtime environments.
All major operating systems (Windows XP, Windows Vista, Windows 7, Mac OS, Ubuntu,...) are supported. All major operating systems (Windows XP, Windows Vista, Windows 7, Mac OS, Ubuntu,...) are supported.
</p> </p>
......
...@@ -149,7 +149,7 @@ public class SysProperties { ...@@ -149,7 +149,7 @@ public class SysProperties {
* H2 Console: session timeout in milliseconds. The default is 30 minutes. * H2 Console: session timeout in milliseconds. The default is 30 minutes.
*/ */
public static final int CONSOLE_TIMEOUT = Utils.getProperty("h2.consoleTimeout", 30 * 60 * 1000); public static final int CONSOLE_TIMEOUT = Utils.getProperty("h2.consoleTimeout", 30 * 60 * 1000);
/** /**
* System property <code>h2.dataSourceTraceLevel</code> (default: 1).<br /> * System property <code>h2.dataSourceTraceLevel</code> (default: 1).<br />
* The trace level of the data source implementation. Default is 1 for * The trace level of the data source implementation. Default is 1 for
......
...@@ -1236,7 +1236,7 @@ public class Session extends SessionWithState { ...@@ -1236,7 +1236,7 @@ public class Session extends SessionWithState {
/** /**
* Get the transaction to use for this session. * Get the transaction to use for this session.
* *
* @param store the store * @param store the store
* @return the transaction * @return the transaction
*/ */
......
...@@ -2345,7 +2345,7 @@ public class JdbcDatabaseMetaData extends TraceObject implements DatabaseMetaDat ...@@ -2345,7 +2345,7 @@ public class JdbcDatabaseMetaData extends TraceObject implements DatabaseMetaDat
String m = getMode(); String m = getMode();
if (m.equals("MySQL")) { if (m.equals("MySQL")) {
return true; return true;
} }
return false; return false;
} }
...@@ -2386,7 +2386,7 @@ public class JdbcDatabaseMetaData extends TraceObject implements DatabaseMetaDat ...@@ -2386,7 +2386,7 @@ public class JdbcDatabaseMetaData extends TraceObject implements DatabaseMetaDat
String m = getMode(); String m = getMode();
if (m.equals("MySQL")) { if (m.equals("MySQL")) {
return true; return true;
} }
return false; return false;
} }
...@@ -2401,7 +2401,7 @@ public class JdbcDatabaseMetaData extends TraceObject implements DatabaseMetaDat ...@@ -2401,7 +2401,7 @@ public class JdbcDatabaseMetaData extends TraceObject implements DatabaseMetaDat
String m = getMode(); String m = getMode();
if (m.equals("MySQL")) { if (m.equals("MySQL")) {
return false; return false;
} }
return true; return true;
} }
...@@ -2972,7 +2972,7 @@ public class JdbcDatabaseMetaData extends TraceObject implements DatabaseMetaDat ...@@ -2972,7 +2972,7 @@ public class JdbcDatabaseMetaData extends TraceObject implements DatabaseMetaDat
public String toString() { public String toString() {
return getTraceObjectName() + ": " + conn; return getTraceObjectName() + ": " + conn;
} }
private String getMode() throws SQLException { private String getMode() throws SQLException {
if (mode == null) { if (mode == null) {
PreparedStatement prep = conn.prepareStatement( PreparedStatement prep = conn.prepareStatement(
......
...@@ -592,7 +592,7 @@ public class MVMap<K, V> extends AbstractMap<K, V> ...@@ -592,7 +592,7 @@ public class MVMap<K, V> extends AbstractMap<K, V>
/** /**
* Check whether the two values are equal. * Check whether the two values are equal.
* *
* @param a the first value * @param a the first value
* @param b the second value * @param b the second value
* @return true if they are equal * @return true if they are equal
......
...@@ -18,7 +18,7 @@ import org.h2.util.New; ...@@ -18,7 +18,7 @@ import org.h2.util.New;
* A store that supports concurrent transactions. * A store that supports concurrent transactions.
*/ */
public class TransactionStore { public class TransactionStore {
private static final String LAST_TRANSACTION_ID = "lastTransactionId"; private static final String LAST_TRANSACTION_ID = "lastTransactionId";
/** /**
...@@ -101,10 +101,10 @@ public class TransactionStore { ...@@ -101,10 +101,10 @@ public class TransactionStore {
} }
} }
} }
/** /**
* Get the list of currently open transactions. * Get the list of currently open transactions.
* *
* @return the list of transactions * @return the list of transactions
*/ */
public synchronized List<Transaction> getOpenTransactions() { public synchronized List<Transaction> getOpenTransactions() {
...@@ -141,10 +141,10 @@ public class TransactionStore { ...@@ -141,10 +141,10 @@ public class TransactionStore {
openTransactionMap.put(transactionId, t); openTransactionMap.put(transactionId, t);
return t; return t;
} }
/** /**
* Prepare a transaction. * Prepare a transaction.
* *
* @param transactionId the transaction id * @param transactionId the transaction id
*/ */
void prepare(long transactionId) { void prepare(long transactionId) {
...@@ -152,11 +152,11 @@ public class TransactionStore { ...@@ -152,11 +152,11 @@ public class TransactionStore {
Object[] v = { Transaction.STATUS_PREPARED, old[1] }; Object[] v = { Transaction.STATUS_PREPARED, old[1] };
openTransactions.put(transactionId, v); openTransactions.put(transactionId, v);
store.commit(); store.commit();
} }
/** /**
* Set the name of a transaction. * Set the name of a transaction.
* *
* @param transactionId the transaction id * @param transactionId the transaction id
* @param name the new name * @param name the new name
*/ */
...@@ -165,7 +165,7 @@ public class TransactionStore { ...@@ -165,7 +165,7 @@ public class TransactionStore {
Object[] v = { old[0], name }; Object[] v = { old[0], name };
openTransactions.put(transactionId, v); openTransactions.put(transactionId, v);
store.commit(); store.commit();
} }
/** /**
* Commit a transaction. * Commit a transaction.
...@@ -261,7 +261,7 @@ public class TransactionStore { ...@@ -261,7 +261,7 @@ public class TransactionStore {
* A transaction. * A transaction.
*/ */
public static class Transaction { public static class Transaction {
/** /**
* The status of an open transaction. * The status of an open transaction.
*/ */
...@@ -291,9 +291,9 @@ public class TransactionStore { ...@@ -291,9 +291,9 @@ public class TransactionStore {
* The transaction id. * The transaction id.
*/ */
final long transactionId; final long transactionId;
private int status; private int status;
private String name; private String name;
private long logId; private long logId;
...@@ -305,39 +305,39 @@ public class TransactionStore { ...@@ -305,39 +305,39 @@ public class TransactionStore {
this.name = name; this.name = name;
this.logId = logId; this.logId = logId;
} }
/** /**
* Get the transaction id. * Get the transaction id.
* *
* @return the transaction id * @return the transaction id
*/ */
public long getId() { public long getId() {
return transactionId; return transactionId;
} }
/** /**
* Get the transaction status. * Get the transaction status.
* *
* @return the status * @return the status
*/ */
public int getStatus() { public int getStatus() {
return status; return status;
} }
/** /**
* Set the name of the transaction. * Set the name of the transaction.
* *
* @param name the new name * @param name the new name
*/ */
public void setName(String name) { public void setName(String name) {
checkOpen(); checkOpen();
store.setTransactionName(transactionId, name); store.setTransactionName(transactionId, name);
this.name = name; this.name = name;
} }
/** /**
* Get the name of the transaction. * Get the name of the transaction.
* *
* @return name the name * @return name the name
*/ */
public String getName() { public String getName() {
...@@ -398,7 +398,7 @@ public class TransactionStore { ...@@ -398,7 +398,7 @@ public class TransactionStore {
/** /**
* Roll back to the given savepoint. This is only allowed if the * Roll back to the given savepoint. This is only allowed if the
* transaction is open. * transaction is open.
* *
* @param savepointId the savepoint id * @param savepointId the savepoint id
*/ */
public void rollbackToSavepoint(long savepointId) { public void rollbackToSavepoint(long savepointId) {
...@@ -426,7 +426,7 @@ public class TransactionStore { ...@@ -426,7 +426,7 @@ public class TransactionStore {
status = STATUS_CLOSED; status = STATUS_CLOSED;
} }
} }
/** /**
* Roll the transaction back. Afterwards, this transaction is closed. * Roll the transaction back. Afterwards, this transaction is closed.
*/ */
...@@ -459,7 +459,7 @@ public class TransactionStore { ...@@ -459,7 +459,7 @@ public class TransactionStore {
private Transaction transaction; private Transaction transaction;
private final int mapId; private final int mapId;
/** /**
* The map used for writing (the latest version). * The map used for writing (the latest version).
* <p> * <p>
...@@ -467,14 +467,14 @@ public class TransactionStore { ...@@ -467,14 +467,14 @@ public class TransactionStore {
* Value: { transactionId, oldVersion, value } * Value: { transactionId, oldVersion, value }
*/ */
private final MVMap<K, Object[]> mapWrite; private final MVMap<K, Object[]> mapWrite;
/** /**
* The map used for reading (possibly an older version). Reading is done * The map used for reading (possibly an older version). Reading is done
* on an older version so that changes are not immediately visible, to * on an older version so that changes are not immediately visible, to
* support statement processing (for example * support statement processing (for example
* "update test set id = id + 1"). * "update test set id = id + 1").
* <p> * <p>
* Key: key the key of the data. * Key: key the key of the data.
* Value: { transactionId, oldVersion, value } * Value: { transactionId, oldVersion, value }
*/ */
private final MVMap<K, Object[]> mapRead; private final MVMap<K, Object[]> mapRead;
...@@ -489,7 +489,7 @@ public class TransactionStore { ...@@ -489,7 +489,7 @@ public class TransactionStore {
mapRead = mapWrite; mapRead = mapWrite;
} }
} }
/** /**
* Get the size of the map as seen by this transaction. * Get the size of the map as seen by this transaction.
* *
...@@ -530,7 +530,7 @@ public class TransactionStore { ...@@ -530,7 +530,7 @@ public class TransactionStore {
* <p> * <p>
* If the row is locked, this method will retry until the row could be * If the row is locked, this method will retry until the row could be
* updated or until a lock timeout. * updated or until a lock timeout.
* *
* @param key the key * @param key the key
* @param value the new value (not null) * @param value the new value (not null)
* @throws IllegalStateException if a lock timeout occurs * @throws IllegalStateException if a lock timeout occurs
...@@ -539,7 +539,7 @@ public class TransactionStore { ...@@ -539,7 +539,7 @@ public class TransactionStore {
DataUtils.checkArgument(value != null, "The value may not be null"); DataUtils.checkArgument(value != null, "The value may not be null");
return set(key, value); return set(key, value);
} }
private V set(K key, V value) { private V set(K key, V value) {
checkOpen(); checkOpen();
long start = 0; long start = 0;
...@@ -571,13 +571,13 @@ public class TransactionStore { ...@@ -571,13 +571,13 @@ public class TransactionStore {
} }
} }
} }
/** /**
* Try to remove the value for the given key. * Try to remove the value for the given key.
* <p> * <p>
* This will fail if the row is locked by another transaction (that * This will fail if the row is locked by another transaction (that
* means, if another open transaction changed the row). * means, if another open transaction changed the row).
* *
* @param key the key * @param key the key
* @return whether the entry could be removed * @return whether the entry could be removed
*/ */
...@@ -599,12 +599,12 @@ public class TransactionStore { ...@@ -599,12 +599,12 @@ public class TransactionStore {
DataUtils.checkArgument(value != null, "The value may not be null"); DataUtils.checkArgument(value != null, "The value may not be null");
return trySet(key, value, false); return trySet(key, value, false);
} }
/** /**
* Try to set or remove the value. When updating only unchanged entries, * Try to set or remove the value. When updating only unchanged entries,
* then the value is only changed if it was not changed after opening * then the value is only changed if it was not changed after opening
* the map. * the map.
* *
* @param key the key * @param key the key
* @param value the new value (null to remove the value) * @param value the new value (null to remove the value)
* @param onlyIfUnchanged only set the value if it was not changed (by * @param onlyIfUnchanged only set the value if it was not changed (by
...@@ -620,7 +620,7 @@ public class TransactionStore { ...@@ -620,7 +620,7 @@ public class TransactionStore {
long tx = (Long) current[0]; long tx = (Long) current[0];
if (tx == transaction.transactionId) { if (tx == transaction.transactionId) {
if (value == null) { if (value == null) {
// ignore removing an entry // ignore removing an entry
// if it was added or changed // if it was added or changed
// in the same statement // in the same statement
return true; return true;
...@@ -698,7 +698,7 @@ public class TransactionStore { ...@@ -698,7 +698,7 @@ public class TransactionStore {
/** /**
* Get the value for the given key at the time when this map was opened. * Get the value for the given key at the time when this map was opened.
* *
* @param key the key * @param key the key
* @return the value or null * @return the value or null
*/ */
...@@ -715,7 +715,7 @@ public class TransactionStore { ...@@ -715,7 +715,7 @@ public class TransactionStore {
public V getLatest(K key) { public V getLatest(K key) {
return get(key, mapWrite); return get(key, mapWrite);
} }
/** /**
* Get the value for the given key. * Get the value for the given key.
* *
...@@ -758,7 +758,7 @@ public class TransactionStore { ...@@ -758,7 +758,7 @@ public class TransactionStore {
/** /**
* Open the map to store the data. * Open the map to store the data.
* *
* @param <A> the key type * @param <A> the key type
* @param <B> the value type * @param <B> the value type
* @param name the map name * @param name the map name
......
...@@ -322,7 +322,7 @@ public class MVPrimaryIndex extends BaseIndex { ...@@ -322,7 +322,7 @@ public class MVPrimaryIndex extends BaseIndex {
public boolean isRowIdIndex() { public boolean isRowIdIndex() {
return true; return true;
} }
/** /**
* Get the map to store the data. * Get the map to store the data.
* *
......
...@@ -295,7 +295,7 @@ public class MVSecondaryIndex extends BaseIndex { ...@@ -295,7 +295,7 @@ public class MVSecondaryIndex extends BaseIndex {
} }
} }
/** /**
* Get the map to store the data. * Get the map to store the data.
* *
......
...@@ -672,17 +672,17 @@ public class MVTable extends TableBase { ...@@ -672,17 +672,17 @@ public class MVTable extends TableBase {
public void checkRename() { public void checkRename() {
// ok // ok
} }
/** /**
* Get the transaction to use for this session. * Get the transaction to use for this session.
* *
* @param session the session * @param session the session
* @return the transaction * @return the transaction
*/ */
Transaction getTransaction(Session session) { Transaction getTransaction(Session session) {
return session.getTransaction(store); return session.getTransaction(store);
} }
public TransactionStore getStore() { public TransactionStore getStore() {
return store; return store;
} }
......
...@@ -139,7 +139,7 @@ public class MVTableEngine implements TableEngine { ...@@ -139,7 +139,7 @@ public class MVTableEngine implements TableEngine {
* The store. * The store.
*/ */
private final MVStore store; private final MVStore store;
/** /**
* The transaction store. * The transaction store.
*/ */
......
...@@ -236,7 +236,7 @@ public class TestCompatibility extends TestBase { ...@@ -236,7 +236,7 @@ public class TestCompatibility extends TestBase {
conn = getConnection("compatibility;MODE=MYSQL"); conn = getConnection("compatibility;MODE=MYSQL");
stat = conn.createStatement(); stat = conn.createStatement();
testLog(Math.log(10), stat); testLog(Math.log(10), stat);
DatabaseMetaData meta = conn.getMetaData(); DatabaseMetaData meta = conn.getMetaData();
assertTrue(meta.storesLowerCaseIdentifiers()); assertTrue(meta.storesLowerCaseIdentifiers());
assertTrue(meta.storesLowerCaseQuotedIdentifiers()); assertTrue(meta.storesLowerCaseQuotedIdentifiers());
......
...@@ -45,7 +45,7 @@ public class TestTransactionStore extends TestBase { ...@@ -45,7 +45,7 @@ public class TestTransactionStore extends TestBase {
testSingleConnection(); testSingleConnection();
testCompareWithPostgreSQL(); testCompareWithPostgreSQL();
} }
/** /**
* Tests behavior when used for a sequence of SQL statements. Each statement * Tests behavior when used for a sequence of SQL statements. Each statement
* uses a savepoint. Within a statement, changes by the statement itself are * uses a savepoint. Within a statement, changes by the statement itself are
...@@ -63,14 +63,14 @@ public class TestTransactionStore extends TestBase { ...@@ -63,14 +63,14 @@ public class TestTransactionStore extends TestBase {
TransactionMap<String, String> m; TransactionMap<String, String> m;
long startUpdate; long startUpdate;
long version; long version;
tx = ts.begin(); tx = ts.begin();
// start of statement // start of statement
// create table test // create table test
startUpdate = tx.setSavepoint(); startUpdate = tx.setSavepoint();
tx.openMap("test"); tx.openMap("test");
// start of statement // start of statement
// insert into test(id, name) values(1, 'Hello'), (2, 'World') // insert into test(id, name) values(1, 'Hello'), (2, 'World')
startUpdate = tx.setSavepoint(); startUpdate = tx.setSavepoint();
...@@ -81,10 +81,10 @@ public class TestTransactionStore extends TestBase { ...@@ -81,10 +81,10 @@ public class TestTransactionStore extends TestBase {
// not seen yet (within the same statement) // not seen yet (within the same statement)
assertNull(m.get("1")); assertNull(m.get("1"));
assertNull(m.get("2")); assertNull(m.get("2"));
// start of statement // start of statement
startUpdate = tx.setSavepoint(); startUpdate = tx.setSavepoint();
version = s.getCurrentVersion(); version = s.getCurrentVersion();
// now we see the newest version // now we see the newest version
m = tx.openMap("test", version); m = tx.openMap("test", version);
assertEquals("Hello", m.get("1")); assertEquals("Hello", m.get("1"));
...@@ -98,25 +98,25 @@ public class TestTransactionStore extends TestBase { ...@@ -98,25 +98,25 @@ public class TestTransactionStore extends TestBase {
// already updated by this statement, so it has no effect // already updated by this statement, so it has no effect
// but still returns true because it was changed by this transaction // but still returns true because it was changed by this transaction
assertTrue(m.trySet("2", null, true)); assertTrue(m.trySet("2", null, true));
assertTrue(m.trySet("3", "World", true)); assertTrue(m.trySet("3", "World", true));
// not seen within this statement // not seen within this statement
assertEquals("Hello", m.get("1")); assertEquals("Hello", m.get("1"));
assertEquals("World", m.get("2")); assertEquals("World", m.get("2"));
assertNull(m.get("3")); assertNull(m.get("3"));
// start of statement // start of statement
startUpdate = tx.setSavepoint(); startUpdate = tx.setSavepoint();
version = s.getCurrentVersion(); version = s.getCurrentVersion();
m = tx.openMap("test", version); m = tx.openMap("test", version);
// select * from test // select * from test
assertNull(m.get("1")); assertNull(m.get("1"));
assertEquals("Hello", m.get("2")); assertEquals("Hello", m.get("2"));
assertEquals("World", m.get("3")); assertEquals("World", m.get("3"));
// start of statement // start of statement
startUpdate = tx.setSavepoint(); startUpdate = tx.setSavepoint();
version = s.getCurrentVersion(); version = s.getCurrentVersion();
m = tx.openMap("test", version); m = tx.openMap("test", version);
// update test set id = 1 // update test set id = 1
// should fail: duplicate key // should fail: duplicate key
...@@ -125,30 +125,30 @@ public class TestTransactionStore extends TestBase { ...@@ -125,30 +125,30 @@ public class TestTransactionStore extends TestBase {
assertTrue(m.trySet("3", null, true)); assertTrue(m.trySet("3", null, true));
assertFalse(m.trySet("1", "World", true)); assertFalse(m.trySet("1", "World", true));
tx.rollbackToSavepoint(startUpdate); tx.rollbackToSavepoint(startUpdate);
version = s.getCurrentVersion(); version = s.getCurrentVersion();
m = tx.openMap("test", version); m = tx.openMap("test", version);
assertNull(m.get("1")); assertNull(m.get("1"));
assertEquals("Hello", m.get("2")); assertEquals("Hello", m.get("2"));
assertEquals("World", m.get("3")); assertEquals("World", m.get("3"));
tx.commit(); tx.commit();
ts.close(); ts.close();
s.close(); s.close();
} }
private void testTwoPhaseCommit() throws Exception { private void testTwoPhaseCommit() throws Exception {
String fileName = getBaseDir() + "/testTwoPhaseCommit.h3"; String fileName = getBaseDir() + "/testTwoPhaseCommit.h3";
FileUtils.delete(fileName); FileUtils.delete(fileName);
MVStore s; MVStore s;
TransactionStore ts; TransactionStore ts;
Transaction tx; Transaction tx;
Transaction txOld; Transaction txOld;
TransactionMap<String, String> m; TransactionMap<String, String> m;
List<Transaction> list; List<Transaction> list;
s = MVStore.open(fileName); s = MVStore.open(fileName);
ts = new TransactionStore(s); ts = new TransactionStore(s);
tx = ts.begin(); tx = ts.begin();
...@@ -166,7 +166,7 @@ public class TestTransactionStore extends TestBase { ...@@ -166,7 +166,7 @@ public class TestTransactionStore extends TestBase {
s.commit(); s.commit();
ts.close(); ts.close();
s.close(); s.close();
s = MVStore.open(fileName); s = MVStore.open(fileName);
ts = new TransactionStore(s); ts = new TransactionStore(s);
tx = ts.begin(); tx = ts.begin();
...@@ -188,7 +188,7 @@ public class TestTransactionStore extends TestBase { ...@@ -188,7 +188,7 @@ public class TestTransactionStore extends TestBase {
txOld.rollback(); txOld.rollback();
s.commit(); s.commit();
s.close(); s.close();
s = MVStore.open(fileName); s = MVStore.open(fileName);
ts = new TransactionStore(s); ts = new TransactionStore(s);
tx = ts.begin(); tx = ts.begin();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论