use of org.h2.mvstore.db.TransactionStore.Transaction in project h2database by h2database.
the class MVTable method addRow.
@Override
public void addRow(Session session, Row row) {
lastModificationId = database.getNextModificationDataId();
Transaction t = session.getTransaction();
long savepoint = t.setSavepoint();
try {
for (Index index : indexes) {
index.add(session, row);
}
} catch (Throwable e) {
t.rollbackToSavepoint(savepoint);
DbException de = DbException.convert(e);
if (de.getErrorCode() == ErrorCode.DUPLICATE_KEY_1) {
for (Index index : indexes) {
if (index.getIndexType().isUnique() && index instanceof MultiVersionIndex) {
MultiVersionIndex mv = (MultiVersionIndex) index;
if (mv.isUncommittedFromOtherSession(session, row)) {
throw DbException.get(ErrorCode.CONCURRENT_UPDATE_1, index.getName());
}
}
}
}
throw de;
}
analyzeIfRequired(session);
}
use of org.h2.mvstore.db.TransactionStore.Transaction in project h2database by h2database.
the class MVTable method removeRow.
@Override
public void removeRow(Session session, Row row) {
lastModificationId = database.getNextModificationDataId();
Transaction t = session.getTransaction();
long savepoint = t.setSavepoint();
try {
for (int i = indexes.size() - 1; i >= 0; i--) {
Index index = indexes.get(i);
index.remove(session, row);
}
} catch (Throwable e) {
t.rollbackToSavepoint(savepoint);
throw DbException.convert(e);
}
analyzeIfRequired(session);
}
use of org.h2.mvstore.db.TransactionStore.Transaction in project h2database by h2database.
the class MVPrimaryIndex method remove.
@Override
public void remove(Session session) {
TransactionMap<Value, Value> map = getMap(session);
if (!map.isClosed()) {
Transaction t = session.getTransaction();
t.removeMap(map);
}
}
use of org.h2.mvstore.db.TransactionStore.Transaction in project h2database by h2database.
the class MVSpatialIndex method remove.
@Override
public void remove(Session session) {
TransactionMap<SpatialKey, Value> map = getMap(session);
if (!map.isClosed()) {
Transaction t = session.getTransaction();
t.removeMap(map);
}
}
use of org.h2.mvstore.db.TransactionStore.Transaction in project h2database by h2database.
the class TestCluster method testCreateClusterAtRuntime.
private void testCreateClusterAtRuntime() throws SQLException {
if (config.memory || config.networked || config.cipher != null) {
return;
}
deleteFiles();
org.h2.Driver.load();
String user = getUser(), password = getPassword();
Connection conn;
Statement stat;
int len = 10;
// initialize the database
Server n1 = org.h2.tools.Server.createTcpServer("-baseDir", getBaseDir() + "/node1").start();
int port1 = n1.getPort();
String url1 = getURL("jdbc:h2:tcp://localhost:" + port1 + "/test", false);
conn = getConnection(url1, user, password);
stat = conn.createStatement();
stat.execute("create table test(id int primary key, name varchar) as " + "select x, 'Data' || x from system_range(0, " + (len - 1) + ")");
stat.execute("create user test password 'test'");
stat.execute("grant all on test to test");
// start the second server
Server n2 = org.h2.tools.Server.createTcpServer("-baseDir", getBaseDir() + "/node2").start();
int port2 = n2.getPort();
String url2 = getURL("jdbc:h2:tcp://localhost:" + port2 + "/test", false);
// copy the database and initialize the cluster
String serverList = "localhost:" + port1 + ",localhost:" + port2;
CreateCluster.main("-urlSource", url1, "-urlTarget", url2, "-user", user, "-password", password, "-serverList", serverList);
// check the original connection is closed
assertThrows(ErrorCode.CONNECTION_BROKEN_1, stat).execute("select * from test");
JdbcUtils.closeSilently(conn);
// test the cluster connection
String urlCluster = getURL("jdbc:h2:tcp://" + serverList + "/test", false);
Connection connApp = getConnection(urlCluster + ";AUTO_RECONNECT=TRUE", user, password);
check(connApp, len, "'" + serverList + "'");
// delete the rows, but don't commit
connApp.setAutoCommit(false);
connApp.createStatement().execute("delete from test");
// stop server 2, and test if only one server is available
n2.stop();
// rollback the transaction
connApp.createStatement().executeQuery("select count(*) from test");
connApp.rollback();
check(connApp, len, "''");
connApp.setAutoCommit(true);
// re-create the cluster
n2 = org.h2.tools.Server.createTcpServer("-tcpPort", "" + port2, "-baseDir", getBaseDir() + "/node2").start();
CreateCluster.main("-urlSource", url1, "-urlTarget", url2, "-user", user, "-password", password, "-serverList", serverList);
// test the cluster connection
check(connApp, len, "'" + serverList + "'");
connApp.close();
// test a non-admin user
String user2 = "test", password2 = getPassword("test");
connApp = getConnection(urlCluster, user2, password2);
check(connApp, len, "'" + serverList + "'");
connApp.close();
n1.stop();
// test non-admin cluster connection if only one server runs
Connection connApp2 = getConnection(urlCluster + ";AUTO_RECONNECT=TRUE", user2, password2);
check(connApp2, len, "''");
connApp2.close();
// test non-admin cluster connection if only one server runs
connApp2 = getConnection(urlCluster + ";AUTO_RECONNECT=TRUE", user2, password2);
check(connApp2, len, "''");
connApp2.close();
n2.stop();
deleteFiles();
}
Aggregations