use of org.h2.engine.Mode in project h2database by h2database.
the class MixedMode method main.
/**
* This method is called when executing this sample application from the
* command line.
*
* @param args the command line parameters
*/
public static void main(String... args) throws Exception {
// start the server, allows to access the database remotely
Server server = Server.createTcpServer("-tcpPort", "9081");
server.start();
System.out.println("You can access the database remotely now, using the URL:");
System.out.println("jdbc:h2:tcp://localhost:9081/~/test (user: sa, password: sa)");
// now use the database in your application in embedded mode
Class.forName("org.h2.Driver");
Connection conn = DriverManager.getConnection("jdbc:h2:~/test", "sa", "sa");
// some simple 'business usage'
Statement stat = conn.createStatement();
stat.execute("DROP TABLE TIMER IF EXISTS");
stat.execute("CREATE TABLE TIMER(ID INT PRIMARY KEY, TIME VARCHAR)");
System.out.println("Execute this a few times: " + "SELECT TIME FROM TIMER");
System.out.println("To stop this application " + "(and the server), run: DROP TABLE TIMER");
try {
while (true) {
// runs forever, except if you drop the table remotely
stat.execute("MERGE INTO TIMER VALUES(1, NOW())");
Thread.sleep(1000);
}
} catch (SQLException e) {
System.out.println("Error: " + e.toString());
}
conn.close();
// stop the server
server.stop();
}
use of org.h2.engine.Mode in project h2database by h2database.
the class TestTableEngines method testAffinityKey.
private void testAffinityKey() throws SQLException {
deleteDb("tableEngine");
Connection conn = getConnection("tableEngine;mode=Ignite;MV_STORE=FALSE");
Statement stat = conn.createStatement();
stat.executeUpdate("CREATE TABLE T(ID INT AFFINITY PRIMARY KEY, NAME VARCHAR, AGE INT)" + " ENGINE \"" + AffinityTableEngine.class.getName() + "\"");
Table tbl = AffinityTableEngine.createdTbl;
assertNotNull(tbl);
assertEquals(3, tbl.getIndexes().size());
Index aff = tbl.getIndexes().get(2);
assertTrue(aff.getIndexType().isAffinity());
assertEquals("T_AFF", aff.getName());
assertEquals(1, aff.getIndexColumns().length);
assertEquals("ID", aff.getIndexColumns()[0].columnName);
conn.close();
deleteDb("tableEngine");
}
use of org.h2.engine.Mode in project h2database by h2database.
the class FileReorderWrites method open.
@Override
public FileChannel open(String mode) throws IOException {
InputStream in = newInputStream();
FilePath copy = FilePath.get(getBase().toString() + ".copy");
OutputStream out = copy.newOutputStream(false);
IOUtils.copy(in, out);
in.close();
out.close();
FileChannel base = getBase().open(mode);
FileChannel readBase = copy.open(mode);
return new FileReorderWrites(this, base, readBase);
}
use of org.h2.engine.Mode in project jdbi by jdbi.
the class TestOnDemandSqlObject method setUp.
@Before
public void setUp() throws Exception {
ds = new JdbcDataSource();
// in MVCC mode h2 doesn't shut down immediately on all connections closed, so need random db name
ds.setURL(String.format("jdbc:h2:mem:%s;MVCC=TRUE", UUID.randomUUID()));
db = Jdbi.create(ds);
db.installPlugin(new SqlObjectPlugin());
handle = db.open();
handle.execute("create table something (id int primary key, name varchar(100))");
db.installPlugin(tracker);
}
use of org.h2.engine.Mode in project jdbi by jdbi.
the class TestReentrancy method setUp.
@Before
public void setUp() throws Exception {
JdbcDataSource ds = new JdbcDataSource();
// in MVCC mode h2 doesn't shut down immediately on all connections closed, so need random db name
ds.setURL(String.format("jdbc:h2:mem:%s;MVCC=TRUE", UUID.randomUUID()));
db = Jdbi.create(ds);
db.installPlugin(new SqlObjectPlugin());
db.registerRowMapper(new SomethingMapper());
handle = db.open();
handle.execute("create table something (id int primary key, name varchar(100))");
}
Aggregations