use of org.h2.tools.Server in project main by JohnPeng739.
the class H2ServerFactory method initPgServer.
/**
* 初始化PG服务器
*/
private void initPgServer() {
boolean enable = env.getProperty("h2.pg.enable", Boolean.class, false);
if (enable) {
int port = env.getProperty("h2.pg.port", Integer.class, 5435);
String baseDir = env.getProperty("h2.pg.baseDir", String.class, "~/h2db");
boolean daemon = env.getProperty("h2.pg.daemon", Boolean.class, true);
boolean trace = env.getProperty("h2.pg.trace", Boolean.class, true);
List<String> args = new ArrayList<>();
args.add("-pgPort");
args.add(String.valueOf(port));
args.add("-baseDir");
args.add(baseDir);
if (daemon) {
args.add("-pgDaemon");
}
if (trace) {
args.add("-trace");
}
try {
Server server = Server.createPgServer(args.toArray(new String[0]));
server.start();
if (logger.isDebugEnabled()) {
logger.debug(String.format("Start H2 pg Server success, conf: %s.", StringUtils.merge(args, " ")));
}
this.pgServer = server;
} catch (SQLException ex) {
if (logger.isErrorEnabled()) {
logger.error(String.format("Create H2 pg server fail, conf: %s.", StringUtils.merge(args, " ")));
}
}
}
}
use of org.h2.tools.Server in project main by JohnPeng739.
the class H2ServerFactory method initTcpServer.
/**
* 初始化TCP服务器
*/
private void initTcpServer() {
boolean enable = env.getProperty("h2.tcp.enable", Boolean.class, false);
if (enable) {
int port = env.getProperty("h2.tcp.port", Integer.class, 9092);
String baseDir = env.getProperty("h2.tcp.baseDir", String.class, "~/h2db");
boolean daemon = env.getProperty("h2.tcp.daemon", Boolean.class, true);
boolean trace = env.getProperty("h2.tcp.trace", Boolean.class, true);
List<String> args = new ArrayList<>();
args.add("-tcpPort");
args.add(String.valueOf(port));
// args.add(baseDir);
if (daemon) {
args.add("-tcpDaemon");
}
if (trace) {
args.add("-trace");
}
try {
Server server = Server.createTcpServer(args.toArray(new String[0]));
server.start();
if (logger.isDebugEnabled()) {
logger.debug(String.format("Start H2 TCP Server success, conf: %s.", StringUtils.merge(args, " ")));
}
this.tcpServer = server;
} catch (SQLException ex) {
if (logger.isErrorEnabled()) {
logger.error(String.format("Create H2 TCP server fail, conf: %s.", StringUtils.merge(args, " ")));
}
}
}
}
use of org.h2.tools.Server in project jbpm by kiegroup.
the class JBPMHelper method startH2Server.
public static Server startH2Server() {
try {
// start h2 in memory database
Server server = Server.createTcpServer(new String[0]);
server.start();
return server;
} catch (Throwable t) {
throw new RuntimeException("Could not start H2 server", t);
}
}
use of org.h2.tools.Server in project spf4j by zolyfarkas.
the class JdbcSemaphoreTest method testMultiProcess2.
@Test
public void testMultiProcess2() throws SQLException, IOException, InterruptedException, ExecutionException, TimeoutException {
int port = PORT.getAndIncrement();
Server server = Server.createTcpServer(new String[] { "-tcpPort", Integer.toString(port), "-ifNotExists" }).start();
try {
File tempDB = File.createTempFile("test", "h2db");
tempDB.deleteOnExit();
String connStr = "jdbc:h2:tcp://localhost:" + port + "/nio:" + tempDB.getAbsolutePath() + ";AUTO_SERVER=TRUE";
JdbcDataSource ds = new JdbcDataSource();
ds.setURL(connStr);
ds.setUser("sa");
ds.setPassword("sa");
createSchemaObjects(ds);
JdbcSemaphore semaphore = new JdbcSemaphore(ds, "test_sem2", 1, true);
String o1 = org.spf4j.base.Runtime.jrun(DecentSemaphoreHandler.class, 10000000, connStr, "test_sem2").toString();
String o2 = org.spf4j.base.Runtime.jrun(DecentSemaphoreHandler.class, 10000000, connStr, "test_sem2").toString();
Assert.assertTrue(semaphore.tryAcquire(1, TimeUnit.SECONDS));
Assert.assertFalse(semaphore.tryAcquire(10, TimeUnit.SECONDS));
LOG.debug("P1: {}", o1);
LOG.debug("P2: {}", o2);
String[] nr1 = o1.split("\n");
String[] nr2 = o2.split("\n");
int totatl = nr1.length + nr2.length;
Set<String> numbers = new HashSet<>(totatl);
numbers.addAll(Arrays.asList(nr1));
numbers.addAll(Arrays.asList(nr2));
Assert.assertEquals(totatl, numbers.size());
} finally {
JdbcHeartBeat.stopHeartBeats();
server.shutdown();
}
}
Aggregations