Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorafinkbein2008-01-03 15:20:08 +0000
committerafinkbein2008-01-03 15:20:08 +0000
commita2620813e6bbf996f017f0f434356f55d4d43855 (patch)
treee58caa3d17d6f737df7ed9094c4a35597fbde4fe
parentaca8284d2572f479dccc0900b31fee64287440cc (diff)
downloadorg.eclipse.osee-a2620813e6bbf996f017f0f434356f55d4d43855.tar.gz
org.eclipse.osee-a2620813e6bbf996f017f0f434356f55d4d43855.tar.xz
org.eclipse.osee-a2620813e6bbf996f017f0f434356f55d4d43855.zip
-rw-r--r--MS_0.1.4_20080103/org.eclipse.osee.framework.database/.classpath7
-rw-r--r--MS_0.1.4_20080103/org.eclipse.osee.framework.database/.project29
-rw-r--r--MS_0.1.4_20080103/org.eclipse.osee.framework.database/META-INF/MANIFEST.MF23
-rw-r--r--MS_0.1.4_20080103/org.eclipse.osee.framework.database/build.properties9
-rw-r--r--MS_0.1.4_20080103/org.eclipse.osee.framework.database/plugin.xml54
-rw-r--r--MS_0.1.4_20080103/org.eclipse.osee.framework.database/schema/AddDbInitChoice.exsd105
-rw-r--r--MS_0.1.4_20080103/org.eclipse.osee.framework.database/schema/IDbInitializationTask.exsd107
-rw-r--r--MS_0.1.4_20080103/org.eclipse.osee.framework.database/schema/ProductionDatabase.exsd102
-rw-r--r--MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/ConfigDatabase.java45
-rw-r--r--MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/DatabaseActivator.java56
-rw-r--r--MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/GenerateTypeEnumAction.java158
-rw-r--r--MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/PlatformRunnableAvailableInitTasks.java49
-rw-r--r--MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/SkynetTypesEnumGenerator.java300
-rw-r--r--MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/config/SchemaConfigUtility.java55
-rw-r--r--MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/config/TableConfigUtility.java232
-rw-r--r--MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/core/DatabaseNotSupportedException.java27
-rw-r--r--MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/core/DbClientThread.java64
-rw-r--r--MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/core/IConfigClient.java20
-rw-r--r--MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/initialize/DbComparator.java73
-rw-r--r--MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/initialize/DbFactory.java67
-rw-r--r--MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/initialize/DbTaskRunner.java58
-rw-r--r--MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/initialize/LaunchOseeDbConfigClient.java162
-rw-r--r--MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/initialize/tasks/DbInitializationTask.java20
-rw-r--r--MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/initialize/tasks/GatherStatistics.java36
-rw-r--r--MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/initialize/tasks/IDbInitializationTask.java19
-rw-r--r--MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/initialize/tasks/ImportDataFromDbService.java229
-rw-r--r--MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/initialize/tasks/InitTablesFromCSV.java60
-rw-r--r--MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/initialize/tasks/PrintTables.java79
-rw-r--r--MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/initialize/tasks/relational/BackupTableData.java127
-rw-r--r--MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/initialize/tasks/relational/RestoreTableData.java132
-rw-r--r--MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/utility/DatabaseConfigurationData.java130
-rw-r--r--MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/utility/DatabaseDataExtractor.java299
-rw-r--r--MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/utility/DatabaseDataImporter.java257
-rw-r--r--MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/utility/DatabaseSchemaExtractor.java532
-rw-r--r--MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/utility/DbInit.java181
-rw-r--r--MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/utility/FileUtility.java84
-rw-r--r--MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/utility/GroupSelection.java122
-rw-r--r--MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/utility/IAddDbInitChoice.java18
-rw-r--r--MS_0.1.4_20080103/org.eclipse.osee.framework.database/support/dbrelease.xml88
-rw-r--r--MS_0.1.4_20080103/org.eclipse.osee.framework.database/support/sqlAnt.xml84
40 files changed, 4299 insertions, 0 deletions
diff --git a/MS_0.1.4_20080103/org.eclipse.osee.framework.database/.classpath b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/.classpath
new file mode 100644
index 00000000000..02159672985
--- /dev/null
+++ b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/MS_0.1.4_20080103/org.eclipse.osee.framework.database/.project b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/.project
new file mode 100644
index 00000000000..c6fe077dcdf
--- /dev/null
+++ b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/.project
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.osee.framework.database</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.apache.derby.ui.derbyEngine</nature>
+ </natures>
+</projectDescription>
diff --git a/MS_0.1.4_20080103/org.eclipse.osee.framework.database/META-INF/MANIFEST.MF b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/META-INF/MANIFEST.MF
new file mode 100644
index 00000000000..4eed4b89ae4
--- /dev/null
+++ b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/META-INF/MANIFEST.MF
@@ -0,0 +1,23 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Database Plug-in (Incubation)
+Bundle-SymbolicName: org.eclipse.osee.framework.database;singleton:=true
+Bundle-Version: 0.1.0.qualifier
+Bundle-ClassPath: database.jar
+Bundle-Activator: org.eclipse.osee.framework.database.DatabaseActivator
+Export-Package: org.eclipse.osee.framework.database,
+ org.eclipse.osee.framework.database.config,
+ org.eclipse.osee.framework.database.core,
+ org.eclipse.osee.framework.database.initialize,
+ org.eclipse.osee.framework.database.initialize.tasks,
+ org.eclipse.osee.framework.database.initialize.tasks.relational,
+ org.eclipse.osee.framework.database.utility
+Require-Bundle: org.eclipse.ui,
+ org.eclipse.ui.ide,
+ org.eclipse.core.runtime,
+ org.eclipse.osee.framework.jdk.core,
+ org.eclipse.core.resources,
+ org.eclipse.osee.framework.ui.plugin,
+ org.eclipse.osee.framework.plugin.core
+Eclipse-LazyStart: true
+Bundle-Vendor: Eclipse.org
diff --git a/MS_0.1.4_20080103/org.eclipse.osee.framework.database/build.properties b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/build.properties
new file mode 100644
index 00000000000..d1306cd5bf5
--- /dev/null
+++ b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/build.properties
@@ -0,0 +1,9 @@
+source.database.jar = src/
+output.database.jar = bin/
+bin.includes = plugin.xml,\
+ database.jar,\
+ META-INF/,\
+ support/,\
+ src/
+bin.excludes = support/RelationSide.java
+
diff --git a/MS_0.1.4_20080103/org.eclipse.osee.framework.database/plugin.xml b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/plugin.xml
new file mode 100644
index 00000000000..b5ef45dcda8
--- /dev/null
+++ b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/plugin.xml
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.0"?>
+<plugin>
+ <extension-point id="IDbInitializationTask" name="DbInitializationTask" schema="schema/IDbInitializationTask.exsd"/>
+ <extension-point id="ProductionDatabase" name="Production Database" schema="schema/ProductionDatabase.exsd"/>
+ <extension-point id="AddDbInitChoice" name="Add Database Initialization Choice" schema="schema/AddDbInitChoice.exsd"/>
+ <extension
+ id="configClient"
+ point="org.eclipse.core.runtime.applications">
+ <application>
+ <run class="org.eclipse.osee.framework.database.ConfigDatabase"/>
+ </application>
+ </extension>
+<extension
+ point="org.eclipse.ui.popupMenus">
+ <objectContribution
+ adaptable="true"
+ id="osee.database.projectContribution"
+ objectClass="org.eclipse.core.resources.IResource">
+ <action
+ class="org.eclipse.osee.framework.database.GenerateTypeEnumAction"
+ id="osee.define.popup.open.artifact"
+ label="Generate Type Classes"
+ menubarPath="osee.define.menu.main/main"/>
+ </objectContribution>
+
+</extension>
+<extension
+ id="BackupTableData"
+ point="org.eclipse.osee.framework.database.IDbInitializationTask">
+ <DatabaseTask
+ classname="org.eclipse.osee.framework.database.initialize.tasks.relational.BackupTableData"/>
+</extension>
+<extension
+ id="RestoreTableData"
+ point="org.eclipse.osee.framework.database.IDbInitializationTask">
+ <DatabaseTask classname="org.eclipse.osee.framework.database.initialize.tasks.relational.RestoreTableData"/>
+</extension>
+<extension
+ id="ImportDataFromDbService"
+ point="org.eclipse.osee.framework.database.IDbInitializationTask">
+ <DatabaseTask classname="org.eclipse.osee.framework.database.initialize.tasks.ImportDataFromDbService"/>
+</extension>
+<extension
+ id="availableDbTasks"
+ name="availableDbTasks"
+ point="org.eclipse.core.runtime.applications">
+ <application>
+ <run class="org.eclipse.osee.framework.database.PlatformRunnableAvailableInitTasks"/>
+ </application>
+</extension>
+
+
+</plugin>
diff --git a/MS_0.1.4_20080103/org.eclipse.osee.framework.database/schema/AddDbInitChoice.exsd b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/schema/AddDbInitChoice.exsd
new file mode 100644
index 00000000000..17670ac4781
--- /dev/null
+++ b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/schema/AddDbInitChoice.exsd
@@ -0,0 +1,105 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.eclipse.osee.framework.database">
+<annotation>
+ <appInfo>
+ <meta.schema plugin="org.eclipse.osee.framework.database" id="AddDbInitChoice" name="Add Database Initialization Choice"/>
+ </appInfo>
+ <documentation>
+ [Enter description of this extension point.]
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <complexType>
+ <sequence>
+ <element ref="dbInitChoice"/>
+ </sequence>
+ <attribute name="point" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appInfo>
+ <meta.attribute translatable="true"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="dbInitChoice">
+ <complexType>
+ <attribute name="classname" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appInfo>
+ <meta.attribute kind="java" basedOn=":org.eclipse.osee.framework.database.utility.IAddDbInitChoice"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="since"/>
+ </appInfo>
+ <documentation>
+ [Enter the first release in which this extension point appears.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="examples"/>
+ </appInfo>
+ <documentation>
+ [Enter extension point usage example here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="apiInfo"/>
+ </appInfo>
+ <documentation>
+ [Enter API information here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="implementation"/>
+ </appInfo>
+ <documentation>
+ [Enter information about supplied implementation of this extension point.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="copyright"/>
+ </appInfo>
+ <documentation>
+
+ </documentation>
+ </annotation>
+
+</schema>
diff --git a/MS_0.1.4_20080103/org.eclipse.osee.framework.database/schema/IDbInitializationTask.exsd b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/schema/IDbInitializationTask.exsd
new file mode 100644
index 00000000000..cc9ef286727
--- /dev/null
+++ b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/schema/IDbInitializationTask.exsd
@@ -0,0 +1,107 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.eclipse.osee.framework.database">
+<annotation>
+ <appInfo>
+ <meta.schema plugin="org.eclipse.osee.framework.database" id="IDbInitializationTask" name="DbInitializationTask"/>
+ </appInfo>
+ <documentation>
+ [Enter description of this extension point.]
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <complexType>
+ <sequence>
+ <element ref="DatabaseTask"/>
+ </sequence>
+ <attribute name="point" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appInfo>
+ <meta.attribute translatable="true"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="DatabaseTask">
+ <complexType>
+ <sequence>
+ </sequence>
+ <attribute name="classname" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appInfo>
+ <meta.attribute kind="java" basedOn="IDbInitializationTask"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="since"/>
+ </appInfo>
+ <documentation>
+ [Enter the first release in which this extension point appears.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="examples"/>
+ </appInfo>
+ <documentation>
+ [Enter extension point usage example here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="apiInfo"/>
+ </appInfo>
+ <documentation>
+ [Enter API information here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="implementation"/>
+ </appInfo>
+ <documentation>
+ [Enter information about supplied implementation of this extension point.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="copyright"/>
+ </appInfo>
+ <documentation>
+
+ </documentation>
+ </annotation>
+
+</schema>
diff --git a/MS_0.1.4_20080103/org.eclipse.osee.framework.database/schema/ProductionDatabase.exsd b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/schema/ProductionDatabase.exsd
new file mode 100644
index 00000000000..3374d522439
--- /dev/null
+++ b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/schema/ProductionDatabase.exsd
@@ -0,0 +1,102 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.eclipse.osee.framework.database">
+<annotation>
+ <appInfo>
+ <meta.schema plugin="org.eclipse.osee.framework.database" id="ProductionDatabase" name="Production Database"/>
+ </appInfo>
+ <documentation>
+ [Enter description of this extension point.]
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <complexType>
+ <sequence>
+ <element ref="ProductionDatabase"/>
+ </sequence>
+ <attribute name="point" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appInfo>
+ <meta.attribute translatable="true"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="ProductionDatabase">
+ <complexType>
+ <attribute name="databaseInstance" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="since"/>
+ </appInfo>
+ <documentation>
+ [Enter the first release in which this extension point appears.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="examples"/>
+ </appInfo>
+ <documentation>
+ [Enter extension point usage example here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="apiInfo"/>
+ </appInfo>
+ <documentation>
+ [Enter API information here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="implementation"/>
+ </appInfo>
+ <documentation>
+ [Enter information about supplied implementation of this extension point.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="copyright"/>
+ </appInfo>
+ <documentation>
+
+ </documentation>
+ </annotation>
+
+</schema>
diff --git a/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/ConfigDatabase.java b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/ConfigDatabase.java
new file mode 100644
index 00000000000..5d911d2e09c
--- /dev/null
+++ b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/ConfigDatabase.java
@@ -0,0 +1,45 @@
+/*******************************************************************************
+ * 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.database;
+
+import org.eclipse.equinox.app.IApplication;
+import org.eclipse.equinox.app.IApplicationContext;
+import org.eclipse.osee.framework.database.initialize.LaunchOseeDbConfigClient;
+
+public class ConfigDatabase implements IApplication {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.equinox.app.IApplication#start(org.eclipse.equinox.app.IApplicationContext)
+ */
+ public Object start(IApplicationContext context) throws Exception {
+ LaunchOseeDbConfigClient.main(null);
+ // keepAlive = new Object();
+ // synchronized (keepAlive) {
+ // try {
+ // keepAlive.wait();
+ // } catch (InterruptedException e) {
+ // e.printStackTrace();
+ // }
+ // }
+ return EXIT_OK;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.equinox.app.IApplication#stop()
+ */
+ public void stop() {
+ }
+
+}
diff --git a/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/DatabaseActivator.java b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/DatabaseActivator.java
new file mode 100644
index 00000000000..b6c078b81f1
--- /dev/null
+++ b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/DatabaseActivator.java
@@ -0,0 +1,56 @@
+/*******************************************************************************
+ * 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.database;
+
+import java.util.List;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.osee.framework.plugin.core.config.ConfigUtil;
+import org.eclipse.osee.framework.plugin.core.util.ExtensionPoints;
+import org.eclipse.osee.framework.ui.plugin.OseeUiActivator;
+
+/**
+ * The main plug-in class to be used in the desktop.
+ *
+ * @author Ryan D. Brooks
+ */
+public class DatabaseActivator extends OseeUiActivator {
+
+ // The shared instance.
+ private static DatabaseActivator plugin;
+
+ /**
+ * The constructor.
+ */
+ public DatabaseActivator() {
+ plugin = this;
+ }
+
+ /**
+ * Returns the shared instance.
+ */
+ public static DatabaseActivator getInstance() {
+ return plugin;
+ }
+
+ public boolean isProductionDb() {
+ List<IConfigurationElement> elements =
+ ExtensionPoints.getExtensionElements(DatabaseActivator.getInstance(), "ProductionDatabase",
+ "ProductionDatabase");
+
+ String dbServiceId = ConfigUtil.getConfigFactory().getOseeConfig().getServiceID();
+ for (IConfigurationElement element : elements) {
+ if (dbServiceId.equals(element.getAttribute("databaseInstance"))) {
+ return true;
+ }
+ }
+ return false;
+ }
+} \ No newline at end of file
diff --git a/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/GenerateTypeEnumAction.java b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/GenerateTypeEnumAction.java
new file mode 100644
index 00000000000..e7dbde41351
--- /dev/null
+++ b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/GenerateTypeEnumAction.java
@@ -0,0 +1,158 @@
+/*******************************************************************************
+ * 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.database;
+
+import java.io.File;
+import java.util.Iterator;
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.viewers.CheckStateChangedEvent;
+import org.eclipse.jface.viewers.CheckboxTreeViewer;
+import org.eclipse.jface.viewers.ICheckStateListener;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerFilter;
+import org.eclipse.jface.window.Window;
+import org.eclipse.osee.framework.ui.plugin.util.AWorkspace;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.ui.IActionDelegate;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.dialogs.CheckedTreeSelectionDialog;
+import org.eclipse.ui.model.WorkbenchContentProvider;
+import org.eclipse.ui.model.WorkbenchLabelProvider;
+
+public class GenerateTypeEnumAction implements IActionDelegate {
+
+ public GenerateTypeEnumAction() {
+ super();
+ }
+
+ @SuppressWarnings("unchecked")
+ public void run(IAction action) {
+ try {
+ StructuredSelection sel = AWorkspace.getSelection();
+ Iterator i = sel.iterator();
+ File selection = null;
+ while (i.hasNext()) {
+ Object obj = i.next();
+ if (obj instanceof IResource) {
+ IResource resource = (IResource) obj;
+ if (resource != null) {
+ selection = resource.getLocation().toFile();
+ if (selection != null) {
+
+ Object destinationObj = getFolderToStoreAutoGenFilesIn(resource);
+ if (destinationObj instanceof IContainer) {
+ IContainer destinationFolder = (IContainer) destinationObj;
+ File storeAt = destinationFolder.getLocation().toFile();
+ SkynetTypesEnumGenerator gen = new SkynetTypesEnumGenerator();
+ gen.extractTypesFromSheet(selection, storeAt);
+ gen.finish();
+
+ destinationFolder.refreshLocal(IResource.DEPTH_INFINITE, null);
+ }
+ }
+ }
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ private Object getFolderToStoreAutoGenFilesIn(IResource resource) {
+ CheckedTreeSelectionDialog resourceDialog =
+ new ResourceSelectionTree(PlatformUI.getWorkbench().getDisplay().getActiveShell(),
+ new WorkbenchLabelProvider(), new WorkbenchContentProvider());
+
+ resourceDialog.setInput(resource.getWorkspace().getRoot());
+ resourceDialog.addFilter(new ViewerFilter() {
+
+ @Override
+ public boolean select(Viewer viewer, Object parentElement, Object element) {
+ IResource resource = null;
+ if (element instanceof IContainer) {
+ IContainer container = (IContainer) element;
+ String name = container.getName();
+ if (name.startsWith(".") == false && name.equals("bin") == false) {
+ resource = container;
+ }
+ }
+ if (resource != null) {
+ return true;
+ }
+ return false;
+ }
+ });
+ resourceDialog.setMessage("Select where Auto-Generated classes should be stored.");
+ resourceDialog.setTitle("Select Destination");
+ resourceDialog.setEmptyListMessage("No Projects Available");
+ resourceDialog.setInitialSelection(resource.getParent());
+ resourceDialog.setExpandedElements(new Object[] {resource.getParent()});
+ int result = resourceDialog.open();
+ return result != Window.CANCEL ? resourceDialog.getFirstResult() : null;
+ }
+
+ public void selectionChanged(IAction action, ISelection selection) {
+ }
+
+ private final class ResourceSelectionTree extends CheckedTreeSelectionDialog {
+
+ public ResourceSelectionTree(Shell parent, ILabelProvider labelProvider, ITreeContentProvider contentProvider) {
+ super(parent, labelProvider, contentProvider);
+ }
+
+ protected Control createDialogArea(Composite parent) {
+ Composite composite = new Composite(parent, SWT.NONE);
+ GridLayout layout = new GridLayout();
+ layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
+ layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
+ layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
+ layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
+ composite.setLayout(layout);
+ composite.setLayoutData(new GridData(GridData.FILL_BOTH));
+ applyDialogFont(composite);
+
+ Label messageLabel = createMessageArea(composite);
+ CheckboxTreeViewer treeViewer = createTreeViewer(composite);
+ GridData data = new GridData(GridData.FILL_BOTH);
+ data.widthHint = convertWidthInCharsToPixels(80);
+ data.heightHint = convertHeightInCharsToPixels(16);
+ Tree treeWidget = treeViewer.getTree();
+ treeViewer.addCheckStateListener(new ICheckStateListener() {
+
+ public void checkStateChanged(CheckStateChangedEvent event) {
+ boolean wasChecked = event.getChecked();
+ getTreeViewer().setAllChecked(false);
+ event.getCheckable().setChecked(event.getElement(), wasChecked);
+ }
+
+ });
+ treeWidget.setLayoutData(data);
+ treeWidget.setFont(parent.getFont());
+ messageLabel.setEnabled(true);
+ treeWidget.setEnabled(true);
+ return composite;
+ }
+ };
+}
diff --git a/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/PlatformRunnableAvailableInitTasks.java b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/PlatformRunnableAvailableInitTasks.java
new file mode 100644
index 00000000000..7ef6208013a
--- /dev/null
+++ b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/PlatformRunnableAvailableInitTasks.java
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * 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.database;
+
+import org.eclipse.core.runtime.IExtension;
+import org.eclipse.core.runtime.IExtensionPoint;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.equinox.app.IApplication;
+import org.eclipse.equinox.app.IApplicationContext;
+
+public class PlatformRunnableAvailableInitTasks implements IApplication {
+
+ private void printExtensionPoints(String pointId) {
+ System.out.println("Point [" + pointId + "] search results:");
+ IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(pointId);
+ if (point != null) {
+ for (IExtension ex : point.getExtensions()) {
+ System.out.println(" " + ex.getNamespaceIdentifier() + "/" + ex.getUniqueIdentifier());
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.equinox.app.IApplication#start(org.eclipse.equinox.app.IApplicationContext)
+ */
+ public Object start(IApplicationContext context) throws Exception {
+ printExtensionPoints("org.eclipse.osee.framework.database.IDbInitializationTask");
+ printExtensionPoints("org.eclipse.osee.framework.database.SkynetDbTypes");
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.equinox.app.IApplication#stop()
+ */
+ public void stop() {
+ }
+}
diff --git a/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/SkynetTypesEnumGenerator.java b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/SkynetTypesEnumGenerator.java
new file mode 100644
index 00000000000..1fb9cc384b6
--- /dev/null
+++ b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/SkynetTypesEnumGenerator.java
@@ -0,0 +1,300 @@
+/*******************************************************************************
+ * 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.database;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.sql.SQLException;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.TreeSet;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import java.util.regex.Pattern;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.osee.framework.jdk.core.util.io.xml.ExcelSaxHandler;
+import org.eclipse.osee.framework.jdk.core.util.io.xml.RowProcessor;
+import org.eclipse.osee.framework.plugin.core.config.ConfigUtil;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.XMLReader;
+import org.xml.sax.helpers.XMLReaderFactory;
+
+public class SkynetTypesEnumGenerator implements RowProcessor {
+ private static final Logger logger = ConfigUtil.getConfigFactory().getLogger(SkynetTypesEnumGenerator.class);
+
+ private static final Pattern nonJavaCharP = Pattern.compile("[^a-zA-Z_0-9]");
+
+ private static final String relationImports =
+ "import org.eclipse.osee.framework.skynet.core.artifact.Branch;\n" + "import org.eclipse.osee.framework.skynet.core.relation.IRelationEnumeration;\n" + "import org.eclipse.osee.framework.skynet.core.relation.IRelationLink;\n" + "import org.eclipse.osee.framework.skynet.core.relation.IRelationLinkDescriptor;\n" + "import org.eclipse.osee.framework.skynet.core.relation.RelationPersistenceManager;\n\n";
+
+ private static final String relationEnumCode =
+ " private boolean sideA;\n" + "\n" + " private String typeName;\n" + " private static final RelationPersistenceManager relationManager = RelationPersistenceManager.getInstance();\n" + "\n" + " private CLASSNAME_PLACEHOLDER(boolean sideA, String typeName) {\n" + " this.sideA = sideA;\n" + " this.typeName = typeName;\n" + " RelationPersistenceManager.sideHash.put(typeName, sideA, this);\n" + " }\n" + " \n" + " public static IRelationEnumeration getRelationSide(String relationType, String relationSide, Branch branch) {\n" + " IRelationLinkDescriptor desc = relationManager.getIRelationLinkDescriptor(relationType, branch);\n" + " boolean isSideA = (desc.getSideAName().equals(relationSide));\n" + " return RelationPersistenceManager.sideHash.get(relationType, isSideA);\n" + " }\n" + "\n" + " /**\n" + " * @return Returns the sideName.\n" + " */\n" + " public boolean isSideA() {\n" + " return sideA;\n" + " }\n" + "\n" + " public String getSideName(Branch branch) {\n" + " if (isSideA())\n" + " return getDescriptor(branch).getSideAName();\n" + " else\n" + " return getDescriptor(branch).getSideBName();\n" + " }\n" + "\n" + " /**\n" + " * @return Returns the typeName.\n" + " */\n" + " public String getTypeName() {\n" + " return typeName;\n" + " }\n" + "\n" + " public IRelationLinkDescriptor getDescriptor(Branch branch) {\n" + " return relationManager.getIRelationLinkDescriptor(typeName, branch);\n" + " }\n" + " \n" + " public boolean isThisType(IRelationLink link) {\n" + " return link.getLinkDescriptor().getName().equals(typeName);\n" + " }\n";
+
+ private enum Table {
+ ARTIFACT_TYPE_TABLE, ATTRIBUTE_TYPE_TABLE, ATTRIBUTE_MAP_TABLE, RELATION_TYPE_TABLE, RELATION_SIDE_TABLE
+ }
+
+ private static final String description = "Setup artifact, attribute, and relation type data";
+
+ private final ExcelSaxHandler excelHandler;
+
+ private Table currentTable;
+
+ private Iterator<Table> tableIterator;
+
+ private boolean done;
+
+ private final XMLReader xmlReader;
+
+ private TreeSet<String> artifacts;
+
+ private TreeSet<String> attributes;
+
+ private TreeSet<String> relations;
+
+ private String sheetName;
+
+ private File destinationDir;
+
+ private static final String skynetTypeCode =
+ " private String name;\n private CLASSNAME_PLACEHOLDER(String name){ this.name = name; }\n public String getName(){ return this.name;}\n";
+
+ /**
+ * @throws SAXException
+ * @throws SAXException
+ * @throws IOException
+ * @throws SQLException
+ */
+ public SkynetTypesEnumGenerator() throws SAXException {
+
+ excelHandler = new ExcelSaxHandler(this, true, true);
+
+ xmlReader = XMLReaderFactory.createXMLReader();
+ xmlReader.setContentHandler(excelHandler);
+
+ artifacts = new TreeSet<String>();
+ attributes = new TreeSet<String>();
+ relations = new TreeSet<String>();
+ }
+
+ public void extractTypesFromSheet(File importFile, File destinationDir) throws IOException, SAXException {
+ done = false;
+ tableIterator = Arrays.asList(Table.values()).iterator();
+ xmlReader.parse(new InputSource(new FileInputStream(importFile)));
+
+ this.destinationDir =
+ (destinationDir != null && destinationDir.isDirectory()) ? destinationDir : importFile.getParentFile();
+ }
+
+ public void finish() throws SQLException, CoreException, IOException {
+ try {
+ BufferedWriter out;
+ //relation enum gen
+ String relClassName = this.sheetName + "_RELATIONS";
+ out = new BufferedWriter(new FileWriter(new File(destinationDir, relClassName + ".java")));
+ out.append("\n\n");
+ out.append(relationImports);
+ out.append("public enum ");
+ out.append(relClassName);
+ out.append(" implements IRelationEnumeration {\n");
+ Iterator<String> it = relations.iterator();
+ while (it.hasNext()) {
+ out.append(" ");
+ out.append(it.next());
+ if (it.hasNext()) out.append(",\n");
+ }
+ out.append(";\n");
+ out.append(relationEnumCode.replace("CLASSNAME_PLACEHOLDER", relClassName));
+ out.append("}");
+ out.close();
+ //attribute enum gen
+ String attrClassName = this.sheetName + "_ATTRIBUTES";
+ out = new BufferedWriter(new FileWriter(new File(destinationDir, attrClassName + ".java")));
+ out.append("\n\nimport org.eclipse.osee.framework.skynet.core.ISkynetType;\n\npublic enum ");
+ out.append(attrClassName);
+ out.append(" implements ISkynetType {\n");
+ it = attributes.iterator();
+ while (it.hasNext()) {
+ out.append(" ");
+ out.append(it.next());
+ if (it.hasNext()) out.append(",\n");
+ }
+ out.append(";\n\n");
+ out.append(skynetTypeCode.replace("CLASSNAME_PLACEHOLDER", attrClassName));
+ out.append("}");
+ out.close();
+ //artifact enum gen
+ String artClassName = this.sheetName + "_ARTIFACTS";
+ out = new BufferedWriter(new FileWriter(new File(destinationDir, artClassName + ".java")));
+ out.append("\n\nimport org.eclipse.osee.framework.skynet.core.ISkynetType;\n\npublic enum ");
+ out.append(artClassName);
+ out.append(" implements ISkynetType {\n");
+ it = artifacts.iterator();
+ while (it.hasNext()) {
+ out.append(" ");
+ out.append(it.next());
+ if (it.hasNext()) out.append(",\n");
+ }
+ out.append(";\n\n");
+ out.append(skynetTypeCode.replace("CLASSNAME_PLACEHOLDER", artClassName));
+ out.append("}");
+ out.close();
+
+ } catch (Exception ex) {
+ logger.log(Level.SEVERE, ex.toString(), ex);
+ }
+ }
+
+ public static String getDescription() {
+ return description;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see osee.define.artifact.Import.RowProcessor#processHeaderRow(java.lang.String[])
+ */
+ public void processHeaderRow(String[] headerRow) {
+ if (done) return;
+ if (tableIterator.hasNext()) {
+ currentTable = tableIterator.next();
+ } else {
+ throw new IllegalArgumentException(
+ "Encountered row past end of last expected table: " + Arrays.deepToString(headerRow));
+ }
+ }
+
+ /**
+ * import Artifacts
+ *
+ * @param row
+ */
+ public void processRow(String[] row) {
+ if (done) return;
+ try {
+ switch (currentTable) {
+ case ARTIFACT_TYPE_TABLE:
+ addArtifactType(row);
+ break;
+ case ATTRIBUTE_TYPE_TABLE:
+ addAttributeType(row);
+ break;
+ case RELATION_TYPE_TABLE:
+ addRelationType(row);
+ break;
+ default:
+ break;
+ }
+ } catch (SQLException ex) {
+ logger.log(Level.SEVERE, ex.toString(), ex);
+ } catch (ClassNotFoundException ex) {
+ logger.log(Level.SEVERE, ex.toString(), ex);
+ } catch (Exception ex) {
+ logger.log(Level.SEVERE, ex.toString(), ex);
+ }
+ }
+
+ /**
+ * @param row
+ * @throws ClassNotFoundException
+ * @throws SQLException
+ */
+ private void addAttributeType(String[] row) throws ClassNotFoundException, SQLException {
+ // String attrBaseType = row[0];
+ String attributeName = row[1];
+ // String defaultValue = row[2];
+ // String validityXml = row[3];
+ // int minOccurrence = getQuantity(row[4]);
+ // int maxOccurrence = getQuantity(row[5]);
+ // String tipText = row[6];
+
+ attributes.add(nonJavaCharP.matcher(attributeName).replaceAll("_").toUpperCase() + "(\"" + attributeName + "\")");
+ }
+
+ /**
+ * @param row
+ */
+ private void addRelationType(String[] row) {
+
+ String relationTypeName = row[0];
+ String sideAName = row[1];
+ // String A2BPhrase = row[2];
+ String sideBName = row[3];
+ // String B2APhrase = row[4];
+ // String shortName = row[5];
+ generateRelationSideEnum(relationTypeName, sideAName, sideBName);
+ }
+
+ private void generateRelationSideEnum(String relationTypeName, String sideAName, String sideBName) {
+ sideAName = nonJavaCharP.matcher(sideAName).replaceAll("_").toUpperCase();
+ sideBName = nonJavaCharP.matcher(sideBName).replaceAll("_").toUpperCase();
+ String enumPrefix = nonJavaCharP.matcher(relationTypeName).replaceAll("_").toUpperCase();
+ relations.add(String.format("%s__%s(true, \"%s\"),\n %s__%s(false, \"%s\")", enumPrefix, sideAName,
+ relationTypeName, enumPrefix, sideBName, relationTypeName));
+ }
+
+ /**
+ * @param row
+ */
+ private void addArtifactType(String[] row) {
+ // String factoryClassName = row[0];
+ String artifactTypeName = row[1];
+ // String superTypeName = row[2];
+
+ artifacts.add(nonJavaCharP.matcher(artifactTypeName).replaceAll("_").toUpperCase() + "(\"" + artifactTypeName + "\")");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see osee.define.artifact.Import.RowProcessor#processEmptyRow(java.lang.String[])
+ */
+ public void processEmptyRow() {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see osee.define.artifact.Import.RowProcessor#processCommentRow(java.lang.String[])
+ */
+ public void processCommentRow(String[] row) {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see osee.define.artifact.Import.RowProcessor#reachedEndOfWorksheet()
+ */
+ public void reachedEndOfWorksheet() {
+ done = true;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see osee.define.artifact.Import.RowProcessor#detectedTotalRowCount(int)
+ */
+ public void detectedRowAndColumnCounts(int rowCount, int columnCount) {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see osee.define.artifact.Import.RowProcessor#foundStartOfWorksheet(java.lang.String)
+ */
+ public void foundStartOfWorksheet(String sheetName) {
+ this.sheetName = nonJavaCharP.matcher(sheetName).replaceAll("_").toUpperCase();
+ }
+}
diff --git a/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/config/SchemaConfigUtility.java b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/config/SchemaConfigUtility.java
new file mode 100644
index 00000000000..74299eff634
--- /dev/null
+++ b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/config/SchemaConfigUtility.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.database.config;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.eclipse.osee.framework.ui.plugin.util.db.data.SchemaData;
+import org.eclipse.osee.framework.ui.plugin.util.db.data.TableElement;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class SchemaConfigUtility {
+
+ /**
+ * Reads files containing Schema Table information and groups tables by schema.
+ */
+ public static Map<String, SchemaData> getUserDefinedConfig(List<URL> files) {
+ Map<String, SchemaData> userSpecifiedConfig = new HashMap<String, SchemaData>();
+
+ for (URL file : files) {
+ SchemaData schemaData;
+ try {
+ schemaData = TableConfigUtility.getInstance().getTableConfigData(file.openStream());
+ List<TableElement> tables = schemaData.getTablesOrderedByDependency();
+ for (TableElement table : tables) {
+ String schemaAddress = table.getSchema();
+
+ SchemaData schema = null;
+ if (!userSpecifiedConfig.containsKey(schemaAddress)) {
+ schema = new SchemaData();
+ userSpecifiedConfig.put(schemaAddress, schema);
+ } else {
+ schema = userSpecifiedConfig.get(schemaAddress);
+ }
+ schema.addTableDefinition(table);
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ return userSpecifiedConfig;
+ }
+}
diff --git a/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/config/TableConfigUtility.java b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/config/TableConfigUtility.java
new file mode 100644
index 00000000000..bb4883b824d
--- /dev/null
+++ b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/config/TableConfigUtility.java
@@ -0,0 +1,232 @@
+/*******************************************************************************
+ * 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.database.config;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import javax.xml.parsers.ParserConfigurationException;
+import org.eclipse.osee.framework.jdk.core.util.xml.Jaxp;
+import org.eclipse.osee.framework.plugin.core.config.ConfigUtil;
+import org.eclipse.osee.framework.ui.plugin.util.db.data.AppliesToClause;
+import org.eclipse.osee.framework.ui.plugin.util.db.data.ColumnMetadata;
+import org.eclipse.osee.framework.ui.plugin.util.db.data.ConstraintElement;
+import org.eclipse.osee.framework.ui.plugin.util.db.data.ConstraintFactory;
+import org.eclipse.osee.framework.ui.plugin.util.db.data.ConstraintTypes;
+import org.eclipse.osee.framework.ui.plugin.util.db.data.ForeignKey;
+import org.eclipse.osee.framework.ui.plugin.util.db.data.IndexElement;
+import org.eclipse.osee.framework.ui.plugin.util.db.data.ReferenceClause;
+import org.eclipse.osee.framework.ui.plugin.util.db.data.SchemaData;
+import org.eclipse.osee.framework.ui.plugin.util.db.data.TableElement;
+import org.eclipse.osee.framework.ui.plugin.util.db.data.AppliesToClause.AppliesToEntries;
+import org.eclipse.osee.framework.ui.plugin.util.db.data.AppliesToClause.OrderType;
+import org.eclipse.osee.framework.ui.plugin.util.db.data.ConstraintElement.ConstraintFields;
+import org.eclipse.osee.framework.ui.plugin.util.db.data.IndexElement.IndexFields;
+import org.eclipse.osee.framework.ui.plugin.util.db.data.ReferenceClause.OnDeleteEnum;
+import org.eclipse.osee.framework.ui.plugin.util.db.data.ReferenceClause.OnUpdateEnum;
+import org.eclipse.osee.framework.ui.plugin.util.db.data.ReferenceClause.ReferencesFields;
+import org.eclipse.osee.framework.ui.plugin.util.db.data.TableElement.ColumnFields;
+import org.eclipse.osee.framework.ui.plugin.util.db.data.TableElement.TableDescriptionFields;
+import org.eclipse.osee.framework.ui.plugin.util.db.data.TableElement.TableSections;
+import org.eclipse.osee.framework.ui.plugin.util.db.data.TableElement.TableTags;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.xml.sax.SAXException;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class TableConfigUtility {
+
+ private static Logger logger = ConfigUtil.getConfigFactory().getLogger(TableConfigUtility.class);
+ private static TableConfigUtility instance = null;
+
+ private SchemaData parsedData;
+ private Document document;
+
+ private TableConfigUtility() {
+ }
+
+ public static TableConfigUtility getInstance() {
+ if (instance == null) instance = new TableConfigUtility();
+ return instance;
+ }
+
+ public SchemaData getTableConfigData(InputStream configFile) {
+ this.document = xmlFileToDocument(configFile);
+ this.parsedData = parseTableConfigData();
+ return parsedData;
+ }
+
+ public static Document xmlFileToDocument(InputStream configFile) {
+ Document document = null;
+ try {
+ document = Jaxp.readXmlDocument(configFile);
+ } catch (ParserConfigurationException ex) {
+ logger.log(Level.SEVERE, ex.toString(), ex);
+ } catch (SAXException ex) {
+ logger.log(Level.SEVERE, ex.toString(), ex);
+ } catch (IOException ex) {
+ logger.log(Level.SEVERE, ex.toString(), ex);
+ }
+ return document;
+ }
+
+ private void parseTableDescription(Element element, TableElement tableEntry) {
+ NamedNodeMap attributes = element.getAttributes();
+ for (int i = 0; i < attributes.getLength(); i++) {
+ Attr attribute = (Attr) attributes.item(i);
+ TableDescriptionFields tableField = TableDescriptionFields.valueOf(attribute.getName());
+ tableEntry.addTableDescription(tableField, attribute.getValue());
+ }
+ }
+
+ private void parseColumnEntries(Element element, TableElement tableEntry) {
+ List<Element> columns = Jaxp.getChildDirects(element, TableSections.Column.name());
+ for (Element column : columns) {
+ NamedNodeMap attributes = column.getAttributes();
+ ColumnMetadata columnMetadata = new ColumnMetadata("");
+ for (int i = 0; i < attributes.getLength(); i++) {
+ Attr attribute = (Attr) attributes.item(i);
+ ColumnFields columnField = ColumnFields.valueOf(attribute.getName());
+ columnMetadata.addColumnField(columnField, attribute.getValue().toUpperCase());
+ }
+ tableEntry.addColumn(columnMetadata);
+ }
+ }
+
+ private void parseConstraintEntries(Element element, TableElement tableEntry) {
+ List<Element> constraints = Jaxp.getChildDirects(element, TableSections.Constraint.name());
+ for (Element constraint : constraints) {
+ Attr type = constraint.getAttributeNode(ConstraintFields.type.name());
+ Attr id = constraint.getAttributeNode(ConstraintFields.id.name());
+ String schema = constraint.getAttribute(ConstraintFields.schema.name());
+ String deferrable = constraint.getAttribute(ConstraintFields.deferrable.name());
+ if (type != null && id != null) {
+
+ ConstraintElement constraintElement =
+ ConstraintFactory.getConstraint(ConstraintTypes.textToType(type.getValue().toUpperCase()),
+ schema.toUpperCase(), id.getValue().toUpperCase(),
+ deferrable.equalsIgnoreCase(Boolean.toString(true)));
+
+ Attr appliesTo = constraint.getAttributeNode(ConstraintFields.appliesTo.name());
+ if (appliesTo != null) {
+ String[] columns = appliesTo.getValue().split(",");
+ for (String column : columns) {
+ constraintElement.addColumn(column.toUpperCase());
+ }
+ }
+
+ if (constraintElement instanceof ForeignKey) {
+ Element reference = Jaxp.getChildDirect(constraint, ReferenceClause.REFERENCES_TAG);
+ if (reference != null) {
+ Attr table = reference.getAttributeNode(ReferencesFields.table.name());
+ Attr refColumn = reference.getAttributeNode(ReferencesFields.column.name());
+ Attr onUpdate = reference.getAttributeNode(ReferencesFields.onUpdate.name());
+ Attr onDelete = reference.getAttributeNode(ReferencesFields.onDelete.name());
+ String refSchema = reference.getAttribute(ReferencesFields.schema.name());
+
+ if (table != null) {
+
+ ReferenceClause references =
+ new ReferenceClause(refSchema.toUpperCase(), table.getValue().toUpperCase());
+ if (refColumn != null) {
+ String[] columns = refColumn.getValue().split(",");
+ for (String column : columns) {
+ references.addColumn(column.toUpperCase());
+ }
+ }
+ if (onUpdate != null) {
+ OnUpdateEnum[] values = OnUpdateEnum.values();
+ for (OnUpdateEnum value : values) {
+ if (value.toString().equals(onUpdate.getValue().toUpperCase())) {
+ references.setOnUpdateAction(value);
+ }
+ }
+ }
+ if (onDelete != null) {
+ OnDeleteEnum[] values = OnDeleteEnum.values();
+ for (OnDeleteEnum value : values) {
+ if (value.toString().equals(onDelete.getValue().toUpperCase())) {
+ references.setOnDeleteAction(value);
+ }
+ }
+ }
+ ((ForeignKey) constraintElement).addReference(references);
+ }
+ }
+ }
+ tableEntry.addConstraint(constraintElement);
+ }
+ }
+ }
+
+ private void parseIndexDataEntries(Element element, TableElement tableEntry) {
+ List<Element> indexDataList = Jaxp.getChildDirects(element, TableSections.Index.name());
+ for (Element indexDataEntry : indexDataList) {
+ String id = indexDataEntry.getAttribute(IndexFields.id.name());
+ String ignore = indexDataEntry.getAttribute(IndexFields.mySqlIgnore.name());
+ Attr indexType = indexDataEntry.getAttributeNode(IndexFields.type.name());
+ if (id.length() > 0) {
+ IndexElement indexData = new IndexElement(id);
+ if (Boolean.parseBoolean(ignore)) {
+ indexData.setMySqlIgnore(true);
+ }
+ if (indexType != null) {
+ indexData.setIndexType(indexType.getValue());
+ }
+ parseAppliesToClause(indexDataEntry, indexData);
+ tableEntry.addIndexData(indexData);
+ }
+ }
+ }
+
+ public void parseAppliesToClause(Element element, IndexElement indexData) {
+ List<Element> appliesToList = Jaxp.getChildDirects(element, AppliesToClause.APPLIES_TO_TAG);
+ for (Element appliesToElement : appliesToList) {
+ String idString = appliesToElement.getAttribute(AppliesToEntries.id.name());
+ String sortString = appliesToElement.getAttribute(AppliesToEntries.sort.name());
+ if (idString.length() > 0) {
+ OrderType orderType = OrderType.Undefined;
+ if (sortString.equalsIgnoreCase("Ascending")) {
+ orderType = OrderType.Ascending;
+ } else if (sortString.equalsIgnoreCase("Descending")) {
+ orderType = OrderType.Descending;
+ }
+ indexData.addAppliesTo(idString, orderType);
+ }
+ }
+ }
+
+ private SchemaData parseTableConfigData() {
+ if (document == null) {
+ return null;
+ }
+ SchemaData tableData = new SchemaData();
+ List<Element> elements = Jaxp.getChildDirects(document.getDocumentElement(), TableTags.Table.name());
+ for (Element element : elements) {
+
+ TableElement tableEntry = new TableElement();
+
+ parseTableDescription(element, tableEntry);
+ parseColumnEntries(element, tableEntry);
+ parseConstraintEntries(element, tableEntry);
+ parseIndexDataEntries(element, tableEntry);
+
+ tableData.addTableDefinition(tableEntry);
+ }
+ return tableData;
+ }
+}
diff --git a/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/core/DatabaseNotSupportedException.java b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/core/DatabaseNotSupportedException.java
new file mode 100644
index 00000000000..71a7a0a5c88
--- /dev/null
+++ b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/core/DatabaseNotSupportedException.java
@@ -0,0 +1,27 @@
+/*******************************************************************************
+ * 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.database.core;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class DatabaseNotSupportedException extends Exception {
+
+ private static final long serialVersionUID = 155062269031207620L;
+
+ public DatabaseNotSupportedException() {
+ super("Database is not supported.");
+ }
+
+ public DatabaseNotSupportedException(String message) {
+ super("Database is not supported. \n" + message);
+ }
+}
diff --git a/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/core/DbClientThread.java b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/core/DbClientThread.java
new file mode 100644
index 00000000000..1f0cc0cb57f
--- /dev/null
+++ b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/core/DbClientThread.java
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * 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.database.core;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import org.eclipse.osee.framework.plugin.core.config.data.DbInformation;
+import org.eclipse.osee.framework.ui.plugin.util.db.DBConnection;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public abstract class DbClientThread extends Thread {
+ protected Connection connection;
+ protected DbInformation databaseService;
+ protected Logger logger;
+
+ public DbClientThread(Logger logger, String threadName, DbInformation databaseService) {
+ this.setName(threadName);
+ this.connection = null;
+ this.databaseService = databaseService;
+ this.logger = logger;
+ }
+
+ public void run() {
+ logger.log(Level.INFO, "Starting " + getName() + "...");
+ try {
+ connection = DBConnection.getNewConnection(databaseService, false);
+ connection.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
+
+ processTask();
+
+ } catch (SQLException ex) {
+ logger.log(Level.SEVERE, ex.getMessage(), ex);
+ } catch (DatabaseNotSupportedException ex) {
+ logger.log(Level.SEVERE, ex.getMessage(), ex);
+ } catch (Exception ex) {
+ logger.log(Level.SEVERE, ex.getMessage(), ex);
+ } catch (ExceptionInInitializerError ex) {
+ logger.log(Level.SEVERE, ex.getMessage(), ex);
+ } finally {
+ if (connection != null) {
+ try {
+ logger.log(Level.INFO, "Closing " + getName() + " Connection...");
+ connection.close();
+ } catch (SQLException ex) {
+ logger.log(Level.SEVERE, ex.getMessage(), ex);
+ }
+ }
+ }
+ }
+
+ public abstract void processTask() throws SQLException, DatabaseNotSupportedException, Exception;
+}
diff --git a/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/core/IConfigClient.java b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/core/IConfigClient.java
new file mode 100644
index 00000000000..4824908fe0e
--- /dev/null
+++ b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/core/IConfigClient.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.database.core;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public interface IConfigClient {
+
+ public abstract void startConfigClient();
+
+}
diff --git a/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/initialize/DbComparator.java b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/initialize/DbComparator.java
new file mode 100644
index 00000000000..1806eb879b4
--- /dev/null
+++ b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/initialize/DbComparator.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.database.initialize;
+
+import java.util.Map;
+import java.util.Set;
+import org.eclipse.osee.framework.ui.plugin.util.db.data.SchemaData;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class DbComparator {
+
+ private Map<String, SchemaData> db1;
+ private Map<String, SchemaData> db2;
+
+ public DbComparator(Map<String, SchemaData> db1, Map<String, SchemaData> db2) {
+ this.db1 = db1;
+ this.db2 = db2;
+ }
+
+ public boolean collectDifferences() {
+ boolean matched = false;
+ if (db1.equals(db2)) {
+ matched = true;
+ } else {
+ matched = false;
+ Set<String> db1Schemas = db1.keySet();
+ Set<String> db2Schemas = db2.keySet();
+ if (!db1Schemas.equals(db2Schemas)) {
+ // TODO - Report here - Schemas Different looking at different items - Done Comparing.
+ } else {
+ // Schemas Equal compare SchemaData
+ // List<SchemaData> db1DiffSchemaData = new ArrayList<SchemaData>();
+ // List<SchemaData> db2DiffSchemaData = new ArrayList<SchemaData>();
+ //
+ // for (String key : db1Schemas) {
+ // SchemaData db1SchemaData = db1.get(key);
+ // SchemaData db2SchemaData = db2.get(key);
+ // if (!db1SchemaData.equals(db2SchemaData)) {
+ // //Build TableMaps so we compare tables correctly
+ // Map<String, TableElement> db1TableMap = db1SchemaData.getTableMap();
+ // Map<String, TableElement> db2TableMap = db2SchemaData.getTableMap();
+ //
+ // Set<String> thisKey1 = db1TableMap.keySet();
+ // Set<String> thatKey2 = db2TableMap.keySet();
+
+ matched = true;
+
+ // if(thisKey1.equals(thatKey2)){
+ // for(String key : thisKey1){
+ // toReturn &= EqualsUtility.areEqual(thisTableMap.get(key), thatTableMap.get(key));
+ // }
+ // } else {
+ // // Keys didn't equal -- Find key that didn't equal??
+ // // compare other tables so you can see if anything else didn't match
+ // toReturn = false;
+ // }
+ }
+ }
+ // }
+ // }
+ return matched;
+ }
+}
diff --git a/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/initialize/DbFactory.java b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/initialize/DbFactory.java
new file mode 100644
index 00000000000..dad7a6cf57a
--- /dev/null
+++ b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/initialize/DbFactory.java
@@ -0,0 +1,67 @@
+/*******************************************************************************
+ * 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.database.initialize;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.List;
+import java.util.logging.Logger;
+import org.eclipse.osee.framework.plugin.core.config.ConfigUtil;
+import org.eclipse.osee.framework.plugin.core.config.SupportedDatabase;
+import org.eclipse.osee.framework.ui.plugin.sql.SqlFactory;
+import org.eclipse.osee.framework.ui.plugin.sql.manager.SqlManager;
+import org.eclipse.osee.framework.ui.plugin.util.db.data.SchemaData;
+import org.eclipse.osee.framework.ui.plugin.util.db.data.TableElement;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class DbFactory {
+
+ private SchemaData schemaData;
+ protected SqlManager sqlManager;
+ protected Connection connection;
+ protected Logger logger;
+
+ public DbFactory(Connection connection, SupportedDatabase databaseType, SchemaData schemaData) {
+ this.schemaData = schemaData;
+ this.connection = connection;
+ this.sqlManager = SqlFactory.getSqlManager(databaseType);
+ this.logger = ConfigUtil.getConfigFactory().getLogger(DbFactory.class);
+ }
+
+ public void createTables() throws SQLException, Exception {
+ List<TableElement> tableDefs = schemaData.getTablesOrderedByDependency();
+ for (TableElement tableDef : tableDefs) {
+ sqlManager.createTable(connection, tableDef);
+ }
+ }
+
+ public void dropTables() throws SQLException, Exception {
+ List<TableElement> tableDefs = schemaData.getTablesOrderedByDependency();
+ for (int index = (tableDefs.size() - 1); index >= 0; index--) {
+ TableElement tableDef = tableDefs.get(index);
+ sqlManager.dropTable(connection, tableDef);
+ }
+ }
+
+ public void createIndeces() throws SQLException, Exception {
+ for (TableElement tableDef : schemaData.getTableMap().values()) {
+ sqlManager.createIndex(connection, tableDef);
+ }
+ }
+
+ public void dropIndeces() throws SQLException, Exception {
+ for (TableElement tableDef : schemaData.getTableMap().values()) {
+ sqlManager.dropIndex(connection, tableDef);
+ }
+ }
+}
diff --git a/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/initialize/DbTaskRunner.java b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/initialize/DbTaskRunner.java
new file mode 100644
index 00000000000..92b6c68a51e
--- /dev/null
+++ b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/initialize/DbTaskRunner.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.database.initialize;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.Queue;
+import org.eclipse.osee.framework.database.core.DatabaseNotSupportedException;
+import org.eclipse.osee.framework.database.initialize.tasks.IDbInitializationTask;
+import org.eclipse.osee.framework.plugin.core.config.SupportedDatabase;
+import org.eclipse.osee.framework.ui.plugin.sql.SqlFactory;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class DbTaskRunner {
+
+ private static DbTaskRunner instance = null;
+
+ private DbTaskRunner() {
+ }
+
+ public static DbTaskRunner getInstance() {
+ if (instance == null) instance = new DbTaskRunner();
+ return instance;
+ }
+
+ public void processTasks(Connection connection, Queue<IDbInitializationTask> tasks) throws SQLException, DatabaseNotSupportedException, Exception {
+ SupportedDatabase databaseType = SqlFactory.getDatabaseType(connection);
+ if (databaseType != null) {
+ int safetyNet = 0;
+ while (!tasks.isEmpty()) {
+ IDbInitializationTask task = tasks.remove();
+ if (task.canRun()) {
+ task.run(connection);
+ safetyNet = 0;
+ } else {
+ tasks.add(task);
+ safetyNet++;
+ if (safetyNet == tasks.size() + 1) {
+ throw new Exception("Unable to run all of the IDbInitializationTask because canRun() failed");
+ }
+ }
+ }
+ } else {
+ throw new DatabaseNotSupportedException("Connected to " + connection.getMetaData().getDatabaseProductName());
+ }
+ System.out.println("finished the initialization");
+ }
+}
diff --git a/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/initialize/LaunchOseeDbConfigClient.java b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/initialize/LaunchOseeDbConfigClient.java
new file mode 100644
index 00000000000..b2e6485981d
--- /dev/null
+++ b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/initialize/LaunchOseeDbConfigClient.java
@@ -0,0 +1,162 @@
+/*******************************************************************************
+ * 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.database.initialize;
+
+import static org.eclipse.osee.framework.jdk.core.util.OseeProperties.OSEE_CONFIG_FACTORY;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtension;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.osee.framework.database.DatabaseActivator;
+import org.eclipse.osee.framework.database.core.DatabaseNotSupportedException;
+import org.eclipse.osee.framework.database.core.DbClientThread;
+import org.eclipse.osee.framework.database.initialize.tasks.IDbInitializationTask;
+import org.eclipse.osee.framework.database.utility.GroupSelection;
+import org.eclipse.osee.framework.jdk.core.util.OseeProperties;
+import org.eclipse.osee.framework.plugin.core.config.ConfigUtil;
+import org.eclipse.osee.framework.plugin.core.config.data.DbInformation;
+import org.eclipse.osee.framework.plugin.core.config.data.DbDetailData.ConfigField;
+import org.osgi.framework.Bundle;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class LaunchOseeDbConfigClient extends DbClientThread {
+
+ private static BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
+
+ public LaunchOseeDbConfigClient(DbInformation databaseService) {
+ super(ConfigUtil.getConfigFactory().getLogger(LaunchOseeDbConfigClient.class), "Config Client Thread",
+ databaseService);
+ }
+
+ @Override
+ public void processTask() throws SQLException, DatabaseNotSupportedException, Exception {
+ logger.log(Level.INFO, "Begin Database Initialization...");
+ run(connection, GroupSelection.getInstance().getDbInitTasks());
+ logger.log(Level.INFO, "Database Initialization Complete.");
+ }
+
+ private static final String dbInitExtensionPointId = "org.eclipse.osee.framework.database.IDbInitializationTask";
+ private Logger logger = ConfigUtil.getConfigFactory().getLogger(LaunchOseeDbConfigClient.class);
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.osee.framework.database.initialize.tasks.IDbInitializationTask#run(java.sql.Connection)
+ */
+ public void run(Connection connection, List<String> extensionIds) throws Exception {
+ for (String pointId : extensionIds) {
+ IExtension extension = Platform.getExtensionRegistry().getExtension(pointId);
+ if (extension == null) {
+ logger.log(Level.SEVERE, "Unable to locate extension [" + pointId + "]");
+ } else {
+ String extsionPointId = extension.getExtensionPointUniqueIdentifier();
+ if (dbInitExtensionPointId.equals(extsionPointId)) {
+ runDbInitTasks(extension, connection);
+ } else {
+ logger.log(Level.SEVERE,
+ "Unknown extension id [" + extsionPointId + "] from extension [" + pointId + "]");
+ }
+ }
+ }
+ }
+
+ /**
+ * @param skynetDbTypesExtensions
+ * @param extensionIds
+ */
+ private void runDbInitTasks(IExtension extension, Connection connection) {
+ IConfigurationElement[] elements = extension.getConfigurationElements();
+ String classname = null;
+ String bundleName = null;
+ for (IConfigurationElement el : elements) {
+ if (el.getName().equals("DatabaseTask")) {
+ classname = el.getAttribute("classname");
+ bundleName = el.getContributor().getName();
+ }
+ }
+ if (classname != null && bundleName != null) {
+ Bundle bundle = Platform.getBundle(bundleName);
+ try {
+ logger.log(Level.INFO, "Starting [" + extension.getUniqueIdentifier() + "]");
+ Class<?> taskClass = bundle.loadClass(classname);
+ Object obj = taskClass.newInstance();
+ IDbInitializationTask task = (IDbInitializationTask) obj;
+ task.run(connection);
+ // logger.log(Level.INFO, "Completed [" + extension.getUniqueIdentifier() + "]");
+ } catch (Exception ex) {
+ logger.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
+ } catch (NoClassDefFoundError er) {
+ logger.log(Level.SEVERE, er.getLocalizedMessage(), er);
+ }
+ }
+ }
+
+ private static String waitForUserResponse() {
+ System.out.println("Enter: [Y|N]\n");
+ String line = "N";
+
+ if (!OseeProperties.getInstance().isPromptEnabled()) {
+ line = "Y";
+ } else {
+ try {
+ line = stdin.readLine();
+ } catch (IOException ex) {
+ ex.printStackTrace();
+ }
+ }
+ return line;
+ }
+
+ public static void main(String[] args) {
+ System.setProperty(OSEE_CONFIG_FACTORY,
+ "org.eclipse.osee.framework.plugin.core.config.HeadlessEclipseConfigurationFactory");
+
+ Logger.getLogger("org.eclipse.osee.framework.jdk.core.util.db.ConnectionHandler").setLevel(Level.SEVERE);
+ Logger.getLogger("org.eclipse.osee.framework.jdk.core.util.db.DBConnection").setLevel(Level.SEVERE);
+ Logger.getLogger("org.eclipse.osee.framework.jdk.core.sql.manager.OracleSqlManager").setLevel(Level.SEVERE);
+ Logger.getLogger("org.eclipse.osee.framework.jdk.core.sql.manager.OracleSqlManager").setLevel(Level.SEVERE);
+
+ DbInformation dbInfo = ConfigUtil.getConfigFactory().getOseeConfig().getDefaultClientData();
+ String dbName = dbInfo.getDatabaseDetails().getFieldValue(ConfigField.DatabaseName);
+ String userName = dbInfo.getDatabaseDetails().getFieldValue(ConfigField.UserName);
+
+ if (DatabaseActivator.getInstance().isProductionDb()) {
+ System.err.println("You are not allowed to run config client against production servers.\nExiting.");
+ System.exit(0);
+ }
+
+ System.out.println("\nAre you sure you want to configure: " + dbName + ":" + userName);
+ String line = waitForUserResponse();
+ if (line.equalsIgnoreCase("Y")) {
+ System.out.println("Configuring Database...");
+
+ LaunchOseeDbConfigClient configClient = new LaunchOseeDbConfigClient(dbInfo);
+ configClient.start();
+ try {
+ configClient.join();
+ } catch (InterruptedException ex) {
+ ex.printStackTrace();
+ }
+ } else {
+ System.out.println("Database will not be configured. ");
+ Runtime.getRuntime().exit(0);
+ }
+ }
+}
diff --git a/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/initialize/tasks/DbInitializationTask.java b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/initialize/tasks/DbInitializationTask.java
new file mode 100644
index 00000000000..b152abcd66b
--- /dev/null
+++ b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/initialize/tasks/DbInitializationTask.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.database.initialize.tasks;
+
+/**
+ * @author Donald G. Dunne
+ */
+public abstract class DbInitializationTask implements IDbInitializationTask {
+ public boolean canRun() {
+ return true;
+ }
+} \ No newline at end of file
diff --git a/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/initialize/tasks/GatherStatistics.java b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/initialize/tasks/GatherStatistics.java
new file mode 100644
index 00000000000..071b9f95a30
--- /dev/null
+++ b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/initialize/tasks/GatherStatistics.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.database.initialize.tasks;
+
+import java.sql.Connection;
+import org.eclipse.osee.framework.plugin.core.config.SupportedDatabase;
+import org.eclipse.osee.framework.ui.plugin.util.db.ConnectionHandler;
+
+public class GatherStatistics extends DbInitializationTask {
+ private static final String gatherStats =
+ "begin" + " DBMS_STATS.GATHER_SCHEMA_STATS (ownname => '', estimate_percent => 99," + " granularity => 'ALL', degree => NULL , cascade => TRUE);" + "end;";
+
+ private SupportedDatabase database;
+
+ /**
+ * @param database
+ */
+ public GatherStatistics(SupportedDatabase database) {
+ this.database = database;
+ }
+
+ public void run(Connection connection) throws Exception {
+ System.out.println("GatherStatistics");
+ if (this.database == SupportedDatabase.oracle) {
+ ConnectionHandler.runPreparedQuery(gatherStats);
+ }
+ }
+}
diff --git a/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/initialize/tasks/IDbInitializationTask.java b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/initialize/tasks/IDbInitializationTask.java
new file mode 100644
index 00000000000..65a61456c12
--- /dev/null
+++ b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/initialize/tasks/IDbInitializationTask.java
@@ -0,0 +1,19 @@
+/*******************************************************************************
+ * 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.database.initialize.tasks;
+
+import java.sql.Connection;
+
+public interface IDbInitializationTask {
+ public abstract void run(Connection connection) throws Exception;
+
+ public abstract boolean canRun();
+}
diff --git a/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/initialize/tasks/ImportDataFromDbService.java b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/initialize/tasks/ImportDataFromDbService.java
new file mode 100644
index 00000000000..d113b4e7f32
--- /dev/null
+++ b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/initialize/tasks/ImportDataFromDbService.java
@@ -0,0 +1,229 @@
+/*******************************************************************************
+ * 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.database.initialize.tasks;
+
+import java.io.File;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
+import org.eclipse.osee.framework.database.utility.DatabaseDataExtractor;
+import org.eclipse.osee.framework.database.utility.DatabaseSchemaExtractor;
+import org.eclipse.osee.framework.database.utility.FileUtility;
+import org.eclipse.osee.framework.jdk.core.util.OseeProperties;
+import org.eclipse.osee.framework.plugin.core.config.ConfigUtil;
+import org.eclipse.osee.framework.plugin.core.config.data.DbInformation;
+import org.eclipse.osee.framework.ui.plugin.util.db.DBConnection;
+import org.eclipse.osee.framework.ui.plugin.util.db.data.SchemaData;
+import org.eclipse.osee.framework.ui.plugin.util.db.data.TableElement;
+
+public class ImportDataFromDbService implements IDbInitializationTask {
+ private Map<String, SchemaData> userSpecifiedConfig;
+ private static final File backupDirectory = new File("BackupDirectory");
+
+ public ImportDataFromDbService(Map<String, SchemaData> userSpecifiedConfig) {
+ this.userSpecifiedConfig = userSpecifiedConfig;
+ }
+
+ public void run(Connection connection) throws Exception {
+ Set<String> importConnections = getImportConnections();
+ for (String importFromDbService : importConnections) {
+ System.out.println("Import Table Data from Db: " + importFromDbService);
+
+ DbInformation databaseService =
+ ConfigUtil.getConfigFactory().getOseeConfig().getDatabaseService(importFromDbService);
+
+ Connection importConnection = null;
+ try {
+ importConnection = DBConnection.getNewConnection(databaseService, false);
+ } catch (SQLException ex) {
+ System.out.println("Unable to import table data");
+ }
+ if (importConnection != null) {
+ System.out.println("Gathering information from ..." + importFromDbService);
+
+ String userName = importConnection.getMetaData().getUserName();
+ if (userName != null && !userName.equals("")) {
+
+ Set<String> schemasToGet = new TreeSet<String>();
+ schemasToGet.add(userName.toUpperCase());
+
+ Map<String, Set<String>> dataToImport =
+ getTablesToImport(importConnection, userName.toUpperCase(), schemasToGet);
+ if (dataToImport.size() > 0) {
+ System.out.println(dataToImport.toString().replaceAll(", ", "\n"));
+ makeBackupDirectoryIfItDoesntExist();
+
+ System.out.println("Backing up Files to: " + backupDirectory.getAbsolutePath());
+ DatabaseDataExtractor dbDataExtractor =
+ new DatabaseDataExtractor(importConnection, schemasToGet, backupDirectory);
+
+ Set<String> tablesToImport;
+ if (importFromDbService.equals(determineDefaultConnection())) {
+ tablesToImport = dataToImport.get(OseeProperties.OSEE_IMPORT_FROM_DB_SERVICE);
+ } else {
+ tablesToImport = dataToImport.get(importFromDbService);
+ }
+
+ for (String importTable : tablesToImport) {
+ dbDataExtractor.addTableNameToExtract(importTable);
+ }
+ dbDataExtractor.extract();
+ dbDataExtractor.waitForWorkerThreads();
+
+ prepareFilesForImport();
+ }
+ }
+ importConnection.close();
+ }
+ }
+ }
+
+ private void prepareFilesForImport() {
+ Set<String> keys = userSpecifiedConfig.keySet();
+ if (keys.size() == 1) {
+ String userName = "";
+ for (String temp : keys) {
+ userName = temp;
+ }
+ List<File> files = FileUtility.getDBDataFileList(backupDirectory);
+ for (File fileName : files) {
+ String filename = fileName.getAbsolutePath().toString();
+ filename = filename.substring(filename.lastIndexOf(File.separator) + 1, filename.length());
+ filename = filename.substring(filename.indexOf(".") + 1, filename.length());
+ fileName.renameTo(new File(backupDirectory + File.separator + userName + "." + filename));
+ }
+ }
+ }
+
+ private String determineDefaultConnection() {
+ String importFromDbService = System.getProperty(OseeProperties.OSEE_IMPORT_FROM_DB_SERVICE);
+ if (importFromDbService == null || importFromDbService.equals("")) {
+ importFromDbService = "oracle";
+ }
+ return importFromDbService;
+ }
+
+ private Set<String> getImportConnections() {
+ String defaultConnection = determineDefaultConnection();
+ Set<String> userSchemas = userSpecifiedConfig.keySet();
+ Set<String> connectionsNeeded = new TreeSet<String>();
+ for (String key : userSchemas) {
+ SchemaData schemaDataInUserConfig = userSpecifiedConfig.get(key);
+ Map<String, Set<String>> tableNamesToImport = schemaDataInUserConfig.getTablesToImport();
+ Set<String> keys = tableNamesToImport.keySet();
+ for (String connectionString : keys) {
+ if (connectionString.equals(OseeProperties.OSEE_IMPORT_FROM_DB_SERVICE)) {
+ connectionsNeeded.add(defaultConnection);
+ } else {
+ connectionsNeeded.add(connectionString);
+ }
+ }
+ }
+ return connectionsNeeded;
+ }
+
+ public boolean canRun() {
+ return true;
+ }
+
+ private Map<String, SchemaData> getAvailableSchemasFromImportDb(Connection importConnection, Set<String> schemas) throws SQLException {
+ DatabaseSchemaExtractor schemaExtractor = new DatabaseSchemaExtractor(importConnection, schemas);
+ schemaExtractor.extractSchemaData();
+ return schemaExtractor.getSchemas();
+ }
+
+ private Map<String, Set<String>> getTablesToImport(Connection importConnection, String userName, Set<String> schemasToGet) throws Exception {
+ Map<String, SchemaData> currentDbSchemas = getAvailableSchemasFromImportDb(importConnection, schemasToGet);
+ Set<String> userSchemas = userSpecifiedConfig.keySet();
+
+ SchemaData schemaData = currentDbSchemas.get(userName);
+ Map<String, TableElement> tableMap = schemaData.getTableMap();
+
+ Map<String, Set<String>> importTables = new HashMap<String, Set<String>>();
+ for (String key : userSchemas) {
+ SchemaData schemaDataInUserConfig = userSpecifiedConfig.get(key);
+ Map<String, Set<String>> tableNamesToImport = schemaDataInUserConfig.getTablesToImport();
+
+ Set<String> keys = tableNamesToImport.keySet();
+ for (String importKey : keys) {
+ Set<String> namesToImport = tableNamesToImport.get(importKey);
+
+ for (String tableName : namesToImport) {
+ tableName = tableName.replaceAll(key + "\\.", userName + ".");
+
+ if (tableMap.containsKey(tableName)) {
+ Set<String> tableSet;
+ if (importTables.containsKey(importKey)) {
+ tableSet = importTables.get(importKey);
+ } else {
+ tableSet = new TreeSet<String>();
+ }
+ tableSet.add(tableName);
+ importTables.put(importKey, tableSet);
+ }
+ }
+ }
+ }
+ return importTables;
+ }
+
+ private void makeBackupDirectoryIfItDoesntExist() {
+ if (backupDirectory != null && backupDirectory.exists() && backupDirectory.canWrite()) {
+ return;
+ } else {
+ backupDirectory.mkdirs();
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.database.initialize.tasks.IDbInitializationTask#setDependancies(java.util.List)
+ */
+ public void setDependancies(List<String> bundles) {
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.database.initialize.tasks.IDbInitializationTask#getBundle()
+ */
+ public String getBundle() {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.database.initialize.tasks.IDbInitializationTask#getDependancies()
+ */
+ public List<String> getDependancies() {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.database.initialize.tasks.IDbInitializationTask#setBundle(java.lang.String)
+ */
+ public void setBundle(String bundle) {
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Comparable#compareTo(java.lang.Object)
+ */
+ public int compareTo(IDbInitializationTask o) {
+ return 0;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Comparable#compareTo(java.lang.Object)
+ */
+ public int compareTo(Object o) {
+ return 0;
+ }
+} \ No newline at end of file
diff --git a/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/initialize/tasks/InitTablesFromCSV.java b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/initialize/tasks/InitTablesFromCSV.java
new file mode 100644
index 00000000000..080ee7a5563
--- /dev/null
+++ b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/initialize/tasks/InitTablesFromCSV.java
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * 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.database.initialize.tasks;
+
+import java.io.File;
+import java.net.URL;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.sql.Types;
+import java.util.List;
+import org.eclipse.osee.framework.jdk.core.db.DbConfigFileInformation;
+
+public class InitTablesFromCSV extends DbInitializationTask {
+
+ private List<URL> csvTableInitData;
+ private String schemaName;
+
+ public InitTablesFromCSV(String schemaName, List<URL> csvTableInitData) {
+ super();
+ this.csvTableInitData = csvTableInitData;
+ this.schemaName = schemaName;
+ }
+
+ public void run(Connection connection) throws Exception {
+ for (URL file : csvTableInitData) {
+ insertTableData(connection, schemaName, new File(file.getFile()));
+ }
+ }
+
+ private void insertTableData(Connection connection, String schemaName, File file) throws SQLException {
+ // SYSCS_UTIL.SYSCS_IMPORT_TABLE (
+ // IN SCHEMANAME VARCHAR(128),
+ // IN TABLENAME VARCHAR(128),
+ // IN FILENAME VARCHAR(32672),
+ // IN COLUMNDELIMITER CHAR(1),
+ // IN CHARACTERDELIMITER CHAR(1),
+ // IN CODESET VARCHAR(128),
+ // IN REPLACE SMALLINT)
+ String tableName = file.getName().replace(DbConfigFileInformation.getCSVFileExtension(), "").toUpperCase();
+ PreparedStatement statement = connection.prepareStatement("CALL SYSCS_UTIL.SYSCS_IMPORT_TABLE (?,?,?,?,?,?,?)");
+ statement.setString(1, schemaName);
+ statement.setString(2, tableName);
+ statement.setString(3, file.getAbsolutePath());
+ statement.setNull(4, Types.CHAR);
+ statement.setNull(5, Types.CHAR);
+ statement.setNull(6, Types.VARCHAR);
+ statement.setInt(7, 0);
+ statement.execute();
+ statement.close();
+ }
+}
diff --git a/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/initialize/tasks/PrintTables.java b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/initialize/tasks/PrintTables.java
new file mode 100644
index 00000000000..b86e7a5ba9d
--- /dev/null
+++ b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/initialize/tasks/PrintTables.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.database.initialize.tasks;
+
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Map;
+import java.util.Set;
+import org.eclipse.osee.framework.ui.plugin.util.db.data.SchemaData;
+
+public class PrintTables extends DbInitializationTask {
+
+ private Map<String, SchemaData> userConfig;
+
+ public PrintTables(Map<String, SchemaData> userConfig) {
+ super();
+ this.userConfig = userConfig;
+ }
+
+ public void run(Connection connection) throws Exception {
+ Set<String> keys = userConfig.keySet();
+ for (String key : keys) {
+ SchemaData schemaData = userConfig.get(key);
+ Set<String> tables = schemaData.getTableMap().keySet();
+ for (String tableName : tables) {
+ printTable(connection, tableName);
+ }
+ }
+ }
+
+ private void printTable(Connection connection, String tableName) {
+ Statement statement;
+ try {
+ statement = connection.createStatement();
+ ResultSet resultSet = statement.executeQuery("select * from " + tableName);
+ ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
+ int numberOfColumns = resultSetMetaData.getColumnCount();
+ String header = "\nTable:\t" + tableName + "\n";
+ header += "Columns:\t";
+ for (int index = 1; index <= numberOfColumns; index++) {
+ header += resultSetMetaData.getColumnLabel(index);
+ if (index + 1 <= numberOfColumns) {
+ header += ", ";
+ }
+ }
+ header += "\n";
+
+ System.out.print(header);
+
+ String results = "";
+ while (resultSet.next()) {
+ results = "Data:\t";
+ for (int index = 1; index <= numberOfColumns; index++) {
+ results += resultSet.getObject(index).toString();
+ if (index + 1 <= numberOfColumns) {
+ results += ", ";
+ }
+ }
+ results += "\n";
+ System.out.print(results);
+ }
+ resultSet.close();
+ statement.close();
+ } catch (SQLException ex) {
+ ex.printStackTrace();
+ }
+ }
+}
diff --git a/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/initialize/tasks/relational/BackupTableData.java b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/initialize/tasks/relational/BackupTableData.java
new file mode 100644
index 00000000000..6ddded43e19
--- /dev/null
+++ b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/initialize/tasks/relational/BackupTableData.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.database.initialize.tasks.relational;
+
+import java.io.File;
+import java.sql.Connection;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
+import org.eclipse.osee.framework.database.initialize.tasks.IDbInitializationTask;
+import org.eclipse.osee.framework.database.utility.DatabaseDataExtractor;
+import org.eclipse.osee.framework.ui.plugin.util.db.data.SchemaData;
+import org.eclipse.osee.framework.ui.plugin.util.db.data.TableElement;
+
+public class BackupTableData implements IDbInitializationTask {
+ private Set<String> schemas;
+ private Map<String, SchemaData> userSpecifiedConfig;
+ private Map<String, SchemaData> currentDatabaseConfig;
+ private static final File backupDirectory = new File("BackupDirectory");
+
+ public BackupTableData(Set<String> schemas, Map<String, SchemaData> userSpecifiedConfig, Map<String, SchemaData> currentDatabaseConfig) {
+ this.schemas = schemas;
+ this.userSpecifiedConfig = userSpecifiedConfig;
+ this.currentDatabaseConfig = currentDatabaseConfig;
+ }
+
+ public void run(Connection connection) throws Exception {
+ System.out.println("BackupTableData: ");
+ Set<String> dataToBackup = getTablesToBackup();
+ if (dataToBackup.size() > 0) {
+ System.out.println(dataToBackup.toString().replaceAll(", ", "\n"));
+ clearBackupDirectory();
+ DatabaseDataExtractor dbDataExtractor = new DatabaseDataExtractor(connection, schemas, backupDirectory);
+ Set<String> backupTables = dataToBackup;
+ for (String backupTable : backupTables) {
+ dbDataExtractor.addTableNameToExtract(backupTable);
+ }
+ dbDataExtractor.extract();
+ dbDataExtractor.waitForWorkerThreads();
+ }
+ }
+
+ public boolean canRun() {
+ return true;
+ }
+
+ private Set<String> getTablesToBackup() {
+ Set<String> backupTables = new TreeSet<String>();
+ Set<String> userSchemas = userSpecifiedConfig.keySet();
+ for (String key : userSchemas) {
+ // Backup data only if data exists in the current database
+ if (currentDatabaseConfig.containsKey(key)) {
+ SchemaData schemaDataInDb = currentDatabaseConfig.get(key);
+ Map<String, TableElement> currentDbTableMap = schemaDataInDb.getTableMap();
+ Set<String> currentDbTableNames = currentDbTableMap.keySet();
+
+ SchemaData schemaData = userSpecifiedConfig.get(key);
+ Set<String> tableNamesToBackup = schemaData.getTablesToBackup();
+ for (String tableName : tableNamesToBackup) {
+ // Check that table we want to backup exists in the database
+ // before we add it to the list
+ if (currentDbTableNames.contains(tableName)) {
+ backupTables.add(tableName);
+ } else {
+ System.out.println("Table doesn't exist in Db. Unable to backup [" + tableName + "]");
+ }
+ }
+ } else {
+ System.out.println("Schema doesn't exist in Db. Unable to backup tables from schema [" + key + "]");
+ }
+ }
+ return backupTables;
+ }
+
+ private void clearBackupDirectory() {
+ if (backupDirectory != null && backupDirectory.exists() && backupDirectory.canWrite()) {
+ File[] fileList = backupDirectory.listFiles();
+ for (File fileToDelete : fileList) {
+ fileToDelete.delete();
+ }
+ backupDirectory.delete();
+ backupDirectory.mkdirs();
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.database.initialize.tasks.IDbInitializationTask#getBundle()
+ */
+ public String getBundle() {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.database.initialize.tasks.IDbInitializationTask#getDependancies()
+ */
+ public List<String> getDependancies() {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.database.initialize.tasks.IDbInitializationTask#setBundle(java.lang.String)
+ */
+ public void setBundle(String bundle) {
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.database.initialize.tasks.IDbInitializationTask#setDependancies(java.util.List)
+ */
+ public void setDependancies(List<String> bundles) {
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Comparable#compareTo(java.lang.Object)
+ */
+ public int compareTo(Object o) {
+ return 0;
+ }
+} \ No newline at end of file
diff --git a/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/initialize/tasks/relational/RestoreTableData.java b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/initialize/tasks/relational/RestoreTableData.java
new file mode 100644
index 00000000000..116c52ca4bf
--- /dev/null
+++ b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/initialize/tasks/relational/RestoreTableData.java
@@ -0,0 +1,132 @@
+/*******************************************************************************
+ * 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.database.initialize.tasks.relational;
+
+import java.io.File;
+import java.sql.Connection;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import org.eclipse.osee.framework.database.initialize.tasks.IDbInitializationTask;
+import org.eclipse.osee.framework.database.utility.DatabaseDataImporter;
+import org.eclipse.osee.framework.plugin.core.config.SupportedDatabase;
+import org.eclipse.osee.framework.ui.plugin.sql.SqlFactory;
+import org.eclipse.osee.framework.ui.plugin.sql.manager.SqlManager;
+import org.eclipse.osee.framework.ui.plugin.util.db.data.SchemaData;
+import org.eclipse.osee.framework.ui.plugin.util.db.data.TableElement;
+
+public class RestoreTableData implements IDbInitializationTask {
+ private Set<String> schemas;
+ private Map<String, SchemaData> userSpecifiedConfig;
+ private SupportedDatabase databaseType;
+ private static final File backupDirectory = new File("backupDirectory");
+
+ public RestoreTableData(Set<String> schemas, Map<String, SchemaData> userSpecifiedConfig, SupportedDatabase databaseType) {
+ this.schemas = schemas;
+ this.userSpecifiedConfig = userSpecifiedConfig;
+ this.databaseType = databaseType;
+ }
+
+ public void run(Connection connection) throws Exception {
+ System.out.println("RestoreTables");
+ System.out.flush();
+ SqlManager sqlManager = SqlFactory.getSqlManager(databaseType);
+
+ for (String schemaKey : schemas) {
+ if (userSpecifiedConfig.containsKey(schemaKey)) {
+ DatabaseDataImporter importer = new DatabaseDataImporter(connection, backupDirectory, sqlManager);
+ SchemaData schemaData = userSpecifiedConfig.get(schemaKey);
+
+ setImportOrder(importer, schemaData);
+ setTablesToImport(importer, schemaData);
+ importer.setSchemaToImportTo(schemaKey);
+
+ importer.importDataIntoDatabase();
+ }
+ }
+
+ clearBackupDirectory();
+ }
+
+ private void setImportOrder(DatabaseDataImporter importer, SchemaData schemaData) {
+ List<String> importOrder = new ArrayList<String>();
+
+ List<TableElement> tables = schemaData.getTablesOrderedByDependency();
+ for (TableElement table : tables) {
+ importOrder.add(table.getFullyQualifiedTableName());
+ }
+ importer.setImportOrder(importOrder);
+ }
+
+ private void setTablesToImport(DatabaseDataImporter importer, SchemaData schemaData) {
+ importer.clearTableFilter();
+ Set<String> selectedTables = schemaData.getTablesToBackup();
+ for (String tableName : selectedTables) {
+ importer.addToTableFilter(tableName);
+ }
+ Map<String, Set<String>> importedTables = schemaData.getTablesToImport();
+ Set<String> keys = importedTables.keySet();
+ for (String key : keys) {
+ Set<String> tables = importedTables.get(key);
+ for (String tableName : tables) {
+ importer.addToTableFilter(tableName);
+ }
+ }
+ }
+
+ public boolean canRun() {
+ return true;
+ }
+
+ private void clearBackupDirectory() {
+ if (backupDirectory != null && backupDirectory.exists() && backupDirectory.canWrite()) {
+ File[] fileList = backupDirectory.listFiles();
+ for (File fileToDelete : fileList) {
+ fileToDelete.delete();
+ }
+ backupDirectory.delete();
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.database.initialize.tasks.IDbInitializationTask#getBundle()
+ */
+ public String getBundle() {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.database.initialize.tasks.IDbInitializationTask#getDependancies()
+ */
+ public List<String> getDependancies() {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.database.initialize.tasks.IDbInitializationTask#setBundle(java.lang.String)
+ */
+ public void setBundle(String bundle) {
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.database.initialize.tasks.IDbInitializationTask#setDependancies(java.util.List)
+ */
+ public void setDependancies(List<String> bundles) {
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Comparable#compareTo(java.lang.Object)
+ */
+ public int compareTo(Object o) {
+ return 0;
+ }
+}
diff --git a/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/utility/DatabaseConfigurationData.java b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/utility/DatabaseConfigurationData.java
new file mode 100644
index 00000000000..42569fd0da5
--- /dev/null
+++ b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/utility/DatabaseConfigurationData.java
@@ -0,0 +1,130 @@
+/*******************************************************************************
+ * 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.database.utility;
+
+import java.net.URL;
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.SQLException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import org.eclipse.osee.framework.database.config.SchemaConfigUtility;
+import org.eclipse.osee.framework.jdk.core.util.OseeProperties;
+import org.eclipse.osee.framework.ui.plugin.util.db.data.ColumnMetadata;
+import org.eclipse.osee.framework.ui.plugin.util.db.data.ConstraintElement;
+import org.eclipse.osee.framework.ui.plugin.util.db.data.ForeignKey;
+import org.eclipse.osee.framework.ui.plugin.util.db.data.IndexElement;
+import org.eclipse.osee.framework.ui.plugin.util.db.data.ReferenceClause;
+import org.eclipse.osee.framework.ui.plugin.util.db.data.SchemaData;
+import org.eclipse.osee.framework.ui.plugin.util.db.data.TableElement;
+import org.eclipse.osee.framework.ui.plugin.util.db.data.TableElement.TableDescriptionFields;
+
+public class DatabaseConfigurationData {
+
+ private List<URL> filesToProcess;
+ private Connection connection;
+
+ public DatabaseConfigurationData(Connection connection, List<URL> filesToProcess) {
+ this.filesToProcess = filesToProcess;
+ this.connection = connection;
+ }
+
+ public List<URL> getUserSchemaFilesToProcess() {
+ return filesToProcess;
+ }
+
+ public Map<String, SchemaData> getUserSpecifiedSchemas() {
+ Map<String, SchemaData> schemasFromUserFiles =
+ SchemaConfigUtility.getUserDefinedConfig(getUserSchemaFilesToProcess());
+ if (!useFileSpecifiedSchemas()) {
+ try {
+ DatabaseMetaData meta = connection.getMetaData();
+ if (meta != null) {
+ String userName = meta.getUserName();
+ if (userName != null && !userName.equals("")) {
+ int index = userName.indexOf('@');
+ if (index > 1) {
+ userName = userName.substring(0, index);
+ }
+ schemasFromUserFiles = useUserNameAsSchema(userName.toUpperCase(), schemasFromUserFiles);
+ }
+ }
+ } catch (SQLException ex) {
+ ex.printStackTrace();
+ }
+ }
+ return schemasFromUserFiles;
+ }
+
+ private boolean useFileSpecifiedSchemas() {
+ return OseeProperties.getInstance().useSchemasSpecifiedInDbConfigFiles();
+ }
+
+ private Map<String, SchemaData> useUserNameAsSchema(String userName, Map<String, SchemaData> userSchemas) {
+ Map<String, SchemaData> newData = new HashMap<String, SchemaData>();
+ SchemaData newSchemaData = new SchemaData();
+ Set<String> keys = userSchemas.keySet();
+ for (String key : keys) {
+ SchemaData schemaData = userSchemas.get(key);
+ List<TableElement> tables = schemaData.getTablesOrderedByDependency();
+ for (TableElement table : tables) {
+ TableElement newTable = useUserNameAsSchemaForTable(userName, table);
+ newSchemaData.addTableDefinition(newTable);
+ }
+ }
+ newData.put(userName, newSchemaData);
+ return newData;
+ }
+
+ private TableElement useUserNameAsSchemaForTable(String userName, TableElement table) {
+ TableElement newTable = new TableElement();
+
+ Map<TableDescriptionFields, String> tableDescription = table.getDescription();
+ Map<String, ColumnMetadata> columns = table.getColumns();
+ List<ConstraintElement> constraints = table.getConstraints();
+ List<ForeignKey> foreignKeys = table.getForeignKeyConstraints();
+ List<IndexElement> indexElements = table.getIndexData();
+
+ TableDescriptionFields[] descriptors = TableDescriptionFields.values();
+ for (TableDescriptionFields field : descriptors) {
+ String value = tableDescription.get(field);
+ if (field.equals(TableDescriptionFields.schema)) {
+ value = userName;
+ }
+ if (value != null && !value.equals("")) {
+ newTable.addTableDescription(field, value);
+ }
+ }
+
+ Set<String> columnKeys = columns.keySet();
+ for (String key : columnKeys) {
+ newTable.addColumn(columns.get(key));
+ }
+ for (ConstraintElement constraint : constraints) {
+ constraint.setSchema(userName);
+ newTable.addConstraint(constraint);
+ }
+ for (ForeignKey constraint : foreignKeys) {
+ constraint.setSchema(userName);
+ List<ReferenceClause> references = constraint.getReferences();
+ for (ReferenceClause clause : references) {
+ clause.setSchema(userName);
+ }
+ newTable.addConstraint(constraint);
+ }
+ for (IndexElement indexElement : indexElements) {
+ newTable.addIndexData(indexElement);
+ }
+ return newTable;
+ }
+}
diff --git a/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/utility/DatabaseDataExtractor.java b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/utility/DatabaseDataExtractor.java
new file mode 100644
index 00000000000..7309d1d32cc
--- /dev/null
+++ b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/utility/DatabaseDataExtractor.java
@@ -0,0 +1,299 @@
+/*******************************************************************************
+ * 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.database.utility;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.math.BigDecimal;
+import java.sql.Connection;
+import java.sql.Date;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.sql.Types;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import org.eclipse.osee.framework.jdk.core.db.DbConfigFileInformation;
+import org.eclipse.osee.framework.plugin.core.config.ConfigUtil;
+import org.eclipse.osee.framework.plugin.core.config.SupportedDatabase;
+import org.eclipse.osee.framework.ui.plugin.sql.SQL3DataType;
+import org.eclipse.osee.framework.ui.plugin.sql.SqlFactory;
+import org.eclipse.osee.framework.ui.plugin.util.db.DbUtil;
+import org.eclipse.osee.framework.ui.plugin.util.db.data.SchemaData;
+import org.eclipse.osee.framework.ui.plugin.util.db.data.TableElement;
+import org.eclipse.osee.framework.ui.plugin.util.db.data.TableElement.ColumnFields;
+import org.eclipse.osee.framework.ui.plugin.util.db.data.TableElement.TableDescriptionFields;
+import org.eclipse.osee.framework.ui.plugin.util.db.data.TableElement.TableTags;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import com.sun.org.apache.xerces.internal.dom.DocumentImpl;
+import com.sun.org.apache.xml.internal.serialize.OutputFormat;
+import com.sun.org.apache.xml.internal.serialize.XMLSerializer;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class DatabaseDataExtractor {
+
+ private static final String SQL_WILD_QUERY = "SELECT * FROM ";
+ private Connection connection;
+ private DatabaseSchemaExtractor databaseInfo;
+ private Set<String> schemas;
+ private File directory;
+ private Logger logger;
+ private List<Thread> workerThreads;
+ private Set<String> extractTables;
+ private SupportedDatabase dbType;
+
+ private class ColumnInfo {
+ String name;
+ SQL3DataType type;
+ }
+
+ public DatabaseDataExtractor(Connection connection, Set<String> schemas, File directory) {
+ this.connection = connection;
+ this.schemas = schemas;
+ this.directory = directory;
+ this.logger = ConfigUtil.getConfigFactory().getLogger(DatabaseDataExtractor.class);
+ this.workerThreads = new ArrayList<Thread>();
+ this.extractTables = new TreeSet<String>();
+ try {
+ this.dbType = SqlFactory.getDatabaseType(connection);
+ } catch (SQLException ex) {
+ logger.log(Level.SEVERE, "Invalid database type. ", ex);
+ }
+ }
+
+ public void addTableNameToExtract(String fullyQualifiedTableName) {
+ this.extractTables.add(fullyQualifiedTableName);
+ }
+
+ public void clearFilter() {
+ this.extractTables.clear();
+ }
+
+ public void extract() {
+ try {
+ FileUtility.setupDirectoryForWrite(directory);
+ extractData();
+ } catch (IOException ex) {
+ logger.log(Level.SEVERE, "Directory Invalid. ", ex);
+ } catch (SQLException ex) {
+ logger.log(Level.SEVERE, "Extract Exception. ", ex);
+ } finally {
+
+ }
+
+ }
+
+ private class DataExtractorThread extends Thread {
+ private TableElement table;
+
+ public DataExtractorThread(TableElement table) {
+ this.table = table;
+ setName(table.getName() + " Extractor");
+ }
+
+ public void run() {
+ Statement statement = null;
+ ResultSet resultSet = null;
+ try {
+ resultSet = getTableData(statement, table);
+ Document document = buildXml(resultSet, table);
+ resultSet.close();
+ if (document != null) {
+ writeDocumentToFile(document, table.getFullyQualifiedTableName());
+ }
+ } catch (Exception ex) {
+ logger.log(Level.SEVERE,
+ "Error Processing Table [ " + table.getSchema() + "." + table.getName() + " ] Data ", ex);
+ } finally {
+ DbUtil.close(statement);
+ }
+ }
+ }
+
+ public void waitForWorkerThreads() {
+ for (Thread worker : workerThreads) {
+ try {
+ worker.join();
+ } catch (InterruptedException ex) {
+ logger.log(Level.SEVERE, "Thread [" + worker.getName() + "] was Interrupted. ", ex);
+ }
+ }
+ }
+
+ private void extractData() throws SQLException {
+ databaseInfo = new DatabaseSchemaExtractor(connection, schemas);
+ databaseInfo.extractSchemaData();
+ Map<String, SchemaData> schemaDataMap = databaseInfo.getSchemas();
+ Set<String> schemaKeys = schemaDataMap.keySet();
+ for (String schema : schemaKeys) {
+ SchemaData schemaData = schemaDataMap.get(schema);
+
+ List<TableElement> tables = schemaData.getTablesOrderedByDependency();
+ for (TableElement table : tables) {
+
+ boolean extract = true;
+ // only extract items in filter since filter was set with data
+ if (this.extractTables != null && this.extractTables.size() > 0) {
+ extract = extractTables.contains(table.getFullyQualifiedTableName());
+ }
+
+ if (extract) {
+ DataExtractorThread workerThread = new DataExtractorThread(table);
+ workerThreads.add(workerThread);
+ workerThread.start();
+ }
+ }
+ }
+ }
+
+ private ResultSet getTableData(Statement statement, TableElement table) throws SQLException {
+ statement = connection.createStatement();
+
+ ResultSet rset = null;
+ try {
+ rset = statement.executeQuery(SQL_WILD_QUERY + table.getFullyQualifiedTableName());
+ } catch (SQLException ex) {
+ rset = statement.executeQuery(SQL_WILD_QUERY + table.getName());
+ }
+ return rset;
+ }
+
+ private Document buildXml(ResultSet resultSet, TableElement table) throws SQLException {
+ ResultSetMetaData resultMetaData = resultSet.getMetaData();
+
+ ArrayList<ColumnInfo> columns = new ArrayList<ColumnInfo>();
+ int numberOfColumns = resultMetaData.getColumnCount();
+ for (int index = 1; index <= numberOfColumns; index++) {
+ ColumnInfo columnInfo = new ColumnInfo();
+ columnInfo.name = resultMetaData.getColumnName(index);
+ columnInfo.name = columnInfo.name.toUpperCase();
+
+ int dataType = resultMetaData.getColumnType(index);
+ if (dbType.equals(SupportedDatabase.foxpro)) {
+ if (dataType == Types.CHAR) {
+ dataType = Types.VARCHAR;
+ }
+ }
+ columnInfo.type = SQL3DataType.get(dataType);
+ columns.add(columnInfo);
+ }
+
+ Document xmlDoc = new DocumentImpl();
+ Element rootElement = xmlDoc.createElement(TableTags.Table.name());
+ xmlDoc.appendChild(rootElement);
+ rootElement.setAttribute(TableDescriptionFields.schema.name(), table.getSchema());
+ rootElement.setAttribute(TableDescriptionFields.name.name(), table.getName());
+
+ for (ColumnInfo info : columns) {
+ Element columnInfo = xmlDoc.createElement(TableTags.ColumnInfo.name());
+ rootElement.appendChild(columnInfo);
+ columnInfo.setAttribute(ColumnFields.id.name(), info.name);
+ columnInfo.setAttribute(ColumnFields.type.name(), info.type.name());
+ }
+
+ while (resultSet.next()) {
+ Element columnElement = xmlDoc.createElement(TableTags.Row.name());
+ for (ColumnInfo column : columns) {
+ String columnValue;
+ switch (column.type) {
+ case BIGINT:
+ BigDecimal bigD = resultSet.getBigDecimal(column.name);
+ columnValue = (bigD != null ? bigD.toString() : "");
+ break;
+ case DATE:
+ Date date = resultSet.getDate(column.name);
+ columnValue = (date != null ? date.toString() : "");
+ break;
+ case TIME:
+ Time time = resultSet.getTime(column.name);
+ columnValue = (time != null ? time.toString() : "");
+ break;
+ case TIMESTAMP:
+ Timestamp timestamp = resultSet.getTimestamp(column.name);
+ columnValue = (timestamp != null ? timestamp.toString() : "");
+ break;
+ default:
+ columnValue = resultSet.getString(column.name);
+ columnValue = handleSpecialCharacters(columnValue);
+ break;
+ }
+ columnElement.setAttribute(column.name, (columnValue != null ? columnValue : ""));
+ }
+ rootElement.appendChild(columnElement);
+ }
+ return xmlDoc;
+ }
+
+ private String handleSpecialCharacters(String value) {
+ // \0 An ASCII 0 (NUL) character.
+ // '' A single quote (�'�) character.
+ // \b A backspace character.
+ // \n A newline (linefeed) character.
+ // \r A carriage return character.
+ // \t A tab character.
+ // \Z ASCII 26 (Control-Z). See note following the table.
+
+ if (value != null) {
+
+ value = value.replaceAll("\0", "");
+ value = value.replaceAll("'", "''");
+ // value = value.replaceAll("\"", "\\\\\""); No need to do this.
+ Pattern pattern =
+ Pattern.compile("[^" + "a-zA-Z0-9" + "!@#$%\\^&*\\(\\)" + "+ _.-=" + "\'\"<>{}\\[\\]|:;,\n\r\t\b?/`~\\\\]+");
+ Matcher matcher = pattern.matcher(value);
+
+ while (matcher.find()) {
+ // System.out.println("Matcher: [" + matcher.group() + "]");
+ value = value.replace(matcher.group(), "");
+ }
+ }
+ return value;
+ }
+
+ private void writeDocumentToFile(Document doc, String tableName) throws IOException {
+ String fileString = directory + File.separator + tableName + DbConfigFileInformation.getDbDataFileExtension();
+ OutputFormat outputFormat;
+ OutputStreamWriter out = null;
+ try {
+ OutputStream bout = new BufferedOutputStream(new FileOutputStream(fileString));
+ out = new OutputStreamWriter(bout);
+
+ outputFormat = new OutputFormat("XML", "UTF-8", true);
+ XMLSerializer xmlSerializer = new XMLSerializer(out, outputFormat);
+ xmlSerializer.serialize(doc.getDocumentElement());
+ } catch (FileNotFoundException ex) {
+ logger.log(Level.SEVERE, "File error [" + fileString + "] ", ex);
+ } catch (IOException ex) {
+ logger.log(Level.SEVERE, "Error writing to File [" + fileString + "] ", ex);
+ } finally {
+ out.flush();
+ out.close();
+ }
+ }
+} \ No newline at end of file
diff --git a/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/utility/DatabaseDataImporter.java b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/utility/DatabaseDataImporter.java
new file mode 100644
index 00000000000..13a2504ea03
--- /dev/null
+++ b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/utility/DatabaseDataImporter.java
@@ -0,0 +1,257 @@
+/*******************************************************************************
+ * 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.database.utility;
+
+import java.io.File;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import org.eclipse.osee.framework.jdk.core.db.DbConfigFileInformation;
+import org.eclipse.osee.framework.plugin.core.config.ConfigUtil;
+import org.eclipse.osee.framework.ui.plugin.sql.manager.SqlManager;
+import org.eclipse.osee.framework.ui.plugin.util.db.data.ColumnDbData;
+import org.eclipse.osee.framework.ui.plugin.util.db.data.ColumnMetadata;
+import org.eclipse.osee.framework.ui.plugin.util.db.data.TableElement;
+import org.eclipse.osee.framework.ui.plugin.util.db.data.TableElement.ColumnFields;
+import org.eclipse.osee.framework.ui.plugin.util.db.data.TableElement.TableDescriptionFields;
+import org.eclipse.osee.framework.ui.plugin.util.db.data.TableElement.TableTags;
+import org.w3c.dom.Document;
+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 DatabaseDataImporter {
+ private Connection connection;
+ private File directory;
+ private Logger logger;
+ private SqlManager sqlManager;
+ private List<String> tableOrder;
+ private String schemaToImportTo;
+ private Set<String> tableFilter;
+
+ private class TableData extends TableElement {
+ private List<List<ColumnDbData>> rowData;
+
+ public TableData() {
+ rowData = new ArrayList<List<ColumnDbData>>();
+ }
+
+ public void addRow(List<ColumnDbData> row) {
+ rowData.add(row);
+ }
+
+ public List<List<ColumnDbData>> getRows() {
+ return rowData;
+ }
+ }
+
+ public DatabaseDataImporter(Connection connection, File directory, SqlManager sqlManager) {
+ this.connection = connection;
+ this.directory = directory;
+ this.logger = ConfigUtil.getConfigFactory().getLogger(DatabaseDataImporter.class);
+ this.sqlManager = sqlManager;
+ this.tableFilter = new TreeSet<String>();
+ }
+
+ public void setImportOrder(List<String> tableOrder) {
+ this.tableOrder = tableOrder;
+ }
+
+ public void setSchemaToImportTo(String schema) {
+ this.schemaToImportTo = schema;
+ }
+
+ public void addToTableFilter(String fullyQualifiedTableName) {
+ this.tableFilter.add(fullyQualifiedTableName);
+ }
+
+ public void clearTableFilter() {
+ this.tableFilter.clear();
+ }
+
+ public List<File> orderFilesByImportOrder(Map<String, File> toOrder) {
+ List<File> orderedSet = new ArrayList<File>();
+ if (tableOrder != null && tableOrder.size() != 0) {
+ for (String tableName : tableOrder) {
+ if (toOrder.containsKey(tableName + DbConfigFileInformation.getDbDataFileExtension())) {
+ orderedSet.add(toOrder.get(tableName + DbConfigFileInformation.getDbDataFileExtension()));
+ }
+ }
+ } else {
+ Set<String> keys = toOrder.keySet();
+ for (String key : keys) {
+ orderedSet.add(toOrder.get(key));
+ }
+ }
+ return orderedSet;
+ }
+
+ public Map<String, File> filterDataToImport(Map<String, File> toProcess) {
+ Map<String, File> filteredList = new HashMap<String, File>();
+ if (tableFilter != null && tableFilter.size() != 0) {
+ for (String tableName : tableFilter) {
+ if (toProcess.containsKey(tableName + DbConfigFileInformation.getDbDataFileExtension())) {
+ filteredList.put(tableName + DbConfigFileInformation.getDbDataFileExtension(),
+ toProcess.get(tableName + DbConfigFileInformation.getDbDataFileExtension()));
+ }
+ }
+ } else {
+ return toProcess;
+ }
+ return filteredList;
+ }
+
+ public void importDataIntoDatabase() {
+ if (FileUtility.isValidDirectory(directory)) {
+ Map<String, File> filesToProcess = getFilesToProcess();
+ Map<String, File> filteredFiles = filterDataToImport(filesToProcess);
+ List<File> files = orderFilesByImportOrder(filteredFiles);
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder builder;
+ Document document;
+ for (File file : files) {
+ try {
+ builder = factory.newDocumentBuilder();
+ document = builder.parse(file);
+ processData(parseXMLDbDataFile(document));
+ } catch (ParserConfigurationException ex) {
+ logger.log(Level.SEVERE, "Unable to Parse File. ", ex);
+ } catch (Exception ex) {
+ logger.log(Level.SEVERE, "Exception: \n", ex);
+ }
+ }
+ }
+ }
+
+ private Map<String, File> getFilesToProcess() {
+ Map<String, File> toReturn = new HashMap<String, File>();
+ List<File> files = FileUtility.getDBDataFileList(directory);
+ for (File fileName : files) {
+ toReturn.put(fileName.getName(), new File(directory + File.separator + fileName.getName()));
+ }
+ return toReturn;
+ }
+
+ private void processData(List<TableData> tables) throws SQLException, Exception {
+ if (tables.size() != 0) {
+ for (TableData tableData : tables) {
+ logger.log(Level.INFO, "Populating: [ " + tableData.getFullyQualifiedTableName() + "]\n");
+ List<List<ColumnDbData>> rows = tableData.getRows();
+ if (!rows.isEmpty()) {
+ for (List<ColumnDbData> rowData : rows) {
+ sqlManager.insertData(connection, rowData, tableData);
+ }
+ }
+ }
+ }
+ }
+
+ private void parseColumnMetadata(Element tableElement, TableData tableData) {
+ NodeList columnElements = tableElement.getElementsByTagName(TableTags.ColumnInfo.name());
+ if (columnElements != null) {
+ for (int index = 0; index < columnElements.getLength(); index++) {
+ Element columnElement = (Element) columnElements.item(index);
+ if (columnElement != null) {
+
+ NamedNodeMap attributeMap = columnElement.getAttributes();
+ if (attributeMap != null && attributeMap.getLength() != 0) {
+ ColumnMetadata columnMetaData = new ColumnMetadata("");
+ for (int attributeIndex = 0; attributeIndex < attributeMap.getLength(); attributeIndex++) {
+ Node node = attributeMap.item(attributeIndex);
+ String nodeName = node.getNodeName();
+ String nodeValue = node.getTextContent();
+ if (nodeName != null && !nodeName.equals("")) {
+ columnMetaData.addColumnField(ColumnFields.valueOf(nodeName),
+ (nodeValue != null ? nodeValue : ""));
+ }
+ }
+ tableData.addColumn(columnMetaData);
+ }
+ }
+ }
+ }
+ }
+
+ private void parseRowInformation(Element tableElement, TableData tableData) {
+ NodeList rowElements = tableElement.getElementsByTagName(TableTags.Row.name());
+ if (rowElements != null) {
+ for (int rowIndex = 0; rowIndex < rowElements.getLength(); rowIndex++) {
+ Element row = (Element) rowElements.item(rowIndex);
+ if (row != null) {
+ NamedNodeMap attributeMap = row.getAttributes();
+ if (attributeMap != null && attributeMap.getLength() != 0) {
+ List<ColumnDbData> rowData = new ArrayList<ColumnDbData>();
+ tableData.addRow(rowData);
+ for (int attributeIndex = 0; attributeIndex < attributeMap.getLength(); attributeIndex++) {
+ Node node = attributeMap.item(attributeIndex);
+ String nodeName = node.getNodeName();
+ String nodeValue = node.getTextContent();
+ if (nodeName != null && !nodeName.equals("")) {
+ rowData.add(new ColumnDbData(nodeName, (nodeValue != null ? nodeValue : "")));
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ private List<TableData> parseXMLDbDataFile(Document document) {
+ NodeList tableElements = document.getElementsByTagName(TableTags.Table.name());
+ List<TableData> tables = new ArrayList<TableData>();
+ for (int index = 0; index < tableElements.getLength(); index++) {
+ Element tableXmlElement = (Element) tableElements.item(index);
+ if (tableXmlElement != null) {
+ NamedNodeMap map = tableXmlElement.getAttributes();
+ if (map != null && map.getLength() != 0) {
+ Node tableName = map.getNamedItem(TableDescriptionFields.name.name());
+ Node tableAddress = map.getNamedItem(TableDescriptionFields.schema.name());
+ String tableNameString = "";
+ String tableAddressString = "";
+ if (tableName != null) {
+ tableNameString = tableName.getTextContent();
+ }
+ if (tableAddress != null) {
+ tableAddressString = tableAddress.getTextContent();
+ }
+
+ if (tableNameString != null && !tableNameString.equals("") && tableAddressString != null && !tableAddressString.equals("")) {
+ TableData tableData = new TableData();
+ tableData.addTableDescription(TableDescriptionFields.name, tableNameString);
+ if (this.schemaToImportTo != null && !this.schemaToImportTo.equals("")) {
+ tableData.addTableDescription(TableDescriptionFields.schema, schemaToImportTo);
+ } else {
+ tableData.addTableDescription(TableDescriptionFields.schema, tableAddressString);
+ }
+ parseRowInformation(tableXmlElement, tableData);
+ parseColumnMetadata(tableXmlElement, tableData);
+ tables.add(tableData);
+ }
+ }
+ }
+ }
+ return tables;
+ }
+}
diff --git a/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/utility/DatabaseSchemaExtractor.java b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/utility/DatabaseSchemaExtractor.java
new file mode 100644
index 00000000000..51f8835b2c9
--- /dev/null
+++ b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/utility/DatabaseSchemaExtractor.java
@@ -0,0 +1,532 @@
+/*******************************************************************************
+ * 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.database.utility;
+
+import java.io.File;
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Types;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.TransformerException;
+import org.eclipse.osee.framework.jdk.core.db.DbConfigFileInformation;
+import org.eclipse.osee.framework.jdk.core.util.xml.Jaxp;
+import org.eclipse.osee.framework.plugin.core.config.ConfigUtil;
+import org.eclipse.osee.framework.plugin.core.config.SupportedDatabase;
+import org.eclipse.osee.framework.ui.plugin.sql.SQL3DataType;
+import org.eclipse.osee.framework.ui.plugin.sql.SqlFactory;
+import org.eclipse.osee.framework.ui.plugin.util.db.data.AppliesToClause;
+import org.eclipse.osee.framework.ui.plugin.util.db.data.ColumnMetadata;
+import org.eclipse.osee.framework.ui.plugin.util.db.data.ConstraintElement;
+import org.eclipse.osee.framework.ui.plugin.util.db.data.ConstraintFactory;
+import org.eclipse.osee.framework.ui.plugin.util.db.data.ConstraintTypes;
+import org.eclipse.osee.framework.ui.plugin.util.db.data.ForeignKey;
+import org.eclipse.osee.framework.ui.plugin.util.db.data.IndexElement;
+import org.eclipse.osee.framework.ui.plugin.util.db.data.ReferenceClause;
+import org.eclipse.osee.framework.ui.plugin.util.db.data.SchemaData;
+import org.eclipse.osee.framework.ui.plugin.util.db.data.TableElement;
+import org.eclipse.osee.framework.ui.plugin.util.db.data.AppliesToClause.OrderType;
+import org.eclipse.osee.framework.ui.plugin.util.db.data.ReferenceClause.OnDeleteEnum;
+import org.eclipse.osee.framework.ui.plugin.util.db.data.ReferenceClause.OnUpdateEnum;
+import org.eclipse.osee.framework.ui.plugin.util.db.data.TableElement.ColumnFields;
+import org.eclipse.osee.framework.ui.plugin.util.db.data.TableElement.TableDescriptionFields;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class DatabaseSchemaExtractor {
+
+ private static final Logger logger = ConfigUtil.getConfigFactory().getLogger(DatabaseSchemaExtractor.class);
+
+ private Connection connection;
+ private DatabaseMetaData dbData;
+ private String dbName;
+ private String dbVersion;
+ private Map<String, SchemaData> database;
+ private List<String> filter;
+ private Set<String> tablesToExtract;
+ private Set<String> schemas;
+ private SupportedDatabase dbType;
+
+ private static final String DEFAULT_FILTER = "BIN.*";
+
+ public DatabaseSchemaExtractor(Connection connection, Set<String> schemas) throws SQLException {
+ super();
+ this.connection = connection;
+ this.dbData = this.connection.getMetaData();
+ this.dbName = dbData.getDatabaseProductName();
+ this.dbVersion = dbData.getDatabaseProductVersion();
+ this.dbType = SqlFactory.getDatabaseType(connection);
+ this.filter = new ArrayList<String>();
+ filter.add(DEFAULT_FILTER);
+ this.tablesToExtract = new TreeSet<String>();
+ this.schemas = schemas;
+ }
+
+ public void addToFilter(String value) {
+ filter.add(value);
+ }
+
+ public String getDBName() {
+ return dbName;
+ }
+
+ public String getDBVersion() {
+ return dbVersion;
+ }
+
+ public Map<String, SchemaData> getSchemas() {
+ return database;
+ }
+
+ public void extractSchemaData() throws SQLException {
+ populateDatabaseMap(schemas);
+ }
+
+ private void populateDatabaseMap(Set<String> schemas) throws SQLException {
+ database = new HashMap<String, SchemaData>();
+ for (String schema : schemas) {
+ SchemaData dbTables = getTableInformation(schema);
+ database.put(schema, dbTables);
+ }
+ }
+
+ public Set<String> getAllSchemas() throws SQLException {
+ ResultSet schemaResults = dbData.getSchemas();
+ Set<String> schemaSet = new TreeSet<String>();
+
+ while (schemaResults.next()) {
+ String schema = schemaResults.getString("TABLE_SCHEM");
+ if (schema != null && !schema.equals("")) {
+ schemaSet.add(schema);
+ }
+ }
+ schemaResults.close();
+ return schemaSet;
+ }
+
+ /**
+ * Writes the XML files in the directory specified.
+ *
+ * @param directory The directory tow write the XML files.
+ * @throws IOException
+ */
+ public void writeToFile(File directory) throws IOException {
+ FileUtility.setupDirectoryForWrite(directory);
+ Set<String> keys = database.keySet();
+ for (String schema : keys) {
+ SchemaData tableData = database.get(schema);
+ File xmlFile =
+ new File(
+ directory.getAbsolutePath() + File.separator + schema + DbConfigFileInformation.getSchemaFileExtension());
+ try {
+ Jaxp.writeXmlDocument(tableData.getXmlDocument(), xmlFile);
+ } catch (TransformerException ex) {
+ logger.log(Level.SEVERE, ex.toString(), ex);
+ } catch (ParserConfigurationException ex) {
+ logger.log(Level.SEVERE, ex.toString(), ex);
+ }
+ }
+ }
+
+ public String toString() {
+ String toReturn = "Name: " + dbName + "\tVer: " + dbVersion + "\n";
+ Set<String> keys = database.keySet();
+ for (String schema : keys) {
+ SchemaData tableData = database.get(schema);
+ toReturn += " Schema: \n" + schema + "\n" + tableData.toString();
+ }
+ return toReturn;
+ }
+
+ private boolean isFiltered(String value) {
+ for (String filterExpression : filter) {
+ Pattern searchPattern = Pattern.compile(filterExpression, Pattern.DOTALL);
+ Matcher matcher = searchPattern.matcher(value);
+ if (matcher.find()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public void addTableToExtract(String fullyqualifiedTableName) {
+ this.tablesToExtract.add(fullyqualifiedTableName);
+ }
+
+ public void clearTableFilter() {
+ tablesToExtract.clear();
+ }
+
+ private SchemaData getTableInformation(String schemaPattern) throws SQLException {
+ SchemaData dbTables = new SchemaData();
+ ResultSet tables = null;
+ tables = dbData.getTables(null, null, null, new String[] {"TABLE"});
+
+ while (tables.next()) {
+ String tableName = tables.getString("TABLE_NAME").toUpperCase();
+ String schemaName = tables.getString("TABLE_SCHEM");
+ if (tableName != null && !isFiltered(tableName) && schemaName.equalsIgnoreCase(schemaPattern)) {
+ boolean extract = true;
+ if (this.tablesToExtract != null && this.tablesToExtract.size() > 0) {
+ extract = tablesToExtract.contains(schemaPattern + "." + tableName);
+ }
+
+ if (extract) {
+ TableElement tableEntry = new TableElement();
+ tableEntry.addTableDescription(TableDescriptionFields.name, tableName);
+ tableEntry.addTableDescription(TableDescriptionFields.schema, schemaName);
+ getColumnInformation(tableEntry);
+ getColumnPrimaryKey(tableEntry);
+
+ if (!(dbType.equals(SupportedDatabase.foxpro) || dbType.equals(SupportedDatabase.postgresql))) {
+ getColumnForeignKey(tableEntry);
+ }
+ getIndexInfo(tableEntry);
+ dbTables.addTableDefinition(tableEntry);
+ }
+ }
+ }
+ tables.close();
+ return dbTables;
+ }
+
+ private void getColumnInformation(TableElement aTable) throws SQLException {
+ ResultSet columns = null;
+ try {
+ columns = dbData.getColumns(null, aTable.getSchema(), aTable.getName(), null);
+ } catch (SQLException ex) {
+ columns = dbData.getColumns(null, null, aTable.getName(), null);
+ }
+ while (columns.next()) {
+ String id = columns.getString("COLUMN_NAME");
+ id = id.toUpperCase();
+ ColumnMetadata column = new ColumnMetadata(id);
+
+ int dataType = columns.getInt("DATA_TYPE");
+ if (dbType.equals(SupportedDatabase.foxpro)) {
+ if (dataType == Types.CHAR) {
+ dataType = Types.VARCHAR;
+ }
+ }
+ String dataTypeName = SQL3DataType.get(dataType).name();
+ column.addColumnField(ColumnFields.type, dataTypeName);
+
+ String defaultValue = "";
+ int defaultType = columns.getInt("NULLABLE");
+ switch (defaultType) {
+ case java.sql.DatabaseMetaData.columnNoNulls:
+ defaultValue = "not null";
+ break;
+ case java.sql.DatabaseMetaData.columnNullable:
+ // Dont specify if Null - Let DB Decide.
+ defaultValue = "";
+ break;
+ case java.sql.DatabaseMetaData.columnNullableUnknown:
+ default:
+ // Since unknown then don't specify
+ defaultValue = "";
+ break;
+ }
+ if (!defaultValue.equals("")) {
+ column.addColumnField(ColumnFields.defaultValue, defaultValue);
+ }
+
+ if (!dbType.equals(SupportedDatabase.foxpro)) {
+ // int dataType = columns.getInt("DATA_TYPE");
+ switch (dataType) {
+ case java.sql.Types.CHAR:
+ case java.sql.Types.VARCHAR:
+ String limits = columns.getString("COLUMN_SIZE");
+ if (limits != null && !limits.equals("")) {
+ column.addColumnField(ColumnFields.limits, limits);
+ }
+ break;
+ case java.sql.Types.DECIMAL:
+ case java.sql.Types.NUMERIC:
+ limits = columns.getString("COLUMN_SIZE");
+ String decimal = columns.getString("DECIMAL_DIGITS");
+ if (decimal != null && !decimal.equals("")) {
+ if (limits != null && !limits.equals("")) {
+ limits += "," + decimal;
+ }
+ }
+ if (limits != null && !limits.equals("")) {
+ column.addColumnField(ColumnFields.limits, limits);
+ }
+ default:
+ break;
+ }
+ } else {
+ switch (dataType) {
+ case java.sql.Types.CHAR:
+ case java.sql.Types.VARCHAR:
+ String limits = "255";
+ if (limits != null && !limits.equals("")) {
+ column.addColumnField(ColumnFields.limits, limits);
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ // System.out.println("\nCol: " + id);
+ // //System.out.println("Sql Data Type: " + columns.getString("SQL_DATA_TYPE"));
+ // System.out.println("DataType : " + dataTypeName);
+ // System.out.println("Data Type Number: " + columns.getString("DATA_TYPE"));
+ //
+ // try{
+ // System.out.println("Column Size?: " + columns.getString("COLUMN_SIZE"));
+ // } catch(SQLException ex){
+ // }
+ // try{
+ // System.out.println("Decimal Digits: " + columns.getString("DECIMAL_DIGITS"));
+ // } catch(SQLException ex){
+ // }
+ // try{
+ // System.out.println("Num Precision Radix: " + columns.getString("NUM_PREC_RADIX"));
+ // } catch(SQLException ex){
+ // }
+ // try{
+ // System.out.println("Char Octet Length: " + columns.getString("CHAR_OCTET_LENGTHE"));
+ // } catch(SQLException ex){
+ // }
+ // try{
+ // System.out.println("Remarks: " + columns.getString("REMARKS"));
+ // } catch(SQLException ex){
+ // }
+ // try{
+ // System.out.println("BUFFER_LENGTH: " + columns.getString("BUFFER_LENGTH"));
+ // } catch(SQLException ex){
+ // }
+ aTable.addColumn(column);
+ }
+ columns.close();
+ }
+
+ private void getColumnPrimaryKey(TableElement aTable) throws SQLException {
+ ResultSet primaryKeys = null;
+ try {
+ primaryKeys = dbData.getPrimaryKeys(null, aTable.getSchema(), aTable.getName());
+ } catch (SQLException ex) {
+ primaryKeys = dbData.getPrimaryKeys(null, null, aTable.getName());
+ }
+ Map<String, Set<String>> constraintKeyMap = new HashMap<String, Set<String>>();
+
+ while (primaryKeys.next()) {
+ String column = primaryKeys.getString("COLUMN_NAME");
+ String keyId = primaryKeys.getString("PK_NAME");
+
+ if (keyId == null || keyId.equals("")) {
+ keyId = column + "_PK";
+ }
+
+ if (!constraintKeyMap.containsKey(keyId)) {
+ Set<String> set = new TreeSet<String>();
+ set.add(column);
+ constraintKeyMap.put(keyId, set);
+ } else {
+ Set<String> set = constraintKeyMap.get(keyId);
+ if (!set.contains(column)) {
+ set.add(column);
+ }
+ }
+ }
+
+ Set<String> keys = constraintKeyMap.keySet();
+ for (String pk : keys) {
+ ConstraintElement constraint =
+ ConstraintFactory.getConstraint(ConstraintTypes.PRIMARY_KEY, aTable.getSchema(), pk, false);
+ Set<String> columnSet = constraintKeyMap.get(pk);
+ for (String column : columnSet) {
+ constraint.addColumn(column);
+ }
+ aTable.addConstraint(constraint);
+ }
+ primaryKeys.close();
+ }
+
+ private void getColumnForeignKey(TableElement aTable) throws SQLException {
+ ResultSet importedKeys = dbData.getImportedKeys(null, aTable.getSchema(), aTable.getName());
+
+ while (importedKeys.next()) {
+
+ String appliesToColumnId = importedKeys.getString("FKCOLUMN_NAME");
+ String fkeyId = importedKeys.getString("FK_NAME");
+ String fKeyAddress = importedKeys.getString("FKTABLE_SCHEM");
+
+ String refersToTable = importedKeys.getString("PKTABLE_NAME");
+ String refersToTableAddress = importedKeys.getString("PKTABLE_SCHEM");
+ String referencesColumn = importedKeys.getString("PKCOLUMN_NAME");
+
+ OnDeleteEnum onDeleteAction = OnDeleteEnum.UNSPECIFIED;
+ String onDeleteRule = importedKeys.getString("DELETE_RULE");
+ if (onDeleteRule != null && !onDeleteRule.equals("")) {
+ // System.out.println("onDelete: " + onDeleteRule);
+ int type = Integer.parseInt(onDeleteRule);
+ switch (type) {
+ case java.sql.DatabaseMetaData.importedKeyNoAction:
+ onDeleteAction = OnDeleteEnum.NO_ACTION;
+ break;
+ case java.sql.DatabaseMetaData.importedKeyRestrict:
+ onDeleteAction = OnDeleteEnum.RESTRICT;
+ break;
+ case java.sql.DatabaseMetaData.importedKeyCascade:
+ onDeleteAction = OnDeleteEnum.CASCADE;
+ break;
+ case java.sql.DatabaseMetaData.importedKeySetNull:
+ onDeleteAction = OnDeleteEnum.SET_NULL;
+ break;
+ case java.sql.DatabaseMetaData.importedKeySetDefault:
+ default:
+ onDeleteAction = OnDeleteEnum.UNSPECIFIED;
+ break;
+ }
+ }
+
+ OnUpdateEnum onUpdateAction = OnUpdateEnum.UNSPECIFIED;
+ String onUpdateRule = importedKeys.getString("UPDATE_RULE");
+ if (onUpdateRule != null && !onUpdateRule.equals("")) {
+ // System.out.println("onUpdate: " + onUpdateRule);
+ int type = Integer.parseInt(onUpdateRule);
+ switch (type) {
+ case java.sql.DatabaseMetaData.importedKeyNoAction:
+ onUpdateAction = OnUpdateEnum.NO_ACTION;
+ break;
+ case java.sql.DatabaseMetaData.importedKeyRestrict:
+ onUpdateAction = OnUpdateEnum.RESTRICT;
+ break;
+ case java.sql.DatabaseMetaData.importedKeyCascade:
+ case java.sql.DatabaseMetaData.importedKeySetNull:
+ case java.sql.DatabaseMetaData.importedKeySetDefault:
+ default:
+ onUpdateAction = OnUpdateEnum.UNSPECIFIED;
+ break;
+ }
+ }
+
+ boolean deferrable = false;
+ String deferrabilityId = importedKeys.getString("DEFERRABILITY");
+ if (deferrabilityId != null && !deferrabilityId.equals("")) {
+ int type = Integer.parseInt(deferrabilityId);
+ switch (type) {
+ case java.sql.DatabaseMetaData.importedKeyInitiallyDeferred:
+ case java.sql.DatabaseMetaData.importedKeyInitiallyImmediate:
+ deferrable = true;
+ break;
+ case java.sql.DatabaseMetaData.importedKeyNotDeferrable:
+ deferrable = false;
+ break;
+ default:
+ deferrable = false;
+ break;
+ }
+ }
+
+ if (fKeyAddress == null || fKeyAddress.equals("")) {
+ fKeyAddress = aTable.getSchema();
+ }
+
+ if (fkeyId == null || fkeyId.equals("")) {
+ fkeyId = appliesToColumnId + "_FK";
+ }
+
+ if (refersToTableAddress == null || refersToTableAddress.equals("")) {
+ refersToTableAddress = aTable.getSchema();
+ }
+
+ ConstraintElement constraint =
+ ConstraintFactory.getConstraint(ConstraintTypes.FOREIGN_KEY, fKeyAddress, fkeyId, deferrable);
+ constraint.addColumn(appliesToColumnId);
+
+ ReferenceClause ref = new ReferenceClause(refersToTableAddress, refersToTable);
+ ref.addColumn(referencesColumn);
+
+ ref.setOnDeleteAction(onDeleteAction);
+ ref.setOnUpdateAction(onUpdateAction);
+
+ ((ForeignKey) constraint).addReference(ref);
+
+ aTable.addConstraint(constraint);
+ }
+ importedKeys.close();
+ }
+
+ private void getIndexInfo(TableElement aTable) throws SQLException {
+ ResultSet indexKeys = dbData.getIndexInfo(null, aTable.getSchema(), aTable.getName(), false, false);
+ Pattern pattern = Pattern.compile("SQL\\d+");
+
+ Map<String, Map<Integer, AppliesToClause>> indexMap = new HashMap<String, Map<Integer, AppliesToClause>>();
+
+ while (indexKeys.next()) {
+ String indexName = indexKeys.getString("INDEX_NAME");
+
+ if (indexName != null && indexName.length() > 0) {
+ Matcher matcher = pattern.matcher(indexName);
+ if (!matcher.matches()) {
+ if (indexKeys.getShort("TYPE") == DatabaseMetaData.tableIndexOther) {
+
+ short ordinal = indexKeys.getShort("ORDINAL_POSITION");
+ String columnName = indexKeys.getString("COLUMN_NAME");
+
+ String orderTypeString = indexKeys.getString("ASC_OR_DESC");
+ OrderType orderType = OrderType.Undefined;
+ if (orderTypeString != null) {
+ if (orderTypeString.equalsIgnoreCase("A")) {
+ orderType = OrderType.Ascending;
+ } else if (orderTypeString.equalsIgnoreCase("D")) {
+ orderType = OrderType.Descending;
+ }
+ }
+
+ Map<Integer, AppliesToClause> appliesTo = null;
+ if (indexMap.containsKey(indexName)) {
+ appliesTo = indexMap.get(indexName);
+ } else {
+ appliesTo = new HashMap<Integer, AppliesToClause>();
+ indexMap.put(indexName, appliesTo);
+ }
+ appliesTo.put(new Integer(ordinal), new AppliesToClause(columnName, orderType));
+ }
+ }
+ }
+ }
+ for (String indexName : indexMap.keySet()) {
+ Map<Integer, AppliesToClause> clauseMap = indexMap.get(indexName);
+ IndexElement element = new IndexElement(indexName);
+
+ Set<Integer> index = clauseMap.keySet();
+ Set<Integer> sortedIndex = new TreeSet<Integer>();
+ for (Integer val : index) {
+ sortedIndex.add(val);
+ }
+
+ for (Integer val : sortedIndex) {
+ AppliesToClause clause = clauseMap.get(val);
+ element.addAppliesTo(clause.getColumnName(), clause.getOrderType());
+ }
+ aTable.addIndexData(element);
+ }
+ indexKeys.close();
+ }
+} \ No newline at end of file
diff --git a/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/utility/DbInit.java b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/utility/DbInit.java
new file mode 100644
index 00000000000..72dabcad1c1
--- /dev/null
+++ b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/utility/DbInit.java
@@ -0,0 +1,181 @@
+/*******************************************************************************
+ * 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.database.utility;
+
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Map;
+import java.util.Set;
+import org.eclipse.osee.framework.database.initialize.DbFactory;
+import org.eclipse.osee.framework.plugin.core.config.SupportedDatabase;
+import org.eclipse.osee.framework.ui.plugin.util.db.data.SchemaData;
+import org.eclipse.osee.framework.ui.plugin.util.db.data.TableElement;
+import org.eclipse.osee.framework.ui.plugin.util.db.schemas.SkynetDatabase;
+import org.eclipse.osee.framework.ui.plugin.util.db.schemas.View;
+
+public class DbInit {
+
+ private static String oracleCreateViewCmd = "CREATE OR REPLACE FORCE VIEW ";
+ private static String derbyCreateViewCmd = "CREATE VIEW ";
+ private static String mysqlCreateViewCmd = "CREATE VIEW ";
+ private static String postgresqlCreateViewCmd = "CREATE VIEW ";
+
+ /**
+ * @param connection
+ * @param databaseType
+ * @param databaseType2
+ * @throws SQLException
+ */
+ public static void addViews(Connection connection, SupportedDatabase databaseType) throws SQLException {
+ for (View view : SkynetDatabase.getSkynetViews()) {
+ Statement statement = connection.createStatement();
+ String viewCreateCmd = "";
+ if (databaseType == SupportedDatabase.derby)
+ viewCreateCmd = derbyCreateViewCmd;
+ else if (databaseType == SupportedDatabase.oracle)
+ viewCreateCmd = oracleCreateViewCmd;
+ else if (databaseType == SupportedDatabase.mysql)
+ viewCreateCmd = mysqlCreateViewCmd;
+ else if (databaseType == SupportedDatabase.postgresql) {
+ viewCreateCmd = postgresqlCreateViewCmd;
+ } else
+ throw new IllegalArgumentException("Unhandled database type.");
+
+ statement.executeUpdate(viewCreateCmd + view.toString() + view.getDefinition());
+
+ statement.executeUpdate("create OR REPLACE public synonym " + view.toString() + " for " + view.toString());
+ statement.close();
+ }
+ }
+
+ /**
+ * @param schemas
+ * @param schemas
+ * @param userSpecifiedConfig
+ * @param connection
+ * @param databaseType
+ * @param userSpecifiedConfig2
+ * @param databaseType2
+ * @throws Exception
+ * @throws SQLException
+ */
+ public static void addIndeces(Set<String> schemas, Map<String, SchemaData> userSpecifiedConfig, Connection connection, SupportedDatabase databaseType) throws SQLException, Exception {
+ for (String schemaId : schemas) {
+ if (userSpecifiedConfig.containsKey(schemaId)) {
+ SchemaData userSpecifiedSchemaData = userSpecifiedConfig.get(schemaId);
+ DbFactory userDbFactory = new DbFactory(connection, databaseType, userSpecifiedSchemaData);
+ userDbFactory.createIndeces();
+ }
+ }
+ }
+
+ /**
+ * @param schemas
+ * @param userSpecifiedConfig2
+ * @param databaseType2
+ * @throws Exception
+ * @throws SQLException
+ */
+ public static void addTables(Set<String> schemas, Map<String, SchemaData> userSpecifiedConfig, Connection connection, SupportedDatabase databaseType) throws SQLException, Exception {
+ for (String schemaId : schemas) {
+ if (userSpecifiedConfig.containsKey(schemaId)) {
+ SchemaData userSpecifiedSchemaData = userSpecifiedConfig.get(schemaId);
+ DbFactory userDbFactory = new DbFactory(connection, databaseType, userSpecifiedSchemaData);
+ userDbFactory.createTables();
+ }
+ }
+ }
+
+ /**
+ * @param schemas
+ * @param currentDatabaseConfig
+ * @param userSpecifiedConfig2
+ * @param currentDatabaseConfig2
+ * @param databaseType2
+ * @throws Exception
+ * @throws SQLException
+ */
+ public static void dropTables(Set<String> schemas, Map<String, SchemaData> userSpecifiedConfig, Connection connection, SupportedDatabase databaseType, Map<String, SchemaData> currentDatabaseConfig) throws SQLException, Exception {
+ for (String schemaId : schemas) {
+ if (currentDatabaseConfig.containsKey(schemaId)) {
+ SchemaData currentDbSchemaData = currentDatabaseConfig.get(schemaId);
+ SchemaData userSchema = userSpecifiedConfig.get(schemaId);
+ Map<String, TableElement> currentDBmap = currentDbSchemaData.getTableMap();
+ Map<String, TableElement> userDbMap = userSchema.getTableMap();
+ Set<String> currentDbKeys = currentDBmap.keySet();
+ Set<String> userDbKeys = userDbMap.keySet();
+
+ SchemaData toDrop = new SchemaData();
+ for (String userKey : userDbKeys) {
+ if (currentDbKeys.contains(userKey)) {
+ toDrop.addTableDefinition(currentDBmap.get(userKey));
+ }
+ }
+ DbFactory currentDbFactory = new DbFactory(connection, databaseType, toDrop);
+ currentDbFactory.dropTables();
+ }
+ }
+ }
+
+ /**
+ * @param schemas
+ * @param currentDatabaseConfig
+ * @param userSpecifiedConfig2
+ * @param currentDatabaseConfig2
+ * @param databaseType2
+ * @throws Exception
+ * @throws SQLException
+ */
+ public static void dropIndeces(Set<String> schemas, Map<String, SchemaData> userSpecifiedConfig, Connection connection, SupportedDatabase databaseType, Map<String, SchemaData> currentDatabaseConfig) throws SQLException, Exception {
+ System.out.println("Drop Indeces");
+ for (String schemaId : schemas) {
+ if (currentDatabaseConfig.containsKey(schemaId)) {
+ SchemaData currentDbSchemaData = currentDatabaseConfig.get(schemaId);
+ SchemaData userSchema = userSpecifiedConfig.get(schemaId);
+ Map<String, TableElement> currentDBmap = currentDbSchemaData.getTableMap();
+ Map<String, TableElement> userDbMap = userSchema.getTableMap();
+ Set<String> currentDbKeys = currentDBmap.keySet();
+ Set<String> userDbKeys = userDbMap.keySet();
+
+ SchemaData toDrop = new SchemaData();
+ for (String userKey : userDbKeys) {
+ if (currentDbKeys.contains(userKey)) {
+ toDrop.addTableDefinition(currentDBmap.get(userKey));
+ }
+ }
+ DbFactory currentDbFactory = new DbFactory(connection, databaseType, toDrop);
+ currentDbFactory.dropIndeces();
+ }
+ }
+ }
+
+ /**
+ * @param connection
+ * @throws SQLException
+ */
+ public static void dropViews(Connection connection) throws SQLException {
+ DatabaseMetaData dbData = connection.getMetaData();
+ ResultSet tables = dbData.getTables(null, null, null, new String[] {"VIEW"});
+ while (tables.next()) {
+ String viewName = tables.getString("TABLE_NAME").toUpperCase();
+ for (View viewToDrop : SkynetDatabase.getSkynetViews()) {
+ if (viewToDrop.toString().equalsIgnoreCase(viewName)) {
+ Statement statement = connection.createStatement();
+ statement.executeUpdate("DROP VIEW " + viewName);
+ statement.close();
+ }
+ }
+ }
+ }
+}
diff --git a/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/utility/FileUtility.java b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/utility/FileUtility.java
new file mode 100644
index 00000000000..7771abdbd51
--- /dev/null
+++ b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/utility/FileUtility.java
@@ -0,0 +1,84 @@
+/*******************************************************************************
+ * 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.database.utility;
+
+import java.io.File;
+import java.io.FilenameFilter;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import org.eclipse.osee.framework.jdk.core.db.DbConfigFileInformation;
+
+// TODO: this class has some overlap with methods provided in org.eclipse.osee.framework.jdk.core.Lib
+public class FileUtility {
+
+ public static boolean isValidDirectory(File directory) {
+ if (directory != null && directory.exists() && directory.canRead()) {
+ File[] listOfFiles = directory.listFiles();
+ if (listOfFiles.length != 0) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public static void setupDirectoryForWrite(File directory) throws IOException {
+ if (directory.exists() && directory.canWrite()) {
+ if (!directory.isDirectory()) {
+ directory.mkdirs();
+ }
+ } else {
+ directory.mkdirs();
+ }
+ }
+
+ public static List<File> getFileList(File sourceDirectory, final String extension) {
+ File[] listOfFiles = sourceDirectory.listFiles(new FilenameFilter() {
+ public boolean accept(File directoryName, String filename) {
+ return filename.endsWith(extension) && (new File(directoryName + File.separator + filename)).canRead();
+ }
+ });
+ return Arrays.asList(listOfFiles);
+ }
+
+ public static List<URL> getSchemaFileList(File sourceDirectory) {
+ List<File> files = getFileList(sourceDirectory, DbConfigFileInformation.getSchemaFileExtension());
+ List<URL> streams = new ArrayList<URL>();
+ for (File file : files) {
+ try {
+ streams.add(file.toURL());
+ } catch (MalformedURLException e) {
+ e.printStackTrace();
+ }
+ }
+ return streams;
+ }
+
+ public static List<File> getDBDataFileList(File sourceDirectory) {
+ return getFileList(sourceDirectory, DbConfigFileInformation.getDbDataFileExtension());
+ }
+
+ public static List<URL> getDBDataFileListInputStream(File sourceDirectory) {
+ List<File> files = getFileList(sourceDirectory, DbConfigFileInformation.getDbDataFileExtension());
+ List<URL> streams = new ArrayList<URL>();
+ for (File file : files) {
+ try {
+ streams.add(file.toURL());
+ } catch (MalformedURLException e) {
+ e.printStackTrace();
+ }
+ }
+ return streams;
+ }
+}
diff --git a/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/utility/GroupSelection.java b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/utility/GroupSelection.java
new file mode 100644
index 00000000000..4153e2b4d65
--- /dev/null
+++ b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/utility/GroupSelection.java
@@ -0,0 +1,122 @@
+/*******************************************************************************
+ * 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.database.utility;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.osee.framework.database.DatabaseActivator;
+import org.eclipse.osee.framework.jdk.core.util.OseeProperties;
+import org.eclipse.osee.framework.jdk.core.util.Strings;
+import org.eclipse.osee.framework.plugin.core.config.ConfigUtil;
+import org.eclipse.osee.framework.plugin.core.util.ExtensionPoints;
+
+/**
+ * @author Andrew M. Finkbeiner
+ */
+public class GroupSelection {
+ private static final Logger logger = ConfigUtil.getConfigFactory().getLogger(GroupSelection.class);
+ private static final GroupSelection instance = new GroupSelection();
+ private Map<String, List<String>> initGroups;
+ private String choice = null;
+
+ /**
+ * @param initGroups
+ */
+ private GroupSelection() {
+ super();
+ initGroups = new LinkedHashMap<String, List<String>>();
+ populateDbInitChoices();
+ }
+
+ public static GroupSelection getInstance() {
+ return instance;
+ }
+
+ private void populateDbInitChoices() {
+ List<IConfigurationElement> elements =
+ ExtensionPoints.getExtensionElements(DatabaseActivator.getInstance(), "AddDbInitChoice", "dbInitChoice");
+
+ for (IConfigurationElement element : elements) {
+ String choiceClass = element.getAttribute("classname");
+ try {
+ IAddDbInitChoice choice =
+ (IAddDbInitChoice) Platform.getBundle(element.getContributor().getName()).loadClass(choiceClass).newInstance();
+ choice.addDbInitChoice(this);
+ } catch (InstantiationException ex) {
+ logger.log(Level.SEVERE, ex.toString(), ex);
+ } catch (IllegalAccessException ex) {
+ logger.log(Level.SEVERE, ex.toString(), ex);
+ } catch (ClassNotFoundException ex) {
+ logger.log(Level.SEVERE, ex.toString(), ex);
+ }
+ }
+ }
+
+ private void addCommonChoices(List<String> dbInitTasks, boolean bareBones) {
+ List<String> initTasks = new ArrayList<String>();
+ initTasks.add("org.eclipse.osee.framework.skynet.core.SkynetDbInit");
+ dbInitTasks.addAll(0, initTasks);
+ }
+
+ public void addChoice(String listName, List<String> dbInitTasks, boolean bareBones) {
+ addCommonChoices(dbInitTasks, bareBones);
+ initGroups.put(listName, dbInitTasks);
+ }
+
+ public List<String> getDbInitTasks() {
+ if (choice == null) {
+ chooser("Select Init Group To Run.", new ArrayList<String>(initGroups.keySet()));
+ }
+ return initGroups.get(choice);
+ }
+
+ private String chooser(String message, List<String> choices) {
+ String configChoice = OseeProperties.getInstance().getDBConfigInitChoice();
+ int selection = -1;
+ if (false != Strings.isValid(configChoice)) {
+ selection = choices.indexOf(configChoice);
+ }
+
+ if (selection <= -1) {
+ BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
+ while (selection == -1) {
+ try {
+ System.out.println(message);
+ for (int i = 0; i < choices.size(); i++) {
+ System.out.println(" " + i + ") " + choices.get(i));
+ }
+ System.out.println("Enter: 0 - " + (choices.size() - 1));
+ String line = stdin.readLine();
+ selection = Integer.parseInt(line);
+ if (selection < 0 || selection >= choices.size()) {
+ System.out.println("Invalid selection: Index [" + selection + "] is out of range.");
+ selection = -1;
+ }
+ } catch (Exception ex) {
+ System.out.println("Invalid selection: Index [" + selection + "] is out of range.");
+ ex.printStackTrace();
+ }
+ }
+ }
+ choice = choices.get(selection);
+ logger.log(Level.INFO, String.format("DB Config Choice Selected: [%s]", choice));
+ return choice;
+ }
+} \ No newline at end of file
diff --git a/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/utility/IAddDbInitChoice.java b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/utility/IAddDbInitChoice.java
new file mode 100644
index 00000000000..1f7a007b32f
--- /dev/null
+++ b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/utility/IAddDbInitChoice.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.database.utility;
+
+/**
+ * @author Ryan D. Brooks
+ */
+public interface IAddDbInitChoice {
+ public abstract void addDbInitChoice(GroupSelection groupSelection);
+}
diff --git a/MS_0.1.4_20080103/org.eclipse.osee.framework.database/support/dbrelease.xml b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/support/dbrelease.xml
new file mode 100644
index 00000000000..84fd5bb354d
--- /dev/null
+++ b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/support/dbrelease.xml
@@ -0,0 +1,88 @@
+<project name="DBRelease" default="dbrelease" basedir="..">
+
+ <property name="ECLIPSE_HOME" value="C:\Program Files\OSEE" />
+ <property name="release" value="dbrelease/" />
+ <property name="targetzip" value="${release}../oseeDatabase.zip" />
+ <property name="manifestname" value="RELEASE.MF" />
+ <property name="antdir" value="ant/" />
+ <property name="derby" value="${ECLIPSE_HOME}\plugins\org.apache.derby.core_10.1.2.1" />
+
+ <property name="eclipseruntimejar" value="org.eclipse.core.runtime_3.1.2.jar"/>
+ <property name="eclipseJFacejar" value="org.eclipse.jface_3.1.1.jar" />
+ <property name="eclipseRuntime" value="${ECLIPSE_HOME}\plugins\${eclipseruntimejar}" />
+ <property name="eclipseJFace" value="${ECLIPSE_HOME}\plugins\${eclipseJFacejar}" />
+
+ <property name="oseecore" value="osee.jdk.core/bin/" />
+ <property name="oseedb" value="osee.database/bin/" />
+ <property name="oseejini" value="osee.jini/bin/" />
+ <property name="oseeats2" value="osee.ats2/bin/" />
+ <property name="oseedefine" value="osee.define/bin/" />
+
+ <target name="clean">
+ <delete file="${manifestname}" />
+ <delete dir="${release}" />
+ </target>
+
+ <target name="createrelease">
+ <echo message="createrelease PATH=${PATH}" />
+ <mkdir dir="${PATH}" />
+ <manifest file="RELEASE.MF">
+ <attribute name="Main-Class" value="osee/database/core/OseeDbLauncher" />
+ <attribute name="Class-Path" value="oseecore.jar oseejini.jar oseedefine.jar oseeats2.jar derby.jar derbyclient.jar derbynet.jar derbytools.jar ${eclipseruntimejar} ${eclipseJFacejar}" />
+ <section name="common">
+ <attribute name="Specification-Title" value="Example" />
+ <attribute name="Specification-Version" value="${version}" />
+ <attribute name="Specification-Vendor" value="Example Organization" />
+ <attribute name="Implementation-Title" value="common" />
+ <attribute name="Implementation-Version" value="${version} ${TODAY}" />
+ <attribute name="Implementation-Vendor" value="Example Corp." />
+ </section>
+ </manifest>
+
+ <jar jarfile="${PATH}/oseedb.jar" basedir="../${oseedb}" manifest="RELEASE.MF" />
+ <jar jarfile="${PATH}/oseecore.jar" basedir="../${oseecore}" />
+ <jar jarfile="${PATH}/oseejini.jar" basedir="../${oseejini}" />
+ <jar jarfile="${PATH}/oseeats2.jar" basedir="../${oseeats2}" />
+ <jar jarfile="${PATH}/oseedefine.jar" basedir="../${oseedefine}" />
+
+ <copy toDir="${PATH}/">
+ <fileset file="${eclipseRuntime}"/>
+ <fileset file="${eclipseJFace}" />
+ </copy>
+
+ <copy toDir="${PATH}/">
+ <fileset dir="${derby}" includes="*.jar" />
+ </copy>
+
+ <copy toDir="${PATH}/DatabaseSchemaDump">
+ <fileset dir="DatabaseSchemaDump"/>
+ </copy>
+
+ <copy toDir="${PATH}/excelFiles">
+ <fileset dir="excelFiles"/>
+ </copy>
+
+ <copy toDir="${PATH}/support/">
+ <fileset file="../${oseecore}/../support/oseeSiteConfig.xml" />
+ </copy>
+ <delete file="${manifestname}" />
+ </target>
+
+ <target name="dbrelease">
+ <antcall target="createrelease">
+ <param name="PATH" value="dbrelease/" />
+ </antcall>
+ </target>
+
+ <target name="dbreleasezip">
+ <antcall target="createrelease">
+ <param name="PATH" value="temp/" />
+ </antcall>
+ <zip destfile="${targetzip}">
+ <fileset dir="temp/" />
+ </zip>
+
+ <delete dir="temp/" />
+ </target>
+
+</project> \ No newline at end of file
diff --git a/MS_0.1.4_20080103/org.eclipse.osee.framework.database/support/sqlAnt.xml b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/support/sqlAnt.xml
new file mode 100644
index 00000000000..9363f690fc2
--- /dev/null
+++ b/MS_0.1.4_20080103/org.eclipse.osee.framework.database/support/sqlAnt.xml
@@ -0,0 +1,84 @@
+<project name="SQLAnt" default="query" basedir=".">
+
+ <!-- LOCAL DERBY PROPERTIES -->
+ <property name="driver" value="org.apache.derby.jdbc.ClientDriver"/>
+ <property name="url" value="jdbc:derby://localhost:1621/DerbyDatabase;create=true"/>
+ <property name="userid" value="osee"/>
+ <property name="password" value="osee"/>
+ <property name="driverpath" value="C:\Program Files\OSEE\plugins\org.apache.derby.core_10.1.2.1\derbyclient.jar" />
+
+ <target name="query" >
+ <sql driver="${driver}" url="${url}" userid="${userid}" password="${password}" print="true" >
+ <classpath><pathelement location="${driverpath}"/></classpath>
+ select * from OSEE_DEFINE_ATTRIBUTE_TYPE
+ </sql>
+ </target>
+
+ <target name="getAllOseeInfo" >
+ <sql driver="${driver}" url="${url}" userid="${userid}" password="${password}" print="true" >
+ <classpath><pathelement location="${driverpath}"/></classpath>
+ select * from OSEE_INFO
+ </sql>
+ </target>
+
+ <target name="insertderbyTestScriptOutputFalse" >
+ <sql driver="${driver}" url="${url}" userid="${userid}" password="${password}" print="true" >
+ <classpath><pathelement location="${driverpath}"/></classpath>
+ insert into OSEE_INFO (OSEE_VALUE, OSEE_KEY) values ('FALSE', 'SAVE_OUTFILE_IN_DB')
+ </sql>
+ </target>
+
+ <target name="saveTestScriptOutputTrue" >
+ <sql driver="${driver}" url="${url}" userid="${userid}" password="${password}" print="true" >
+ <classpath><pathelement location="${driverpath}"/></classpath>
+ UPDATE OSEE_INFO SET OSEE_VALUE = 'TRUE'
+ WHERE OSEE_KEY = 'SAVE_OUTFILE_IN_DB'
+ </sql>
+ </target>
+
+ <target name="saveTestScriptOutputFalse" >
+ <sql driver="${driver}" url="${url}" userid="${userid}" password="${password}" print="true" >
+ <classpath><pathelement location="${driverpath}"/></classpath>
+ UPDATE OSEE_INFO SET OSEE_VALUE = 'FALSE'
+ WHERE OSEE_KEY = 'SAVE_OUTFILE_IN_DB'
+ </sql>
+ </target>
+
+ <target name="testskynet" >
+ <sql driver="${driver}" url="${url}" userid="${userid}" password="${password}" print="true" >
+ <classpath><pathelement location="${driverpath}"/></classpath>
+ SELECT attr_type_id FROM OSEE_DEFINE_valid_attributes WHERE art_type_id = 20 AND gamma_id &lt;= 100000
+ </sql>
+ </target>
+
+
+ <target name="testskynet2" >
+ <sql driver="${driver}" url="${url}" userid="${userid}" password="${password}" print="true" >
+ <classpath><pathelement location="${driverpath}"/></classpath>
+ SELECT OSEE_DEFINE_attr_base_type.attribute_class,
+ OSEE_DEFINE_attribute_type.attr_type_id,
+ OSEE_DEFINE_attribute_type.name,
+ OSEE_DEFINE_attribute_type.default_value,
+ OSEE_DEFINE_attribute_type.validity_xml,
+ OSEE_DEFINE_attribute_type.min_occurence,
+ OSEE_DEFINE_attribute_type.max_occurence,
+ OSEE_DEFINE_attribute_type.user_viewable,
+ OSEE_DEFINE_attribute_type.tip_text
+ FROM OSEE_DEFINE_attribute_type, OSEE_DEFINE_attr_base_type,transaction_gamma_view
+ WHERE OSEE_DEFINE_attr_base_type.attr_base_type_id=OSEE_DEFINE_attribute_type.attr_base_type_id
+ AND transaction_gamma_view.transaction_id=179
+ AND OSEE_DEFINE_attribute_type.gamma_id&lt;=transaction_gamma_view.largest_gamma_id
+ </sql>
+ </target>
+
+
+ <target name="getseqtable" >
+ <sql driver="${driver}" url="${url}" userid="${userid}" password="${password}" print="true" >
+ <classpath><pathelement location="${driverpath}"/></classpath>
+ SELECT * FROM OSEE_DEFINE_SEQUENCE
+ </sql>
+ </target>
+
+</project>
+
+

Back to the top