]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.project/src/org/simantics/project/management/DatabaseAgent.java
Merge commit '728147df5d63a3333daff3d8c0e9bfd4f5597e3a'
[simantics/platform.git] / bundles / org.simantics.project / src / org / simantics / project / management / DatabaseAgent.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007 VTT Technical Research Centre of Finland and others.\r
3  * All rights reserved. This program and the accompanying materials\r
4  * are made available under the terms of the Eclipse Public License v1.0\r
5  * which accompanies this distribution, and is available at\r
6  * http://www.eclipse.org/legal/epl-v10.html\r
7  *\r
8  * Contributors:\r
9  *     VTT Technical Research Centre of Finland - initial API and implementation\r
10  *******************************************************************************/\r
11 package org.simantics.project.management;\r
12 \r
13 import java.util.ArrayList;\r
14 import java.util.List;\r
15 import java.util.Properties;\r
16 \r
17 import org.eclipse.equinox.p2.metadata.VersionedId;\r
18 import org.simantics.db.ServerEx;\r
19 import org.simantics.db.Session;\r
20 import org.simantics.db.exception.DatabaseException;\r
21 import org.simantics.db.service.LifecycleSupport;\r
22 \r
23 /**\r
24  * Database agent installs ontologies and   \r
25  *\r
26  * @author Toni Kalajainen <toni.kalajainen@vtt.fi>\r
27  */\r
28 public class DatabaseAgent {\r
29 \r
30         ServerEx server;\r
31         BundlePool bundlePool;\r
32         \r
33         /**\r
34          * Create a new agent.\r
35          * \r
36          * @param server\r
37          * @param bundlePool\r
38          * @throws DatabaseException\r
39          */\r
40         public DatabaseAgent(ServerEx server, BundlePool bundlePool) {\r
41                 this.server = server;\r
42                 this.bundlePool = bundlePool;\r
43         }\r
44         \r
45         /**\r
46          * Get a snapshot of database current profile\r
47          * \r
48          * @return database specification\r
49          * @throws DatabaseException\r
50          */\r
51         public DatabaseSpec getSpecification() throws DatabaseException {\r
52                 // Create session\r
53                 Properties props = new Properties();\r
54                 Session session = server.createSession(props);\r
55                 try {\r
56                         return session.syncRequest( DatabaseSpec.QUERY );\r
57                 } finally {\r
58                         // Close session\r
59                         session.getService(LifecycleSupport.class).close();\r
60                 }\r
61         }\r
62         \r
63         /**\r
64          * Perform install operation to \r
65          * @param spec\r
66          * @throws DatabaseException\r
67          */\r
68         public void perform(DatabaseSpec spec) throws DatabaseException {\r
69 \r
70                 // 1. Validate Spec\r
71                 \r
72                 \r
73         }\r
74         \r
75         public List<Problem> validate(DatabaseSpec spec) {\r
76                 ArrayList<Problem> result = new ArrayList<Problem>();\r
77                 \r
78                 // 1. Ontology exists for all features\r
79                 for (ProjectSpec ps : spec.projects) {\r
80                         for (FeatureSpec fs : ps.features) {\r
81                                 /*IVersionedId vid =*/ VersionedId.parse(fs.versionedId);\r
82                                 // Now use BundlePool to find out ontologies\r
83 //                              bundlePool.getMetadataRepository()\r
84                         }\r
85                 }\r
86                 \r
87                 return result;\r
88         }\r
89 \r
90         \r
91         static class Problem {\r
92                 // Cost of the problem. 0-100\r
93                 public int severity;\r
94                 public String msg;\r
95         }\r
96 \r
97         static class OntologyVersionConflict {\r
98                 \r
99         }\r
100         \r
101 }\r
102 \r