]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/SessionImplDb.java
isImmutable can NPE
[simantics/platform.git] / bundles / org.simantics.db.procore / src / fi / vtt / simantics / procore / internal / SessionImplDb.java
index d0e9d55f05fdaf151b55b09471aeb7ecf6fafbd9..d60c0573ad83882ea21fe547ea18041e5a719b84 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 java.io.File;\r
-\r
-import org.simantics.db.Database;\r
-import org.simantics.db.SessionManager;\r
-import org.simantics.db.SessionReference;\r
-import org.simantics.db.VirtualGraph;\r
-import org.simantics.db.authentication.UserAuthenticationAgent;\r
-import org.simantics.db.common.utils.Logger;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.exception.InvalidAuthenticationException;\r
-import org.simantics.db.exception.InvalidUserException;\r
-import org.simantics.db.impl.ClusterI;\r
-import org.simantics.db.impl.ClusterSupport;\r
-import org.simantics.db.impl.ClusterTranslator;\r
-import org.simantics.db.impl.ResourceImpl;\r
-import org.simantics.db.impl.graph.WriteSupport;\r
-import org.simantics.db.impl.query.QueryProcessor;\r
-import org.simantics.db.impl.query.QuerySupport;\r
-import org.simantics.db.service.ServerInformation;\r
-\r
-final public class SessionImplDb extends SessionImplSocket {\r
-\r
-    /**\r
-     * Cached ServerInformation structure fetched from the server at connection\r
-     * time. It should never change during a single session and therefore it\r
-     * should be perfectly safe to cache it.\r
-     */\r
-    protected ServerInformationImpl serverInfo;\r
-\r
-    public SessionImplDb(SessionManager sessionManager, UserAuthenticationAgent authAgent) {\r
-        super(sessionManager, authAgent);\r
-    }\r
-\r
-    @Override\r
-    protected VirtualGraph getProvider(VirtualGraph vg) {\r
-        return vg;\r
-    }\r
-\r
-    @Override\r
-    public ResourceImpl getNewResource() throws DatabaseException {\r
-        if (null != defaultClusterSet)\r
-            return getNewResource(defaultClusterSet);\r
-        ClusterI cluster = getNewResourceCluster();\r
-        int newId;\r
-        try {\r
-            newId = cluster.createResource(clusterTranslator);\r
-        } catch (DatabaseException e) {\r
-            Logger.defaultLogError(e);\r
-            return null;\r
-        }\r
-        return new ResourceImpl(resourceSupport, newId);\r
-    }\r
-\r
-    public void connect(SessionReference sessionReference, final Database.Session dbSession) throws Exception {\r
-        if (null == clusterTable) {\r
-            File t = StaticSessionProperties.virtualGraphStoragePath;\r
-            if (null == t)\r
-                t = new File(".");\r
-            clusterTable = new ClusterTable(this, t);\r
-        }\r
-\r
-        graphSession = new GraphSessionSocket(this, sessionReference, dbSession);\r
-\r
-        try {\r
-\r
-            clusterStream = new ClusterStream(this, graphSession, false);\r
-\r
-            clusterTranslator = new ClusterTranslatorImpl(this);\r
-            serviceLocator.registerService(ClusterTranslator.class, clusterTranslator);\r
-            serviceLocator.registerService(ClusterSupport.class, clusterTranslator);\r
-\r
-            resourceSupport = new ResourceSupportImpl(this);\r
-\r
-            requestManager = new SessionRequestManager(this, state);\r
-\r
-            querySupport = new QuerySupportImpl(this, clusterTranslator, new SerialisationSupportImpl(this), requestManager);\r
-            serviceLocator.registerService(QuerySupport.class, querySupport);\r
-\r
-            queryProvider2 = new QueryProcessor(getAmountOfQueryThreads(), querySupport, sessionThreads);\r
-\r
-            writeSupport = new WriteSupportImpl(this);\r
-            serviceLocator.registerService(WriteSupport.class, writeSupport);\r
-\r
-            state.setGraphSession(this, graphSession, queryProvider2, clusterTable);\r
-\r
-            this.serverInfo = graphSession.getServerInformation();\r
-            \r
-//            authenticator = authAgent.getAuthenticator(serverInfo);\r
-//            if (authenticator == null)\r
-//                throw new InvalidAuthenticationException("Authentication agent did not provide an authenticator");\r
-//            if (authenticator instanceof BackdoorAuthenticator)\r
-//                user = authenticator.getUser(this);\r
-\r
-        } catch (InvalidAuthenticationException e) {\r
-            throw e;\r
-        } catch (InvalidUserException e) {\r
-            throw e;\r
-//        } catch (IOException e) {\r
-//            Logger.defaultLogError("I/O error. See exception for details.", e);\r
-//            graphSession = null;\r
-//            clusterTable.dispose(); clusterTable = null;\r
-//            throw e;\r
-        } catch (Throwable e) {\r
-            e.printStackTrace();\r
-            Logger.defaultLogError("Unhandled error. See exception for details.", e);\r
-            graphSession = null;\r
-            clusterTable.dispose(); clusterTable = null;\r
-            throw new Exception(e);\r
-        }\r
-\r
-        String databaseId = serverInfo.getDatabaseId();\r
-        String serverId = serverInfo.getServerId();\r
-        virtualGraphServerSupport.connect(databaseId + "." + serverId);\r
-        clusterSetsSupport.connect(databaseId + "." + serverId);\r
-\r
-    }\r
-\r
-    @Override\r
-    protected ServerInformation getCachedServerInformation() {\r
-        return serverInfo;\r
-    }\r
-\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 java.io.File;
+
+import org.simantics.db.Database;
+import org.simantics.db.SessionManager;
+import org.simantics.db.SessionReference;
+import org.simantics.db.VirtualGraph;
+import org.simantics.db.authentication.UserAuthenticationAgent;
+import org.simantics.db.common.utils.Logger;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.exception.InvalidAuthenticationException;
+import org.simantics.db.exception.InvalidUserException;
+import org.simantics.db.impl.ClusterI;
+import org.simantics.db.impl.ClusterSupport;
+import org.simantics.db.impl.ClusterTranslator;
+import org.simantics.db.impl.ResourceImpl;
+import org.simantics.db.impl.graph.WriteSupport;
+import org.simantics.db.impl.query.QueryProcessor;
+import org.simantics.db.impl.query.QuerySupport;
+import org.simantics.db.service.ServerInformation;
+
+final public class SessionImplDb extends SessionImplSocket {
+
+    /**
+     * Cached ServerInformation structure fetched from the server at connection
+     * time. It should never change during a single session and therefore it
+     * should be perfectly safe to cache it.
+     */
+    protected ServerInformationImpl serverInfo;
+
+    public SessionImplDb(SessionManager sessionManager, UserAuthenticationAgent authAgent) {
+        super(sessionManager, authAgent);
+    }
+
+    @Override
+    protected VirtualGraph getProvider(VirtualGraph vg) {
+        return vg;
+    }
+
+    @Override
+    public ResourceImpl getNewResource() throws DatabaseException {
+        if (null != defaultClusterSet)
+            return getNewResource(defaultClusterSet);
+        ClusterI cluster = getNewResourceCluster();
+        int newId;
+        try {
+            newId = cluster.createResource(clusterTranslator);
+        } catch (DatabaseException e) {
+            Logger.defaultLogError(e);
+            return null;
+        }
+        return new ResourceImpl(resourceSupport, newId);
+    }
+
+    public void connect(SessionReference sessionReference, final Database.Session dbSession) throws Exception {
+        if (null == clusterTable) {
+            File t = StaticSessionProperties.virtualGraphStoragePath;
+            if (null == t)
+                t = new File(".");
+            clusterTable = new ClusterTable(this, t);
+        }
+
+        graphSession = new GraphSessionSocket(this, sessionReference, dbSession);
+
+        try {
+
+            clusterStream = new ClusterStream(this, graphSession, false);
+
+            clusterTranslator = new ClusterTranslatorImpl(this);
+            serviceLocator.registerService(ClusterTranslator.class, clusterTranslator);
+            serviceLocator.registerService(ClusterSupport.class, clusterTranslator);
+
+            resourceSupport = new ResourceSupportImpl(this);
+
+            requestManager = new SessionRequestManager(this, state);
+
+            querySupport = new QuerySupportImpl(this, clusterTranslator, new SerialisationSupportImpl(this), requestManager);
+            serviceLocator.registerService(QuerySupport.class, querySupport);
+
+            queryProvider2 = new QueryProcessor(getAmountOfQueryThreads(), querySupport, sessionThreads);
+
+            writeSupport = new WriteSupportImpl(this);
+            serviceLocator.registerService(WriteSupport.class, writeSupport);
+
+            state.setGraphSession(this, graphSession, queryProvider2, clusterTable);
+
+            this.serverInfo = graphSession.getServerInformation();
+            
+//            authenticator = authAgent.getAuthenticator(serverInfo);
+//            if (authenticator == null)
+//                throw new InvalidAuthenticationException("Authentication agent did not provide an authenticator");
+//            if (authenticator instanceof BackdoorAuthenticator)
+//                user = authenticator.getUser(this);
+
+        } catch (InvalidAuthenticationException e) {
+            throw e;
+        } catch (InvalidUserException e) {
+            throw e;
+//        } catch (IOException e) {
+//            Logger.defaultLogError("I/O error. See exception for details.", e);
+//            graphSession = null;
+//            clusterTable.dispose(); clusterTable = null;
+//            throw e;
+        } catch (Throwable e) {
+            e.printStackTrace();
+            Logger.defaultLogError("Unhandled error. See exception for details.", e);
+            graphSession = null;
+            clusterTable.dispose(); clusterTable = null;
+            throw new Exception(e);
+        }
+
+        String databaseId = serverInfo.getDatabaseId();
+        String serverId = serverInfo.getServerId();
+        virtualGraphServerSupport.connect(databaseId + "." + serverId);
+        clusterSetsSupport.connect(databaseId + "." + serverId);
+
+    }
+
+    @Override
+    protected ServerInformation getCachedServerInformation() {
+        return serverInfo;
+    }
+
+}