From a7e8c79fe7385f5bceac77563b1bb9b607204432 Mon Sep 17 00:00:00 2001
From: rescobar
Date: Tue, 28 Sep 2010 19:24:10 -0700
Subject: feature[bgz_326568]: Add H2 Database support
---
.../support/osee.demo.db.connection.xml | 138 +++++++++++----------
.../schema/operations/CreateSchemaOperation.java | 6 +-
.../core/datastore/schema/sql/H2DataType.java | 112 +++++++++++++++++
.../core/datastore/schema/sql/H2SqlManager.java | 42 +++++++
.../core/datastore/schema/sql/SqlFactory.java | 3 +
.../framework/database/core/ConnectionHandler.java | 16 ++-
.../framework/database/core/SupportedDatabase.java | 5 +-
plugins/org.eclipse.osee.framework.h2/.classpath | 7 ++
plugins/org.eclipse.osee.framework.h2/.project | 33 +++++
.../META-INF/MANIFEST.MF | 21 ++++
.../h2.client.connection.driver.provider.xml | 7 ++
.../org.eclipse.osee.framework.h2/build.properties | 5 +
.../osee/framework/h2/H2ClientConnection.java | 48 +++++++
.../org/eclipse/osee/framework/h2/H2DbServer.java | 108 ++++++++++++++++
.../eclipse/osee/framework/h2/H2DbServerUtil.java | 71 +++++++++++
15 files changed, 547 insertions(+), 75 deletions(-)
create mode 100644 plugins/org.eclipse.osee.framework.core.datastore/src/org/eclipse/osee/framework/core/datastore/schema/sql/H2DataType.java
create mode 100644 plugins/org.eclipse.osee.framework.core.datastore/src/org/eclipse/osee/framework/core/datastore/schema/sql/H2SqlManager.java
create mode 100644 plugins/org.eclipse.osee.framework.h2/.classpath
create mode 100644 plugins/org.eclipse.osee.framework.h2/.project
create mode 100644 plugins/org.eclipse.osee.framework.h2/META-INF/MANIFEST.MF
create mode 100644 plugins/org.eclipse.osee.framework.h2/OSGI-INF/h2.client.connection.driver.provider.xml
create mode 100644 plugins/org.eclipse.osee.framework.h2/build.properties
create mode 100644 plugins/org.eclipse.osee.framework.h2/src/org/eclipse/osee/framework/h2/H2ClientConnection.java
create mode 100644 plugins/org.eclipse.osee.framework.h2/src/org/eclipse/osee/framework/h2/H2DbServer.java
create mode 100644 plugins/org.eclipse.osee.framework.h2/src/org/eclipse/osee/framework/h2/H2DbServerUtil.java
diff --git a/plugins/org.eclipse.osee.demo.db.connection/support/osee.demo.db.connection.xml b/plugins/org.eclipse.osee.demo.db.connection/support/osee.demo.db.connection.xml
index f86f76b5b8c..e4b6d4df76a 100644
--- a/plugins/org.eclipse.osee.demo.db.connection/support/osee.demo.db.connection.xml
+++ b/plugins/org.eclipse.osee.demo.db.connection/support/osee.demo.db.connection.xml
@@ -1,68 +1,70 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- org.h2.Driver
- #PREFIX#:tcp://#HOST#:#PORT#/#DBHOME##DBNAME#;MODE=PostgreSQL;IGNORECASE=TRUE
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- org.postgresql.Driver
- #PREFIX#://#HOST#:#PORT#/#DBHOME##DBNAME#
-
-
-
- org.apache.derby.jdbc.ClientDriver
- #PREFIX#://#HOST#:#PORT#/#DBHOME##DBNAME#;
-
- create=true
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ org.h2.Driver
+ #PREFIX#:tcp://#HOST#:#PORT#/#DBHOME##DBNAME#;IGNORECASE=TRUE;SCHEMA_SEARCH_PATH=OSEE, PUBLIC
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ org.postgresql.Driver
+ #PREFIX#://#HOST#:#PORT#/#DBHOME##DBNAME#
+
+
+
+ org.apache.derby.jdbc.ClientDriver
+ #PREFIX#://#HOST#:#PORT#/#DBHOME##DBNAME#;
+
+ create=true
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/plugins/org.eclipse.osee.framework.core.datastore/src/org/eclipse/osee/framework/core/datastore/schema/operations/CreateSchemaOperation.java b/plugins/org.eclipse.osee.framework.core.datastore/src/org/eclipse/osee/framework/core/datastore/schema/operations/CreateSchemaOperation.java
index 211a1add070..a4d46bb7839 100644
--- a/plugins/org.eclipse.osee.framework.core.datastore/src/org/eclipse/osee/framework/core/datastore/schema/operations/CreateSchemaOperation.java
+++ b/plugins/org.eclipse.osee.framework.core.datastore/src/org/eclipse/osee/framework/core/datastore/schema/operations/CreateSchemaOperation.java
@@ -41,18 +41,20 @@ public class CreateSchemaOperation extends AbstractDbTxOperation {
@Override
protected void doTxWork(IProgressMonitor monitor, OseeConnection connection) throws OseeCoreException {
DatabaseMetaData metaData = connection.getMetaData();
+ SupportedDatabase dbType = SupportedDatabase.getDatabaseType(metaData);
SqlManager sqlManager = SqlFactory.getSqlManager(metaData);
SchemaSqlUtil dbInit = new SchemaSqlUtil(sqlManager);
Set schemas = userSchema.keySet();
+
dbInit.dropIndices(schemas, userSchema, dbSchema);
dbInit.dropTables(schemas, userSchema, dbSchema);
- if (SupportedDatabase.isDatabaseType(metaData, SupportedDatabase.postgresql)) {
+
+ if (dbType == SupportedDatabase.postgresql || dbType == SupportedDatabase.h2) {
dbInit.dropSchema(schemas);
dbInit.createSchema(schemas);
}
dbInit.addTables(schemas, userSchema);
dbInit.addIndices(schemas, userSchema);
}
-
}
diff --git a/plugins/org.eclipse.osee.framework.core.datastore/src/org/eclipse/osee/framework/core/datastore/schema/sql/H2DataType.java b/plugins/org.eclipse.osee.framework.core.datastore/src/org/eclipse/osee/framework/core/datastore/schema/sql/H2DataType.java
new file mode 100644
index 00000000000..d9f74bf1ce5
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.core.datastore/src/org/eclipse/osee/framework/core/datastore/schema/sql/H2DataType.java
@@ -0,0 +1,112 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2007 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.framework.core.datastore.schema.sql;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class H2DataType extends SqlDataType {
+
+ public H2DataType() {
+ super();
+ }
+
+ @Override
+ public String getBooleanType() {
+ return "boolean";
+ }
+
+ @Override
+ public String getBitType() {
+ return "tinyint";
+ }
+
+ @Override
+ public String getIntegerType() {
+ return "int";
+ }
+
+ @Override
+ public String getDecimalType() {
+ return "decimal";
+ }
+
+ @Override
+ public String getFloatType() {
+ return "double";
+ }
+
+ @Override
+ public String getRealType() {
+ return "real";
+ }
+
+ @Override
+ public String getDoubleType() {
+ return "double";
+ }
+
+ @Override
+ public String getDateType() {
+ return "date";
+ }
+
+ @Override
+ public String getCharType() {
+ return "char";
+ }
+
+ @Override
+ public String getVarCharType() {
+ return "varchar";
+ }
+
+ @Override
+ public String getSmallIntType() {
+ return "smallint";
+ }
+
+ @Override
+ protected String getClobType() {
+ return "clob";
+ }
+
+ @Override
+ protected String getTimestamp() {
+ return "timestamp";
+ }
+
+ @Override
+ protected String getTime() {
+ return "time";
+ }
+
+ @Override
+ protected String getBlobType() {
+ return "blob";
+ }
+
+ @Override
+ protected String getBigInt() {
+ return "bigint";
+ }
+
+ @Override
+ protected String getLongVarCharType() {
+ return "varchar";
+ }
+
+ @Override
+ protected String getNumericType() {
+ return "numeric";
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.framework.core.datastore/src/org/eclipse/osee/framework/core/datastore/schema/sql/H2SqlManager.java b/plugins/org.eclipse.osee.framework.core.datastore/src/org/eclipse/osee/framework/core/datastore/schema/sql/H2SqlManager.java
new file mode 100644
index 00000000000..c5505c5d821
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.core.datastore/src/org/eclipse/osee/framework/core/datastore/schema/sql/H2SqlManager.java
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2007 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.framework.core.datastore.schema.sql;
+
+import org.eclipse.osee.framework.core.datastore.schema.data.TableElement;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.framework.database.core.ConnectionHandler;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class H2SqlManager extends SqlManagerImpl {
+
+ public H2SqlManager(SqlDataType sqlDataType) {
+ super(sqlDataType);
+ }
+
+ @Override
+ public void createSchema(String schema) throws OseeCoreException {
+ ConnectionHandler.runPreparedUpdate(String.format("%s SCHEMA IF NOT EXISTS \"%s\"", CREATE_STRING,
+ schema.toUpperCase()));
+ }
+
+ @Override
+ public void dropSchema(String schema) throws OseeCoreException {
+ ConnectionHandler.runPreparedUpdate(String.format("%s SCHEMA IF EXISTS \"%s\"", DROP_STRING, schema.toUpperCase()));
+ }
+
+ @Override
+ public void dropIndex(TableElement tableDef) {
+ // Do Nothing -- Indexes are dropped during table drop
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.framework.core.datastore/src/org/eclipse/osee/framework/core/datastore/schema/sql/SqlFactory.java b/plugins/org.eclipse.osee.framework.core.datastore/src/org/eclipse/osee/framework/core/datastore/schema/sql/SqlFactory.java
index 612aac946c3..bbc751a5a85 100644
--- a/plugins/org.eclipse.osee.framework.core.datastore/src/org/eclipse/osee/framework/core/datastore/schema/sql/SqlFactory.java
+++ b/plugins/org.eclipse.osee.framework.core.datastore/src/org/eclipse/osee/framework/core/datastore/schema/sql/SqlFactory.java
@@ -45,6 +45,9 @@ public class SqlFactory {
case postgresql:
instance = new PostgreSqlManager(new PostgresqlDataType());
break;
+ case h2:
+ instance = new H2SqlManager(new H2DataType());
+ break;
default:
break;
}
diff --git a/plugins/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/core/ConnectionHandler.java b/plugins/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/core/ConnectionHandler.java
index 2c122d64d76..4e37a2d7cc9 100644
--- a/plugins/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/core/ConnectionHandler.java
+++ b/plugins/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/core/ConnectionHandler.java
@@ -155,11 +155,19 @@ public final class ConnectionHandler {
* Cause constraint checking to be deferred until the end of the current transaction.
*/
public static void deferConstraintChecking(OseeConnection connection) throws OseeCoreException {
- if (SupportedDatabase.getDatabaseType(connection.getMetaData()) == SupportedDatabase.derby) {
- return;
+ SupportedDatabase dbType = SupportedDatabase.getDatabaseType(connection.getMetaData());
+ switch (dbType) {
+ case derby:
+ // Derby Does not support deferring constraints
+ break;
+ case h2:
+ runPreparedUpdate(connection, "SET REFERENTIAL_INTEGRITY = FALSE");
+ break;
+ default:
+ // NOTE: this must be a PreparedStatement to play correctly with DB Transactions.
+ runPreparedUpdate(connection, "SET CONSTRAINTS ALL DEFERRED");
+ break;
}
- // NOTE: this must be a PreparedStatement to play correctly with DB Transactions.
- runPreparedUpdate(connection, "SET CONSTRAINTS ALL DEFERRED");
}
public static DatabaseMetaData getMetaData() throws OseeCoreException {
diff --git a/plugins/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/core/SupportedDatabase.java b/plugins/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/core/SupportedDatabase.java
index 618f6668608..589b794486a 100644
--- a/plugins/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/core/SupportedDatabase.java
+++ b/plugins/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/core/SupportedDatabase.java
@@ -17,6 +17,7 @@ import org.eclipse.osee.framework.core.exception.OseeDataStoreException;
import org.eclipse.osee.framework.core.exception.OseeExceptions;
public enum SupportedDatabase {
+ h2,
oracle,
derby,
foxpro,
@@ -28,7 +29,9 @@ public enum SupportedDatabase {
try {
String dbName = metaData.getDatabaseProductName();
String lowerCaseName = dbName.toLowerCase();
- if (lowerCaseName.contains(SupportedDatabase.derby.toString())) {
+ if (lowerCaseName.contains(SupportedDatabase.h2.toString())) {
+ toReturn = SupportedDatabase.h2;
+ } else if (lowerCaseName.contains(SupportedDatabase.derby.toString())) {
toReturn = SupportedDatabase.derby;
} else if (lowerCaseName.contains(SupportedDatabase.oracle.toString())) {
toReturn = SupportedDatabase.oracle;
diff --git a/plugins/org.eclipse.osee.framework.h2/.classpath b/plugins/org.eclipse.osee.framework.h2/.classpath
new file mode 100644
index 00000000000..ad32c83a788
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.h2/.classpath
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/plugins/org.eclipse.osee.framework.h2/.project b/plugins/org.eclipse.osee.framework.h2/.project
new file mode 100644
index 00000000000..074edb12524
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.h2/.project
@@ -0,0 +1,33 @@
+
+
+ org.eclipse.osee.framework.h2
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+ org.eclipse.pde.ManifestBuilder
+
+
+
+
+ org.eclipse.pde.SchemaBuilder
+
+
+
+
+ org.eclipse.pde.ds.core.builder
+
+
+
+
+
+ org.eclipse.pde.PluginNature
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/plugins/org.eclipse.osee.framework.h2/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.framework.h2/META-INF/MANIFEST.MF
new file mode 100644
index 00000000000..7ea69c5459c
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.h2/META-INF/MANIFEST.MF
@@ -0,0 +1,21 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: H2 Db Connector Plug-in (Incubation)
+Bundle-SymbolicName: org.eclipse.osee.framework.h2;singleton:=true
+Bundle-Version: 0.9.6.qualifier
+Bundle-ActivationPolicy: lazy
+Import-Package:
+ org.eclipse.osee.framework.database.core,
+ org.eclipse.osee.framework.jdk.core.type,
+ org.eclipse.osee.framework.jdk.core.util,
+ org.eclipse.osee.framework.logging,
+ org.h2,
+ org.h2.jdbc,
+ org.h2.server,
+ org.h2.tools,
+ org.h2.util,
+ org.osgi.framework
+Export-Package: org.eclipse.osee.framework.h2
+Service-Component: OSGI-INF/h2.client.connection.driver.provider.xml
+Bundle-Vendor: Eclipse Open System Engineering Environment
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
diff --git a/plugins/org.eclipse.osee.framework.h2/OSGI-INF/h2.client.connection.driver.provider.xml b/plugins/org.eclipse.osee.framework.h2/OSGI-INF/h2.client.connection.driver.provider.xml
new file mode 100644
index 00000000000..322f9bad26e
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.h2/OSGI-INF/h2.client.connection.driver.provider.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/plugins/org.eclipse.osee.framework.h2/build.properties b/plugins/org.eclipse.osee.framework.h2/build.properties
new file mode 100644
index 00000000000..c58ea2178c3
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.h2/build.properties
@@ -0,0 +1,5 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ OSGI-INF/
diff --git a/plugins/org.eclipse.osee.framework.h2/src/org/eclipse/osee/framework/h2/H2ClientConnection.java b/plugins/org.eclipse.osee.framework.h2/src/org/eclipse/osee/framework/h2/H2ClientConnection.java
new file mode 100644
index 00000000000..0d3d2a629b4
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.h2/src/org/eclipse/osee/framework/h2/H2ClientConnection.java
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2007 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.framework.h2;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.util.Properties;
+import org.eclipse.osee.framework.database.core.IConnectionFactory;
+import org.eclipse.osee.framework.jdk.core.type.Pair;
+import org.eclipse.osee.framework.jdk.core.util.OseeProperties;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class H2ClientConnection implements IConnectionFactory {
+
+ private static final String driver = "org.h2.Driver";
+ private boolean firstTime = true;
+
+ @Override
+ public Connection getConnection(Properties properties, String connectionURL) throws Exception {
+ Class.forName(driver);
+
+ if (firstTime) {
+ firstTime = false;
+ Pair addressAndPort = OseeProperties.getDerbyServerAddress();
+ if (addressAndPort != null) {
+ H2DbServer.startServer(addressAndPort.getFirst(), addressAndPort.getSecond());
+ }
+ }
+ Connection connection = DriverManager.getConnection(connectionURL, properties);
+ return connection;
+ }
+
+ @Override
+ public String getDriver() {
+ return driver;
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.framework.h2/src/org/eclipse/osee/framework/h2/H2DbServer.java b/plugins/org.eclipse.osee.framework.h2/src/org/eclipse/osee/framework/h2/H2DbServer.java
new file mode 100644
index 00000000000..0ef17a03a88
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.h2/src/org/eclipse/osee/framework/h2/H2DbServer.java
@@ -0,0 +1,108 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2007 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.osee.framework.h2;
+
+import java.net.InetAddress;
+import java.util.logging.Level;
+import org.eclipse.osee.framework.logging.OseeLog;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class H2DbServer {
+ protected static Object keepAlive;
+ private H2DbServerUtil nwServer;
+ private static final H2DbServer instance = new H2DbServer();
+
+ private H2DbServer() {
+ this.nwServer = null;
+ }
+
+ public static void startServer(String host, int port) throws Exception {
+ instance.startServerInternal(host, port);
+ }
+
+ private void startServerInternal(String host, int port) throws Exception {
+ try {
+ OseeLog.log(H2DbServer.class, Level.INFO, "Starting H2 Database Server ....");
+ nwServer = new H2DbServerUtil(InetAddress.getByName(host), port);
+ nwServer.start();
+
+ if (isConnectionAvailable()) {
+ nwServer.printInfo();
+ addShutdownHook();
+ // stayAlive();
+ } else {
+ OseeLog.log(H2DbServer.class, Level.INFO, "Exiting, since unable to connect to Derby Network Server.");
+ OseeLog.log(H2DbServer.class, Level.INFO,
+ "Please try to increase the amount of time to keep trying to connect to the Server.");
+ }
+ } catch (Exception ex) {
+ OseeLog.log(H2DbServer.class, Level.SEVERE, ex);
+ }
+ }
+
+ // private void stayAlive() {
+ // keepAlive = new Object();
+ // synchronized (keepAlive) {
+ // try {
+ // keepAlive.wait();
+ // } catch (InterruptedException e) {
+ // OseeLog.log(H2DbServer.class, Level.SEVERE, e.getMessage(), e);
+ // }
+ // }
+ // }
+
+ // private void commitSuicide() {
+ // if (keepAlive != null) {
+ // synchronized (keepAlive) {
+ // keepAlive.notify();
+ // }
+ // }
+ // }
+
+ private void shutdown() {
+ OseeLog.log(H2DbServer.class, Level.INFO, "Shutting down H2 Database server...");
+ nwServer.shutdown();
+ OseeLog.log(H2DbServer.class, Level.INFO, "Server down.");
+ // commitSuicide();
+ }
+
+ private void addShutdownHook() {
+ Runtime.getRuntime().addShutdownHook(new Thread() {
+ @Override
+ public void run() {
+ OseeLog.log(H2DbServer.class, Level.INFO, "Shutting down");
+ shutdown();
+ }
+ });
+ }
+
+ private boolean isConnectionAvailable() throws InterruptedException {
+ boolean knowIfServerUp = false;
+ int numTimes = 5;
+
+ while (!knowIfServerUp && numTimes > 0) {
+ try {
+ numTimes--;
+ nwServer.testForConnection();
+ knowIfServerUp = true;
+ } catch (Exception e) {
+ OseeLog.log(H2DbServer.class, Level.SEVERE,
+ "Unable to obtain a connection to network server, trying again after 3000 ms.", e);
+ Thread.sleep(3000);
+ }
+ }
+ return knowIfServerUp;
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.framework.h2/src/org/eclipse/osee/framework/h2/H2DbServerUtil.java b/plugins/org.eclipse.osee.framework.h2/src/org/eclipse/osee/framework/h2/H2DbServerUtil.java
new file mode 100644
index 00000000000..3c4f3ab53dd
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.h2/src/org/eclipse/osee/framework/h2/H2DbServerUtil.java
@@ -0,0 +1,71 @@
+package org.eclipse.osee.framework.h2;
+
+import java.io.PrintStream;
+import java.net.InetAddress;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.logging.Level;
+import org.eclipse.osee.framework.logging.OseeLog;
+import org.h2.tools.Server;
+
+public final class H2DbServerUtil {
+
+ private final Collection serverControls = new ArrayList();
+
+ public H2DbServerUtil(InetAddress host, int port) {
+ try {
+ String[] webArgs = new String[] {"-webAllowOthers", "true", "-webPort", String.valueOf(port - 1)};
+ serverControls.add(Server.createWebServer(webArgs));
+
+ String[] dbArgs = new String[] {"-tcp", "-tcpAllowOthers", "true", "-tcpPort", String.valueOf(port)};
+ serverControls.add(Server.createTcpServer(dbArgs));
+
+ OseeLog.log(H2DbServer.class, Level.INFO, "H2 Database Server created");
+ } catch (Exception e) {
+ OseeLog.log(H2DbServer.class, Level.SEVERE, "Error Initializing Server Control.", e);
+ }
+
+ for (Server server : serverControls) {
+ server.setOut(new PrintStream(System.out, true));
+ }
+ }
+
+ public void testForConnection() throws Exception {
+ for (Server server : serverControls) {
+ server.isRunning(true);
+ }
+ }
+
+ public void shutdown() {
+ for (Server server : serverControls) {
+ try {
+ server.shutdown();
+ } catch (Exception e) {
+ OseeLog.log(H2DbServer.class, Level.SEVERE, e.getMessage(), e);
+ }
+ }
+ }
+
+ public void start() {
+ for (Server server : serverControls) {
+ try {
+ server.start();
+ } catch (Exception e) {
+ OseeLog.log(H2DbServer.class, Level.SEVERE, e.getMessage(), e);
+ }
+ }
+ }
+
+ public void printInfo() {
+ try {
+ StringBuilder builder = new StringBuilder();
+ builder.append("H2 Database: ");
+ for (Server server : serverControls) {
+ builder.append(server.getStatus());
+ }
+ OseeLog.log(H2DbServer.class, Level.INFO, builder.toString());
+ } catch (Exception ex) {
+ OseeLog.log(H2DbServer.class, Level.SEVERE, "Error getting Server Information", ex);
+ }
+ }
+}
\ No newline at end of file
--
cgit v1.2.3