Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db')
-rw-r--r--org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/ConnectionHandler.java376
-rw-r--r--org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/ConnectionHandlerStatement.java388
-rw-r--r--org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/DatabaseConnectionInfo.java101
-rw-r--r--org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/DatabaseInfoManager.java63
-rw-r--r--org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/DbTransaction.java127
-rw-r--r--org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/IApplicationDatabaseInfoProvider.java24
-rw-r--r--org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/IConnection.java24
-rw-r--r--org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/IDatabaseInfo.java33
-rw-r--r--org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/IDbConnectionInformationContributor.java20
-rw-r--r--org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/OseeConnection.java120
-rw-r--r--org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/OseeConnectionPool.java106
-rw-r--r--org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/OseeDbConnection.java77
-rw-r--r--org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/StaleConnectionCloser.java44
-rw-r--r--org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/core/KeyedLevelManager.java193
-rw-r--r--org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/core/ResultSetProcessor.java93
-rw-r--r--org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/core/RsetProcessor.java23
-rw-r--r--org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/core/SequenceManager.java189
-rw-r--r--org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/core/query/Query.java55
-rw-r--r--org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/core/query/QueryLog.java81
-rw-r--r--org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/core/query/QueryRecord.java140
-rw-r--r--org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/core/schema/LocalAliasTable.java28
-rw-r--r--org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/core/schema/SkynetDatabase.java58
-rw-r--r--org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/core/schema/Table.java142
-rw-r--r--org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/core/schema/View.java31
-rw-r--r--org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/core/transaction/DbTransactionEventCompleted.java31
-rw-r--r--org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/core/transaction/IDbTransactionEvent.java18
-rw-r--r--org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/core/transaction/IDbTransactionListener.java20
-rw-r--r--org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/ArtifactDoesNotExist.java24
-rw-r--r--org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/AttributeDoesNotExist.java25
-rw-r--r--org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/BranchDoesNotExist.java33
-rw-r--r--org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/BranchMergeException.java24
-rw-r--r--org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/ConflictDetectionException.java25
-rw-r--r--org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/InvalidTaggerException.java23
-rw-r--r--org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/MergeChangesInArtifactException.java25
-rw-r--r--org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/MultipleArtifactsExist.java24
-rw-r--r--org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/MultipleAttributesExist.java25
-rw-r--r--org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/MultipleBranchesExist.java23
-rw-r--r--org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/OseeAccessDeniedException.java23
-rw-r--r--org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/OseeArgumentException.java23
-rw-r--r--org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/OseeCoreException.java40
-rw-r--r--org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/OseeDataStoreException.java41
-rw-r--r--org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/OseeMultipleEnumTypesExist.java24
-rw-r--r--org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/OseeStateException.java24
-rw-r--r--org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/OseeTypeDoesNotExist.java23
-rw-r--r--org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/OseeWrappedException.java40
-rw-r--r--org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/TransactionDoesNotExist.java33
-rw-r--r--org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/UserInDatabaseMultipleTimes.java36
-rw-r--r--org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/UserNotInDatabase.java36
-rw-r--r--org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/info/SQL3DataType.java81
-rw-r--r--org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/info/SupportedDatabase.java73
-rw-r--r--org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/internal/ApplicationDatabaseManager.java75
-rw-r--r--org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/internal/DbConnectionFactory.java88
-rw-r--r--org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/internal/DbConnectionInformation.java111
-rw-r--r--org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/internal/IApplicationDatabaseManager.java26
-rw-r--r--org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/internal/IDbConnectionFactory.java26
-rw-r--r--org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/internal/IDbConnectionInformation.java29
-rw-r--r--org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/internal/InternalActivator.java79
-rw-r--r--org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/internal/TransactionMonitor.java118
-rw-r--r--org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/internal/UriDbConnectionInfo.java46
-rw-r--r--org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/internal/parser/DbConfigParser.java208
-rw-r--r--org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/internal/parser/DbConnectionData.java90
-rw-r--r--org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/internal/parser/DbDetailData.java90
-rw-r--r--org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/internal/parser/DbInformation.java143
-rw-r--r--org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/internal/parser/DbSetupData.java68
64 files changed, 4550 insertions, 0 deletions
diff --git a/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/ConnectionHandler.java b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/ConnectionHandler.java
new file mode 100644
index 00000000000..623a4dd7a63
--- /dev/null
+++ b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/ConnectionHandler.java
@@ -0,0 +1,376 @@
+/*******************************************************************************
+ * 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.db.connection;
+
+import java.io.ByteArrayInputStream;
+import java.sql.DatabaseMetaData;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.List;
+import java.util.logging.Level;
+import org.eclipse.osee.framework.db.connection.core.query.QueryRecord;
+import org.eclipse.osee.framework.db.connection.exception.OseeDataStoreException;
+import org.eclipse.osee.framework.db.connection.info.SQL3DataType;
+import org.eclipse.osee.framework.db.connection.info.SupportedDatabase;
+import org.eclipse.osee.framework.db.connection.internal.InternalActivator;
+import org.eclipse.osee.framework.logging.OseeLog;
+
+/**
+ * Handles connection recovery in the event of database connection being lost
+ *
+ * @author Jeff C. Phillips
+ */
+public final class ConnectionHandler {
+
+ private static void close(PreparedStatement stmt) {
+ if (stmt != null) {
+ try {
+ stmt.close();
+ } catch (SQLException ex) {
+ OseeLog.log(InternalActivator.class, Level.WARNING, "Unable to close database statement: ", ex);
+ }
+ }
+ }
+
+ /**
+ * This method should only be used when not contained in a DB transaction
+ *
+ * @param query
+ * @param data
+ * @return number of records updated
+ * @throws OseeDataStoreException
+ */
+ public static int runPreparedUpdate(String query, Object... data) throws OseeDataStoreException {
+ OseeConnection connection = OseeDbConnection.getConnection();
+ try {
+ return runPreparedUpdate(connection, query, data);
+ } finally {
+ connection.close();
+ }
+ }
+
+ /**
+ * This method should only be used when not contained in a DB transaction
+ *
+ * @param query
+ * @param dataList
+ * @return number of records updated
+ * @throws OseeDataStoreException
+ */
+ public static int runBatchUpdate(String query, List<Object[]> dataList) throws OseeDataStoreException {
+ OseeConnection connection = OseeDbConnection.getConnection();
+ try {
+ return runBatchUpdate(connection, query, dataList);
+ } finally {
+ connection.close();
+ }
+ }
+
+ /**
+ * This method should only be used when contained in a DB transaction
+ *
+ * @param connection
+ * @param query
+ * @param data
+ * @return number of records updated
+ * @throws OseeDataStoreException
+ */
+ public static int runPreparedUpdate(OseeConnection connection, String query, Object... data) throws OseeDataStoreException {
+ if (connection == null) {
+ return runPreparedUpdate(query, data);
+ }
+ PreparedStatement preparedStatement = null;
+ int updateCount = 0;
+ try {
+ preparedStatement = connection.prepareStatement(query);
+ populateValuesForPreparedStatement(preparedStatement, data);
+ updateCount = preparedStatement.executeUpdate();
+ } catch (SQLException ex) {
+ throw new OseeDataStoreException(ex);
+ } finally {
+ close(preparedStatement);
+ }
+ return updateCount;
+ }
+
+ public static int runBatchUpdate(OseeConnection connection, String query, List<Object[]> dataList) throws OseeDataStoreException {
+ if (connection == null) {
+ return runBatchUpdate(query, dataList);
+ }
+
+ QueryRecord record = new QueryRecord("<batchable: batched> " + query, dataList.size());
+ int returnCount = 0;
+ PreparedStatement preparedStatement = null;
+ try {
+ preparedStatement = connection.prepareStatement(query);
+ record.markStart();
+ boolean needExecute = false;
+ int count = 0;
+ for (Object[] data : dataList) {
+ count++;
+ populateValuesForPreparedStatement(preparedStatement, data);
+ preparedStatement.addBatch();
+ preparedStatement.clearParameters();
+ needExecute = true;
+ if (count > 2000) {
+ int[] updates = preparedStatement.executeBatch();
+ returnCount += processBatchUpdateResults(updates);
+ count = 0;
+ needExecute = false;
+ }
+ }
+ if (needExecute) {
+ int[] updates = preparedStatement.executeBatch();
+ returnCount += processBatchUpdateResults(updates);
+ }
+
+ record.markEnd();
+ } catch (SQLException ex) {
+ record.setSqlException(ex);
+ SQLException exlist;
+ if ((exlist = ex.getNextException()) != null) {
+ OseeLog.log(InternalActivator.class, Level.SEVERE, "This is the nested exception", exlist);
+ }
+ StringBuilder details = new StringBuilder(dataList.size() * dataList.get(0).length * 20);
+ details.append("[ DATA OBJECT: \n");
+ for (Object[] data : dataList) {
+ for (int i = 0; i < data.length; i++) {
+ details.append(i);
+ details.append(": ");
+ Object dataValue = data[i];
+ if (dataValue != null) {
+ details.append(dataValue.getClass().getName());
+ details.append(":");
+
+ String value = dataValue.toString();
+ if (value.length() > 35) {
+ details.append(value.substring(0, 35));
+ } else {
+ details.append(value);
+ }
+ details.append("\n");
+ } else {
+ details.append("NULL\n");
+ }
+ }
+ }
+ details.append("]\n");
+ throw new OseeDataStoreException("sql update failed: \n" + query + "\n" + details, ex);
+ } finally {
+ close(preparedStatement);
+ }
+ return returnCount;
+ }
+
+ public static int runPreparedQueryFetchInt(int defaultValue, String query, Object... data) throws OseeDataStoreException {
+ return runPreparedQueryFetchInt(new ConnectionHandlerStatement(), defaultValue, query, data);
+ }
+
+ public static int runPreparedQueryFetchInt(OseeConnection connection, int defaultValue, String query, Object... data) throws OseeDataStoreException {
+ return runPreparedQueryFetchInt(new ConnectionHandlerStatement(connection), defaultValue, query, data);
+ }
+
+ private static int runPreparedQueryFetchInt(ConnectionHandlerStatement chStmt, int defaultValue, String query, Object... data) throws OseeDataStoreException {
+ try {
+ chStmt.runPreparedQuery(1, query, data);
+ if (chStmt.next()) {
+ return chStmt.getInt(1);
+ }
+ return defaultValue;
+ } finally {
+ chStmt.close();
+ }
+ }
+
+ public static int runCallableStatementFetchInt(String query, Object... data) throws OseeDataStoreException {
+ return runCallableStatementFetchInt(new ConnectionHandlerStatement(), query, data);
+ }
+
+ public static int runCallableStatementFetchInt(OseeConnection connection, String query, Object... data) throws OseeDataStoreException {
+ return runCallableStatementFetchInt(new ConnectionHandlerStatement(connection), query, data);
+ }
+
+ public static int runCallableStatementFetchInt(ConnectionHandlerStatement chStmt, String query, Object... data) throws OseeDataStoreException {
+ try {
+ chStmt.runCallableStatement(query, data);
+ return chStmt.getCallableInt(1);
+ } finally {
+ chStmt.close();
+ }
+ }
+
+ public static double runCallableStatementFetchDouble(String query, Object... data) throws OseeDataStoreException {
+ return runCallableStatementFetchDouble(new ConnectionHandlerStatement(), query, data);
+ }
+
+ public static double runCallableStatementFetchDouble(OseeConnection connection, String query, Object... data) throws OseeDataStoreException {
+ return runCallableStatementFetchDouble(new ConnectionHandlerStatement(connection), query, data);
+ }
+
+ private static double runCallableStatementFetchDouble(ConnectionHandlerStatement chStmt, String query, Object... data) throws OseeDataStoreException {
+ try {
+ chStmt.runCallableStatement(query, data);
+ return chStmt.getCallableDouble(1);
+ } finally {
+ chStmt.close();
+ }
+ }
+
+ public static long runPreparedQueryFetchLong(long defaultValue, String query, Object... data) throws OseeDataStoreException {
+ return runPreparedQueryFetchLong(new ConnectionHandlerStatement(), defaultValue, query, data);
+ }
+
+ public static long runPreparedQueryFetchLong(OseeConnection connection, long defaultValue, String query, Object... data) throws OseeDataStoreException {
+ return runPreparedQueryFetchLong(new ConnectionHandlerStatement(connection), defaultValue, query, data);
+ }
+
+ private static long runPreparedQueryFetchLong(ConnectionHandlerStatement chStmt, long defaultValue, String query, Object... data) throws OseeDataStoreException {
+ try {
+ chStmt.runPreparedQuery(1, query, data);
+ if (chStmt.next()) {
+ return chStmt.getLong(1);
+ }
+ return defaultValue;
+ } finally {
+ chStmt.close();
+ }
+ }
+
+ public static String runPreparedQueryFetchString(String defaultValue, String query, Object... data) throws OseeDataStoreException {
+ return runPreparedQueryFetchString(new ConnectionHandlerStatement(), defaultValue, query, data);
+ }
+
+ public static String runPreparedQueryFetchString(OseeConnection connection, String defaultValue, String query, Object... data) throws OseeDataStoreException {
+ return runPreparedQueryFetchString(new ConnectionHandlerStatement(connection), defaultValue, query, data);
+ }
+
+ private static String runPreparedQueryFetchString(ConnectionHandlerStatement chStmt, String defaultValue, String query, Object... data) throws OseeDataStoreException {
+ try {
+ chStmt.runPreparedQuery(1, query, data);
+ if (chStmt.next()) {
+ return chStmt.getString(1);
+ }
+ return defaultValue;
+ } finally {
+ chStmt.close();
+ }
+ }
+
+ private static int processBatchUpdateResults(int[] updates) {
+ int returnCount = 0;
+ for (int update : updates) {
+ if (update >= 0) {
+ returnCount += update;
+ } else if (Statement.EXECUTE_FAILED == update) {
+ OseeLog.log(InternalActivator.class, Level.SEVERE, "sql execute failed.");
+ } else if (Statement.SUCCESS_NO_INFO == update) {
+ returnCount++;
+ }
+ }
+ return returnCount;
+ }
+
+ static void populateValuesForPreparedStatement(PreparedStatement preparedStatement, Object... data) throws OseeDataStoreException {
+ try {
+ int preparedIndex = 0;
+ for (Object dataValue : data) {
+ preparedIndex++;
+ if (dataValue instanceof String) {
+ int length = ((String) dataValue).length();
+ if (length > 4000) {
+ throw new OseeDataStoreException(
+ "SQL data value length must be <= 4000 not " + length + "\nValue: " + dataValue);
+ }
+ }
+
+ if (dataValue == null) {
+ throw new OseeDataStoreException(
+ "instead of passing null for an query parameter, pass the corresponding SQL3DataType");
+ } else if (dataValue instanceof SQL3DataType) {
+ int dataTypeNumber = ((SQL3DataType) dataValue).getSQLTypeNumber();
+ if (dataTypeNumber == java.sql.Types.BLOB) {
+ // TODO Need to check this - for PostgreSql, setNull for BLOB with the new JDBC driver gives the error "column
+ // "content" is of type bytea but expression is of type oid"
+ preparedStatement.setBytes(preparedIndex, null);
+ } else {
+ preparedStatement.setNull(preparedIndex, dataTypeNumber);
+ }
+ } else if (dataValue instanceof ByteArrayInputStream) {
+ preparedStatement.setBinaryStream(preparedIndex, (ByteArrayInputStream) dataValue,
+ ((ByteArrayInputStream) dataValue).available());
+ } else {
+ preparedStatement.setObject(preparedIndex, dataValue);
+ }
+ }
+ } catch (SQLException ex) {
+ throw new OseeDataStoreException(ex);
+ }
+ }
+
+ /**
+ * Cause constraint checking to be deferred until the end of the current transaction.
+ *
+ * @param connection
+ * @throws OseeDataStoreException
+ */
+ public static void deferConstraintChecking(OseeConnection connection) throws OseeDataStoreException {
+ if (SupportedDatabase.getDatabaseType(connection) == SupportedDatabase.derby) {
+ return;
+ }
+ // NOTE: this must be a PreparedStatement to play correctly with DB Transactions.
+ runPreparedUpdate(connection, "SET CONSTRAINTS ALL DEFERRED");
+ }
+
+ public static DatabaseMetaData getMetaData() throws OseeDataStoreException {
+ OseeConnection connection = OseeDbConnection.getConnection();
+ try {
+ return connection.getMetaData();
+ } finally {
+ connection.close();
+ }
+ }
+
+ public static boolean doesTableExist(String targetTable) {
+ return doesTableExist(null, targetTable);
+ }
+
+ public static boolean doesTableExist(String targetSchema, String targetTable) {
+ ResultSet resultSet = null;
+ try {
+ resultSet = getMetaData().getTables(null, null, null, new String[] {"TABLE"});
+ if (resultSet != null) {
+ while (resultSet.next()) {
+ String tableName = resultSet.getString("TABLE_NAME");
+ String schemaName = resultSet.getString("TABLE_SCHEM");
+ if (targetTable.equalsIgnoreCase(tableName)) {
+ if (targetSchema == null || targetSchema.equalsIgnoreCase(schemaName)) {
+ return true;
+ }
+ }
+ }
+ }
+ } catch (Exception ex) {
+ // Do nothing
+ } finally {
+ if (resultSet != null) {
+ try {
+ resultSet.close();
+ } catch (SQLException ex) {
+ // Do nothing
+ }
+ }
+ }
+ return false;
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/ConnectionHandlerStatement.java b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/ConnectionHandlerStatement.java
new file mode 100644
index 00000000000..63ebc2cf583
--- /dev/null
+++ b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/ConnectionHandlerStatement.java
@@ -0,0 +1,388 @@
+/*******************************************************************************
+ * 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.db.connection;
+
+import java.io.InputStream;
+import java.math.BigDecimal;
+import java.sql.CallableStatement;
+import java.sql.Date;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.util.logging.Level;
+import org.eclipse.osee.framework.db.connection.core.query.QueryRecord;
+import org.eclipse.osee.framework.db.connection.exception.OseeDataStoreException;
+import org.eclipse.osee.framework.db.connection.info.SQL3DataType;
+import org.eclipse.osee.framework.db.connection.internal.InternalActivator;
+import org.eclipse.osee.framework.logging.OseeLog;
+
+/**
+ * @author Jeff C. Phillips
+ * @author Ryan D. Brooks
+ */
+public class ConnectionHandlerStatement {
+ private ResultSet rSet;
+ private PreparedStatement preparedStatement;
+ private CallableStatement callableStatement;
+ private OseeConnection connection;
+ private final boolean autoClose;
+
+ public ConnectionHandlerStatement(OseeConnection connection) {
+ this(connection, connection == null);
+ }
+
+ public ConnectionHandlerStatement(OseeConnection connection, boolean autoClose) {
+ this.autoClose = autoClose;
+ this.connection = connection;
+ }
+
+ public ConnectionHandlerStatement() {
+ this(null);
+ }
+
+ public void runPreparedQuery(String query, Object... data) throws OseeDataStoreException {
+ runPreparedQuery(0, query, data);
+ }
+
+ /**
+ * @param fetchSize hint as to the number of rows that should be fetched from the database at a time. will be limited
+ * to 10,000
+ * @param query
+ * @param data
+ * @throws OseeDataStoreException
+ */
+ public void runPreparedQuery(int fetchSize, String query, Object... data) throws OseeDataStoreException {
+ QueryRecord record = new QueryRecord(query, data);
+
+ try {
+ allowReuse();
+ preparedStatement = connection.prepareStatement(query);
+ preparedStatement.setFetchSize(Math.min(fetchSize, 10000));
+ ConnectionHandler.populateValuesForPreparedStatement(preparedStatement, data);
+
+ record.markStart();
+ rSet = preparedStatement.executeQuery();
+ record.markEnd();
+ } catch (SQLException ex) {
+ record.setSqlException(ex);
+ throw new OseeDataStoreException(ex);
+ }
+ }
+
+ /**
+ * Invokes a stored procedure parameters of type SQL3DataType are registered as Out parameters and all others are set
+ * as in parameters
+ *
+ * @param query
+ * @param data
+ * @throws OseeDataStoreException
+ */
+ public void runCallableStatement(String query, Object... data) throws OseeDataStoreException {
+ QueryRecord record = new QueryRecord(query, data);
+
+ try {
+ allowReuse();
+ callableStatement = connection.prepareCall(query);
+
+ for (int index = 0; index < data.length; index++) {
+ if (data[index] instanceof SQL3DataType) {
+ callableStatement.registerOutParameter(index + 1, ((SQL3DataType) data[index]).getSQLTypeNumber());
+ }
+ }
+ ConnectionHandler.populateValuesForPreparedStatement(callableStatement, data);
+
+ record.markStart();
+ if (callableStatement.execute()) {
+ rSet = callableStatement.getResultSet();
+ }
+ record.markEnd();
+ } catch (SQLException ex) {
+ record.setSqlException(ex);
+ throw new OseeDataStoreException(ex);
+ }
+ }
+
+ public boolean next() throws OseeDataStoreException {
+ if (rSet != null) {
+ try {
+ return rSet.next();
+ } catch (SQLException ex) {
+ throw new OseeDataStoreException(ex);
+ }
+ }
+ return false;
+ }
+
+ /**
+ * The application must call close when it is done using this object; however, it is safe to use this same object
+ * multiple times, for example calling runPreparedQuery() repeatedly, without any intermediate calls to close
+ */
+ public void close() {
+ try {
+ closePreviousResources();
+ if (autoClose && connection != null) {
+ connection.close();
+ connection = null;// this allows for multiple calls to runPreparedQuery to have an open connection
+ }
+ } catch (SQLException ex) {
+ OseeLog.log(InternalActivator.class, Level.SEVERE, ex);
+ }
+ }
+
+ /**
+ * allows for multiple uses of this object to have an open connection
+ *
+ * @throws SQLException
+ * @throws OseeDataStoreException
+ */
+ private void allowReuse() throws SQLException, OseeDataStoreException {
+ if (connection == null) {
+ connection = OseeDbConnection.getConnection();
+ }
+ closePreviousResources();
+ }
+
+ private void closePreviousResources() throws SQLException {
+ if (rSet != null) {
+ rSet.close();
+ }
+ if (preparedStatement != null) {
+ preparedStatement.close();
+ }
+ if (callableStatement != null) {
+ callableStatement.close();
+ }
+ }
+
+ public InputStream getBinaryStream(String columnName) throws OseeDataStoreException {
+ try {
+ return rSet.getBinaryStream(columnName);
+ } catch (SQLException ex) {
+ throw new OseeDataStoreException(ex);
+ }
+ }
+
+ public InputStream getAsciiStream(String columnName) throws OseeDataStoreException {
+ try {
+ return rSet.getAsciiStream(columnName);
+ } catch (SQLException ex) {
+ throw new OseeDataStoreException(ex);
+ }
+ }
+
+ public String getString(String columnName) throws OseeDataStoreException {
+ try {
+ return rSet.getString(columnName);
+ } catch (SQLException ex) {
+ throw new OseeDataStoreException(ex);
+ }
+ }
+
+ public float getFloat(String columnName) throws OseeDataStoreException {
+ try {
+ return rSet.getFloat(columnName);
+ } catch (SQLException ex) {
+ throw new OseeDataStoreException(ex);
+ }
+ }
+
+ public long getLong(String columnName) throws OseeDataStoreException {
+ try {
+ return rSet.getLong(columnName);
+ } catch (SQLException ex) {
+ throw new OseeDataStoreException(ex);
+ }
+ }
+
+ public int getInt(String columnName) throws OseeDataStoreException {
+ try {
+ return rSet.getInt(columnName);
+ } catch (SQLException ex) {
+ throw new OseeDataStoreException(ex);
+ }
+ }
+
+ /**
+ * should not be used by application code because it is less readable than using the column name
+ *
+ * @param columnIndex
+ * @return
+ * @throws OseeDataStoreException
+ */
+ int getInt(int columnIndex) throws OseeDataStoreException {
+ try {
+ return rSet.getInt(columnIndex);
+ } catch (SQLException ex) {
+ throw new OseeDataStoreException(ex);
+ }
+ }
+
+ int getCallableInt(int columnIndex) throws OseeDataStoreException {
+ try {
+ return callableStatement.getInt(columnIndex);
+ } catch (SQLException ex) {
+ throw new OseeDataStoreException(ex);
+ }
+ }
+
+ public double getCallableDouble(int columnIndex) throws OseeDataStoreException {
+ try {
+ return callableStatement.getDouble(columnIndex);
+ } catch (SQLException ex) {
+ throw new OseeDataStoreException(ex);
+ }
+ }
+
+ /**
+ * should not be used by application code because it is less readable than using the column name
+ *
+ * @param columnIndex
+ * @return
+ * @throws OseeDataStoreException
+ */
+ long getLong(int columnIndex) throws OseeDataStoreException {
+ try {
+ return rSet.getLong(columnIndex);
+ } catch (SQLException ex) {
+ throw new OseeDataStoreException(ex);
+ }
+ }
+
+ /**
+ * should not be used by application code because it is less readable than using the column name
+ *
+ * @param columnIndex
+ * @return
+ * @throws OseeDataStoreException
+ */
+ String getString(int columnIndex) throws OseeDataStoreException {
+ try {
+ return rSet.getString(columnIndex);
+ } catch (SQLException ex) {
+ throw new OseeDataStoreException(ex);
+ }
+ }
+
+ public Timestamp getTimestamp(String columnName) throws OseeDataStoreException {
+ try {
+ return rSet.getTimestamp(columnName);
+ } catch (SQLException ex) {
+ throw new OseeDataStoreException(ex);
+ }
+ }
+
+ public BigDecimal getBigDecimal(String name) throws OseeDataStoreException {
+ try {
+ return rSet.getBigDecimal(name);
+ } catch (SQLException ex) {
+ throw new OseeDataStoreException(ex);
+ }
+ }
+
+ public Time getTime(String name) throws OseeDataStoreException {
+ try {
+ return rSet.getTime(name);
+ } catch (SQLException ex) {
+ throw new OseeDataStoreException(ex);
+ }
+ }
+
+ public double getDouble(String columnName) throws OseeDataStoreException {
+ try {
+ return rSet.getDouble(columnName);
+ } catch (SQLException ex) {
+ throw new OseeDataStoreException(ex);
+ }
+ }
+
+ public Date getDate(String columnName) throws OseeDataStoreException {
+ try {
+ return rSet.getDate(columnName);
+ } catch (SQLException ex) {
+ throw new OseeDataStoreException(ex);
+ }
+ }
+
+ public boolean wasNull() throws OseeDataStoreException {
+ try {
+ return rSet.wasNull();
+ } catch (SQLException ex) {
+ throw new OseeDataStoreException(ex);
+ }
+ }
+
+ public int getColumnCount() throws OseeDataStoreException {
+ try {
+ return rSet.getMetaData().getColumnCount();
+ } catch (SQLException ex) {
+ throw new OseeDataStoreException(ex);
+ }
+ }
+
+ public String getColumnName(int columnIndex) throws OseeDataStoreException {
+ try {
+ return rSet.getMetaData().getColumnName(columnIndex);
+ } catch (SQLException ex) {
+ throw new OseeDataStoreException(ex);
+ }
+ }
+
+ public int getColumnType(int columnIndex) throws OseeDataStoreException {
+ try {
+ return rSet.getMetaData().getColumnType(columnIndex);
+ } catch (SQLException ex) {
+ throw new OseeDataStoreException(ex);
+ }
+ }
+
+ public String getColumnTypeName(int columnIndex) throws OseeDataStoreException {
+ try {
+ return rSet.getMetaData().getColumnTypeName(columnIndex);
+ } catch (SQLException ex) {
+ throw new OseeDataStoreException(ex);
+ }
+ }
+
+ public Object getObject(int columnIndex) throws OseeDataStoreException {
+ try {
+ return rSet.getObject(columnIndex);
+ } catch (SQLException ex) {
+ throw new OseeDataStoreException(ex);
+ }
+ }
+
+ /**
+ * Returns the number of rows in the result set. Once this method returns the result set will be pointing to the last
+ * row
+ *
+ * @return the number of rows in the result set
+ * @throws OseeDataStoreException
+ */
+ public int getRowCount() throws OseeDataStoreException {
+ try {
+ rSet.last();
+ return rSet.getRow();
+ } catch (SQLException ex) {
+ throw new OseeDataStoreException(ex);
+ }
+ }
+
+ public boolean isNullable(int columnIndex) throws OseeDataStoreException {
+ try {
+ return rSet.getMetaData().isNullable(columnIndex) == ResultSetMetaData.columnNullable;
+ } catch (SQLException ex) {
+ throw new OseeDataStoreException(ex);
+ }
+ }
+}
diff --git a/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/DatabaseConnectionInfo.java b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/DatabaseConnectionInfo.java
new file mode 100644
index 00000000000..5bde41942a2
--- /dev/null
+++ b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/DatabaseConnectionInfo.java
@@ -0,0 +1,101 @@
+/*******************************************************************************
+ * 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.db.connection;
+
+import java.util.Properties;
+
+/**
+ * @author Ryan D. Brooks
+ */
+public class DatabaseConnectionInfo implements IDatabaseInfo {
+ private final String databaseLoginName;
+ private final String connectionPrefix;
+ private final String databaseName;
+ private final String driver;
+ private final String id;
+ private final boolean isProduction;
+ private final Properties properties;
+
+ /**
+ * @param databaseLoginName
+ * @param databaseName
+ * @param driver
+ * @param id
+ * @param isProduction
+ */
+ public DatabaseConnectionInfo(String databaseLoginName, String connectionPrefix, String databaseName, String driver, String id, Properties properties, boolean isProduction) {
+ super();
+ this.databaseLoginName = databaseLoginName;
+ this.connectionPrefix = connectionPrefix;
+ this.databaseName = databaseName;
+ this.driver = driver;
+ this.id = id;
+ this.isProduction = isProduction;
+ this.properties = properties;
+ properties.setProperty("user", databaseLoginName);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.db.connection.IDatabaseInfo#getConnectionProperties()
+ */
+ @Override
+ public Properties getConnectionProperties() {
+ return properties;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.db.connection.IDatabaseInfo#getConnectionUrl()
+ */
+ @Override
+ public String getConnectionUrl() {
+ return connectionPrefix + ":" + databaseName;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.db.connection.IDatabaseInfo#getDatabaseLoginName()
+ */
+ @Override
+ public String getDatabaseLoginName() {
+ return databaseLoginName;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.db.connection.IDatabaseInfo#getDatabaseName()
+ */
+ @Override
+ public String getDatabaseName() {
+ return databaseName;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.db.connection.IDatabaseInfo#getDriver()
+ */
+ @Override
+ public String getDriver() {
+ return driver;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.db.connection.IDatabaseInfo#getId()
+ */
+ @Override
+ public String getId() {
+ return id;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.db.connection.IDatabaseInfo#isProduction()
+ */
+ @Override
+ public boolean isProduction() {
+ return isProduction;
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/DatabaseInfoManager.java b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/DatabaseInfoManager.java
new file mode 100644
index 00000000000..fe0c983be07
--- /dev/null
+++ b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/DatabaseInfoManager.java
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * 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.db.connection;
+
+import java.io.IOException;
+import java.io.InputStream;
+import org.eclipse.osee.framework.db.connection.exception.OseeCoreException;
+import org.eclipse.osee.framework.db.connection.exception.OseeDataStoreException;
+import org.eclipse.osee.framework.db.connection.exception.OseeWrappedException;
+import org.eclipse.osee.framework.db.connection.internal.InternalActivator;
+import org.eclipse.osee.framework.db.connection.internal.parser.DbConfigParser;
+import org.eclipse.osee.framework.jdk.core.util.xml.Jaxp;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+public class DatabaseInfoManager {
+
+ private DatabaseInfoManager() {
+ }
+
+ public static IDatabaseInfo getDefault() throws OseeDataStoreException {
+ try {
+ return InternalActivator.getConnectionInfos().getSelectedDatabaseInfo();
+ } catch (InterruptedException ex) {
+ throw new OseeDataStoreException(ex);
+ }
+ }
+
+ public static IDatabaseInfo getDataStoreById(String id) throws OseeDataStoreException {
+ try {
+ return InternalActivator.getConnectionInfos().getDatabaseInfo(id);
+ } catch (InterruptedException ex) {
+ throw new OseeDataStoreException(ex);
+ }
+ }
+
+ public static IDatabaseInfo[] readFromXml(InputStream inputStream) throws OseeCoreException {
+ try {
+ Document document = Jaxp.readXmlDocument(inputStream);
+ Element rootElement = document.getDocumentElement();
+ return DbConfigParser.parse(rootElement);
+ } catch (Exception ex) {
+ throw new OseeWrappedException(ex);
+ } finally {
+ if (inputStream != null) {
+ try {
+ inputStream.close();
+ } catch (IOException ex) {
+ throw new OseeWrappedException(ex);
+ }
+ }
+ }
+ }
+
+}
diff --git a/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/DbTransaction.java b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/DbTransaction.java
new file mode 100644
index 00000000000..19627b3757f
--- /dev/null
+++ b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/DbTransaction.java
@@ -0,0 +1,127 @@
+/*******************************************************************************
+ * 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.db.connection;
+
+import java.util.logging.Level;
+import org.eclipse.osee.framework.db.connection.exception.OseeCoreException;
+import org.eclipse.osee.framework.db.connection.exception.OseeWrappedException;
+import org.eclipse.osee.framework.db.connection.internal.InternalActivator;
+import org.eclipse.osee.framework.logging.OseeLog;
+
+/**
+ * This abstract class provides a uniform way of executing database transactions. It handles exceptions ensuring that
+ * transactions are processed in the correct order and roll-backs are performed whenever errors are detected.
+ *
+ * @author Roberto E. Escobar
+ */
+public abstract class DbTransaction {
+
+ /**
+ * Transaction Constructor
+ *
+ * @throws OseeCoreException TODO
+ */
+ public DbTransaction() throws OseeCoreException {
+ OseeDbConnection.reportTxCreation(this);
+ }
+
+ /**
+ * Gets the name of this transaction. This is provided mainly for logging purposes.
+ *
+ * @return String transaction class Name
+ */
+ protected String getTxName() {
+ return this.getClass().getCanonicalName();
+ }
+
+ /**
+ * This template method calls {@link #handleTxWork} which is provided by child classes. This method handles
+ * roll-backs and exception handling to prevent transactions from being left in an incorrect state.
+ *
+ * @throws Exception
+ */
+ public void execute() throws OseeCoreException {
+ execute(OseeDbConnection.getConnection());
+ }
+
+ private void execute(OseeConnection connection) throws OseeCoreException {
+ boolean initialAutoCommit = true;
+ OseeCoreException saveException = null;
+ try {
+ OseeLog.log(InternalActivator.class, Level.FINEST, String.format("Start Transaction: [%s]", getTxName()));
+ OseeDbConnection.reportTxStart(this);
+
+ initialAutoCommit = connection.getAutoCommit();
+ connection.setAutoCommit(false);
+ ConnectionHandler.deferConstraintChecking(connection);
+ handleTxWork(connection);
+
+ connection.commit();
+ OseeLog.log(InternalActivator.class, Level.FINEST, String.format("End Transaction: [%s]", getTxName()));
+ } catch (Exception ex) {
+ connection.rollback();
+ connection.destroy();
+ handleTxException(ex);
+ if (ex instanceof OseeCoreException) {
+ saveException = (OseeCoreException) ex;
+ } else {
+ saveException = new OseeWrappedException(ex);
+ }
+ } finally {
+ try {
+ if (!connection.isClosed()) {
+ connection.setAutoCommit(initialAutoCommit);
+ connection.close();
+ }
+ OseeDbConnection.reportTxEnd(this);
+ handleTxFinally();
+ } catch (OseeCoreException ex) {
+ OseeLog.log(InternalActivator.class, Level.SEVERE, ex);
+ if (saveException == null) {
+ saveException = ex;
+ }
+ }
+ if (saveException != null) {
+ throw saveException;
+ }
+ }
+ }
+
+ /**
+ * Provides the transaction's work implementation.
+ *
+ * @param connection
+ * @throws OseeCoreException
+ */
+ protected abstract void handleTxWork(OseeConnection connection) throws OseeCoreException;
+
+ /**
+ * When an exception is detected during transaction processing, the exception is caught and passed to this method.
+ * This convenience method is provided so child classes have access to the exception. <br/>
+ * <b>Override to handle transaction exception</b>
+ *
+ * @param ex
+ * @throws Exception
+ */
+ protected void handleTxException(Exception ex) {
+ }
+
+ /**
+ * This convenience method is provided in case child classes have a portion of code that needs to execute always at
+ * the end of the transaction, regardless of exceptions. <br/>
+ * <b>Override to add additional code to finally block</b>
+ *
+ * @throws Exception
+ */
+ protected void handleTxFinally() throws OseeCoreException {
+ // override to add additional code to finally
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/IApplicationDatabaseInfoProvider.java b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/IApplicationDatabaseInfoProvider.java
new file mode 100644
index 00000000000..6f044dce653
--- /dev/null
+++ b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/IApplicationDatabaseInfoProvider.java
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * 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.db.connection;
+
+import org.eclipse.osee.framework.db.connection.exception.OseeDataStoreException;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public interface IApplicationDatabaseInfoProvider {
+
+ public IDatabaseInfo getDatabaseInfo() throws OseeDataStoreException;
+
+ public int getPriority();
+
+}
diff --git a/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/IConnection.java b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/IConnection.java
new file mode 100644
index 00000000000..5a08c1152a1
--- /dev/null
+++ b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/IConnection.java
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * 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.db.connection;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.Properties;
+
+/**
+ * @author Andrew M. Finkbeiner
+ */
+public interface IConnection {
+ Connection getConnection(Properties properties, String connectionURL) throws ClassNotFoundException, SQLException;
+
+ String getDriver();
+}
diff --git a/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/IDatabaseInfo.java b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/IDatabaseInfo.java
new file mode 100644
index 00000000000..a60e337507d
--- /dev/null
+++ b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/IDatabaseInfo.java
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * 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.db.connection;
+
+import java.util.Properties;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public interface IDatabaseInfo {
+
+ String getId();
+
+ String getDatabaseName();
+
+ String getDatabaseLoginName();
+
+ String getDriver();
+
+ String getConnectionUrl();
+
+ Properties getConnectionProperties();
+
+ boolean isProduction();
+}
diff --git a/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/IDbConnectionInformationContributor.java b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/IDbConnectionInformationContributor.java
new file mode 100644
index 00000000000..0be1f5b2719
--- /dev/null
+++ b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/IDbConnectionInformationContributor.java
@@ -0,0 +1,20 @@
+/*******************************************************************************
+ * 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.db.connection;
+
+
+/**
+ * @author Andrew M. Finkbeiner
+ */
+public interface IDbConnectionInformationContributor {
+ IDatabaseInfo[] getDbInformation() throws Exception;
+}
diff --git a/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/OseeConnection.java b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/OseeConnection.java
new file mode 100644
index 00000000000..ac4ce1b05d2
--- /dev/null
+++ b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/OseeConnection.java
@@ -0,0 +1,120 @@
+/*******************************************************************************
+ * 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.db.connection;
+
+import java.sql.CallableStatement;
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import org.eclipse.osee.framework.db.connection.exception.OseeDataStoreException;
+
+public class OseeConnection {
+ final static private long timeout = 60000;
+ private OseeConnectionPool pool;
+ private Connection conn;
+ private volatile boolean inuse;
+ private long lastUsedTime;
+
+ OseeConnection(Connection conn, OseeConnectionPool pool) {
+ this.conn = conn;
+ this.pool = pool;
+ this.inuse = true;
+ this.lastUsedTime = 0;
+ }
+
+ public void close() {
+ pool.returnConnection(this);
+ }
+
+ public boolean isClosed() throws OseeDataStoreException {
+ try {
+ return conn.isClosed();
+ } catch (SQLException ex) {
+ throw new OseeDataStoreException(ex);
+ }
+ }
+
+ public boolean isStale() {
+ return !inUse() && getLastUse() + timeout < System.currentTimeMillis();
+ }
+
+ public DatabaseMetaData getMetaData() throws OseeDataStoreException {
+ try {
+ return conn.getMetaData();
+ } catch (SQLException ex) {
+ throw new OseeDataStoreException(ex);
+ }
+ }
+
+ PreparedStatement prepareStatement(String sql) throws SQLException {
+ return conn.prepareStatement(sql);
+ }
+
+ CallableStatement prepareCall(String sql) throws SQLException {
+ return conn.prepareCall(sql);
+ }
+
+ synchronized boolean lease() {
+ if (inuse) {
+ return false;
+ } else {
+ inuse = true;
+ return true;
+ }
+ }
+
+ void destroy() throws OseeDataStoreException {
+ try {
+ conn.close();
+ } catch (SQLException ex) {
+ throw new OseeDataStoreException(ex);
+ }
+ pool.removeConnection(this);
+ }
+
+ boolean inUse() {
+ return inuse;
+ }
+
+ long getLastUse() {
+ return lastUsedTime;
+ }
+
+ void expireLease() {
+ inuse = false;
+ lastUsedTime = System.currentTimeMillis();
+ }
+
+ void setAutoCommit(boolean autoCommit) throws OseeDataStoreException {
+ try {
+ conn.setAutoCommit(autoCommit);
+ } catch (SQLException ex) {
+ throw new OseeDataStoreException(ex);
+ }
+ }
+
+ boolean getAutoCommit() throws SQLException {
+ return conn.getAutoCommit();
+ }
+
+ void commit() throws SQLException {
+ conn.commit();
+ }
+
+ void rollback() throws OseeDataStoreException {
+ try {
+ conn.rollback();
+ } catch (SQLException ex) {
+ throw new OseeDataStoreException(ex);
+ }
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/OseeConnectionPool.java b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/OseeConnectionPool.java
new file mode 100644
index 00000000000..cc9d8a89249
--- /dev/null
+++ b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/OseeConnectionPool.java
@@ -0,0 +1,106 @@
+/*******************************************************************************
+ * 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.db.connection;
+
+import java.sql.Connection;
+import java.util.List;
+import java.util.Properties;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.logging.Level;
+import org.eclipse.osee.framework.db.connection.exception.OseeDataStoreException;
+import org.eclipse.osee.framework.db.connection.internal.InternalActivator;
+import org.eclipse.osee.framework.logging.OseeLog;
+
+class OseeConnectionPool {
+ private final List<OseeConnection> connections = new CopyOnWriteArrayList<OseeConnection>();
+ private final String dbDriver;
+ private final String dbUrl;
+ private final Properties properties;
+
+ /**
+ * @param dbInformation
+ */
+ public OseeConnectionPool(IDatabaseInfo databaseInfo) {
+ this(databaseInfo.getDriver(), databaseInfo.getConnectionUrl(), databaseInfo.getConnectionProperties());
+ }
+
+ public OseeConnectionPool(String dbDriver, String dbUrl, Properties properties) {
+ this.dbDriver = dbDriver;
+ this.dbUrl = dbUrl;
+ this.properties = properties;
+ }
+
+ public synchronized boolean hasOpenConnection() {
+ return connections.size() > 0;
+ }
+
+ /**
+ * at a minimum this should be called on jvm shutdown
+ */
+ public synchronized void closeConnections() {
+ for (OseeConnection connection : connections) {
+ connection.close();
+ }
+ connections.clear();
+ }
+
+ synchronized void removeConnection(OseeConnection conn) {
+ connections.remove(conn);
+ OseeLog.log(InternalActivator.class, Level.INFO, String.format(
+ "removeConnection - %s - connection pool size [%s]", dbUrl, connections.size()));
+ }
+
+ public synchronized OseeConnection getConnection() throws OseeDataStoreException {
+ for (OseeConnection connection : connections) {
+ if (connection.lease()) {
+ return connection;
+ }
+ }
+
+ try {
+ OseeConnection connection = getOseeConnection();
+ connections.add(connection);
+ OseeLog.log(InternalActivator.class, Level.INFO, String.format(
+ "getConnection - %s - connection pool size [%s]", dbUrl, connections.size()));
+ return connection;
+ } catch (Throwable th) {
+ throw new OseeDataStoreException("Unable to get a database connection: ", th);
+ }
+ }
+
+ private OseeConnection getOseeConnection() throws Exception {
+ IConnection connectionFactory = InternalActivator.getConnectionFactory().get(dbDriver);
+ Connection connection = connectionFactory.getConnection(properties, dbUrl);
+ connection.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
+ return new OseeConnection(connection, this);
+ }
+
+ synchronized void returnConnection(OseeConnection connection) {
+ try {
+ if (connection.isClosed()) {
+ removeConnection(connection);
+ } else {
+ connection.expireLease();
+ }
+ } catch (OseeDataStoreException ex) {
+ OseeLog.log(InternalActivator.class, Level.SEVERE, ex);
+ removeConnection(connection);
+ }
+ }
+
+ synchronized void releaseUneededConnections() throws OseeDataStoreException {
+ for (OseeConnection connection : connections) {
+ if (connection.isStale()) {
+ connection.destroy();
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/OseeDbConnection.java b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/OseeDbConnection.java
new file mode 100644
index 00000000000..55350d1fc87
--- /dev/null
+++ b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/OseeDbConnection.java
@@ -0,0 +1,77 @@
+/*******************************************************************************
+ * 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.db.connection;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Timer;
+import org.eclipse.osee.framework.db.connection.exception.OseeDataStoreException;
+import org.eclipse.osee.framework.db.connection.exception.OseeStateException;
+import org.eclipse.osee.framework.db.connection.exception.OseeWrappedException;
+import org.eclipse.osee.framework.db.connection.internal.InternalActivator;
+import org.eclipse.osee.framework.db.connection.internal.TransactionMonitor;
+
+/**
+ * @author Andrew M. Finkbeiner
+ */
+public class OseeDbConnection {
+ private static final Timer timer = new Timer();
+ private static final Map<String, OseeConnectionPool> dbInfoToPools = new HashMap<String, OseeConnectionPool>();
+ private static final TransactionMonitor txMonitor = new TransactionMonitor();
+
+ public static boolean hasOpenConnection() throws OseeDataStoreException {
+ IDatabaseInfo databaseInfo = getDatabaseInfoProvider();
+ if (databaseInfo == null) {
+ throw new OseeDataStoreException("Unable to get connection - database info was null.");
+ }
+ OseeConnectionPool pool = dbInfoToPools.get(databaseInfo.getId());
+ if (pool == null) {
+ return false;
+ }
+ return pool.hasOpenConnection();
+ }
+
+ public static OseeConnection getConnection() throws OseeDataStoreException {
+ return getConnection(getDatabaseInfoProvider());
+ }
+
+ public static OseeConnection getConnection(IDatabaseInfo databaseInfo) throws OseeDataStoreException {
+ if (databaseInfo == null) {
+ throw new OseeDataStoreException("Unable to get connection - database info was null.");
+ }
+ OseeConnectionPool pool = dbInfoToPools.get(databaseInfo.getId());
+ if (pool == null) {
+ pool =
+ new OseeConnectionPool(databaseInfo.getDriver(), databaseInfo.getConnectionUrl(),
+ databaseInfo.getConnectionProperties());
+ dbInfoToPools.put(databaseInfo.getId(), pool);
+ timer.schedule(new StaleConnectionCloser(pool), 900000, 900000);
+ }
+ return pool.getConnection();
+ }
+
+ private static IDatabaseInfo getDatabaseInfoProvider() throws OseeDataStoreException {
+ return InternalActivator.getApplicationDatabaseProvider().getDatabaseInfo();
+ }
+
+ public static void reportTxStart(final DbTransaction transaction) throws OseeWrappedException, OseeStateException {
+ txMonitor.reportTxStart(transaction);
+ }
+
+ public static void reportTxEnd(final DbTransaction transaction) throws OseeWrappedException, OseeStateException {
+ txMonitor.reportTxEnd(transaction);
+ }
+
+ public static void reportTxCreation(final DbTransaction transaction) throws OseeWrappedException {
+ txMonitor.reportTxCreation(transaction);
+ }
+}
diff --git a/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/StaleConnectionCloser.java b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/StaleConnectionCloser.java
new file mode 100644
index 00000000000..fd006edbce4
--- /dev/null
+++ b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/StaleConnectionCloser.java
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * 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.db.connection;
+
+import java.util.TimerTask;
+import java.util.logging.Level;
+import org.eclipse.osee.framework.db.connection.exception.OseeDataStoreException;
+import org.eclipse.osee.framework.db.connection.internal.InternalActivator;
+import org.eclipse.osee.framework.logging.OseeLog;
+
+/**
+ * @author Ryan D. Brooks
+ */
+public class StaleConnectionCloser extends TimerTask {
+ private final OseeConnectionPool connectionPool;
+
+ /**
+ * @param connectionPool
+ */
+ public StaleConnectionCloser(OseeConnectionPool connectionPool) {
+ super();
+ this.connectionPool = connectionPool;
+ }
+
+ /* (non-Javadoc)
+ * @see java.util.TimerTask#run()
+ */
+ @Override
+ public void run() {
+ try {
+ connectionPool.releaseUneededConnections();
+ } catch (OseeDataStoreException ex) {
+ OseeLog.log(InternalActivator.class, Level.SEVERE, ex);
+ }
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/core/KeyedLevelManager.java b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/core/KeyedLevelManager.java
new file mode 100644
index 00000000000..776a16fb332
--- /dev/null
+++ b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/core/KeyedLevelManager.java
@@ -0,0 +1,193 @@
+/*******************************************************************************
+ * 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.db.connection.core;
+
+import java.util.Stack;
+import org.eclipse.osee.framework.db.connection.exception.OseeDataStoreException;
+
+/**
+ * Keeps track of nested calls by tracking start keys and confirming them upon the end of the level.<br>
+ * <br>
+ * Methods that may be extended
+ * <ul>
+ * <li>startTransactionLevel</li>
+ * <li>endTransactionLevel</li>
+ * </ul>
+ * Methods that may be reimplemented
+ * <ul>
+ * <li>onInitialEntry</li>
+ * <li>onExitLevelError</li>
+ * <li>onLastExit</li>
+ * </ul>
+ *
+ * @author Robert A. Fisher
+ */
+public class KeyedLevelManager {
+ private final Stack<KeyLevel> callKeyQueue;
+
+ private final class KeyLevel {
+ private Object key;
+ private boolean isProcessed;
+
+ private KeyLevel(Object key) {
+ this.key = key;
+ this.isProcessed = false;
+ }
+
+ private boolean isProcessed() {
+ return isProcessed;
+ }
+
+ private void setIsProcessed(boolean isProcessed) {
+ this.isProcessed = isProcessed;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ return key.equals(obj);
+ }
+ }
+
+ public KeyedLevelManager() {
+ this.callKeyQueue = new Stack<KeyLevel>();
+ }
+
+ /**
+ * Marks the start of an abstract level. If the nesting level for this manager is zero then this will initiate a new
+ * series, otherwise this will be included in the series that this manager is already maintaining.
+ *
+ * @param key An object for the manager to track this level. This will need to be passed to
+ * <code>endTransactionLevel</code> when the calling method is done.
+ * @see KeyedLevelManager#endTransactionLevel(Object)
+ */
+ public boolean startTransactionLevel(Object key) throws OseeDataStoreException {
+ if (key == null) throw new IllegalArgumentException("key must not be null");
+ if (isValid(key)) throw new IllegalArgumentException("The provided key is already in use for this manager");
+
+ boolean initialEntry = !inLevel();
+ callKeyQueue.push(new KeyLevel(key));
+
+ if (initialEntry) {
+ onInitialEntry();
+ }
+
+ return initialEntry;
+ }
+
+ /**
+ * Re-implement this method to provide functionality upon initial entry. The default implementation does nothing.
+ *
+ * @throws OseeDataStoreException TODO
+ */
+ protected void onInitialEntry() throws OseeDataStoreException {
+ }
+
+ /**
+ * Marks the end of an abstract level. If the nesting level for this manager is one then this will finish the series,
+ * otherwise this will be included in the series that this manager is already maintaining.
+ *
+ * @param key An object for the manager to track this level. This must be the same key that was passed to
+ * <code>startTransactionLevel</code>.
+ * @see KeyedLevelManager#startTransactionLevel(Object)
+ */
+ public void endTransactionLevel(Object key) throws OseeDataStoreException {
+ if (key == null) throw new IllegalArgumentException("key must not be null");
+ if (true != isValid(key)) throw new IllegalArgumentException("The provided key is not known by this manager");
+
+ try {
+ // Check for an unclosed transaction level. This marks abnormal execution from a prior
+ // calling method.
+ if (true != callKeyQueue.pop().equals(key)) {
+ onExitLevelError();
+
+ // Clean up until the key so that later methods can register as normal.
+ while (true != callKeyQueue.pop().equals(key))
+ ;
+
+ throw new OseeDataStoreException("A transaction level was not closed");
+ }
+ } finally {
+ // Check for the end of the series
+ if (callKeyQueue.isEmpty()) {
+ onLastExit();
+ }
+ }
+ }
+
+ public void setTransactionLevelSuccess(Object key) {
+ if (key == null) throw new IllegalArgumentException("key must not be null");
+ if (true != isValid(key)) throw new IllegalArgumentException("The provided key is not known by this manager");
+
+ if (false != callKeyQueue.peek().equals(key)) {
+ callKeyQueue.peek().setIsProcessed(true);
+ }
+ }
+
+ public boolean isTransactionLevelSuccess(Object key) {
+ if (key == null) throw new IllegalArgumentException("key must not be null");
+ if (true != isValid(key)) throw new IllegalArgumentException("The provided key is not known by this manager");
+
+ boolean toReturn = false;
+ if (false != callKeyQueue.peek().equals(key)) {
+ toReturn = callKeyQueue.peek().isProcessed();
+ }
+ return toReturn;
+ }
+
+ /**
+ * Reimplement to provide functionality when a level is exited abnormally from the wrong key being provided. The
+ * default implementation does nothing.
+ */
+ protected void onExitLevelError() {
+ }
+
+ /**
+ * Reimplement to provide funtionality when a full series of levels have been exited. The default implementation does
+ * nothing.
+ *
+ * @throws OseeDataStoreException TODO
+ */
+ protected void onLastExit() throws OseeDataStoreException {
+ }
+
+ /**
+ * @return The current nesting level for the transaction.
+ */
+ public final int getNestingLevel() {
+ return callKeyQueue.size();
+ }
+
+ /**
+ * @return Whether this manager is already handling a level.
+ */
+ public final boolean inLevel() {
+ return !callKeyQueue.isEmpty();
+ }
+
+ /**
+ * @return Whether this manager is already handling a series.
+ */
+ public final boolean inTransaction() {
+ return !callKeyQueue.isEmpty();
+ }
+
+ private boolean isValid(Object key) {
+ boolean toReturn = false;
+ for (int index = 0; index < callKeyQueue.size(); index++) {
+ if (callKeyQueue.get(index).equals(key)) {
+ toReturn = true;
+ break;
+ }
+ }
+ return toReturn;
+ }
+}
diff --git a/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/core/ResultSetProcessor.java b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/core/ResultSetProcessor.java
new file mode 100644
index 00000000000..65d696c0300
--- /dev/null
+++ b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/core/ResultSetProcessor.java
@@ -0,0 +1,93 @@
+/*******************************************************************************
+ * 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.db.connection.core;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.sql.Date;
+import java.sql.Timestamp;
+import java.sql.Types;
+import org.eclipse.osee.framework.db.connection.ConnectionHandlerStatement;
+import org.eclipse.osee.framework.db.connection.exception.OseeDataStoreException;
+import org.eclipse.osee.framework.db.connection.exception.OseeWrappedException;
+import org.eclipse.osee.framework.jdk.core.type.IVariantData;
+import org.eclipse.osee.framework.jdk.core.type.VariantData;
+import org.eclipse.osee.framework.jdk.core.util.Lib;
+import org.eclipse.osee.framework.jdk.core.util.Strings;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class ResultSetProcessor {
+ public static IVariantData parse(ConnectionHandlerStatement chStmt) throws OseeDataStoreException, OseeWrappedException {
+ IVariantData toReturn = new VariantData();
+ int numberOfColumns = chStmt.getColumnCount() + 1;
+ for (int index = 1; index < numberOfColumns; index++) {
+ int columnIndex = index;
+ int type = chStmt.getColumnType(columnIndex);
+ String name = chStmt.getColumnName(columnIndex);
+ // Store name - all upper case
+ String upperCasedName = name.toUpperCase();
+ switch (type) {
+ case Types.CLOB:
+ case Types.BINARY:
+ InputStream inputStream = chStmt.getAsciiStream(name);
+ toReturn.put(upperCasedName, streamToByteArray(inputStream));
+ break;
+ case Types.BLOB:
+ InputStream blobStream = chStmt.getBinaryStream(name);
+ toReturn.put(upperCasedName, streamToByteArray(blobStream));
+ break;
+ case Types.TIMESTAMP:
+ Timestamp timeStamp = chStmt.getTimestamp(name);
+ if (timeStamp != null) {
+ toReturn.put(upperCasedName, timeStamp.getTime());
+ }
+ break;
+ case Types.DATE:
+ Date date = chStmt.getDate(name);
+ if (date != null) {
+ toReturn.put(upperCasedName, date.getTime());
+ }
+ break;
+ default:
+ try {
+ String value = chStmt.getString(name);
+ if (Strings.isValid(value) != false) {
+ value = value.trim();
+ }
+ toReturn.put(upperCasedName, chStmt.getString(name));
+ } catch (OseeDataStoreException ex) {
+ String typeName = chStmt.getColumnTypeName(columnIndex);
+ throw new OseeDataStoreException(getErrorMessage(name, typeName), ex);
+ }
+ break;
+ }
+ }
+ return toReturn;
+ }
+
+ private static String getErrorMessage(String name, String typeName) {
+ return String.format("Unable to convert [%s] of raw type [%s] to string.", name, typeName);
+ }
+
+ private static byte[] streamToByteArray(InputStream inputStream) throws OseeWrappedException {
+ byte[] toReturn = new byte[0];
+ if (inputStream != null) {
+ try {
+ toReturn = Lib.inputStreamToBytes(inputStream);
+ } catch (IOException ex) {
+ throw new OseeWrappedException(ex);
+ }
+ }
+ return toReturn;
+ }
+}
diff --git a/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/core/RsetProcessor.java b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/core/RsetProcessor.java
new file mode 100644
index 00000000000..5bda428f612
--- /dev/null
+++ b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/core/RsetProcessor.java
@@ -0,0 +1,23 @@
+/*******************************************************************************
+ * 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.db.connection.core;
+
+import org.eclipse.osee.framework.db.connection.ConnectionHandlerStatement;
+import org.eclipse.osee.framework.db.connection.exception.OseeCoreException;
+
+/**
+ * @author Robert A. Fisher
+ */
+public interface RsetProcessor<T> {
+ public T process(ConnectionHandlerStatement chStmt) throws OseeCoreException;
+
+ public boolean validate(T item);
+}
diff --git a/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/core/SequenceManager.java b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/core/SequenceManager.java
new file mode 100644
index 00000000000..bc2982a2671
--- /dev/null
+++ b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/core/SequenceManager.java
@@ -0,0 +1,189 @@
+/*******************************************************************************
+ * 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.db.connection.core;
+
+import java.util.HashMap;
+import org.eclipse.osee.framework.db.connection.ConnectionHandler;
+import org.eclipse.osee.framework.db.connection.OseeConnection;
+import org.eclipse.osee.framework.db.connection.OseeDbConnection;
+import org.eclipse.osee.framework.db.connection.exception.OseeDataStoreException;
+
+/**
+ * @author Ryan D. Brooks
+ */
+public class SequenceManager {
+ private static final String QUERY_SEQUENCE = "SELECT last_sequence FROM osee_sequence WHERE sequence_name = ?";
+ private static final String INSERT_SEQUENCE =
+ "INSERT INTO osee_sequence (last_sequence, sequence_name) VALUES (?,?)";
+ private static final String UPDATE_SEQUENCE =
+ "UPDATE osee_sequence SET last_sequence = ? WHERE sequence_name = ? AND last_sequence = ?";
+
+ public static final String ART_ID_SEQ = "SKYNET_ART_ID_SEQ";
+ public static final String ENUM_TYPE_ID_SEQ = "SKYNET_ENUM_TYPE_ID_SEQ";
+ public static final String ART_TYPE_ID_SEQ = "SKYNET_ART_TYPE_ID_SEQ";
+ public static final String ATTR_BASE_TYPE_ID_SEQ = "SKYNET_ATTR_BASE_TYPE_ID_SEQ";
+ public static final String ATTR_PROVIDER_TYPE_ID_SEQ = "SKYNET_ATTR_PROVIDER_TYPE_ID_SEQ";
+ public static final String ATTR_ID_SEQ = "SKYNET_ATTR_ID_SEQ";
+ public static final String ATTR_TYPE_ID_SEQ = "SKYNET_ATTR_TYPE_ID_SEQ";
+ public static final String FACTORY_ID_SEQ = "SKYNET_FACTORY_ID_SEQ";
+ public static final String BRANCH_ID_SEQ = "SKYNET_BRANCH_ID_SEQ";
+ public static final String REL_LINK_TYPE_ID_SEQ = "SKYNET_REL_LINK_TYPE_ID_SEQ";
+ public static final String REL_LINK_ID_SEQ = "SKYNET_REL_LINK_ID_SEQ";
+ public static final String GAMMA_ID_SEQ = "SKYNET_GAMMA_ID_SEQ";
+ public static final String TRANSACTION_ID_SEQ = "SKYNET_TRANSACTION_ID_SEQ";
+ public static final String IMPORT_ID_SEQ = "SKYNET_IMPORT_ID_SEQ";
+ public static final String IMPORT_MAPPED_INDEX_SEQ = "SKYNET_IMPORT_MAPPED_INDEX_SEQ";
+ public static final String TTE_SESSION_SEQ = "TTE_SESSION_SEQ";
+
+ public static final String[] sequenceNames =
+ new String[] {ART_ID_SEQ, ENUM_TYPE_ID_SEQ, ART_TYPE_ID_SEQ, ATTR_BASE_TYPE_ID_SEQ, ATTR_PROVIDER_TYPE_ID_SEQ,
+ ATTR_ID_SEQ, ATTR_TYPE_ID_SEQ, FACTORY_ID_SEQ, BRANCH_ID_SEQ, REL_LINK_TYPE_ID_SEQ, REL_LINK_ID_SEQ,
+ GAMMA_ID_SEQ, TRANSACTION_ID_SEQ, IMPORT_ID_SEQ, IMPORT_MAPPED_INDEX_SEQ, TTE_SESSION_SEQ};
+
+ private final static HashMap<String, SequenceRange> sequences = new HashMap<String, SequenceRange>(30);
+
+ private SequenceManager() {
+ }
+
+ private static SequenceRange getRange(String sequenceName) {
+ SequenceRange range = sequences.get(sequenceName);
+ if (range == null) {
+ // do this to keep transaction id's sequential in the face of concurrent transaction by multiple users
+ range = new SequenceRange(!sequenceName.equals(TRANSACTION_ID_SEQ));
+ sequences.put(sequenceName, range);
+ }
+ return range;
+ }
+
+ public static synchronized long getNextSequence(String sequenceName) throws OseeDataStoreException {
+ SequenceRange range = getRange(sequenceName);
+ if (range.lastAvailable == 0) {
+ long lastValue = -1;
+ boolean gotSequence = false;
+ OseeConnection connection = OseeDbConnection.getConnection();
+ try {
+ while (!gotSequence) {
+ lastValue = ConnectionHandler.runPreparedQueryFetchLong(connection, -1, QUERY_SEQUENCE, sequenceName);
+ if (lastValue == -1) {
+ throw new OseeDataStoreException("Sequence name [" + sequenceName + "] was not found");
+ }
+ gotSequence =
+ ConnectionHandler.runPreparedUpdate(connection, UPDATE_SEQUENCE, lastValue + range.prefetchSize,
+ sequenceName, lastValue) == 1;
+ }
+ range.updateRange(lastValue);
+ } finally {
+ connection.close();
+ }
+ }
+ range.currentValue++;
+ if (range.currentValue == range.lastAvailable) {
+ range.lastAvailable = 0;
+ }
+ return range.currentValue;
+ }
+
+ public static void internalInitializeSequence(String sequenceName) throws OseeDataStoreException {
+ SequenceRange range = getRange(sequenceName);
+ range.lastAvailable = 0;
+ ConnectionHandler.runPreparedUpdate(INSERT_SEQUENCE, 0, sequenceName);
+ }
+
+ public static int getNextSessionId() throws OseeDataStoreException {
+ return (int) getNextSequence(TTE_SESSION_SEQ);
+ }
+
+ public static int getNextTransactionId() throws OseeDataStoreException {
+ return (int) getNextSequence(TRANSACTION_ID_SEQ);
+ }
+
+ public static int getNextArtifactId() throws OseeDataStoreException {
+ return (int) getNextSequence(ART_ID_SEQ);
+ }
+
+ public static int getNextOseeEnumTypeId() throws OseeDataStoreException {
+ return (int) getNextSequence(ENUM_TYPE_ID_SEQ);
+ }
+
+ public static int getNextGammaId() throws OseeDataStoreException {
+ return (int) getNextSequence(GAMMA_ID_SEQ);
+ }
+
+ public static int getNextArtifactTypeId() throws OseeDataStoreException {
+ return (int) getNextSequence(ART_TYPE_ID_SEQ);
+ }
+
+ public static int getNextAttributeBaseTypeId() throws OseeDataStoreException {
+ return (int) getNextSequence(ATTR_BASE_TYPE_ID_SEQ);
+ }
+
+ public static int getNextAttributeProviderTypeId() throws OseeDataStoreException {
+ return (int) getNextSequence(ATTR_PROVIDER_TYPE_ID_SEQ);
+ }
+
+ public static int getNextAttributeId() throws OseeDataStoreException {
+ return (int) getNextSequence(ATTR_ID_SEQ);
+ }
+
+ public static int getNextAttributeTypeId() throws OseeDataStoreException {
+ return (int) getNextSequence(ATTR_TYPE_ID_SEQ);
+ }
+
+ public static int getNextFactoryId() throws OseeDataStoreException {
+ return (int) getNextSequence(FACTORY_ID_SEQ);
+ }
+
+ public static int getNextBranchId() throws OseeDataStoreException {
+ return (int) getNextSequence(BRANCH_ID_SEQ);
+ }
+
+ public static int getNextRelationTypeId() throws OseeDataStoreException {
+ return (int) getNextSequence(REL_LINK_TYPE_ID_SEQ);
+ }
+
+ public static int getNextRelationId() throws OseeDataStoreException {
+ return (int) getNextSequence(REL_LINK_ID_SEQ);
+ }
+
+ public static int getNextImportId() throws OseeDataStoreException {
+ return (int) getNextSequence(IMPORT_ID_SEQ);
+ }
+
+ public static int getNextImportMappedIndexId() throws OseeDataStoreException {
+ return (int) getNextSequence(IMPORT_MAPPED_INDEX_SEQ);
+ }
+
+ private static final class SequenceRange {
+ private long currentValue;
+ private long lastAvailable;
+ private int prefetchSize;
+ private final boolean aggressiveFetch;
+
+ /**
+ * @param aggressiveFetch
+ */
+ public SequenceRange(boolean aggressiveFetch) {
+ super();
+ this.prefetchSize = 1;
+ this.aggressiveFetch = aggressiveFetch;
+ }
+
+ public void updateRange(long lastValue) {
+ currentValue = lastValue;
+ lastAvailable = lastValue + prefetchSize;
+
+ if (aggressiveFetch) {
+ prefetchSize *= 2; // next time grab twice as many
+ }
+ }
+ }
+
+} \ No newline at end of file
diff --git a/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/core/query/Query.java b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/core/query/Query.java
new file mode 100644
index 00000000000..d27c59e1d79
--- /dev/null
+++ b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/core/query/Query.java
@@ -0,0 +1,55 @@
+/*******************************************************************************
+ * 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.db.connection.core.query;
+
+import java.util.Collection;
+import java.util.logging.Level;
+import org.eclipse.osee.framework.db.connection.ConnectionHandlerStatement;
+import org.eclipse.osee.framework.db.connection.core.RsetProcessor;
+import org.eclipse.osee.framework.db.connection.exception.OseeCoreException;
+import org.eclipse.osee.framework.db.connection.internal.InternalActivator;
+import org.eclipse.osee.framework.logging.OseeLog;
+
+/**
+ * @author Robert A. Fisher
+ */
+public class Query {
+
+ /**
+ * Builds a collection of items from an SQL statement from the basic DBConnection.
+ *
+ * @param collection The collection to add the objects to.
+ * @param sql The SQL statement to use to acquire a ResultSet.
+ * @param processor The RsetProcessor used for providing and validating items.
+ * @param <A> The type of object being placed into the collection.
+ * @throws OseeCoreException
+ */
+ @Deprecated
+ // all code that uses this is also Deprecated
+ public static <A extends Object> void acquireCollection(Collection<A> collection, RsetProcessor<A> processor, String sql, Object... data) throws OseeCoreException {
+ A item;
+ ConnectionHandlerStatement chStmt = new ConnectionHandlerStatement();
+ try {
+ chStmt.runPreparedQuery(sql, data);
+ while (chStmt.next()) {
+ try {
+ item = processor.process(chStmt);
+ if (processor.validate(item)) collection.add(item);
+ } catch (IllegalStateException ex) {
+ OseeLog.log(InternalActivator.class, Level.SEVERE,
+ "Encountered Exception when trying to acquire a collection.", ex);
+ }
+ }
+ } finally {
+ chStmt.close();
+ }
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/core/query/QueryLog.java b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/core/query/QueryLog.java
new file mode 100644
index 00000000000..b35cee1a0ec
--- /dev/null
+++ b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/core/query/QueryLog.java
@@ -0,0 +1,81 @@
+/*******************************************************************************
+ * 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.db.connection.core.query;
+
+import java.util.ArrayList;
+
+/**
+ * Configurable log to track query characteristics.
+ *
+ * @author Robert A. Fisher
+ */
+public class QueryLog {
+ private static QueryLog reference = null;
+ private ArrayList<QueryRecord> records;
+ private int maxRecords;
+
+ public static synchronized QueryLog getInstance() {
+ if (reference == null) {
+ reference = new QueryLog();
+ }
+
+ return reference;
+ }
+
+ private QueryLog() {
+ this.maxRecords = 200;
+ this.records = new ArrayList<QueryRecord>(maxRecords);
+ }
+
+ protected synchronized void add(QueryRecord record) {
+ if (record == null) throw new IllegalArgumentException("record can not be null");
+
+ if (records.size() < maxRecords) {
+ records.add(record);
+ }
+ }
+
+ /**
+ * @return the maxRecords
+ */
+ public int getMaxRecords() {
+ return maxRecords;
+ }
+
+ /**
+ * @param maxRecords the maxRecords to set
+ */
+ public void setMaxRecords(int maxRecords) {
+ if (maxRecords < 0) throw new IllegalArgumentException("maxRecords can not be negative");
+
+ if (maxRecords < this.maxRecords && records.size() > maxRecords) {
+ records.subList(maxRecords, records.size()).clear();
+ records.trimToSize();
+ }
+
+ this.maxRecords = maxRecords;
+ }
+
+ /**
+ * @return the records
+ */
+ public ArrayList<QueryRecord> getRecords() {
+ return records;
+ }
+
+ public boolean isFull() {
+ return records.size() >= maxRecords;
+ }
+
+ public void clear() {
+ records.clear();
+ }
+}
diff --git a/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/core/query/QueryRecord.java b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/core/query/QueryRecord.java
new file mode 100644
index 00000000000..e89cf0cf6cc
--- /dev/null
+++ b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/core/query/QueryRecord.java
@@ -0,0 +1,140 @@
+/*******************************************************************************
+ * 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.db.connection.core.query;
+
+import java.sql.SQLException;
+import java.util.Date;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Interesting information from a query. These are automatically added to the QueryLog if it is not full.
+ *
+ * @author Robert A. Fisher
+ */
+public class QueryRecord {
+ private static final QueryLog log = QueryLog.getInstance();
+ private final Date date;
+ private final String sql;
+ private Object[] bindVariables;
+ private SQLException sqlException;
+ private Long runDurationMs;
+ private long startTime;
+
+ /**
+ * @param sql The sql text
+ */
+ public QueryRecord(String sql) {
+ this(sql, (Object[]) null);
+ }
+
+ /**
+ * Replaces all of the '?' characters with ':#' values, where # is in incrementing integer value starting at 1.
+ *
+ * @param sql The sql string to perform the replacement on.
+ */
+ private String replaceBindValues(String sql) {
+ int count = 1;
+
+ Matcher matcher = Pattern.compile("\\?").matcher(sql);
+ while (matcher.find()) {
+ sql = matcher.replaceFirst(":" + count++);
+ matcher.reset(sql);
+ }
+ return sql;
+ }
+
+ /**
+ * @param sql The sql text
+ * @param bindVariables The bind variables, if any
+ */
+ public QueryRecord(String sql, Object... bindVariablesLocal) {
+ if (sql == null) throw new IllegalArgumentException("sql can not be null");
+ this.date = new Date();
+ this.sql = replaceBindValues(sql);
+ this.bindVariables = new Object[bindVariablesLocal.length];
+ System.arraycopy(bindVariablesLocal, 0, bindVariables, 0, bindVariables.length);
+
+ for (int i = 0; i < bindVariables.length; i++) {
+ Object obj = bindVariables[i];
+ if (obj != null) {
+ if (obj instanceof String) {
+ String str = ((String) obj);
+ if (str.length() > 80) {
+ bindVariables[i] = str.substring(0, 80);
+ }
+ } else if (!(obj instanceof Date || obj instanceof Integer || obj instanceof Long || obj instanceof Double)) {
+ bindVariables[i] = "binary type";
+ } else {
+ bindVariables[i] = obj.toString();
+ }
+ }
+ }
+ log.add(this);
+ }
+
+ /**
+ * @return the runDurationMs
+ */
+ public Long getRunDurationMs() {
+ return runDurationMs;
+ }
+
+ /**
+ * Mark the start of the query being run
+ */
+ public void markStart() {
+ startTime = System.currentTimeMillis();
+ }
+
+ /**
+ * Mark the end of the query being run
+ */
+ public void markEnd() {
+ runDurationMs = System.currentTimeMillis() - startTime;
+ }
+
+ /**
+ * @return the sqlException
+ */
+ public SQLException getSqlException() {
+ return sqlException;
+ }
+
+ /**
+ * @param sqlException the sqlException to set
+ */
+ public void setSqlException(SQLException sqlException) {
+ this.sqlException = sqlException;
+ }
+
+ /**
+ * @return the bindVariables
+ */
+ public Object[] getBindVariables() {
+ return bindVariables;
+ }
+
+ /**
+ * @return the sql
+ */
+ public String getSql() {
+ return sql;
+ }
+
+ /**
+ * @return the date
+ */
+ public Date getDate() {
+ return date;
+ }
+
+}
diff --git a/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/core/schema/LocalAliasTable.java b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/core/schema/LocalAliasTable.java
new file mode 100644
index 00000000000..4674c455d50
--- /dev/null
+++ b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/core/schema/LocalAliasTable.java
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * 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.db.connection.core.schema;
+
+/**
+ * @author Robert A. Fisher
+ */
+public class LocalAliasTable extends Table {
+ private final String declarationName;
+
+ public LocalAliasTable(Table aliasedTable, String aliasName) {
+ super(aliasName);
+ this.declarationName = String.format("%s %s", aliasedTable.name, aliasName);
+ }
+
+ @Override
+ public String toString() {
+ return declarationName;
+ }
+}
diff --git a/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/core/schema/SkynetDatabase.java b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/core/schema/SkynetDatabase.java
new file mode 100644
index 00000000000..2541bde3cfb
--- /dev/null
+++ b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/core/schema/SkynetDatabase.java
@@ -0,0 +1,58 @@
+/*******************************************************************************
+ * 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.db.connection.core.schema;
+
+/**
+ * Provides the ability to build the tables and sequences necessary for the Define tools to be able to work. This class
+ * is only intended for installation purposes, and is not to support general runtime needs.
+ *
+ * @author Robert A. Fisher
+ */
+public class SkynetDatabase {
+ public static final int RELATION_SIDE_NAME_SIZE = 50;
+
+ public static final Table ARTIFACT_TABLE = new Table("OSEE_ARTIFACT");
+ public static final Table ARTIFACT_VERSION_TABLE = new Table("OSEE_ARTIFACT_VERSION");
+ public static final Table ARTIFACT_TABLE_ACL = new Table("OSEE_ARTIFACT_ACL");
+ public static final Table TRANSACTIONS_TABLE = new Table("OSEE_TXS");
+ public static final Table REMOVED_TRANSACTIONS_TABLE = new Table("OSEE_REMOVED_TXS");
+ public static final Table TRANSACTION_DETAIL_TABLE = new Table("OSEE_TX_DETAILS");
+ public static final Table ARTIFACT_TYPE_TABLE = new Table("OSEE_ARTIFACT_TYPE");
+ public static final Table ARTIFACT_TYPE_TABLE_ACL = new Table("OSEE_ARTIFACT_TYPE_ACL");
+ public static final Table ATTRIBUTE_PROVIDER_TYPE_TABLE = new Table("OSEE_ATTRIBUTE_PROVIDER_TYPE");
+ public static final Table ATTRIBUTE_BASE_TYPE_TABLE = new Table("OSEE_ATTRIBUTE_BASE_TYPE");
+ public static final Table ATTRIBUTE_VERSION_TABLE = new Table("OSEE_ATTRIBUTE");
+ public static final Table ATTRIBUTE_TYPE_TABLE = new Table("OSEE_ATTRIBUTE_TYPE");
+ public static final Table ATTRIBUTE_TYPE_TABLE_ACL = new Table("OSEE_ATTRIBUTE_TYPE_ACL");
+ public static final Table RELATION_LINK_VERSION_TABLE = new Table("OSEE_RELATION_LINK");
+ public static final Table RELATION_LINK_TYPE_TABLE = new Table("OSEE_RELATION_LINK_TYPE");
+ public static final Table RELATION_LINK_TYPE_TABLE_ACL = new Table("OSEE_RELATION_LINK_TYPE_ACL");
+ public static final Table BRANCH_TABLE = new Table("OSEE_BRANCH");
+ public static final Table BRANCH_DEFINITIONS = new Table("OSEE_BRANCH_DEFINITIONS");
+ public static final Table BRANCH_TABLE_ACL = new Table("OSEE_BRANCH_ACL");
+
+ public static final Table BRANCH_DELETE_HELPER = new Table("OSEE_BRANCH_DELETE_HELPER");
+ public static final Table VALID_ATTRIBUTES_TABLE = new Table("OSEE_VALID_ATTRIBUTES");
+ public static final Table PERMISSION_TABLE = new Table("OSEE_PERMISSION");
+ public static final Table SEQUENCE_TABLE = new Table("OSEE_SEQUENCE");
+ public static final Table OSEE_INFO_TABLE = new Table("OSEE_INFO");
+
+ public static final Table OSEE_MERGE_TABLE = new Table("OSEE_MERGE");
+ public static final Table OSEE_CONFLICT_TABLE = new Table("OSEE_CONFLICT");
+
+ public static final String TXD_COMMENT = "OSEE_COMMENT";
+
+ private static final View[] skynetViews = new View[] {};
+
+ public static View[] getSkynetViews() {
+ return skynetViews;
+ }
+}
diff --git a/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/core/schema/Table.java b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/core/schema/Table.java
new file mode 100644
index 00000000000..c26d1d63bf1
--- /dev/null
+++ b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/core/schema/Table.java
@@ -0,0 +1,142 @@
+/*******************************************************************************
+ * 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.db.connection.core.schema;
+
+public class Table {
+ protected String name;
+
+ //// private static final String aliassyntax;
+ //// private static final Matcher matcher = Pattern.compile(" *PUT_TABLE_ALIAS_HERE *").matcher("");
+ //
+ // static {
+ // aliassyntax = SupportedDatabase.getDatabaseType() == SupportedDatabase.postgresql ? " as " : " ";
+ // }
+
+ // /**
+ // * Remove all PUT_TABLE_ALIAS_HERE tags and replace with table alias specific to this DB
+ // *
+ // * @param sql string with replace tag PUT_TABLE_ALIAS_HERE embedded
+ // * @return sql with corresponding table alias replaced
+ // */
+ // public static String generateTableAliasedSql(String sql) {
+ // matcher.reset(sql);
+ // return matcher.replaceAll(aliassyntax);
+ // }
+
+ /**
+ * @param name
+ */
+ public Table(String name) {
+ this.name = name;
+ }
+
+ public String columnsForInsert(String... cols) {
+ StringBuilder strB = new StringBuilder(200);
+ strB.append(name);
+ strB.append(" (");
+ buildColumnsList(strB, false, cols);
+ strB.append(") ");
+ createValuesList(strB, cols.length);
+ return strB.toString();
+ }
+
+ public String columns(String... columns) {
+ StringBuilder strB = new StringBuilder(200);
+ buildColumnsList(strB, true, columns);
+ return strB.toString();
+ }
+
+ public String column(String columnName) {
+ StringBuilder strB = new StringBuilder(60);
+ qualifyColumnName(strB, columnName);
+ return strB.toString();
+ }
+
+ // public String max(String columnName, String alias) {
+ // return function("max", columnName, alias);
+ // }
+
+ // public String max(String columnName) {
+ // return function("max", columnName, null);
+ // }
+ //
+ // public String min(String columnName, String alias) {
+ // return function("min", columnName, alias);
+ // }
+ //
+ // public String min(String columnName) {
+ // return function("min", columnName, null);
+ // }
+
+ // public static String alias(String sql, String alias) {
+ // StringBuilder strB = new StringBuilder();
+ // strB.append(sql);
+ // alias(strB, alias);
+ // return strB.toString();
+ // }
+ //
+ // private static void alias(StringBuilder strB, String alias) {
+ // strB.append(aliassyntax);
+ // strB.append(alias);
+ // }
+
+ // private String function(String function, String columnName, String alias) {
+ // StringBuilder strB = new StringBuilder(60);
+ // strB.append(function);
+ // strB.append("(");
+ // qualifyColumnName(strB, columnName);
+ // strB.append(")");
+ // if (alias != null && !alias.equals("")) {
+ // alias(strB, alias);
+ // }
+ // return strB.toString();
+ // }
+
+ private void createValuesList(StringBuilder strB, int parameterCount) {
+ strB.append("VALUES (");
+ for (int i = 1; i < parameterCount; i++) {
+ strB.append("?, ");
+ }
+ strB.append("?)");
+ }
+
+ private void buildColumnsList(StringBuilder strB, boolean qualify, String... columns) {
+ for (int i = 0; i < columns.length - 1; i++) {
+ if (qualify)
+ qualifyColumnName(strB, columns[i]);
+ else
+ strB.append(columns[i]);
+ strB.append(", ");
+ }
+ if (qualify)
+ qualifyColumnName(strB, columns[columns.length - 1]);
+ else
+ strB.append(columns[columns.length - 1]);
+ }
+
+ private void qualifyColumnName(StringBuilder strB, String columnName) {
+ strB.append(name);
+ strB.append(".");
+ strB.append(columnName);
+ }
+
+ public String toString() {
+ return name;
+ }
+
+ public String join(Table joinTable, String joinColumn) {
+ return column(joinColumn) + "=" + joinTable.column(joinColumn);
+ }
+
+ // public LocalAliasTable aliasAs(String aliasName) {
+ // return new LocalAliasTable(this, aliasName);
+ // }
+} \ No newline at end of file
diff --git a/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/core/schema/View.java b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/core/schema/View.java
new file mode 100644
index 00000000000..2492c7d88d7
--- /dev/null
+++ b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/core/schema/View.java
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * 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.db.connection.core.schema;
+
+/**
+ * @author Ryan D. Brooks
+ */
+public class View extends Table {
+ private final String definition;
+
+ /**
+ * @param name
+ * @param definition
+ */
+ public View(String name, String definition) {
+ super(name);
+ this.definition = definition;
+ }
+
+ public String getDefinition() {
+ return definition;
+ }
+}
diff --git a/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/core/transaction/DbTransactionEventCompleted.java b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/core/transaction/DbTransactionEventCompleted.java
new file mode 100644
index 00000000000..a137b198adb
--- /dev/null
+++ b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/core/transaction/DbTransactionEventCompleted.java
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * 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.db.connection.core.transaction;
+
+
+/**
+ * @author Jeff C. Phillips
+ */
+public class DbTransactionEventCompleted implements IDbTransactionEvent {
+
+ private boolean committed;
+
+ public DbTransactionEventCompleted(boolean committed) {
+ this.committed = committed;
+ }
+
+ /**
+ * @return the hasCommitted
+ */
+ public boolean isCommitted() {
+ return committed;
+ }
+}
diff --git a/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/core/transaction/IDbTransactionEvent.java b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/core/transaction/IDbTransactionEvent.java
new file mode 100644
index 00000000000..34cb8578d67
--- /dev/null
+++ b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/core/transaction/IDbTransactionEvent.java
@@ -0,0 +1,18 @@
+/*******************************************************************************
+ * 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.db.connection.core.transaction;
+
+/**
+ * @author Jeff C. Phillips
+ */
+public interface IDbTransactionEvent {
+
+}
diff --git a/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/core/transaction/IDbTransactionListener.java b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/core/transaction/IDbTransactionListener.java
new file mode 100644
index 00000000000..510881833c8
--- /dev/null
+++ b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/core/transaction/IDbTransactionListener.java
@@ -0,0 +1,20 @@
+/*******************************************************************************
+ * 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.db.connection.core.transaction;
+
+
+/**
+ * @author Jeff C. Phillips
+ */
+public interface IDbTransactionListener {
+
+ public void onEvent(IDbTransactionEvent event);
+}
diff --git a/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/ArtifactDoesNotExist.java b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/ArtifactDoesNotExist.java
new file mode 100644
index 00000000000..8a61bd9c674
--- /dev/null
+++ b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/ArtifactDoesNotExist.java
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * 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.db.connection.exception;
+
+
+/**
+ * @author Donald G. Dunne
+ */
+public class ArtifactDoesNotExist extends OseeCoreException {
+
+ private static final long serialVersionUID = 1L;
+
+ public ArtifactDoesNotExist(String message) {
+ super(message);
+ }
+}
diff --git a/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/AttributeDoesNotExist.java b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/AttributeDoesNotExist.java
new file mode 100644
index 00000000000..c4428fa8845
--- /dev/null
+++ b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/AttributeDoesNotExist.java
@@ -0,0 +1,25 @@
+/*******************************************************************************
+ * 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.db.connection.exception;
+
+
+/**
+ * @author Donald G. Dunne
+ */
+public class AttributeDoesNotExist extends OseeCoreException {
+
+ private static final long serialVersionUID = 1L;
+
+ public AttributeDoesNotExist(String message) {
+ super(message);
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/BranchDoesNotExist.java b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/BranchDoesNotExist.java
new file mode 100644
index 00000000000..42d01435872
--- /dev/null
+++ b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/BranchDoesNotExist.java
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * 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.db.connection.exception;
+
+/**
+ * @author Ryan D. Brooks
+ */
+public class BranchDoesNotExist extends OseeCoreException {
+ private static final long serialVersionUID = -6197324585250025613L;
+
+ /**
+ * @param message
+ */
+ public BranchDoesNotExist(String message) {
+ super(message);
+ }
+
+ /**
+ * @param message
+ * @param cause
+ */
+ public BranchDoesNotExist(String message, Throwable cause) {
+ super(message, cause);
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/BranchMergeException.java b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/BranchMergeException.java
new file mode 100644
index 00000000000..9f74b0c264e
--- /dev/null
+++ b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/BranchMergeException.java
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * 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.db.connection.exception;
+
+
+/**
+ * @author Donald G. Dunne
+ */
+public class BranchMergeException extends OseeCoreException {
+
+ private static final long serialVersionUID = 1L;
+
+ public BranchMergeException(String message) {
+ super(message);
+ }
+}
diff --git a/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/ConflictDetectionException.java b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/ConflictDetectionException.java
new file mode 100644
index 00000000000..9cfc03dc118
--- /dev/null
+++ b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/ConflictDetectionException.java
@@ -0,0 +1,25 @@
+/*******************************************************************************
+ * 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.db.connection.exception;
+
+
+/**
+ * @author Theron Virgin
+ */
+public class ConflictDetectionException extends OseeCoreException {
+
+ private static final long serialVersionUID = 1L;
+
+ public ConflictDetectionException(String message) {
+ super(message);
+ }
+}
diff --git a/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/InvalidTaggerException.java b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/InvalidTaggerException.java
new file mode 100644
index 00000000000..7c7cae5f1c1
--- /dev/null
+++ b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/InvalidTaggerException.java
@@ -0,0 +1,23 @@
+/*******************************************************************************
+ * 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.db.connection.exception;
+
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class InvalidTaggerException extends OseeCoreException {
+ private static final long serialVersionUID = 1L;
+
+ public InvalidTaggerException() {
+ super("");
+ }
+}
diff --git a/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/MergeChangesInArtifactException.java b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/MergeChangesInArtifactException.java
new file mode 100644
index 00000000000..1b8e36029dd
--- /dev/null
+++ b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/MergeChangesInArtifactException.java
@@ -0,0 +1,25 @@
+/*******************************************************************************
+ * 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.db.connection.exception;
+
+
+/**
+ * @author Theron Virgin
+ */
+public class MergeChangesInArtifactException extends OseeCoreException {
+
+ private static final long serialVersionUID = 1L;
+
+ public MergeChangesInArtifactException(String message) {
+ super(message);
+ }
+}
diff --git a/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/MultipleArtifactsExist.java b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/MultipleArtifactsExist.java
new file mode 100644
index 00000000000..190feebac71
--- /dev/null
+++ b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/MultipleArtifactsExist.java
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * 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.db.connection.exception;
+
+
+/**
+ * @author Donald G. Dunne
+ */
+public class MultipleArtifactsExist extends OseeCoreException {
+
+ private static final long serialVersionUID = 1L;
+
+ public MultipleArtifactsExist(String message) {
+ super(message);
+ }
+}
diff --git a/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/MultipleAttributesExist.java b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/MultipleAttributesExist.java
new file mode 100644
index 00000000000..d1907393e23
--- /dev/null
+++ b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/MultipleAttributesExist.java
@@ -0,0 +1,25 @@
+/*******************************************************************************
+ * 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.db.connection.exception;
+
+
+/**
+ * @author Donald G. Dunne
+ */
+public class MultipleAttributesExist extends OseeCoreException {
+
+ private static final long serialVersionUID = 1L;
+
+ public MultipleAttributesExist(String message) {
+ super(message);
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/MultipleBranchesExist.java b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/MultipleBranchesExist.java
new file mode 100644
index 00000000000..202b38df5a8
--- /dev/null
+++ b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/MultipleBranchesExist.java
@@ -0,0 +1,23 @@
+/*******************************************************************************
+ * 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.db.connection.exception;
+
+/**
+ * @author Donald G. Dunne
+ */
+public class MultipleBranchesExist extends OseeCoreException {
+
+ private static final long serialVersionUID = 1L;
+
+ public MultipleBranchesExist(String message) {
+ super(message);
+ }
+}
diff --git a/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/OseeAccessDeniedException.java b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/OseeAccessDeniedException.java
new file mode 100644
index 00000000000..fa2571eba0c
--- /dev/null
+++ b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/OseeAccessDeniedException.java
@@ -0,0 +1,23 @@
+/*******************************************************************************
+ * 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.db.connection.exception;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class OseeAccessDeniedException extends OseeCoreException {
+
+ private static final long serialVersionUID = 1L;
+
+ public OseeAccessDeniedException(String message) {
+ super(message);
+ }
+}
diff --git a/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/OseeArgumentException.java b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/OseeArgumentException.java
new file mode 100644
index 00000000000..70706fc7ad4
--- /dev/null
+++ b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/OseeArgumentException.java
@@ -0,0 +1,23 @@
+/*******************************************************************************
+ * 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.db.connection.exception;
+
+/**
+ * @author Donald G. Dunne
+ */
+public class OseeArgumentException extends OseeCoreException {
+
+ private static final long serialVersionUID = 1L;
+
+ public OseeArgumentException(String message) {
+ super(message);
+ }
+}
diff --git a/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/OseeCoreException.java b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/OseeCoreException.java
new file mode 100644
index 00000000000..e82609dc707
--- /dev/null
+++ b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/OseeCoreException.java
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * 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.db.connection.exception;
+
+/**
+ * @author Ryan D. Brooks
+ */
+public class OseeCoreException extends Exception {
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * @param message
+ */
+ public OseeCoreException(String message) {
+ super(message);
+ }
+
+ /**
+ * @param message
+ * @param cause
+ */
+ public OseeCoreException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ /**
+ * @param cause
+ */
+ public OseeCoreException(Throwable cause) {
+ super(cause);
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/OseeDataStoreException.java b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/OseeDataStoreException.java
new file mode 100644
index 00000000000..6154226943a
--- /dev/null
+++ b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/OseeDataStoreException.java
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * 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.db.connection.exception;
+
+
+/**
+ * @author Ryan D. Brooks
+ */
+public class OseeDataStoreException extends OseeCoreException {
+ private static final long serialVersionUID = 7339636628746394923L;
+
+ /**
+ * @param message
+ * @param cause
+ */
+ public OseeDataStoreException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ /**
+ * @param message
+ */
+ public OseeDataStoreException(String message) {
+ super(message);
+ }
+
+ /**
+ * @param cause
+ */
+ public OseeDataStoreException(Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/OseeMultipleEnumTypesExist.java b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/OseeMultipleEnumTypesExist.java
new file mode 100644
index 00000000000..706075fd279
--- /dev/null
+++ b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/OseeMultipleEnumTypesExist.java
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * 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.db.connection.exception;
+
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class OseeMultipleEnumTypesExist extends OseeCoreException {
+
+ private static final long serialVersionUID = 1L;
+
+ public OseeMultipleEnumTypesExist(String message) {
+ super(message);
+ }
+}
diff --git a/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/OseeStateException.java b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/OseeStateException.java
new file mode 100644
index 00000000000..cab2880e093
--- /dev/null
+++ b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/OseeStateException.java
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * 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.db.connection.exception;
+
+
+/**
+ * @author Donald G. Dunne
+ */
+public class OseeStateException extends OseeCoreException {
+
+ private static final long serialVersionUID = 1L;
+
+ public OseeStateException(String message) {
+ super(message);
+ }
+}
diff --git a/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/OseeTypeDoesNotExist.java b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/OseeTypeDoesNotExist.java
new file mode 100644
index 00000000000..d8bb5a58a12
--- /dev/null
+++ b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/OseeTypeDoesNotExist.java
@@ -0,0 +1,23 @@
+/*******************************************************************************
+ * 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.db.connection.exception;
+
+/**
+ * @author Ryan D. Brooks
+ */
+public class OseeTypeDoesNotExist extends OseeCoreException {
+
+ private static final long serialVersionUID = 1L;
+
+ public OseeTypeDoesNotExist(String message) {
+ super(message);
+ }
+}
diff --git a/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/OseeWrappedException.java b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/OseeWrappedException.java
new file mode 100644
index 00000000000..432485142a4
--- /dev/null
+++ b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/OseeWrappedException.java
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * 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.db.connection.exception;
+
+/**
+ * @author Ryan D. Brooks
+ */
+public class OseeWrappedException extends OseeCoreException {
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * @param message
+ */
+ public OseeWrappedException(String message) {
+ super(message);
+ }
+
+ /**
+ * @param message
+ * @param cause
+ */
+ public OseeWrappedException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ /**
+ * @param cause
+ */
+ public OseeWrappedException(Throwable cause) {
+ super(cause);
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/TransactionDoesNotExist.java b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/TransactionDoesNotExist.java
new file mode 100644
index 00000000000..a11cbce71ab
--- /dev/null
+++ b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/TransactionDoesNotExist.java
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * 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.db.connection.exception;
+
+/**
+ * @author Ryan D. Brooks
+ */
+public class TransactionDoesNotExist extends OseeCoreException {
+ private static final long serialVersionUID = -6197324585250025613L;
+
+ /**
+ * @param message
+ */
+ public TransactionDoesNotExist(String message) {
+ super(message);
+ }
+
+ /**
+ * @param message
+ * @param cause
+ */
+ public TransactionDoesNotExist(String message, Throwable cause) {
+ super(message, cause);
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/UserInDatabaseMultipleTimes.java b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/UserInDatabaseMultipleTimes.java
new file mode 100644
index 00000000000..d79e404c1ea
--- /dev/null
+++ b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/UserInDatabaseMultipleTimes.java
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * 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.db.connection.exception;
+
+
+/**
+ * @author Ryan D. Brooks
+ * @author Donald G. Dunne
+ */
+public class UserInDatabaseMultipleTimes extends OseeCoreException {
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * @param message
+ */
+ public UserInDatabaseMultipleTimes(String message) {
+ super(message);
+ }
+
+ /**
+ * @param message
+ * @param cause
+ */
+ public UserInDatabaseMultipleTimes(String message, Throwable cause) {
+ super(message, cause);
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/UserNotInDatabase.java b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/UserNotInDatabase.java
new file mode 100644
index 00000000000..5838c4ad7b8
--- /dev/null
+++ b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/exception/UserNotInDatabase.java
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * 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.db.connection.exception;
+
+
+/**
+ * @author Ryan D. Brooks
+ * @author Donald G. Dunne
+ */
+public class UserNotInDatabase extends OseeCoreException {
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * @param message
+ */
+ public UserNotInDatabase(String message) {
+ super(message);
+ }
+
+ /**
+ * @param message
+ * @param cause
+ */
+ public UserNotInDatabase(String message, Throwable cause) {
+ super(message, cause);
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/info/SQL3DataType.java b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/info/SQL3DataType.java
new file mode 100644
index 00000000000..25fcf484673
--- /dev/null
+++ b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/info/SQL3DataType.java
@@ -0,0 +1,81 @@
+/*******************************************************************************
+ * 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.db.connection.info;
+
+import java.math.BigInteger;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.util.Date;
+import java.util.HashMap;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public enum SQL3DataType {
+
+ BIT(java.sql.Types.BIT, Boolean.class),
+ TINYINT(java.sql.Types.TINYINT, Integer.class),
+ SMALLINT(java.sql.Types.SMALLINT, Integer.class),
+ INTEGER(java.sql.Types.INTEGER, Integer.class),
+ BIGINT(java.sql.Types.BIGINT, BigInteger.class),
+ FLOAT(java.sql.Types.FLOAT, Float.class),
+ REAL(java.sql.Types.REAL, Double.class),
+ DOUBLE(java.sql.Types.DOUBLE, Double.class),
+ NUMERIC(java.sql.Types.NUMERIC, Double.class),
+ DECIMAL(java.sql.Types.DECIMAL, Integer.class),
+ CHAR(java.sql.Types.CHAR, Character.class),
+ VARCHAR(java.sql.Types.VARCHAR, String.class),
+ LONGVARCHAR(java.sql.Types.LONGVARCHAR, String.class),
+ DATE(java.sql.Types.DATE, Date.class),
+ TIME(java.sql.Types.TIME, Time.class),
+ TIMESTAMP(java.sql.Types.TIMESTAMP, Timestamp.class),
+ BINARY(java.sql.Types.BINARY, Object.class),
+ VARBINARY(java.sql.Types.VARBINARY, Object.class),
+ LONGVARBINARY(java.sql.Types.LONGVARBINARY, Object.class),
+ NULL(java.sql.Types.NULL, Object.class),
+ OTHER(java.sql.Types.OTHER, Object.class),
+ JAVA_OBJECT(java.sql.Types.JAVA_OBJECT, Object.class),
+ DISTINCT(java.sql.Types.DISTINCT, Object.class),
+ STRUCT(java.sql.Types.STRUCT, Object.class),
+ ARRAY(java.sql.Types.ARRAY, Object.class),
+ BLOB(java.sql.Types.BLOB, Object.class),
+ CLOB(java.sql.Types.CLOB, Object.class),
+ REF(java.sql.Types.REF, Object.class),
+ DATALINK(java.sql.Types.DATALINK, Object.class),
+ BOOLEAN(java.sql.Types.BOOLEAN, Boolean.class);
+
+ private Class<?> javaClassEquivalent;
+ private int sqlTypeNumber;
+
+ private static HashMap<Integer, SQL3DataType> typeToEnum = new HashMap<Integer, SQL3DataType>();
+
+ private SQL3DataType(int sqlTypeNumber, Class<?> classEquiv) {
+ this.javaClassEquivalent = classEquiv;
+ this.sqlTypeNumber = sqlTypeNumber;
+ }
+
+ public int getSQLTypeNumber() {
+ return sqlTypeNumber;
+ }
+
+ public Class<?> getJavaEquivalentClass() {
+ return javaClassEquivalent;
+ }
+
+ public static SQL3DataType get(int type) {
+ if (typeToEnum.isEmpty()) {
+ for (SQL3DataType enumType : SQL3DataType.values()) {
+ typeToEnum.put(enumType.sqlTypeNumber, enumType);
+ }
+ }
+ return typeToEnum.get(type);
+ }
+}
diff --git a/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/info/SupportedDatabase.java b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/info/SupportedDatabase.java
new file mode 100644
index 00000000000..46bb612e724
--- /dev/null
+++ b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/info/SupportedDatabase.java
@@ -0,0 +1,73 @@
+/*******************************************************************************
+ * 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.db.connection.info;
+
+import java.sql.SQLException;
+import org.eclipse.osee.framework.db.connection.ConnectionHandler;
+import org.eclipse.osee.framework.db.connection.OseeConnection;
+import org.eclipse.osee.framework.db.connection.OseeDbConnection;
+import org.eclipse.osee.framework.db.connection.exception.OseeDataStoreException;
+
+public enum SupportedDatabase {
+ oracle, derby, foxpro, mysql, postgresql;
+
+ public static SupportedDatabase getDatabaseType(OseeConnection connection) throws OseeDataStoreException {
+ try {
+ SupportedDatabase toReturn = null;
+ String dbName = connection.getMetaData().getDatabaseProductName();
+ String lowerCaseName = dbName.toLowerCase();
+ if (lowerCaseName.contains(SupportedDatabase.derby.toString())) {
+ toReturn = SupportedDatabase.derby;
+ } else if (lowerCaseName.contains(SupportedDatabase.oracle.toString())) {
+ toReturn = SupportedDatabase.oracle;
+ } else if (lowerCaseName.contains(SupportedDatabase.foxpro.toString())) {
+ toReturn = SupportedDatabase.foxpro;
+ } else if (lowerCaseName.contains(SupportedDatabase.mysql.toString())) {
+ toReturn = SupportedDatabase.mysql;
+ } else if (lowerCaseName.contains(SupportedDatabase.postgresql.toString())) {
+ toReturn = SupportedDatabase.postgresql;
+ } else {
+ throw new OseeDataStoreException("Unsupported database type: " + dbName);
+ }
+ return toReturn;
+ } catch (SQLException ex) {
+ throw new OseeDataStoreException(ex);
+ }
+ }
+
+ public static SupportedDatabase getDatabaseType() throws OseeDataStoreException {
+ OseeConnection connection = OseeDbConnection.getConnection();
+ try {
+ return SupportedDatabase.getDatabaseType(connection);
+ } finally {
+ connection.close();
+ }
+ }
+
+ public static boolean isDatabaseType(SupportedDatabase dbType) throws OseeDataStoreException {
+ return getDatabaseType() == dbType;
+ }
+
+ public static boolean areHintsSupported() throws OseeDataStoreException {
+ try {
+ if (SupportedDatabase.isDatabaseType(oracle)) {
+ return ConnectionHandler.getMetaData().getDatabaseMajorVersion() > 10;
+ }
+ } catch (SQLException ex) {
+ throw new OseeDataStoreException(ex);
+ }
+ return false;
+ }
+
+ public static String getComplementSql() throws OseeDataStoreException {
+ return isDatabaseType(oracle) ? "MINUS" : "EXCEPT";
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/internal/ApplicationDatabaseManager.java b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/internal/ApplicationDatabaseManager.java
new file mode 100644
index 00000000000..1968d8592a0
--- /dev/null
+++ b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/internal/ApplicationDatabaseManager.java
@@ -0,0 +1,75 @@
+/*******************************************************************************
+ * 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.db.connection.internal;
+
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+import org.eclipse.osee.framework.db.connection.IApplicationDatabaseInfoProvider;
+import org.eclipse.osee.framework.db.connection.exception.OseeDataStoreException;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class ApplicationDatabaseManager implements IApplicationDatabaseManager {
+
+ private List<IApplicationDatabaseInfoProvider> applicationDatabaseInfoProvider;
+ private Object myWait;
+
+ public ApplicationDatabaseManager() {
+ this.applicationDatabaseInfoProvider = new CopyOnWriteArrayList<IApplicationDatabaseInfoProvider>();
+ myWait = new Object();
+ }
+
+ public IApplicationDatabaseInfoProvider getInternal() throws OseeDataStoreException {
+ IApplicationDatabaseInfoProvider toReturn = null;
+ for (IApplicationDatabaseInfoProvider provider : applicationDatabaseInfoProvider) {
+ if (toReturn == null || (toReturn.getPriority() < provider.getPriority())) {
+ toReturn = provider;
+ }
+ }
+ return toReturn;
+ }
+
+ public IApplicationDatabaseInfoProvider getProvider() throws OseeDataStoreException {
+ IApplicationDatabaseInfoProvider provider = getInternal();
+ if (provider == null) {
+ long endTime = System.currentTimeMillis() + (1000 * 20);
+ long timeLeft = 1000 * 20;
+ while (timeLeft > 0 && provider == null) {
+ synchronized (myWait) {
+ try {
+ myWait.wait(timeLeft);
+ } catch (InterruptedException ex) {
+ }
+ provider = getInternal();
+ }
+ timeLeft = endTime - System.currentTimeMillis();
+ }
+ }
+ if (provider == null) {
+ throw new OseeDataStoreException("Unable to find an application database provider");
+ }
+ return provider;
+ }
+
+ public void removeDatabaseProvider(IApplicationDatabaseInfoProvider provider) {
+ System.out.println("Removing: " + provider);
+ applicationDatabaseInfoProvider.remove(provider);
+ }
+
+ public void addDatabaseProvider(IApplicationDatabaseInfoProvider provider) {
+ System.out.println("Adding: " + provider);
+ applicationDatabaseInfoProvider.add(provider);
+ synchronized (myWait) {
+ myWait.notifyAll();
+ }
+ }
+}
diff --git a/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/internal/DbConnectionFactory.java b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/internal/DbConnectionFactory.java
new file mode 100644
index 00000000000..cd6d42c759c
--- /dev/null
+++ b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/internal/DbConnectionFactory.java
@@ -0,0 +1,88 @@
+/*******************************************************************************
+ * 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.db.connection.internal;
+
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+import org.eclipse.osee.framework.db.connection.IConnection;
+import org.eclipse.osee.framework.db.connection.exception.OseeCoreException;
+import org.eclipse.osee.framework.db.connection.exception.OseeStateException;
+
+/**
+ * @author Andrew M. Finkbeiner
+ */
+public class DbConnectionFactory implements IDbConnectionFactory {
+
+ private List<IConnection> connectionProviders;
+ private Object myWait;
+
+ public DbConnectionFactory() {
+ connectionProviders = new CopyOnWriteArrayList<IConnection>();
+ myWait = new Object();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.db.connection.IDbConnectionFactory#get(java.lang.String)
+ */
+ @Override
+ public IConnection get(String driver) throws OseeCoreException {
+ IConnection selectedDriver = getInternal(driver);
+ if (selectedDriver == null) {
+ long endTime = System.currentTimeMillis() + (1000 * 20);
+ long timeLeft = 1000 * 20;
+ while (timeLeft > 0 && selectedDriver == null) {
+ synchronized (myWait) {
+ try {
+ myWait.wait(timeLeft);
+ } catch (InterruptedException ex) {
+ }
+ selectedDriver = getInternal(driver);
+ }
+ timeLeft = endTime - System.currentTimeMillis();
+ }
+ }
+ if (selectedDriver == null) {
+ throw new OseeStateException(
+ String.format("Unable to find matching driver provider for [%s].", driver, driver));
+ }
+ return selectedDriver;
+ }
+
+ private IConnection getInternal(String driver) {
+ for (IConnection connection : connectionProviders) {
+ if (connection.getDriver().equals(driver)) {
+ return connection;
+ }
+ }
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.db.connection.IBind#bind(java.lang.Object)
+ */
+ @Override
+ public void bind(IConnection obj) {
+ connectionProviders.add((IConnection) obj);
+ synchronized (myWait) {
+ myWait.notifyAll();
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.db.connection.IBind#unbind(java.lang.Object)
+ */
+ @Override
+ public void unbind(IConnection obj) {
+ connectionProviders.remove((IConnection) obj);
+ }
+
+}
diff --git a/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/internal/DbConnectionInformation.java b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/internal/DbConnectionInformation.java
new file mode 100644
index 00000000000..d3198c0163b
--- /dev/null
+++ b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/internal/DbConnectionInformation.java
@@ -0,0 +1,111 @@
+/*******************************************************************************
+ * 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.db.connection.internal;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.logging.Level;
+import org.eclipse.osee.framework.db.connection.IDatabaseInfo;
+import org.eclipse.osee.framework.db.connection.IDbConnectionInformationContributor;
+import org.eclipse.osee.framework.jdk.core.util.OseeProperties;
+import org.eclipse.osee.framework.logging.OseeLog;
+
+/**
+ * @author Andrew M. Finkbeiner
+ */
+public class DbConnectionInformation implements IDbConnectionInformation {
+
+ private Map<String, IDatabaseInfo> dbInfo;
+ private IDatabaseInfo selectedDbInfo;
+ private Object myWait;
+
+ public DbConnectionInformation() {
+ dbInfo = new HashMap<String, IDatabaseInfo>();
+ myWait = new Object();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.db.connection.IDbConnectionInformation#getDatabaseInfo(java.lang.String)
+ */
+ @Override
+ public IDatabaseInfo getDatabaseInfo(String servicesId) {
+ return dbInfo.get(servicesId);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.db.connection.IDbConnectionInformation#getSelectedDatabaseInfo()
+ */
+ @Override
+ public IDatabaseInfo getSelectedDatabaseInfo() {
+ if (selectedDbInfo == null) {
+ String dbConnectionId = OseeProperties.getOseeDbConnectionId();
+ if (dbConnectionId != null && dbConnectionId.length() > 0) {
+ selectedDbInfo = getDatabaseInfo(dbConnectionId);
+ if (selectedDbInfo == null) {
+ long endTime = System.currentTimeMillis() + (1000 * 20);
+ long timeLeft = 1000 * 20;
+ while (timeLeft > 0 && selectedDbInfo == null) {
+ synchronized (myWait) {
+ try {
+ myWait.wait(timeLeft);
+ } catch (InterruptedException ex) {
+ }
+ selectedDbInfo = getDatabaseInfo(dbConnectionId);
+ }
+ timeLeft = endTime - System.currentTimeMillis();
+ }
+ if (selectedDbInfo == null) {
+ throw new IllegalStateException(String.format(
+ "DB connection information was not found for: [%s]\n Available connection ids are: [%s]\n",
+ dbConnectionId, dbInfo.keySet()));
+ }
+ }
+ } else {
+ throw new IllegalStateException("No DB connection information provided");
+ }
+ }
+ return selectedDbInfo;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.db.connection.IBind#bind(java.lang.Object)
+ */
+ @Override
+ public void bind(IDbConnectionInformationContributor obj) {
+ IDbConnectionInformationContributor contributor = (IDbConnectionInformationContributor) obj;
+ try {
+ for (IDatabaseInfo info : contributor.getDbInformation()) {
+ dbInfo.put(info.getId(), info);
+ }
+ } catch (Exception ex) {
+ OseeLog.log(InternalActivator.class, Level.SEVERE, ex);
+ }
+ synchronized (myWait) {
+ myWait.notifyAll();
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.db.connection.IBind#unbind(java.lang.Object)
+ */
+ @Override
+ public void unbind(IDbConnectionInformationContributor obj) {
+ IDbConnectionInformationContributor contributor = (IDbConnectionInformationContributor) obj;
+ try {
+ for (IDatabaseInfo info : contributor.getDbInformation()) {
+ dbInfo.remove(info.getDatabaseName());
+ }
+ } catch (Exception ex) {
+ OseeLog.log(InternalActivator.class, Level.SEVERE, ex);
+ }
+ }
+}
diff --git a/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/internal/IApplicationDatabaseManager.java b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/internal/IApplicationDatabaseManager.java
new file mode 100644
index 00000000000..0f9c2fbfb8b
--- /dev/null
+++ b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/internal/IApplicationDatabaseManager.java
@@ -0,0 +1,26 @@
+/*******************************************************************************
+ * 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.db.connection.internal;
+
+import org.eclipse.osee.framework.db.connection.IApplicationDatabaseInfoProvider;
+import org.eclipse.osee.framework.db.connection.exception.OseeDataStoreException;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public interface IApplicationDatabaseManager {
+
+ public IApplicationDatabaseInfoProvider getProvider() throws OseeDataStoreException;
+
+ public void removeDatabaseProvider(IApplicationDatabaseInfoProvider provider);
+
+ public void addDatabaseProvider(IApplicationDatabaseInfoProvider provider);
+}
diff --git a/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/internal/IDbConnectionFactory.java b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/internal/IDbConnectionFactory.java
new file mode 100644
index 00000000000..32872ba78f9
--- /dev/null
+++ b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/internal/IDbConnectionFactory.java
@@ -0,0 +1,26 @@
+/*******************************************************************************
+ * 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.db.connection.internal;
+
+import org.eclipse.osee.framework.db.connection.IConnection;
+import org.eclipse.osee.framework.db.connection.exception.OseeCoreException;
+
+/**
+ * @author Andrew M. Finkbeiner
+ */
+public interface IDbConnectionFactory {
+ IConnection get(String driver) throws OseeCoreException;
+
+ void bind(IConnection connection);
+
+ void unbind(IConnection connection);
+}
diff --git a/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/internal/IDbConnectionInformation.java b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/internal/IDbConnectionInformation.java
new file mode 100644
index 00000000000..c485a295135
--- /dev/null
+++ b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/internal/IDbConnectionInformation.java
@@ -0,0 +1,29 @@
+/*******************************************************************************
+ * 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.db.connection.internal;
+
+import org.eclipse.osee.framework.db.connection.IDatabaseInfo;
+import org.eclipse.osee.framework.db.connection.IDbConnectionInformationContributor;
+
+/**
+ * @author Andrew M. Finkbeiner
+ */
+public interface IDbConnectionInformation {
+
+ public IDatabaseInfo getDatabaseInfo(String servicesId);
+
+ public IDatabaseInfo getSelectedDatabaseInfo();
+
+ void bind(IDbConnectionInformationContributor contributor);
+
+ void unbind(IDbConnectionInformationContributor contributor);
+}
diff --git a/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/internal/InternalActivator.java b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/internal/InternalActivator.java
new file mode 100644
index 00000000000..31786f2c497
--- /dev/null
+++ b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/internal/InternalActivator.java
@@ -0,0 +1,79 @@
+/*******************************************************************************
+ * 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.db.connection.internal;
+
+import org.eclipse.osee.framework.db.connection.IApplicationDatabaseInfoProvider;
+import org.eclipse.osee.framework.db.connection.exception.OseeDataStoreException;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.util.tracker.ServiceTracker;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class InternalActivator implements BundleActivator {
+
+ private static final long TIMEOUT = 20000;
+
+ private static InternalActivator instance = null;
+
+ private ServiceTracker applicationDbManagerTracker;
+ private ServiceTracker dbConnectionProviderTracker;
+ private ServiceTracker dbConnectionInfoTracker;
+
+ public static IDbConnectionFactory getConnectionFactory() throws InterruptedException {
+ return (IDbConnectionFactory) instance.dbConnectionProviderTracker.waitForService(TIMEOUT);
+ }
+
+ public static IDbConnectionInformation getConnectionInfos() throws InterruptedException {
+ return (IDbConnectionInformation) instance.dbConnectionInfoTracker.waitForService(TIMEOUT);
+ }
+
+ private static IApplicationDatabaseManager getApplicationDatabaseManager() throws InterruptedException {
+ return (IApplicationDatabaseManager) instance.applicationDbManagerTracker.waitForService(TIMEOUT);
+ }
+
+ public static IApplicationDatabaseInfoProvider getApplicationDatabaseProvider() throws OseeDataStoreException {
+ try {
+ return getApplicationDatabaseManager().getProvider();
+ } catch (InterruptedException ex) {
+ throw new OseeDataStoreException(ex);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception {
+ instance = this;
+
+ dbConnectionProviderTracker = new ServiceTracker(context, IDbConnectionFactory.class.getName(), null);
+ dbConnectionProviderTracker.open();
+
+ dbConnectionInfoTracker = new ServiceTracker(context, IDbConnectionInformation.class.getName(), null);
+ dbConnectionInfoTracker.open();
+
+ applicationDbManagerTracker = new ServiceTracker(context, IApplicationDatabaseManager.class.getName(), null);
+ applicationDbManagerTracker.open();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception {
+ instance = null;
+ dbConnectionProviderTracker.close();
+ dbConnectionInfoTracker.close();
+ applicationDbManagerTracker.close();
+ }
+}
diff --git a/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/internal/TransactionMonitor.java b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/internal/TransactionMonitor.java
new file mode 100644
index 00000000000..3f2958e0e7a
--- /dev/null
+++ b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/internal/TransactionMonitor.java
@@ -0,0 +1,118 @@
+/*******************************************************************************
+ * 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.db.connection.internal;
+
+import java.util.Map;
+import java.util.WeakHashMap;
+import java.util.logging.Level;
+import org.eclipse.osee.framework.db.connection.DbTransaction;
+import org.eclipse.osee.framework.db.connection.exception.OseeStateException;
+import org.eclipse.osee.framework.db.connection.exception.OseeWrappedException;
+import org.eclipse.osee.framework.logging.OseeLog;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class TransactionMonitor {
+
+ private enum TxState {
+ CREATED, RUNNING, ENDED;
+ }
+
+ private final Map<Thread, TxOperation> txMap;
+
+ public TransactionMonitor() {
+ this.txMap = new WeakHashMap<Thread, TxOperation>();
+ }
+
+ public synchronized void reportTxCreation(final DbTransaction transaction) throws OseeWrappedException {
+ final Thread currentThread = Thread.currentThread();
+ TxOperation currentTx = txMap.get(currentThread);
+ if (currentTx != null) {
+ // This log is to support debugging the case where osee transactions are nested and should
+ // use the same transaction.
+ // This case may happens legitimately if an exception occurs outside this API before transaction.execute() is called,
+ // so it is only notification that this is occurring.
+ OseeLog.log(InternalActivator.class, Level.SEVERE, "New transaction created over Last transaction",
+ currentTx.getError());
+ }
+ txMap.put(currentThread, new TxOperation(transaction));
+ }
+
+ public synchronized void reportTxStart(final DbTransaction transaction) throws OseeWrappedException, OseeStateException {
+ final Thread currentThread = Thread.currentThread();
+ TxOperation currentTx = txMap.get(currentThread);
+ if (currentTx == null) {
+ throw new OseeStateException(
+ "reportTxStart called for thread: " + currentThread + " but reportTxCreation had not been called.");
+ } else if (currentTx.getState() != TxState.CREATED) {
+ throw new OseeWrappedException(currentTx.getError());
+ }
+
+ if (currentTx.getTransaction().equals(transaction)) {
+ currentTx.setState(TxState.RUNNING);
+ } else {
+ throw new OseeStateException(
+ "reportTxStart called for thread: " + currentThread + " but was called for incorrect transaction");
+ }
+ }
+
+ public synchronized void reportTxEnd(final DbTransaction transaction) throws OseeWrappedException, OseeStateException {
+ final Thread currentThread = Thread.currentThread();
+
+ TxOperation currentTx = txMap.get(currentThread);
+ if (currentTx == null) {
+ throw new OseeStateException(
+ "reportTxEnd called for thread: " + currentThread + " but reportTxCreation had not been called.");
+ } else if (currentTx.getState() != TxState.RUNNING) {
+ // This is a valid case -- can add a log to detect when a reportTxEnd is called before a transaction has a chance to run
+ }
+
+ if (currentTx.getTransaction().equals(transaction)) {
+ txMap.put(currentThread, null);
+ } else {
+ throw new OseeWrappedException(currentTx.getError());
+ }
+ }
+
+ private final class TxOperation {
+ private final DbTransaction tx;
+ private Throwable throwable;
+ private TxState txState;
+
+ public TxOperation(DbTransaction tx) {
+ this.tx = tx;
+ this.txState = TxState.CREATED;
+ // Not null for stack trace purposes;
+ this.throwable = new Exception();
+ }
+
+ public DbTransaction getTransaction() {
+ return tx;
+ }
+
+ public TxState getState() {
+ return txState;
+ }
+
+ public void setState(TxState txState) {
+ this.txState = txState;
+ }
+
+ public void setError(Throwable throwable) {
+ this.throwable = throwable;
+ }
+
+ public Throwable getError() {
+ return throwable;
+ }
+ }
+}
diff --git a/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/internal/UriDbConnectionInfo.java b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/internal/UriDbConnectionInfo.java
new file mode 100644
index 00000000000..a632abe15c3
--- /dev/null
+++ b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/internal/UriDbConnectionInfo.java
@@ -0,0 +1,46 @@
+/*******************************************************************************
+ * 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.db.connection.internal;
+
+import java.io.File;
+import java.net.URI;
+import java.util.logging.Level;
+import org.eclipse.osee.framework.db.connection.DatabaseInfoManager;
+import org.eclipse.osee.framework.db.connection.IDatabaseInfo;
+import org.eclipse.osee.framework.db.connection.IDbConnectionInformationContributor;
+import org.eclipse.osee.framework.jdk.core.util.OseeProperties;
+import org.eclipse.osee.framework.jdk.core.util.Strings;
+import org.eclipse.osee.framework.logging.OseeLog;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class UriDbConnectionInfo implements IDbConnectionInformationContributor {
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.db.connection.IDbConnectionInformationContributer#getDbInformation()
+ */
+ @Override
+ public IDatabaseInfo[] getDbInformation() throws Exception {
+ String uri = OseeProperties.getOseeConnectionInfoUri();
+ if (Strings.isValid(uri)) {
+ OseeLog.log(InternalActivator.class, Level.INFO, String.format("Loading connection info from: [%s]", uri));
+ URI connectionFile = null;
+ if (!uri.contains("://")) {
+ connectionFile = new File(uri).toURI();
+ } else {
+ connectionFile = new URI(uri);
+ }
+ return DatabaseInfoManager.readFromXml(connectionFile.toURL().openStream());
+ }
+ return new IDatabaseInfo[0];
+ }
+}
diff --git a/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/internal/parser/DbConfigParser.java b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/internal/parser/DbConfigParser.java
new file mode 100644
index 00000000000..847bc43b28e
--- /dev/null
+++ b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/internal/parser/DbConfigParser.java
@@ -0,0 +1,208 @@
+/*******************************************************************************
+ * 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.db.connection.internal.parser;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.eclipse.osee.framework.db.connection.internal.parser.DbInformation.DbObjectType;
+import org.eclipse.osee.framework.jdk.core.type.Pair;
+import org.eclipse.osee.framework.jdk.core.util.xml.Jaxp;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class DbConfigParser {
+
+ private final Map<String, DbDetailData> dbInfoMap;
+ private final Map<String, DbSetupData> servicesMap;
+ private final Map<String, DbConnectionData> connectionMap;
+
+ private DbConfigParser() {
+ dbInfoMap = new HashMap<String, DbDetailData>();
+ servicesMap = new HashMap<String, DbSetupData>();
+ connectionMap = new HashMap<String, DbConnectionData>();
+ }
+
+ public static DbInformation[] parse(Element rootElement) {
+ DbConfigParser worker = new DbConfigParser();
+ worker.parseDbInfo(rootElement);
+ worker.parseDbService(rootElement);
+ worker.parseDbConnection(rootElement);
+ return worker.getAllDbServices();
+ }
+
+ private DbInformation[] getAllDbServices() {
+ DbInformation[] info = new DbInformation[servicesMap.size()];
+ int i = 0;
+ for (String name : servicesMap.keySet()) {
+ info[i] = buildDbInformation(name);
+ i++;
+ }
+ return info;
+ }
+
+ private DbInformation buildDbInformation(String id) {
+ DbSetupData serviceData = servicesMap.get(id);
+ DbDetailData dbInfo = dbInfoMap.get(serviceData.getDbInfo());
+ DbConnectionData connectionData =
+ connectionMap.get(serviceData.getServerInfoValue(DbSetupData.ServerInfoFields.connectsWith));
+ if (dbInfo != null && connectionData != null) {
+ return new DbInformation(dbInfo, serviceData, connectionData);
+ } else {
+ return null;
+ }
+ }
+
+ private void parseDbInfo(Element rootElement) {
+ if (rootElement != null) {
+ NodeList list = rootElement.getElementsByTagName(DbObjectType.DatabaseInfo.name());
+ for (int i = 0; i < list.getLength(); i++) {
+ DbDetailData dbInfo = new DbDetailData();
+ Element element = (Element) list.item(i);
+ NamedNodeMap map = element.getAttributes();
+ if (map != null && map.getLength() != 0) {
+ DbDetailData.DescriptionField[] descriptionFields = DbDetailData.DescriptionField.values();
+ for (DbDetailData.DescriptionField descriptionField : descriptionFields) {
+ Node node = map.getNamedItem(descriptionField.name());
+ String value = node.getTextContent();
+ if (value != null && !value.equals("")) {
+ dbInfo.addDescription(descriptionField, value);
+ }
+ }
+ }
+ DbDetailData.ConfigField[] configfields = DbDetailData.ConfigField.values();
+ for (DbDetailData.ConfigField field : configfields) {
+ Element fieldChild = Jaxp.getChild(element, field.name());
+ if (fieldChild != null) {
+ NamedNodeMap configMap = fieldChild.getAttributes();
+ Node keyNode = configMap.getNamedItem(DbDetailData.ConfigPairField.key.name());
+ Node valueNode = configMap.getNamedItem(DbDetailData.ConfigPairField.value.name());
+ String key = null;
+ if (keyNode != null) {
+ key = keyNode.getTextContent();
+ }
+ String value = null;
+ if (valueNode != null) {
+ value = valueNode.getTextContent();
+ }
+ if (key != null && !key.equals("")) {
+ dbInfo.addConfigField(field, new Pair<String, String>(key, (value != null ? value : "")));
+ }
+
+ }
+ }
+ dbInfoMap.put(dbInfo.getId(), dbInfo);
+ }
+ }
+ }
+
+ private void parseDbService(Element rootElement) {
+ if (rootElement != null) {
+ NodeList list = rootElement.getElementsByTagName(DbObjectType.AvailableDbServices.name());
+ for (int i = 0; i < list.getLength(); i++) {
+
+ Element element = (Element) list.item(i);
+
+ NodeList serverList = element.getElementsByTagName(DbSetupData.ServicesFields.Server.name());
+ for (int index = 0; index < serverList.getLength(); index++) {
+ DbSetupData dbServicesData = new DbSetupData();
+ Element serviceChild = (Element) serverList.item(index);
+ NamedNodeMap map = serviceChild.getAttributes();
+ if (map != null && map.getLength() != 0) {
+ DbSetupData.ServerInfoFields[] infoFields = DbSetupData.ServerInfoFields.values();
+ for (DbSetupData.ServerInfoFields infoField : infoFields) {
+ Node node = map.getNamedItem(infoField.name());
+ String value = null;
+ if (node != null) {
+ value = node.getTextContent();
+ }
+ if (value != null && !value.equals("")) {
+ dbServicesData.addServerInfo(infoField, value);
+ }
+ }
+ }
+ servicesMap.put(dbServicesData.getId(), dbServicesData);
+ }
+ }
+ }
+ }
+
+ private void parseDbConnection(Element rootElement) {
+ if (rootElement != null) {
+ NodeList list = rootElement.getElementsByTagName(DbObjectType.ConnectionDescription.name());
+ for (int i = 0; i < list.getLength(); i++) {
+ DbConnectionData dbConnectionData = new DbConnectionData();
+ Element element = (Element) list.item(i);
+
+ NamedNodeMap map = element.getAttributes();
+ if (map != null && map.getLength() != 0) {
+ Node node = map.getNamedItem(DbConnectionData.DescriptionFields.id.name());
+ if (node != null) {
+ String value = node.getTextContent();
+ if (value != null && !value.equals("")) {
+ dbConnectionData.setId(value);
+ }
+ }
+ }
+
+ DbConnectionData.ConnectionFields[] connectionFields = DbConnectionData.ConnectionFields.values();
+ for (DbConnectionData.ConnectionFields connectionField : connectionFields) {
+ switch (connectionField) {
+ case Driver:
+ String driver = Jaxp.getChildText(element, connectionField.name());
+ if (driver != null && !driver.equals("")) {
+ dbConnectionData.setDBDriver(driver);
+ }
+ break;
+ case Url:
+ String url = Jaxp.getChildText(element, connectionField.name());
+ if (url != null && !url.equals("")) {
+ dbConnectionData.setRawUrl(url);
+ }
+ break;
+ case UrlAttributes:
+ Element urlAttributes =
+ Jaxp.getChild(element, DbConnectionData.ConnectionFields.UrlAttributes.name());
+ if (urlAttributes != null) {
+ NodeList attributes =
+ urlAttributes.getElementsByTagName(DbConnectionData.UrlAttributes.Entry.name());
+ if (attributes != null) {
+ for (int index = 0; index < attributes.getLength(); index++) {
+ Node node = attributes.item(index);
+ String attributeValue = node.getTextContent();
+ if (attributeValue != null && !attributeValue.equals("")) {
+ dbConnectionData.addAttribute(attributeValue);
+ }
+ }
+ }
+ }
+ break;
+ case Property: {
+ NodeList nodes = element.getElementsByTagName(connectionField.name());
+ for (int j = 0; j < nodes.getLength(); j++) {
+ Element el = (Element) nodes.item(j);
+ dbConnectionData.getProperties().setProperty(el.getAttribute("key"), el.getAttribute("value"));
+ }
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ connectionMap.put(dbConnectionData.getId(), dbConnectionData);
+ }
+ }
+ }
+}
diff --git a/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/internal/parser/DbConnectionData.java b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/internal/parser/DbConnectionData.java
new file mode 100644
index 00000000000..3e6aa464c0e
--- /dev/null
+++ b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/internal/parser/DbConnectionData.java
@@ -0,0 +1,90 @@
+/*******************************************************************************
+ * 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.db.connection.internal.parser;
+
+import java.util.ArrayList;
+import java.util.Properties;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class DbConnectionData {
+
+ public enum DescriptionFields {
+ id;
+ }
+
+ public enum UrlAttributes {
+ Entry;
+ }
+
+ public enum ConnectionFields {
+ Url, Driver, UrlAttributes, Property;
+ }
+
+ private String id;
+ private String databaseDriver;
+ private String databaseUrl;
+ private ArrayList<String> attributesList;
+ private Properties properties;
+
+ public DbConnectionData() {
+ attributesList = new ArrayList<String>();
+ properties = new Properties();
+ this.databaseDriver = "";
+ this.databaseUrl = "";
+ this.id = "";
+ }
+
+ public String getDBDriver() {
+ return databaseDriver;
+ }
+
+ public String getRawUrl() {
+ return databaseUrl;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public void addAttribute(String attribute) {
+ attributesList.add(attribute);
+ }
+
+ public void setDBDriver(String driver) {
+ databaseDriver = driver;
+ }
+
+ public void setRawUrl(String url) {
+ databaseUrl = url;
+ }
+
+ public String getAttributes() {
+ String toReturn = "";
+ for (String temp : attributesList) {
+ toReturn += temp + ";";
+ }
+ return toReturn;
+ }
+
+ public String toString() {
+ return "DbConnection: " + id + "\n" + " Driver: " + databaseDriver + "\n" + " RawUrl: " + databaseUrl + "\n" + "Attributes: " + getAttributes() + "\n";
+ }
+
+ public Properties getProperties() {
+ return properties;
+ }
+}
diff --git a/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/internal/parser/DbDetailData.java b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/internal/parser/DbDetailData.java
new file mode 100644
index 00000000000..ea07da7c205
--- /dev/null
+++ b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/internal/parser/DbDetailData.java
@@ -0,0 +1,90 @@
+/*******************************************************************************
+ * 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.db.connection.internal.parser;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import org.eclipse.osee.framework.db.connection.info.SupportedDatabase;
+import org.eclipse.osee.framework.jdk.core.type.Pair;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class DbDetailData {
+
+ public enum ConfigPairField {
+ key, value;
+ }
+
+ public enum ConfigField {
+ DatabaseType, DatabaseName, DatabaseHome, Prefix, UserName, Password, Host, Port
+ }
+
+ public enum DescriptionField {
+ id;
+ }
+
+ private Map<ConfigField, Pair<String, String>> configFieldMap;
+ private Map<DescriptionField, String> descriptionMap;
+
+ public DbDetailData() {
+ super();
+ configFieldMap = new HashMap<ConfigField, Pair<String, String>>();
+ descriptionMap = new HashMap<DescriptionField, String>();
+ }
+
+ public String getId() {
+ return descriptionMap.get(DescriptionField.id);
+ }
+
+ public void addDescription(DescriptionField field, String value) {
+ descriptionMap.put(field, value);
+ }
+
+ public void addConfigField(ConfigField field, Pair<String, String> pair) {
+ configFieldMap.put(field, pair);
+ }
+
+ public SupportedDatabase getDbType() {
+ return SupportedDatabase.valueOf(getFieldValue(ConfigField.DatabaseType).toLowerCase());
+ }
+
+ public String getFieldValue(ConfigField field) {
+ String toReturn = "";
+ if (configFieldMap.containsKey(field)) {
+ Pair<String, String> pair = configFieldMap.get(field);
+ toReturn = pair.getValue();
+ }
+ return toReturn;
+ }
+
+ public String toString() {
+ String toReturn = "DatabaseInfo: \n";
+ Set<DescriptionField> descriptionMapkeys = descriptionMap.keySet();
+ for (DescriptionField field : descriptionMapkeys) {
+ String value = descriptionMap.get(field);
+ toReturn += field + ": " + "[" + value + "]\n";
+ }
+
+ toReturn += "Fields: \n";
+ Set<ConfigField> keys = configFieldMap.keySet();
+ for (ConfigField field : keys) {
+ Pair<String, String> pair = configFieldMap.get(field);
+ toReturn += field + ": " + "[" + pair.getKey() + "],[" + pair.getValue() + "]\n";
+ }
+ return toReturn + "\n";
+ }
+
+ public Map<ConfigField, Pair<String, String>> getConfigMap() {
+ return configFieldMap;
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/internal/parser/DbInformation.java b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/internal/parser/DbInformation.java
new file mode 100644
index 00000000000..0be257e965d
--- /dev/null
+++ b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/internal/parser/DbInformation.java
@@ -0,0 +1,143 @@
+/*******************************************************************************
+ * 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.db.connection.internal.parser;
+
+import java.util.Properties;
+import java.util.Set;
+import org.eclipse.osee.framework.db.connection.IDatabaseInfo;
+import org.eclipse.osee.framework.db.connection.internal.parser.DbDetailData.ConfigField;
+import org.eclipse.osee.framework.db.connection.internal.parser.DbSetupData.ServerInfoFields;
+import org.eclipse.osee.framework.jdk.core.type.Pair;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class DbInformation implements IDatabaseInfo {
+
+ private DbDetailData dbDetailData;
+ private DbSetupData dbSetupData;
+ private DbConnectionData dbConnectionData;
+
+ public enum DbObjectType {
+ ConnectionDescription, AvailableDbServices, DatabaseInfo
+ }
+
+ public DbInformation(DbDetailData dbDetailData, DbSetupData dbSetupData, DbConnectionData dbConnectionData) {
+ this.dbDetailData = dbDetailData;
+ this.dbSetupData = dbSetupData;
+ this.dbConnectionData = dbConnectionData;
+ }
+
+ public DbConnectionData getConnectionData() {
+ return dbConnectionData;
+ }
+
+ public DbDetailData getDatabaseDetails() {
+ return dbDetailData;
+ }
+
+ public DbSetupData getDatabaseSetupDetails() {
+ return dbSetupData;
+ }
+
+ public String getFormattedURL() {
+ String toReturn = dbConnectionData.getRawUrl();
+ Set<DbDetailData.ConfigField> keys = dbDetailData.getConfigMap().keySet();
+ for (DbDetailData.ConfigField field : keys) {
+ Pair<String, String> pair = dbDetailData.getConfigMap().get(field);
+ if (pair.getValue().startsWith("@")) {
+ DbObjectType type = DbObjectType.valueOf(pair.getValue().substring(1, pair.getValue().indexOf('.')));
+ String value = pair.getValue().substring(pair.getValue().indexOf('.') + 1);
+ String realValue = getValue(type, value);
+
+ toReturn = toReturn.replace(pair.getKey(), realValue);
+ } else {
+ toReturn = toReturn.replace(pair.getKey(), pair.getValue());
+ }
+ }
+ return toReturn;
+ }
+
+ private String getValue(DbObjectType type, String key) {
+ switch (type) {
+ case AvailableDbServices:
+ return dbSetupData.getServerInfoValue(DbSetupData.ServerInfoFields.valueOf(key));
+ case ConnectionDescription:
+ break;
+ case DatabaseInfo:
+ break;
+ }
+ return "none";
+ }
+
+ public String toString() {
+ return getFormattedURL() + " : user=" + getDatabaseLoginName();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.db.connection.IDatabaseInfo#getConnectionUrl()
+ */
+ @Override
+ public String getConnectionUrl() {
+ return getFormattedURL() + getConnectionData().getAttributes();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.db.connection.IDatabaseInfo#getConnectionProperties()
+ */
+ @Override
+ public Properties getConnectionProperties() {
+ Properties properties = getConnectionData().getProperties();
+ properties.setProperty("user", getDatabaseLoginName());
+ properties.setProperty("password", getDatabaseDetails().getFieldValue(ConfigField.Password));
+ return properties;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.db.connection.IDatabaseInfo#getDatabaseLoginName()
+ */
+ @Override
+ public String getDatabaseLoginName() {
+ return getDatabaseDetails().getFieldValue(ConfigField.UserName);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.db.connection.IDatabaseInfo#getDatabaseName()
+ */
+ @Override
+ public String getDatabaseName() {
+ return getDatabaseDetails().getFieldValue(ConfigField.DatabaseName);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.db.connection.IDatabaseInfo#getDriver()
+ */
+ @Override
+ public String getDriver() {
+ return getConnectionData().getDBDriver();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.db.connection.IDatabaseInfo#getId()
+ */
+ @Override
+ public String getId() {
+ return getDatabaseSetupDetails().getId();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.db.connection.IDatabaseInfo#isProduction()
+ */
+ @Override
+ public boolean isProduction() {
+ return Boolean.valueOf(getDatabaseSetupDetails().getServerInfoValue(ServerInfoFields.isProduction));
+ }
+}
diff --git a/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/internal/parser/DbSetupData.java b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/internal/parser/DbSetupData.java
new file mode 100644
index 00000000000..92dd69baa05
--- /dev/null
+++ b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/internal/parser/DbSetupData.java
@@ -0,0 +1,68 @@
+/*******************************************************************************
+ * 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.db.connection.internal.parser;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class DbSetupData {
+
+ public enum ServicesFields {
+ Server;
+ }
+
+ public enum ServerInfoFields {
+ id, dbInfo, hostAddress, port, connectsWith, serverConfig, isProduction;
+ }
+
+ Map<ServerInfoFields, String> serverFieldMap;
+
+ public DbSetupData() {
+ this.serverFieldMap = new HashMap<ServerInfoFields, String>();
+ }
+
+ public void addServerInfo(ServerInfoFields field, String value) {
+ serverFieldMap.put(field, value);
+ }
+
+ public String getServerInfoValue(ServerInfoFields field) {
+ if (serverFieldMap.containsKey(field)) {
+ return serverFieldMap.get(field);
+ }
+ return "";
+ }
+
+ public String getId() {
+ return serverFieldMap.get(ServerInfoFields.id);
+ }
+
+ public String getDbInfo() {
+ return serverFieldMap.get(ServerInfoFields.dbInfo);
+ }
+
+ public String toString() {
+ String toReturn = "Service: \n";
+ Set<ServerInfoFields> keys = serverFieldMap.keySet();
+ for (ServerInfoFields field : keys) {
+ String value = serverFieldMap.get(field);
+ toReturn += field + ": " + value + " ";
+ }
+ return toReturn;
+ }
+
+ public Map<ServerInfoFields, String> getServerFieldMap() {
+ return serverFieldMap;
+ }
+}

Back to the top