KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > oracle > toplink > essentials > internal > ejb > cmp3 > transaction > base > TransactionWrapperImpl


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the "License"). You may not use this file except
5  * in compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * glassfish/bootstrap/legal/CDDLv1.0.txt or
9  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * HEADER in each file and include the License file at
15  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
16  * add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your
18  * own identifying information: Portions Copyright [yyyy]
19  * [name of copyright owner]
20  */

21 // Copyright (c) 1998, 2006, Oracle. All rights reserved.
22
package oracle.toplink.essentials.internal.ejb.cmp3.transaction.base;
23
24 import oracle.toplink.essentials.exceptions.TransactionException;
25 import oracle.toplink.essentials.internal.ejb.cmp3.base.*;
26 import oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl;
27
28 public abstract class TransactionWrapperImpl {
29
30     protected EntityManagerImpl entityManager = null;
31         
32     //This attribute will store a reference to the non transactional UnitOfWork used
33
// for queries outside of a transaction
34
protected RepeatableWriteUnitOfWork localUOW;
35         
36     //used to cache the transactional UnitOfWork so that we do not need to look it up each time.
37
protected Object JavaDoc txnKey;
38     
39     
40     public TransactionWrapperImpl(EntityManagerImpl entityManager){
41         this.entityManager = entityManager;
42     }
43         
44     /**
45      * INTERNAL:
46      * This method will be used to check for a transaction and throws exception if none exists.
47      * If this methiod returns without exception then a transaction exists.
48      * This method must be called before accessing the localUOW.
49      */

50     public abstract Object JavaDoc checkForTransaction(boolean validateExistence);
51  
52     /**
53      * INTERNAL:
54      * Clears the transactional UnitOfWork
55      */

56     public void clear(){
57         if (this.localUOW != null){
58             this.localUOW.clear();
59         }
60     }
61     
62     /**
63      * INTERNAL:
64      * THis method is used to get the active UnitOfWork. It is special in that it will
65      * return the required RepeatableWriteUnitOfWork required by the EntityManager. Once
66      * RepeatableWrite is merged into existing UnitOfWork this code can go away.
67      * @param transaction
68      * @return
69      */

70     public abstract RepeatableWriteUnitOfWork getTransactionalUnitOfWork(Object JavaDoc transaction);
71
72     public abstract void registerUnitOfWorkWithTxn(UnitOfWorkImpl uow);
73     
74     public UnitOfWorkImpl getLocalUnitOfWork(){
75         return localUOW;
76     }
77
78     public void setLocalUnitOfWork(RepeatableWriteUnitOfWork uow){
79         this.localUOW = uow;
80     }
81
82     /**
83     * Mark the current transaction so that the only possible
84     * outcome of the transaction is for the transaction to be
85     * rolled back.
86     * @throws IllegalStateException if isActive() is false.
87     */

88     public void setRollbackOnlyInternal(){
89         //No -op for most wrappers as TopLink will mark for rollback in the case
90
//of external transaction controller
91
}
92     
93     /**
94      * This method will be called when an entity manager attempts to close to verify its
95      * transaction is in a closable state.
96      */

97     public abstract boolean shouldClose();
98     
99     /**
100      * This method will be called when a query is executed. If changes in the entity manager
101      * should be flushed this method should return true
102      */

103     public abstract boolean shouldFlushBeforeQuery(UnitOfWorkImpl uow);
104     
105     /**
106      * These two method used for closing of EntityManager in case there is a transaction in progress:
107      * The first method is called by EntityManager.close method to mark the current transaction,
108      * the second one is called by EntityManager.verifyOpen method.
109      */

110     public abstract void markLastTransaction();
111     public abstract boolean hasLastTransactionCompleted();
112 }
113
Popular Tags