X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=bundles%2Forg.simantics.db.procore%2Fsrc%2Ffi%2Fvtt%2Fsimantics%2Fprocore%2Finternal%2FSessionImplVirtual.java;fp=bundles%2Forg.simantics.db.procore%2Fsrc%2Ffi%2Fvtt%2Fsimantics%2Fprocore%2Finternal%2FSessionImplVirtual.java;h=1a109d2e0be42ea9b35bf62d2a813a16ae7a4997;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/SessionImplVirtual.java b/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/SessionImplVirtual.java new file mode 100644 index 000000000..1a109d2e0 --- /dev/null +++ b/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/SessionImplVirtual.java @@ -0,0 +1,115 @@ +/******************************************************************************* + * 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; + virtualGraphServerSupport.connect(databaseId + "." + serverId); + virtualGraphImpl = (VirtualGraphImpl)virtualGraphServerSupport.getWorkspacePersistent("virtualGraph" + "." + serverId); + try { + 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; + } + } +}