1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package fi.vtt.simantics.procore.internal;
16 import org.simantics.db.Database;
17 import org.simantics.db.SessionManager;
18 import org.simantics.db.SessionReference;
19 import org.simantics.db.VirtualGraph;
20 import org.simantics.db.authentication.UserAuthenticationAgent;
21 import org.simantics.db.common.utils.Logger;
22 import org.simantics.db.exception.DatabaseException;
23 import org.simantics.db.exception.InvalidAuthenticationException;
24 import org.simantics.db.exception.InvalidUserException;
25 import org.simantics.db.impl.ClusterI;
26 import org.simantics.db.impl.ClusterSupport;
27 import org.simantics.db.impl.ClusterTranslator;
28 import org.simantics.db.impl.ResourceImpl;
29 import org.simantics.db.impl.graph.WriteSupport;
30 import org.simantics.db.impl.query.QueryProcessor;
31 import org.simantics.db.impl.query.QuerySupport;
32 import org.simantics.db.service.ServerInformation;
34 final public class SessionImplDb extends SessionImplSocket {
37 * Cached ServerInformation structure fetched from the server at connection
38 * time. It should never change during a single session and therefore it
39 * should be perfectly safe to cache it.
41 protected ServerInformationImpl serverInfo;
43 public SessionImplDb(SessionManager sessionManager, UserAuthenticationAgent authAgent) {
44 super(sessionManager, authAgent);
48 protected VirtualGraph getProvider(VirtualGraph vg) {
53 public ResourceImpl getNewResource() throws DatabaseException {
54 if (null != defaultClusterSet)
55 return getNewResource(defaultClusterSet);
56 ClusterI cluster = getNewResourceCluster();
59 newId = cluster.createResource(clusterTranslator);
60 } catch (DatabaseException e) {
61 Logger.defaultLogError(e);
64 return new ResourceImpl(resourceSupport, newId);
67 public void connect(SessionReference sessionReference, final Database.Session dbSession) throws Exception {
68 if (null == clusterTable) {
69 File t = StaticSessionProperties.virtualGraphStoragePath;
72 clusterTable = new ClusterTable(this, t);
75 graphSession = new GraphSessionSocket(this, sessionReference, dbSession);
79 clusterStream = new ClusterStream(this, graphSession, false);
81 clusterTranslator = new ClusterTranslatorImpl(this);
82 serviceLocator.registerService(ClusterTranslator.class, clusterTranslator);
83 serviceLocator.registerService(ClusterSupport.class, clusterTranslator);
85 resourceSupport = new ResourceSupportImpl(this);
87 requestManager = new SessionRequestManager(this, state);
89 querySupport = new QuerySupportImpl(this, clusterTranslator, new SerialisationSupportImpl(this), requestManager);
90 serviceLocator.registerService(QuerySupport.class, querySupport);
92 queryProvider2 = new QueryProcessor(getAmountOfQueryThreads(), querySupport, sessionThreads);
94 writeSupport = new WriteSupportImpl(this);
95 serviceLocator.registerService(WriteSupport.class, writeSupport);
97 state.setGraphSession(this, graphSession, queryProvider2, clusterTable);
99 this.serverInfo = graphSession.getServerInformation();
101 // authenticator = authAgent.getAuthenticator(serverInfo);
102 // if (authenticator == null)
103 // throw new InvalidAuthenticationException("Authentication agent did not provide an authenticator");
104 // if (authenticator instanceof BackdoorAuthenticator)
105 // user = authenticator.getUser(this);
107 } catch (InvalidAuthenticationException e) {
109 } catch (InvalidUserException e) {
111 // } catch (IOException e) {
112 // Logger.defaultLogError("I/O error. See exception for details.", e);
113 // graphSession = null;
114 // clusterTable.dispose(); clusterTable = null;
116 } catch (Throwable e) {
118 Logger.defaultLogError("Unhandled error. See exception for details.", e);
120 clusterTable.dispose(); clusterTable = null;
121 throw new Exception(e);
124 String databaseId = serverInfo.getDatabaseId();
125 String serverId = serverInfo.getServerId();
126 String id = databaseId + "." + serverId;
127 virtualGraphServerSupport.connect(id);
128 clusterSetsSupport.connect(id);
133 protected ServerInformation getCachedServerInformation() {