001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * // Copyright (c) 1998, 2007, Oracle. All rights reserved.
005: *
006: *
007: * The contents of this file are subject to the terms of either the GNU
008: * General Public License Version 2 only ("GPL") or the Common Development
009: * and Distribution License("CDDL") (collectively, the "License"). You
010: * may not use this file except in compliance with the License. You can obtain
011: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
012: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
013: * language governing permissions and limitations under the License.
014: *
015: * When distributing the software, include this License Header Notice in each
016: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
017: * Sun designates this particular file as subject to the "Classpath" exception
018: * as provided by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the License
020: * Header, with the fields enclosed by brackets [] replaced by your own
021: * identifying information: "Portions Copyrighted [year]
022: * [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * If you wish your version of this file to be governed by only the CDDL or
027: * only the GPL Version 2, indicate your decision by adding "[Contributor]
028: * elects to include this software in this distribution under the [CDDL or GPL
029: * Version 2] license." If you don't indicate a single choice of license, a
030: * recipient has the option to distribute your version of this file under
031: * either the CDDL, the GPL Version 2 or to extend the choice of license to
032: * its licensees as provided above. However, if you add GPL Version 2 code
033: * and therefore, elected the GPL Version 2 license, then the option applies
034: * only if the new code is made subject to such option by the copyright
035: * holder.
036: */
037: package oracle.toplink.essentials.internal.ejb.cmp3.transaction.base;
038:
039: import oracle.toplink.essentials.exceptions.TransactionException;
040: import oracle.toplink.essentials.internal.ejb.cmp3.base.*;
041: import oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl;
042:
043: public abstract class TransactionWrapperImpl {
044:
045: protected EntityManagerImpl entityManager = null;
046:
047: //This attribute will store a reference to the non transactional UnitOfWork used
048: // for queries outside of a transaction
049: protected RepeatableWriteUnitOfWork localUOW;
050:
051: //used to cache the transactional UnitOfWork so that we do not need to look it up each time.
052: protected Object txnKey;
053:
054: public TransactionWrapperImpl(EntityManagerImpl entityManager) {
055: this .entityManager = entityManager;
056: }
057:
058: /**
059: * INTERNAL:
060: * This method will be used to check for a transaction and throws exception if none exists.
061: * If this methiod returns without exception then a transaction exists.
062: * This method must be called before accessing the localUOW.
063: */
064: public abstract Object checkForTransaction(boolean validateExistence);
065:
066: /**
067: * INTERNAL:
068: * Clears the transactional UnitOfWork
069: */
070: public void clear() {
071: if (this .localUOW != null) {
072: // all change sets and cache are cleared
073: this .localUOW.clear(true);
074: }
075: }
076:
077: /**
078: * INTERNAL:
079: * THis method is used to get the active UnitOfWork. It is special in that it will
080: * return the required RepeatableWriteUnitOfWork required by the EntityManager. Once
081: * RepeatableWrite is merged into existing UnitOfWork this code can go away.
082: * @param transaction
083: * @return
084: */
085: public abstract RepeatableWriteUnitOfWork getTransactionalUnitOfWork(
086: Object transaction);
087:
088: public abstract void registerUnitOfWorkWithTxn(UnitOfWorkImpl uow);
089:
090: public UnitOfWorkImpl getLocalUnitOfWork() {
091: return localUOW;
092: }
093:
094: public void setLocalUnitOfWork(RepeatableWriteUnitOfWork uow) {
095: this .localUOW = uow;
096: }
097:
098: /**
099: * Mark the current transaction so that the only possible
100: * outcome of the transaction is for the transaction to be
101: * rolled back.
102: * This is an internal method and if the txn is not active will do nothing
103: */
104: public abstract void setRollbackOnlyInternal();
105:
106: /**
107: * This method will be called when a query is executed. If changes in the entity manager
108: * should be flushed this method should return true
109: */
110: public abstract boolean shouldFlushBeforeQuery(UnitOfWorkImpl uow);
111:
112: }
|