org.h2.tools.Server Java Examples
The following examples show how to use
org.h2.tools.Server.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PostgresStorageTest.java From cassandra-reaper with Apache License 2.0 | 6 votes |
@Before public void setUp() throws SQLException, IOException { Server.createTcpServer().start(); DBI dbi = new DBI(DB_URL); Handle handle = dbi.open(); Connection conn = handle.getConnection(); // to suppress output of ScriptRunner PrintStream tmp = new PrintStream(new OutputStream() { @Override public void write(int buff) throws IOException { // do nothing } }); PrintStream console = System.out; System.setOut(tmp); String cwd = Paths.get("").toAbsolutePath().toString(); String path = cwd + "/../src/test/resources/db/postgres/V17_0_0__multi_instance.sql"; ScriptRunner scriptExecutor = new ScriptRunner(conn, false, true); Reader reader = new BufferedReader(new FileReader(path)); scriptExecutor.runScript(reader); System.setOut(console); }
Example #2
Source File: H2GisServer.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
/** * Start the web server mode. * * @param port the optional port to use. * @param doSSL if <code>true</code>, ssl is used. * @param ifExists is <code>true</code>, the database to connect to has to exist. * @param baseDir an optional basedir into which it is allowed to connect. * @return * @throws SQLException */ public static Server startWebServerMode( String port, boolean doSSL, boolean ifExists, String baseDir ) throws SQLException { List<String> params = new ArrayList<>(); params.add("-webAllowOthers"); if (port != null) { params.add("-webPort"); params.add(port); } if (doSSL) { params.add("-webSSL"); } if (ifExists) { params.add("-ifExists"); } if (baseDir != null) { params.add("-baseDir"); params.add(baseDir); } Server server = Server.createWebServer(params.toArray(new String[0])).start(); return server; }
Example #3
Source File: TestJdbcOutput.java From envelope with Apache License 2.0 | 6 votes |
@BeforeClass public static void beforeClass() throws SQLException, ClassNotFoundException { Class.forName("org.h2.Driver"); server = Server.createTcpServer("-tcp", "-tcpAllowOthers").start(); Connection connection = DriverManager.getConnection(String.format(JDBC_URL, server.getPort()), JDBC_USERNAME, JDBC_PASSWORD); Statement stmt = connection.createStatement(); stmt.executeUpdate("create table if not exists user (firstname varchar(30), lastname varchar(30))"); Properties properties = new Properties(); properties.setProperty("url", String.format(JDBC_URL, server.getPort())); properties.setProperty("tablename", JDBC_TABLE); properties.setProperty("username", JDBC_USERNAME); properties.setProperty("password", JDBC_PASSWORD); config = ConfigFactory.parseProperties(properties); }
Example #4
Source File: TestJdbcInput.java From envelope with Apache License 2.0 | 6 votes |
@BeforeClass public static void beforeClass() throws SQLException, ClassNotFoundException { Class.forName("org.h2.Driver"); server = Server.createTcpServer("-tcp", "-tcpAllowOthers").start(); Connection connection = DriverManager.getConnection("jdbc:h2:tcp://127.0.0.1:" + server.getPort() + "/mem:test;DB_CLOSE_DELAY=-1", "sa", ""); Statement stmt = connection.createStatement(); stmt.executeUpdate("create table if not exists user (firstname varchar(30), lastname varchar(30))"); stmt.executeUpdate("insert into user values ('f1','p1')"); stmt.executeUpdate("insert into user values ('f2','p1')"); stmt.executeUpdate("insert into user values ('f3','p1')"); Properties properties = new Properties(); properties.setProperty("url", String.format(JDBC_URL, server.getPort())); properties.setProperty("tablename", JDBC_TABLE); properties.setProperty("username", JDBC_USERNAME); properties.setProperty("password", JDBC_PASSWORD); config = ConfigFactory.parseProperties(properties); }
Example #5
Source File: TaskInitializerTests.java From spring-cloud-task with Apache License 2.0 | 6 votes |
@Bean public Server initH2TCPServer() { Server server = null; try { if (defaultServer == null) { server = Server.createTcpServer("-ifNotExists", "-tcp", "-tcpAllowOthers", "-tcpPort", String.valueOf(randomPort)) .start(); defaultServer = server; } } catch (SQLException e) { throw new IllegalStateException(e); } return defaultServer; }
Example #6
Source File: TaskStartTests.java From spring-cloud-task with Apache License 2.0 | 6 votes |
@Bean public Server initH2TCPServer() { Server server = null; try { if (defaultServer == null) { server = Server.createTcpServer("-ifNotExists", "-tcp", "-tcpAllowOthers", "-tcpPort", String.valueOf(randomPort)) .start(); defaultServer = server; } } catch (SQLException e) { throw new IllegalStateException(e); } return defaultServer; }
Example #7
Source File: H2DBStartAction.java From java-trader with Apache License 2.0 | 6 votes |
@Override public int execute(BeansContainer beansContainer, PrintWriter writer, List<KVPair> options) throws Exception { File h2db = new File( TraderHomeUtil.getTraderHome(), "data/h2db"); h2db.mkdirs(); statusFile = new File(h2db, "status.ini"); int h2TcpPort = ConfigUtil.getInt("/BasisService/h2db.tcpPort", 9092); Server.main("-ifNotExists", "-web", "-webAllowOthers", "-tcp", "-tcpAllowOthers", "-tcpPort", ""+h2TcpPort,"-baseDir", h2db.getAbsolutePath()); String text = "[start]\n" +"pid="+SystemUtil.getPid()+"\n" +"startTime="+DateUtil.date2str(LocalDateTime.now())+"\n" +"traderHome="+TraderHomeUtil.getTraderHome().getAbsolutePath()+"\n" +"h2TcpPort="+h2TcpPort+"\n"; FileUtil.save(statusFile, text); statusFile.deleteOnExit(); //tcpServer.start(); //writer.println(tcpServer.getStatus()); //tcpServer.setShutdownHandler(this); synchronized(statusFile) { statusFile.wait(); } return 0; }
Example #8
Source File: EmbeddedDBHandler.java From OpenAs2App with BSD 2-Clause "Simplified" License | 6 votes |
public void start(String connectString, String userName, String pwd, Map<String, String> params) throws OpenAS2Exception { createConnectionPool(connectString, userName, pwd); String isStartSrvr = params.get(PARAM_TCP_SERVER_START); if (isStartSrvr == null || "true".equalsIgnoreCase(isStartSrvr)) { String tcpPort = params.get(PARAM_TCP_SERVER_PORT); if (tcpPort == null || tcpPort.length() < 1) { tcpPort = "9092"; } String tcpPwd = params.get(PARAM_TCP_SERVER_PWD); if (tcpPwd == null || tcpPwd.length() < 1) { tcpPwd = "OpenAS2"; } String dbDirectory = params.get(PARAM_DB_DIRECTORY); if (dbDirectory == null || dbDirectory.length() < 1) { throw new OpenAS2Exception("TCP server requireds parameter: " + PARAM_DB_DIRECTORY); } try { server = Server.createTcpServer("-tcpPort", tcpPort, "-tcpPassword", tcpPwd, "-baseDir", dbDirectory, "-tcpAllowOthers").start(); } catch (SQLException e) { throw new OpenAS2Exception("Failed to start TCP server", e); } } }
Example #9
Source File: JpaApplicationTests.java From spring-cloud-task with Apache License 2.0 | 6 votes |
@Before public void setup() { DriverManagerDataSource dataSource = new DriverManagerDataSource(); dataSource.setDriverClassName(DATASOURCE_DRIVER_CLASS_NAME); dataSource.setUrl(DATASOURCE_URL); dataSource.setUsername(DATASOURCE_USER_NAME); dataSource.setPassword(DATASOURCE_USER_PASSWORD); this.dataSource = dataSource; try { this.server = Server .createTcpServer("-tcp", "-ifNotExists", "-tcpAllowOthers", "-tcpPort", String .valueOf(randomPort)) .start(); } catch (SQLException e) { throw new IllegalStateException(e); } }
Example #10
Source File: H2CacheStoreStrategy.java From ignite with Apache License 2.0 | 6 votes |
/** * @throws IgniteCheckedException If failed. */ public H2CacheStoreStrategy() throws IgniteCheckedException { Server srv = null; try { srv = Server.createTcpServer().start(); port = srv.getPort(); dataSrc = H2CacheStoreSessionListenerFactory.createDataSource(port); try (Connection conn = connection()) { RunScript.execute(conn, new StringReader(CREATE_CACHE_TABLE)); RunScript.execute(conn, new StringReader(CREATE_STATS_TABLES)); RunScript.execute(conn, new StringReader(POPULATE_STATS_TABLE)); } } catch (SQLException e) { throw new IgniteCheckedException("Failed to set up cache store strategy" + (srv == null ? "" : ": " + srv.getStatus()), e); } }
Example #11
Source File: JDBCStateDatabaseTest.java From celos with Apache License 2.0 | 5 votes |
@BeforeClass public static void setupClass() throws Exception { Class.forName("org.h2.Driver"); SERVER = Server.createTcpServer().start(); try (Connection connection = DriverManager.getConnection(URL, USERNAME, PASSWORD)) { try (Statement statement = connection.createStatement()) { statement.execute(CREATE_SLOT_STATE_TABLE); statement.execute(CREATE_RERUN_SLOT_TABLE); statement.execute(CREATE_WORKFLOW_INFO_TABLE); statement.execute(CREATE_REGISTERS_TABLE); } } }
Example #12
Source File: TaskPartitionerTests.java From spring-cloud-task with Apache License 2.0 | 5 votes |
@Bean(destroyMethod = "stop") public org.h2.tools.Server initH2TCPServer() { Server server; try { server = Server .createTcpServer("-tcp", "-ifNotExists", "-tcpAllowOthers", "-tcpPort", String .valueOf(randomPort)) .start(); } catch (SQLException e) { throw new IllegalStateException(e); } return server; }
Example #13
Source File: SQLService.java From odo with Apache License 2.0 | 5 votes |
/** * Only meant to be called once * * @throws Exception exception */ public void startServer() throws Exception { if (!externalDatabaseHost) { try { this.port = Utils.getSystemPort(Constants.SYS_DB_PORT); server = Server.createTcpServer("-tcpPort", String.valueOf(port), "-tcpAllowOthers").start(); } catch (SQLException e) { if (e.toString().contains("java.net.UnknownHostException")) { logger.error("Startup failure. Potential bug in OSX & Java7. Workaround: add name of local machine to '/etc/hosts.'"); logger.error("Example: 127.0.0.1 MacBook"); throw e; } } } }
Example #14
Source File: H2GisServer.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
/** * Start the server mode. * * <p>This calls: *<pre> * Server server = Server.createTcpServer( * "-tcpPort", "9123", "-tcpAllowOthers").start(); * </pre> * Supported options are: * -tcpPort, -tcpSSL, -tcpPassword, -tcpAllowOthers, -tcpDaemon, * -trace, -ifExists, -baseDir, -key. * See the main method for details. * <p> * * @param port the optional port to use. * @param doSSL if <code>true</code>, ssl is used. * @param tcpPassword an optional tcp passowrd to use. * @param ifExists is <code>true</code>, the database to connect to has to exist. * @param baseDir an optional basedir into which it is allowed to connect. * @return * @throws SQLException */ public static Server startTcpServerMode( String port, boolean doSSL, String tcpPassword, boolean ifExists, String baseDir ) throws SQLException { List<String> params = new ArrayList<>(); params.add("-tcpAllowOthers"); params.add("-tcpPort"); if (port == null) { port = "9123"; } params.add(port); if (doSSL) { params.add("-tcpSSL"); } if (tcpPassword != null) { params.add("-tcpPassword"); params.add(tcpPassword); } if (ifExists) { params.add("-ifExists"); } if (baseDir != null) { params.add("-baseDir"); params.add(baseDir); } Server server = Server.createTcpServer(params.toArray(new String[0])).start(); return server; }
Example #15
Source File: H2StartStopListener.java From syncope with Apache License 2.0 | 5 votes |
@Override public void contextDestroyed(final ServletContextEvent sce) { Server h2TestDb = (Server) sce.getServletContext().getAttribute(H2_TESTDB); if (h2TestDb != null) { h2TestDb.shutdown(); } }
Example #16
Source File: DbH2ServerStartup.java From ignite with Apache License 2.0 | 5 votes |
/** * Start H2 database TCP server. * * @param args Command line arguments, none required. * @throws IgniteException If start H2 database TCP server failed. */ public static void main(String[] args) throws IgniteException { try { // Start H2 database TCP server in order to access sample in-memory database from other processes. Server.createTcpServer("-tcpDaemon").start(); populateDatabase(); // Try to connect to database TCP server. JdbcConnectionPool dataSrc = JdbcConnectionPool.create("jdbc:h2:tcp://localhost/mem:ExampleDb", "sa", ""); // Create Person table in database. RunScript.execute(dataSrc.getConnection(), new StringReader(CREATE_PERSON_TABLE)); // Populates Person table with sample data in database. RunScript.execute(dataSrc.getConnection(), new StringReader(POPULATE_PERSON_TABLE)); } catch (SQLException e) { throw new IgniteException("Failed to start database TCP server", e); } try { do { System.out.println("Type 'q' and press 'Enter' to stop H2 TCP server..."); } while ('q' != System.in.read()); } catch (IOException ignored) { // No-op. } }
Example #17
Source File: WebConfiguration.java From spring-cloud-dataflow with Apache License 2.0 | 5 votes |
public Server initH2TCPServer() { logger.info("Starting H2 Server with URL: " + dataSourceUrl); try { this.server = Server .createTcpServer("-ifNotExists", "-tcp", "-tcpAllowOthers", "-tcpPort", getH2Port(dataSourceUrl)) .start(); } catch (SQLException e) { throw new IllegalStateException(e); } return server; }
Example #18
Source File: FrontAppTest.java From live-chat-engine with Apache License 2.0 | 5 votes |
private static void runH2ServerIfNeed(File testDir, int port) { try { Server.createTcpServer( "-tcpPort", ""+port, "-tcpAllowOthers").start(); }catch(Exception e){ log.error("can't runH2Server: "+e); } }
Example #19
Source File: AbstractConsoleH2DbTest.java From x-pipe with Apache License 2.0 | 5 votes |
protected void startH2Server() throws SQLException { int h2Port = Integer.parseInt(System.getProperty(KEY_H2_PORT, "9123")); h2Server = Server.createTcpServer("-tcpPort", String.valueOf(h2Port), "-tcpAllowOthers"); h2Server.start(); // new Console().runTool(); }
Example #20
Source File: H2WebServerServiceImplTest.java From jwala with Apache License 2.0 | 5 votes |
@Test public void testCreateServer() { String[] params = new String[0]; Server result = service.createServer(params); assertNotNull(result.getPort()); assertEquals("default status", "Not started", result.getStatus()); // default URL is created using the IP address of the running machine so just test for not null assertNotNull("default URL", result.getURL()); assertNotNull("default service", result.getService()); }
Example #21
Source File: TestConfig.java From we-cmdb with Apache License 2.0 | 5 votes |
@Bean(name = "h2server", destroyMethod = "stop") public Server getH2Server() { Server h2Server; try { h2Server = Server.createWebServer("-web", "-webAllowOthers", "-webPort", "8082"); h2Server.start(); return h2Server; } catch (SQLException e) { logger.info("Fail to start H2 server.", e); } return null; }
Example #22
Source File: TaskLauncherSinkTests.java From spring-cloud-task with Apache License 2.0 | 5 votes |
@Bean(destroyMethod = "stop") public Server initH2TCPServer() { Server server; try { server = Server.createTcpServer("-ifNotExists", "-tcp", "-tcpAllowOthers", "-tcpPort", String.valueOf(randomPort)).start(); } catch (SQLException e) { throw new IllegalStateException(e); } return server; }
Example #23
Source File: CamundaEngineHelper.java From flowing-retail-old with Apache License 2.0 | 5 votes |
private static Server startH2Server() { try { return Server.createTcpServer(new String[] { "-tcpPort", "8092", "-tcpAllowOthers" }).start(); // now you can connect to "jdbc:h2:tcp://localhost:8092/mem:camunda" } catch (Exception ex) { throw new RuntimeException("Could not start H2 database server: " + ex.getMessage(), ex); } }
Example #24
Source File: CamundaEngineHelper.java From flowing-retail-old with Apache License 2.0 | 5 votes |
private static Server startH2Server() { try { return Server.createTcpServer(new String[] { "-tcpPort", "8092", "-tcpAllowOthers" }).start(); // now you can connect to "jdbc:h2:tcp://localhost:8092/mem:camunda" } catch (Exception ex) { throw new RuntimeException("Could not start H2 database server: " + ex.getMessage(), ex); } }
Example #25
Source File: MainFrame.java From e with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws SQLException { String[] arg = { "-tcp", "-tcpAllowOthers" }; Server server = Server.createTcpServer(arg); server.start(); new MainFrame().setVisible(true); }
Example #26
Source File: MicroServiceConsole.java From e with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws SQLException { Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { @Override public void run() { killProcess(); } })); String[] arg = { "-tcp", "-tcpAllowOthers" }; Server server = Server.createTcpServer(arg); server.start(); init(); }
Example #27
Source File: MainDb.java From e with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws SQLException { String[] arg = { "-tcp", "-tcpAllowOthers" }; Server server = Server.createTcpServer(arg); server.start(); System.out.println("JVM running for"); }
Example #28
Source File: MicroRegistry.java From sample-boot-micro with MIT License | 5 votes |
/** テスト用途のメモリDBサーバ */ @Bean(initMethod="start", destroyMethod = "stop") @ConditionalOnProperty(prefix = "extension.test.db", name = "enabled", matchIfMissing = false) Server h2Server() { try { return Server.createTcpServer("-tcpAllowOthers", "-ifNotExists", "-tcpPort", "9092"); } catch (SQLException e) { throw new IllegalStateException(e); } }
Example #29
Source File: H2DatabaseInspector.java From morf with Apache License 2.0 | 5 votes |
/** * @see org.alfasoftware.morf.diagnostics.DatabaseInspector#inspect() */ @Override public void inspect() { if (connectionResources instanceof AbstractConnectionResources && "H2".equals(connectionResources.getDatabaseType())) { try { log.info("Launching H2 database inspector..."); Server.startWebServer(connectionResources.getDataSource().getConnection()); } catch (SQLException e) { throw new IllegalStateException("Failed to start the H2 Database Inspector web server", e); } } }
Example #30
Source File: H2TestEnricher.java From keycloak with Apache License 2.0 | 5 votes |
public void startH2(@Observes(precedence = 3) BeforeSuite event) throws SQLException { if (runH2 && dockerDatabaseSkip) { log.info("Starting H2 database."); server = Server.createTcpServer(); server.start(); log.info(String.format("URL: %s", server.getURL())); } }