]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.project/src/org/simantics/project/management/DatabaseAgent.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.project / src / org / simantics / project / management / DatabaseAgent.java
diff --git a/bundles/org.simantics.project/src/org/simantics/project/management/DatabaseAgent.java b/bundles/org.simantics.project/src/org/simantics/project/management/DatabaseAgent.java
new file mode 100644 (file)
index 0000000..afdf3b7
--- /dev/null
@@ -0,0 +1,102 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007 VTT Technical Research Centre of Finland and others.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.project.management;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+import java.util.Properties;\r
+\r
+import org.eclipse.equinox.p2.metadata.VersionedId;\r
+import org.simantics.db.ServerEx;\r
+import org.simantics.db.Session;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.service.LifecycleSupport;\r
+\r
+/**\r
+ * Database agent installs ontologies and   \r
+ *\r
+ * @author Toni Kalajainen <toni.kalajainen@vtt.fi>\r
+ */\r
+public class DatabaseAgent {\r
+\r
+       ServerEx server;\r
+       BundlePool bundlePool;\r
+       \r
+       /**\r
+        * Create a new agent.\r
+        * \r
+        * @param server\r
+        * @param bundlePool\r
+        * @throws DatabaseException\r
+        */\r
+       public DatabaseAgent(ServerEx server, BundlePool bundlePool) {\r
+               this.server = server;\r
+               this.bundlePool = bundlePool;\r
+       }\r
+       \r
+       /**\r
+        * Get a snapshot of database current profile\r
+        * \r
+        * @return database specification\r
+        * @throws DatabaseException\r
+        */\r
+       public DatabaseSpec getSpecification() throws DatabaseException {\r
+               // Create session\r
+               Properties props = new Properties();\r
+               Session session = server.createSession(props);\r
+               try {\r
+                       return session.syncRequest( DatabaseSpec.QUERY );\r
+               } finally {\r
+                       // Close session\r
+                       session.getService(LifecycleSupport.class).close();\r
+               }\r
+       }\r
+       \r
+       /**\r
+        * Perform install operation to \r
+        * @param spec\r
+        * @throws DatabaseException\r
+        */\r
+       public void perform(DatabaseSpec spec) throws DatabaseException {\r
+\r
+               // 1. Validate Spec\r
+               \r
+               \r
+       }\r
+       \r
+       public List<Problem> validate(DatabaseSpec spec) {\r
+               ArrayList<Problem> result = new ArrayList<Problem>();\r
+               \r
+               // 1. Ontology exists for all features\r
+               for (ProjectSpec ps : spec.projects) {\r
+                       for (FeatureSpec fs : ps.features) {\r
+                               /*IVersionedId vid =*/ VersionedId.parse(fs.versionedId);\r
+                               // Now use BundlePool to find out ontologies\r
+//                             bundlePool.getMetadataRepository()\r
+                       }\r
+               }\r
+               \r
+               return result;\r
+       }\r
+\r
+       \r
+       static class Problem {\r
+               // Cost of the problem. 0-100\r
+               public int severity;\r
+               public String msg;\r
+       }\r
+\r
+       static class OntologyVersionConflict {\r
+               \r
+       }\r
+       \r
+}\r
+\r