KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > daffodilwoods > daffodildb > server > sessionsystem > TransactionSerializedDataRetriever


1 package com.daffodilwoods.daffodildb.server.sessionsystem;
2
3 import com.daffodilwoods.daffodildb.server.sql99.dql.iterator._Iterator;
4 import com.daffodilwoods.daffodildb.server.datasystem.interfaces._Table;
5 import com.daffodilwoods.daffodildb.server.sql99.expression.booleanvalueexpression._SingleTableExecuter;
6 import com.daffodilwoods.daffodildb.server.serversystem._ServerSession;
7 import com.daffodilwoods.database.resource.DException;
8 import com.daffodilwoods.database.general.QualifiedIdentifier;
9 import com.daffodilwoods.daffodildb.server.sessionsystem.sessioncondition._SessionCondition;
10 import com.daffodilwoods.daffodildb.server.datasystem.interfaces._IndexTable;
11 import com.daffodilwoods.daffodildb.server.datasystem.mergesystem.MergeTable;
12
13 /**
14  * Provides the iterator to fetch the reocrds which satisfies the requirements of
15  * Read Transaction Serializable Isolation level
16  * @param singleTableExecuter constains condition and order
17  * @param serverSession used by singleTableExecuter to solve the inner query
18  * @return _IndexIterator
19  * @throws DException
20  */

21
22 public class TransactionSerializedDataRetriever extends DataRetrieverWithoutCondition implements _DataRetriever{
23
24   protected Session session;
25   public TransactionSerializedDataRetriever(Session session) {
26     this.session = session;
27   }
28   /*
29    suppose a connection is in TS level and selects some records so a transaction is started.
30    Now second user or connection insert some records and commits them now these records deleted from memory beacuse
31    we always delete inserted records from memory without checking is any dependent transaction.
32    Now first connection which is in TS level select again now we doesn't get any records in memory
33    and we will give iterator on file than it will select all records inserted by other user which
34    violets rule of TS level because first user doesn't have commit or rollback so he can't see data
35    afftected by other users untill it commits or roll back.
36
37    And we use condition of session serializable
38
39
40    */

41
42   public _Iterator getIterator(_Table mergeTable, _SingleTableExecuter singleTableExecuter, _ServerSession serverSession, QualifiedIdentifier tableName, ForUpdateTableHandler forUpdateTableHandler) throws DException{
43       return getConditionalIterator(mergeTable,singleTableExecuter,serverSession,tableName,forUpdateTableHandler);
44   }
45
46   public _Iterator getConditionalIterator(_Table mergeTable, _SingleTableExecuter singleTableExecuter, _ServerSession serverSession, QualifiedIdentifier tableName, ForUpdateTableHandler forUpdateTableHandler) throws DException{
47     SessionIndex sessionIndex = new SessionIndex((_IndexTable)mergeTable, serverSession);
48     _SessionCondition sessionCondition = ((Session)session).getTransactionSessionCondition() ;
49     _Iterator iterator = singleTableExecuter.execute(sessionIndex);
50     return new RowIdSessionIterator(new NonIndexedSessionFilterIterator(iterator,sessionCondition) ,sessionCondition );
51   }
52
53   public _Iterator getFCIterator(_Table mergeTable,
54                                            QualifiedIdentifier tableName,_SingleTableExecuter conditionExecuter,_IndexTable foreignConstrainTable) throws DException{
55       _ServerSession serverSession = ((_SessionGetter)foreignConstrainTable).getServerSession();
56       SessionIndex sessionIndex = new SessionIndex((_IndexTable)mergeTable, serverSession);
57       _SessionCondition sessionCondition = ((Session)session).getTransactionSerializableCondition();
58       _Iterator iterator = conditionExecuter.execute(sessionIndex);
59       _Iterator baseIterator = new NonIndexedSessionFilterIterator(iterator,sessionCondition);
60       _Iterator fcIterator = ((ForeignConstraintTable)foreignConstrainTable).getIterator(baseIterator);
61       return new RowIdSessionIterator( fcIterator,sessionCondition );
62   }
63
64 }
65
Popular Tags