1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package fi.vtt.simantics.procore.internal;
\r
14 import org.simantics.db.SessionReference;
\r
15 import org.simantics.db.Database.Session;
\r
16 import org.simantics.db.Database.Session.Information;
\r
17 import org.simantics.db.Database.Session.Transaction;
\r
18 import org.simantics.db.common.utils.Logger;
\r
19 import org.simantics.db.exception.DatabaseException;
\r
21 import fi.vtt.simantics.procore.DebugPolicy;
\r
23 final class GraphSessionSocket extends GraphSession {
\r
25 public GraphSessionSocket(SessionImplSocket sessionImpl, SessionReference sessionReference, Session dbSession)
\r
26 throws DatabaseException {
\r
27 super(sessionImpl, sessionReference, dbSession);
\r
30 protected ServerInformationImpl getServerInformation()
\r
31 throws DatabaseException {
\r
32 Information t = dbSession.getInformation();
\r
33 return new ServerInformationImpl(t.getServerId(), t.getProtocolId(), t.getDatabaseId(), t.getFirstChangeSetId());
\r
36 public long askReadTransaction(int thread)
\r
37 throws DatabaseException {
\r
38 Transaction t = dbSession.askReadTransaction();
\r
39 updateLastChangeSetId(thread, t.getHeadChangeSetId(), true);
\r
40 return t.getTransactionId();
\r
43 public long askWriteTransaction(int thread, long transactionId)
\r
44 throws DatabaseException {
\r
45 Transaction t = dbSession.askWriteTransaction(transactionId);
\r
46 updateLastChangeSetId(thread, t.getHeadChangeSetId(), true);
\r
47 return t.getTransactionId();
\r
50 public void endTransaction(long transactionId, boolean write)
\r
51 throws DatabaseException {
\r
52 long headChangeSetId = dbSession.endTransaction(transactionId);
\r
53 updateLastChangeSetId(Integer.MIN_VALUE, headChangeSetId, false);
\r
56 public void cancelCommit(long transactionId, long csid, byte[] metadata, SynchronizeContextI context)
\r
57 throws DatabaseException {
\r
59 assert(null == synchronizeContext);
\r
60 synchronizeContext = context;
\r
61 long headChangeSetId = dbSession.cancelCommit(transactionId, csid, metadata, context);
\r
62 if (csid+1 != headChangeSetId)
\r
63 Logger.defaultLogError("Client and server out of synchronisation. Client cs="
\r
64 + (csid+1) + "server cs=" + headChangeSetId);
\r
65 metadataCache.addNext(headChangeSetId, metadata);
\r
67 synchronizeContext = null;
\r
71 public void acceptCommit(long transactionId, long csid, byte[] metadata)
\r
72 throws DatabaseException {
\r
73 dbSession.acceptCommit(transactionId, csid, metadata);
\r
74 metadataCache.addNext(csid+1, metadata);
\r
78 throws DatabaseException {
\r
82 public long reserveIds(int count)
\r
83 throws DatabaseException {
\r
84 Logger.defaultLogTrace("Asking for ids " + count + ".");
\r
85 long firstId = dbSession.reserveIds(count);
\r
86 Logger.defaultLogTrace("First id is " + firstId + ".");
\r
87 if (DebugPolicy.REPORT_CLUSTER_ID_ALLOCATION)
\r
88 System.out.println("Client reserves new ids [" + firstId + " - " + (firstId+count-1) + "] from server.");
\r