X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.db.procore%2Fsrc%2Ffi%2Fvtt%2Fsimantics%2Fprocore%2Finternal%2FSessionImplDb.java;fp=bundles%2Forg.simantics.db.procore%2Fsrc%2Ffi%2Fvtt%2Fsimantics%2Fprocore%2Finternal%2FSessionImplDb.java;h=3c0f71eaf645847ad2fb7b50022995354ce2451b;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/SessionImplDb.java b/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/SessionImplDb.java new file mode 100644 index 000000000..3c0f71eaf --- /dev/null +++ b/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/SessionImplDb.java @@ -0,0 +1,139 @@ +/******************************************************************************* + * 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 java.io.IOException; + +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; + +import fi.vtt.simantics.procore.BackdoorAuthenticator; + +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; + } + +}