]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/GraphSessionVirtual.java
Merge branch 'master' into private/eclipse-4.7
[simantics/platform.git] / bundles / org.simantics.db.procore / src / fi / vtt / simantics / procore / internal / GraphSessionVirtual.java
index f6eba7eb8c3d188c5283d6cbee078ac6eed0d640..461301e8b91a09a66f9ac870ca8ca09f00f67a3f 100644 (file)
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in Industry THTH ry.\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 fi.vtt.simantics.procore.internal;\r
-\r
-import gnu.trove.map.hash.THashMap;\r
-\r
-import java.io.File;\r
-import java.io.FileInputStream;\r
-import java.io.IOException;\r
-import java.io.InputStream;\r
-import java.util.Properties;\r
-import java.util.Set;\r
-import java.util.concurrent.atomic.AtomicLong;\r
-\r
-import org.simantics.db.ClusterCreator;\r
-import org.simantics.db.Database;\r
-import org.simantics.db.SessionReference;\r
-import org.simantics.db.Database.Session;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.impl.support.VirtualGraphServerSupport;\r
-import org.simantics.db.procore.protocol.Constants;\r
-import org.simantics.db.server.ProCoreException;\r
-import org.simantics.db.service.ClusterUID;\r
-\r
-class GraphSessionVirtual extends GraphSession { // Äsh! This extends relation was/is a pure design choice.\r
-    private static String FileName = "virtualGraph.builtins.dat";\r
-    private static long BuiltinClusterId = -1; // Virtual graph doesn't have clusters.\r
-    static class VirtualSession implements Session {\r
-        @Override\r
-        public Database getDatabase() {\r
-            return null;\r
-        }\r
-        @Override\r
-        public void close() throws ProCoreException {\r
-        }\r
-        @Override\r
-        public void open() throws ProCoreException {\r
-        }\r
-        @Override\r
-        public boolean isClosed() throws ProCoreException {\r
-            return false;\r
-        }\r
-        @Override\r
-        public String execute(String command) throws ProCoreException {\r
-            return null;\r
-        }\r
-        @Override\r
-        public void acceptCommit(long transactionId, long changeSetId, byte[] metadata) throws ProCoreException {\r
-        }\r
-        @Override\r
-        public long cancelCommit(long transactionId, long changeSetId, byte[] metadata, OnChangeSetUpdate on) throws ProCoreException {\r
-            return 0;\r
-        }\r
-        @Override\r
-        public Transaction askReadTransaction() throws ProCoreException {\r
-            return null;\r
-        }\r
-        @Override\r
-        public Transaction askWriteTransaction(long transactionId) throws ProCoreException {\r
-            return null;\r
-        }\r
-        @Override\r
-        public long endTransaction(long transactionId) throws ProCoreException {\r
-            return 0;\r
-        }\r
-        @Override\r
-        public byte[] getChangeSetMetadata(long changeSetId) throws ProCoreException {\r
-            return null;\r
-        }\r
-        @Override\r
-        public ChangeSetData getChangeSetData(long minChangeSetId, long maxChangeSetId, OnChangeSetUpdate on) throws ProCoreException {\r
-            return null;\r
-        }\r
-        @Override\r
-        public ChangeSetIds getChangeSetIds() throws ProCoreException {\r
-            return null;\r
-        }\r
-        @Override\r
-        public Cluster getCluster(byte[] clusterId) throws ProCoreException {\r
-            return null;\r
-        }\r
-        @Override\r
-        public ClusterChanges getClusterChanges(long changeSetId, byte[] clusterId) throws ProCoreException {\r
-            return null;\r
-        }\r
-        @Override\r
-        public ClusterIds getClusterIds() throws ProCoreException {\r
-            return null;\r
-        }\r
-        @Override\r
-        public Information getInformation() throws ProCoreException {\r
-            return null;\r
-        }\r
-        @Override\r
-        public Refresh getRefresh(long changeSetId) throws ProCoreException {\r
-            return null;\r
-        }\r
-        @Override\r
-        public ResourceSegment getResourceSegment(byte[] clusterUID, int resourceIndex, long offset, short size) throws ProCoreException {\r
-            return null;\r
-        }\r
-        @Override\r
-        public long reserveIds(int count) throws ProCoreException {\r
-            return 0;\r
-        }\r
-        @Override\r
-        public void updateCluster(byte[] operations) throws ProCoreException {\r
-        }\r
-        @Override\r
-        public boolean undo(long[] cChangeSetIds, OnChangeSetUpdate onChangeSetUpdate) throws ProCoreException {\r
-            return false;\r
-        }\r
-        @Override\r
-        public <T> T clone(ClusterUID clusterUID, ClusterCreator clusterCreator) throws DatabaseException {\r
-            throw new UnsupportedOperationException();\r
-        }\r
-        @Override\r
-        public boolean refreshEnabled() {\r
-            return false;\r
-        }\r
-        @Override\r
-        public boolean rolledback() {\r
-            return false;\r
-        }\r
-    }\r
-    private AtomicLong changeSetId = new AtomicLong(Constants.NullChangeSetId);\r
-    private AtomicLong transactionId = new AtomicLong(Constants.NullTransactionId);\r
-    public static ServerInformationImpl serverInfo = new ServerInformationImpl("serverId", "protocolId", "databaseId", 0);\r
-    private VirtualGraphServerSupport virtualGraphServerSupport;\r
-       public GraphSessionVirtual(SessionImplSocket sessionImpl, SessionReference sessionReference, VirtualGraphServerSupport vgss) {\r
-        super(sessionImpl, sessionReference, new VirtualSession()); // Super does not expect null session.\r
-        virtualGraphServerSupport = vgss;\r
-    }\r
-    protected THashMap<String, BuiltinData> initBuiltinMap()\r
-    throws DatabaseException {\r
-        try {\r
-            Properties props = new Properties();\r
-            File from = new File(FileName);\r
-            InputStream in = new FileInputStream(from);\r
-            props.load(in);\r
-            THashMap<String, BuiltinData>  builtins = new THashMap<String, BuiltinData>();\r
-            Set<String> keys = props.stringPropertyNames();\r
-            for (String key : keys) {\r
-                long resourceId = Long.parseLong(key);\r
-                long cluster = BuiltinClusterId;\r
-                int resourceIndex = (int)resourceId;\r
-                String uri = props.getProperty(key);\r
-                BuiltinData bd = new BuiltinData(resourceIndex, cluster);\r
-                builtins.put(uri, bd);\r
-            }\r
-            return builtins;\r
-        } catch(IOException e) {\r
-            if (DEBUG)\r
-                e.printStackTrace();\r
-            throw new DatabaseException("Failed to read builtins.", e);\r
-        }\r
-    }\r
-    @Override\r
-    protected ServerInformationImpl getServerInformation() {\r
-        return serverInfo;\r
-    }\r
-    @Override\r
-    public void acceptCommit(long transactionId, long csid, byte[] metadata)\r
-    throws DatabaseException {\r
-        changeSetId.incrementAndGet();\r
-    }\r
-\r
-    @Override\r
-    public void cancelCommit(long transactionId, long csid, byte[] metadata, SynchronizeContextI context)\r
-    throws DatabaseException {\r
-        changeSetId.incrementAndGet();\r
-    }\r
-\r
-    @Override\r
-    public void endTransaction(long transactionId, boolean write)\r
-    throws DatabaseException {\r
-\r
-    }\r
-\r
-    @Override\r
-    public long askWriteTransaction(int thread, long transactionId)\r
-    throws DatabaseException {\r
-        if (Constants.NullTransactionId != transactionId)\r
-            return transactionId;\r
-        else\r
-            return this.transactionId.incrementAndGet();\r
-    }\r
-    @Override\r
-    public long askReadTransaction(int thread)\r
-    throws DatabaseException {\r
-        return transactionId.incrementAndGet();\r
-    }\r
-    @Override\r
-    public void stop() throws DatabaseException {\r
-        if (DEBUG)\r
-            System.out.println("GraphSessionVirtual: stop.");\r
-\r
-    }\r
-    @Override\r
-    public long reserveIds(int count)\r
-    throws DatabaseException {\r
-//        VirtualGraphServerSupport s = session.getService(VirtualGraphServerSupport.class);\r
-        long id = Constants.NullSubjectId;\r
-        for (int i=0; i<count; ++i)\r
-           id = virtualGraphServerSupport.createVirtual();\r
-        return id;\r
-    }\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * 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:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package fi.vtt.simantics.procore.internal;
+
+import gnu.trove.map.hash.THashMap;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicLong;
+
+import org.simantics.db.ClusterCreator;
+import org.simantics.db.Database;
+import org.simantics.db.SessionReference;
+import org.simantics.db.Database.Session;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.impl.support.VirtualGraphServerSupport;
+import org.simantics.db.procore.protocol.Constants;
+import org.simantics.db.server.ProCoreException;
+import org.simantics.db.service.ClusterUID;
+
+class GraphSessionVirtual extends GraphSession { // Äsh! This extends relation was/is a pure design choice.
+    private static String FileName = "virtualGraph.builtins.dat";
+    private static long BuiltinClusterId = -1; // Virtual graph doesn't have clusters.
+    static class VirtualSession implements Session {
+        @Override
+        public Database getDatabase() {
+            return null;
+        }
+        @Override
+        public void close() throws ProCoreException {
+        }
+        @Override
+        public void open() throws ProCoreException {
+        }
+        @Override
+        public boolean isClosed() throws ProCoreException {
+            return false;
+        }
+        @Override
+        public String execute(String command) throws ProCoreException {
+            return null;
+        }
+        @Override
+        public void acceptCommit(long transactionId, long changeSetId, byte[] metadata) throws ProCoreException {
+        }
+        @Override
+        public long cancelCommit(long transactionId, long changeSetId, byte[] metadata, OnChangeSetUpdate on) throws ProCoreException {
+            return 0;
+        }
+        @Override
+        public Transaction askReadTransaction() throws ProCoreException {
+            return null;
+        }
+        @Override
+        public Transaction askWriteTransaction(long transactionId) throws ProCoreException {
+            return null;
+        }
+        @Override
+        public long endTransaction(long transactionId) throws ProCoreException {
+            return 0;
+        }
+        @Override
+        public byte[] getChangeSetMetadata(long changeSetId) throws ProCoreException {
+            return null;
+        }
+        @Override
+        public ChangeSetData getChangeSetData(long minChangeSetId, long maxChangeSetId, OnChangeSetUpdate on) throws ProCoreException {
+            return null;
+        }
+        @Override
+        public ChangeSetIds getChangeSetIds() throws ProCoreException {
+            return null;
+        }
+        @Override
+        public Cluster getCluster(byte[] clusterId) throws ProCoreException {
+            return null;
+        }
+        @Override
+        public ClusterChanges getClusterChanges(long changeSetId, byte[] clusterId) throws ProCoreException {
+            return null;
+        }
+        @Override
+        public ClusterIds getClusterIds() throws ProCoreException {
+            return null;
+        }
+        @Override
+        public Information getInformation() throws ProCoreException {
+            return null;
+        }
+        @Override
+        public Refresh getRefresh(long changeSetId) throws ProCoreException {
+            return null;
+        }
+        @Override
+        public ResourceSegment getResourceSegment(byte[] clusterUID, int resourceIndex, long offset, short size) throws ProCoreException {
+            return null;
+        }
+        @Override
+        public long reserveIds(int count) throws ProCoreException {
+            return 0;
+        }
+        @Override
+        public void updateCluster(byte[] operations) throws ProCoreException {
+        }
+        @Override
+        public boolean undo(long[] cChangeSetIds, OnChangeSetUpdate onChangeSetUpdate) throws ProCoreException {
+            return false;
+        }
+        @Override
+        public <T> T clone(ClusterUID clusterUID, ClusterCreator clusterCreator) throws DatabaseException {
+            throw new UnsupportedOperationException();
+        }
+        @Override
+        public boolean refreshEnabled() {
+            return false;
+        }
+        @Override
+        public boolean rolledback() {
+            return false;
+        }
+    }
+    private AtomicLong changeSetId = new AtomicLong(Constants.NullChangeSetId);
+    private AtomicLong transactionId = new AtomicLong(Constants.NullTransactionId);
+    public static ServerInformationImpl serverInfo = new ServerInformationImpl("serverId", "protocolId", "databaseId", 0);
+    private VirtualGraphServerSupport virtualGraphServerSupport;
+       public GraphSessionVirtual(SessionImplSocket sessionImpl, SessionReference sessionReference, VirtualGraphServerSupport vgss) {
+        super(sessionImpl, sessionReference, new VirtualSession()); // Super does not expect null session.
+        virtualGraphServerSupport = vgss;
+    }
+    protected THashMap<String, BuiltinData> initBuiltinMap()
+    throws DatabaseException {
+        try {
+            Properties props = new Properties();
+            File from = new File(FileName);
+            InputStream in = new FileInputStream(from);
+            props.load(in);
+            THashMap<String, BuiltinData>  builtins = new THashMap<String, BuiltinData>();
+            Set<String> keys = props.stringPropertyNames();
+            for (String key : keys) {
+                long resourceId = Long.parseLong(key);
+                long cluster = BuiltinClusterId;
+                int resourceIndex = (int)resourceId;
+                String uri = props.getProperty(key);
+                BuiltinData bd = new BuiltinData(resourceIndex, cluster);
+                builtins.put(uri, bd);
+            }
+            return builtins;
+        } catch(IOException e) {
+            if (DEBUG)
+                e.printStackTrace();
+            throw new DatabaseException("Failed to read builtins.", e);
+        }
+    }
+    @Override
+    protected ServerInformationImpl getServerInformation() {
+        return serverInfo;
+    }
+    @Override
+    public void acceptCommit(long transactionId, long csid, byte[] metadata)
+    throws DatabaseException {
+        changeSetId.incrementAndGet();
+    }
+
+    @Override
+    public void cancelCommit(long transactionId, long csid, byte[] metadata, SynchronizeContextI context)
+    throws DatabaseException {
+        changeSetId.incrementAndGet();
+    }
+
+    @Override
+    public void endTransaction(long transactionId, boolean write)
+    throws DatabaseException {
+
+    }
+
+    @Override
+    public long askWriteTransaction(int thread, long transactionId)
+    throws DatabaseException {
+        if (Constants.NullTransactionId != transactionId)
+            return transactionId;
+        else
+            return this.transactionId.incrementAndGet();
+    }
+    @Override
+    public long askReadTransaction(int thread)
+    throws DatabaseException {
+        return transactionId.incrementAndGet();
+    }
+    @Override
+    public void stop() throws DatabaseException {
+        if (DEBUG)
+            System.out.println("GraphSessionVirtual: stop.");
+
+    }
+    @Override
+    public long reserveIds(int count)
+    throws DatabaseException {
+//        VirtualGraphServerSupport s = session.getService(VirtualGraphServerSupport.class);
+        long id = Constants.NullSubjectId;
+        for (int i=0; i<count; ++i)
+           id = virtualGraphServerSupport.createVirtual();
+        return id;
+    }
 }