]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/GraphSessionSocket.java
Goodbye db-client.log
[simantics/platform.git] / bundles / org.simantics.db.procore / src / fi / vtt / simantics / procore / internal / GraphSessionSocket.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package fi.vtt.simantics.procore.internal;
13
14 import org.simantics.db.SessionReference;
15 import org.simantics.db.Database.Session;
16 import org.simantics.db.Database.Session.Information;
17 import org.simantics.db.Database.Session.Transaction;
18 import org.simantics.db.common.utils.Logger;
19 import org.simantics.db.exception.DatabaseException;
20
21 import fi.vtt.simantics.procore.DebugPolicy;
22
23 final class GraphSessionSocket extends GraphSession {
24     
25     public GraphSessionSocket(SessionImplSocket sessionImpl, SessionReference sessionReference, Session dbSession)
26     throws DatabaseException {
27         super(sessionImpl, sessionReference, dbSession);
28     }
29     @Override
30     protected ServerInformationImpl getServerInformation()
31     throws DatabaseException {
32         Information t = dbSession.getInformation();
33         return new ServerInformationImpl(t.getServerId(), t.getProtocolId(), t.getDatabaseId(), t.getFirstChangeSetId());
34     }
35     @Override
36     public long askReadTransaction(int thread)
37     throws DatabaseException {
38         Transaction t = dbSession.askReadTransaction();
39         updateLastChangeSetId(thread, t.getHeadChangeSetId(), true);
40         return t.getTransactionId();
41     }
42     @Override
43     public long askWriteTransaction(int thread, long transactionId)
44     throws DatabaseException {
45         Transaction t = dbSession.askWriteTransaction(transactionId);
46         updateLastChangeSetId(thread, t.getHeadChangeSetId(), true);
47         return t.getTransactionId();
48     }
49     @Override
50     public void endTransaction(long transactionId, boolean write)
51     throws DatabaseException {
52         long headChangeSetId = dbSession.endTransaction(transactionId);
53         updateLastChangeSetId(Integer.MIN_VALUE, headChangeSetId, false);
54     }
55     @Override
56     public void cancelCommit(long transactionId, long csid, byte[] metadata, SynchronizeContextI context)
57     throws DatabaseException {
58         try {
59             assert(null == synchronizeContext);
60             synchronizeContext = context;
61             long headChangeSetId = dbSession.cancelCommit(transactionId, csid, metadata, context);
62             if (csid+1 != headChangeSetId)
63                 Logger.defaultLogError("Client and server out of synchronisation. Client cs="
64                     + (csid+1) + "server cs=" + headChangeSetId);
65             metadataCache.addNext(headChangeSetId, metadata);
66         } finally {
67             synchronizeContext = null;
68         }
69     }
70     @Override
71     public void acceptCommit(long transactionId, long csid, byte[] metadata)
72     throws DatabaseException {
73         dbSession.acceptCommit(transactionId, csid, metadata);
74         metadataCache.addNext(csid+1, metadata);
75     }
76     @Override
77     public void stop()
78     throws DatabaseException {
79         dbSession.close();
80     }
81     @Override
82     public long reserveIds(int count)
83     throws DatabaseException {
84         long firstId = dbSession.reserveIds(count);
85         if (DebugPolicy.REPORT_CLUSTER_ID_ALLOCATION)
86             System.out.println("Client reserves new ids [" + firstId + " - " + (firstId+count-1) + "] from server.");
87         return firstId;
88     }
89 }