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;
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;
21 import fi.vtt.simantics.procore.DebugPolicy;
23 final class GraphSessionSocket extends GraphSession {
25 public GraphSessionSocket(SessionImplSocket sessionImpl, SessionReference sessionReference, Session dbSession)
26 throws DatabaseException {
27 super(sessionImpl, sessionReference, dbSession);
30 protected ServerInformationImpl getServerInformation()
31 throws DatabaseException {
32 Information t = dbSession.getInformation();
33 return new ServerInformationImpl(t.getServerId(), t.getProtocolId(), t.getDatabaseId(), t.getFirstChangeSetId());
36 public long askReadTransaction(int thread)
37 throws DatabaseException {
38 Transaction t = dbSession.askReadTransaction();
39 updateLastChangeSetId(thread, t.getHeadChangeSetId(), true);
40 return t.getTransactionId();
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();
50 public void endTransaction(long transactionId, boolean write)
51 throws DatabaseException {
52 long headChangeSetId = dbSession.endTransaction(transactionId);
53 updateLastChangeSetId(Integer.MIN_VALUE, headChangeSetId, false);
56 public void cancelCommit(long transactionId, long csid, byte[] metadata, SynchronizeContextI context)
57 throws DatabaseException {
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);
67 synchronizeContext = null;
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);
78 throws DatabaseException {
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.");