X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.db.procore%2Fsrc%2Ffi%2Fvtt%2Fsimantics%2Fprocore%2Finternal%2FSessionImplDb.java;h=d60c0573ad83882ea21fe547ea18041e5a719b84;hp=d0e9d55f05fdaf151b55b09471aeb7ecf6fafbd9;hb=97872f96afc18f4cd5b959d869fed80cd92f6aa1;hpb=ffdf83729b496d5afe74c7888075bb17ce1c4bbb 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 index d0e9d55f0..d60c0573a 100644 --- 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 @@ -1,136 +1,136 @@ -/******************************************************************************* - * 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; - } - -} +/******************************************************************************* + * 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; + } + +}