-/*******************************************************************************\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.IOException;\r
-\r
-import org.simantics.db.ServerI;\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.ResourceImpl;\r
-import org.simantics.db.impl.VirtualGraphImpl;\r
-import org.simantics.db.impl.query.QueryProcessor;\r
-import org.simantics.db.service.ServerInformation;\r
-\r
-import fi.vtt.simantics.procore.BackdoorAuthenticator;\r
-import fi.vtt.simantics.procore.ProCoreServerReference;\r
-import fi.vtt.simantics.procore.ProCoreSessionReference;\r
-import fi.vtt.simantics.procore.SessionManagerSource;\r
-\r
-public class SessionImplVirtual extends SessionImplSocket {\r
- protected VirtualGraphImpl virtualGraphImpl;\r
- public SessionImplVirtual(UserAuthenticationAgent authAgent)\r
- throws DatabaseException {\r
- super(null, authAgent);\r
- init(authAgent, false);\r
- }\r
- public SessionImplVirtual(UserAuthenticationAgent authAgent, boolean init)\r
- throws DatabaseException {\r
- super(null, authAgent);\r
- init(authAgent, init);\r
- }\r
- private void init(UserAuthenticationAgent authAgent, boolean init)\r
- throws DatabaseException {\r
- ProCoreServerReference serverReference = new ProCoreServerReference();\r
- ProCoreSessionReference sessionReference = new ProCoreSessionReference(serverReference, SessionManagerSource.NullSessionId);\r
- if (init)\r
- graphSession = new GraphSessionVirtualInit(this, sessionReference, virtualGraphServerSupport);\r
- else\r
- graphSession = new GraphSessionVirtual(this, sessionReference, virtualGraphServerSupport);\r
- // This is used by QueryProcessor among others.\r
- String databaseId = GraphSessionVirtual.serverInfo.databaseId;\r
- String serverId = GraphSessionVirtual.serverInfo.serverId;\r
- try {\r
- virtualGraphServerSupport.connect(databaseId + "." + serverId);\r
- virtualGraphImpl = (VirtualGraphImpl)virtualGraphServerSupport.getWorkspacePersistent("virtualGraph" + "." + serverId);\r
- requestManager = new SessionRequestManager(this, state);\r
- clusterStream = new ClusterStream(this, graphSession, true);\r
- clusterTranslator = new ClusterTranslatorImpl(this);\r
- writeSupport = new WriteSupportImpl(this);\r
- resourceSupport = new ResourceSupportImpl(this);\r
- querySupport = new QuerySupportImpl(this, clusterTranslator, new SerialisationSupportImpl(this), requestManager);\r
- queryProvider2 = new QueryProcessor(getAmountOfQueryThreads(), querySupport, sessionThreads);\r
- state.setGraphSession(this, graphSession, queryProvider2, clusterTable);\r
- ServerInformationImpl serverInfo = graphSession.getServerInformation();\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
- } 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
- throw new DatabaseException(e);\r
- } catch (Throwable e) {\r
- e.printStackTrace();\r
- Logger.defaultLogError("Unhandled error. See exception for details.", e);\r
- graphSession = null;\r
- throw new DatabaseException(e);\r
- }\r
- this.clusterStream.setOff(true);\r
- }\r
- public static ServerI newVirtualProCoreServer() {\r
- if (DEBUG)\r
- System.out.println("SessionImplVirtual.newVirtualProCoreServer");\r
- return new VirtualServer();\r
- }\r
- @Override\r
- protected VirtualGraph getProvider(VirtualGraph vg) {\r
- return null != vg ? vg : virtualGraphImpl;\r
- }\r
- @Override\r
- protected ResourceImpl getNewResource() throws DatabaseException {\r
- int newId = virtualGraphImpl.newResource(false);\r
- return new ResourceImpl(resourceSupport, newId);\r
- }\r
- @Override\r
- protected ServerInformation getCachedServerInformation() {\r
- GraphSession gs = graphSession;\r
- if (null == gs)\r
- return null;\r
- try {\r
- return gs.getServerInformation();\r
- } catch (DatabaseException e) {\r
- Logger.defaultLogError("Failed to get server info.", e);\r
- return null;\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.IOException;
+
+import org.simantics.db.ServerI;
+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.ResourceImpl;
+import org.simantics.db.impl.VirtualGraphImpl;
+import org.simantics.db.impl.query.QueryProcessor;
+import org.simantics.db.service.ServerInformation;
+
+import fi.vtt.simantics.procore.BackdoorAuthenticator;
+import fi.vtt.simantics.procore.ProCoreServerReference;
+import fi.vtt.simantics.procore.ProCoreSessionReference;
+import fi.vtt.simantics.procore.SessionManagerSource;
+
+public class SessionImplVirtual extends SessionImplSocket {
+ protected VirtualGraphImpl virtualGraphImpl;
+ public SessionImplVirtual(UserAuthenticationAgent authAgent)
+ throws DatabaseException {
+ super(null, authAgent);
+ init(authAgent, false);
+ }
+ public SessionImplVirtual(UserAuthenticationAgent authAgent, boolean init)
+ throws DatabaseException {
+ super(null, authAgent);
+ init(authAgent, init);
+ }
+ private void init(UserAuthenticationAgent authAgent, boolean init)
+ throws DatabaseException {
+ ProCoreServerReference serverReference = new ProCoreServerReference();
+ ProCoreSessionReference sessionReference = new ProCoreSessionReference(serverReference, SessionManagerSource.NullSessionId);
+ if (init)
+ graphSession = new GraphSessionVirtualInit(this, sessionReference, virtualGraphServerSupport);
+ else
+ graphSession = new GraphSessionVirtual(this, sessionReference, virtualGraphServerSupport);
+ // This is used by QueryProcessor among others.
+ String databaseId = GraphSessionVirtual.serverInfo.databaseId;
+ String serverId = GraphSessionVirtual.serverInfo.serverId;
+ try {
+ virtualGraphServerSupport.connect(databaseId + "." + serverId);
+ virtualGraphImpl = (VirtualGraphImpl)virtualGraphServerSupport.getWorkspacePersistent("virtualGraph" + "." + serverId);
+ requestManager = new SessionRequestManager(this, state);
+ clusterStream = new ClusterStream(this, graphSession, true);
+ clusterTranslator = new ClusterTranslatorImpl(this);
+ writeSupport = new WriteSupportImpl(this);
+ resourceSupport = new ResourceSupportImpl(this);
+ querySupport = new QuerySupportImpl(this, clusterTranslator, new SerialisationSupportImpl(this), requestManager);
+ queryProvider2 = new QueryProcessor(getAmountOfQueryThreads(), querySupport, sessionThreads);
+ state.setGraphSession(this, graphSession, queryProvider2, clusterTable);
+ ServerInformationImpl 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;
+ throw new DatabaseException(e);
+ } catch (Throwable e) {
+ e.printStackTrace();
+ Logger.defaultLogError("Unhandled error. See exception for details.", e);
+ graphSession = null;
+ throw new DatabaseException(e);
+ }
+ this.clusterStream.setOff(true);
+ }
+ public static ServerI newVirtualProCoreServer() {
+ if (DEBUG)
+ System.out.println("SessionImplVirtual.newVirtualProCoreServer");
+ return new VirtualServer();
+ }
+ @Override
+ protected VirtualGraph getProvider(VirtualGraph vg) {
+ return null != vg ? vg : virtualGraphImpl;
+ }
+ @Override
+ protected ResourceImpl getNewResource() throws DatabaseException {
+ int newId = virtualGraphImpl.newResource(false);
+ return new ResourceImpl(resourceSupport, newId);
+ }
+ @Override
+ protected ServerInformation getCachedServerInformation() {
+ GraphSession gs = graphSession;
+ if (null == gs)
+ return null;
+ try {
+ return gs.getServerInformation();
+ } catch (DatabaseException e) {
+ Logger.defaultLogError("Failed to get server info.", e);
+ return null;
+ }
+ }
+}