001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036:
037: package javax.transaction;
038:
039: /**
040: * This interface is intended for use by system level application server
041: * components such as persistence managers, resource adapters, as well as
042: * EJB and Web application components. This provides the ability to
043: * register synchronization objects with special ordering semantics,
044: * associate resource objects with the current transaction, get the
045: * transaction context of the current transaction, get current transaction
046: * status, and mark the current transaction for rollback.
047: *
048: * This interface is implemented by the application server by a
049: * stateless service object. The same object can be used by any number of
050: * components with thread safety.
051: *
052: * <P>In standard application server environments, an instance
053: * implementing this interface can be looked up by a standard name via JNDI.
054: * The standard name is java:comp/TransactionSynchronizationRegistry.
055: *
056: * @since JTA 1.1
057: */
058: public interface TransactionSynchronizationRegistry {
059:
060: /**
061: * Return an opaque object to represent the transaction bound to the
062: * current thread at the time this method is called. This object
063: * overrides hashCode and equals to allow its use as the key in a
064: * hashMap for use by the caller. If there is no transaction currently
065: * active, return null.
066: *
067: * <P>This object will return the same hashCode and compare equal to
068: * all other objects returned by calling this method
069: * from any component executing in the same transaction context in the
070: * same application server.
071: *
072: * <P>The toString method returns a String that might be usable by a
073: * human reader to usefully understand the transaction context. The
074: * toString result is otherwise not defined. Specifically, there is no
075: * forward or backward compatibility guarantee of the results of
076: * toString.
077: *
078: * <P>The object is not necessarily serializable, and has no defined
079: * behavior outside the virtual machine whence it was obtained.
080: *
081: * @return an opaque object representing the transaction bound to the
082: * current thread at the time this method is called.
083: *
084: * @since JTA 1.1
085: */
086: Object getTransactionKey();
087:
088: /**
089: * Add or replace an object in the Map of resources being managed for
090: * the transaction bound to the current thread at the time this
091: * method is called. The supplied key should be of an caller-
092: * defined class so as not to conflict with other users. The class
093: * of the key must guarantee that the hashCode and equals methods are
094: * suitable for use as keys in a map. The key and value are not examined
095: * or used by the implementation. The general contract of this method
096: * is that of {@link java.util.Map#put(Object, Object)} for a Map that
097: * supports non-null keys and null values. For example,
098: * if there is already an value associated with the key, it is replaced
099: * by the value parameter.
100: *
101: * @param key the key for the Map entry.
102: * @param value the value for the Map entry.
103: * @exception IllegalStateException if no transaction is active.
104: * @exception NullPointerException if the parameter key is null.
105: *
106: * @since JTA 1.1
107: */
108: void putResource(Object key, Object value);
109:
110: /**
111: * Get an object from the Map of resources being managed for
112: * the transaction bound to the current thread at the time this
113: * method is called. The key should have been supplied earlier
114: * by a call to putResouce in the same transaction. If the key
115: * cannot be found in the current resource Map, null is returned.
116: * The general contract of this method
117: * is that of {@link java.util.Map#get(Object)} for a Map that
118: * supports non-null keys and null values. For example,
119: * the returned value is null if there is no entry for the parameter
120: * key or if the value associated with the key is actually null.
121: *
122: * @param key the key for the Map entry.
123: * @return the value associated with the key.
124: * @exception IllegalStateException if no transaction is active.
125: * @exception NullPointerException if the parameter key is null.
126: *
127: * @since JTA 1.1
128: */
129: Object getResource(Object key);
130:
131: /**
132: * Register a Synchronization instance with special ordering
133: * semantics. Its beforeCompletion will be called after all
134: * SessionSynchronization beforeCompletion callbacks and callbacks
135: * registered directly with the Transaction, but before the 2-phase
136: * commit process starts. Similarly, the afterCompletion
137: * callback will be called after 2-phase commit completes but before
138: * any SessionSynchronization and Transaction afterCompletion callbacks.
139: *
140: * <P>The beforeCompletion callback will be invoked in the transaction
141: * context of the transaction bound to the current thread at the time
142: * this method is called.
143: * Allowable methods include access to resources,
144: * e.g. Connectors. No access is allowed to "user components" (e.g. timer
145: * services or bean methods), as these might change the state of data
146: * being managed by the caller, and might change the state of data that
147: * has already been flushed by another caller of
148: * registerInterposedSynchronization.
149: * The general context is the component
150: * context of the caller of registerInterposedSynchronization.
151: *
152: * <P>The afterCompletion callback will be invoked in an undefined
153: * context. No access is permitted to "user components"
154: * as defined above. Resources can be closed but no transactional
155: * work can be performed with them.
156: *
157: * <P>If this method is invoked without an active transaction context, an
158: * IllegalStateException is thrown.
159: *
160: * <P>If this method is invoked after the two-phase commit processing has
161: * started, an IllegalStateException is thrown.
162: *
163: * @param sync the Synchronization instance.
164: * @exception IllegalStateException if no transaction is active.
165: *
166: * @since JTA 1.1
167: */
168: void registerInterposedSynchronization(Synchronization sync);
169:
170: /**
171: * Return the status of the transaction bound to the
172: * current thread at the time this method is called.
173: * This is the result of executing TransactionManager.getStatus() in
174: * the context of the transaction bound to the current thread at the time
175: * this method is called.
176: *
177: * @return the status of the transaction bound to the current thread
178: * at the time this method is called.
179: *
180: * @since JTA 1.1
181: */
182: int getTransactionStatus();
183:
184: /**
185: * Set the rollbackOnly status of the transaction bound to the
186: * current thread at the time this method is called.
187: *
188: * @exception IllegalStateException if no transaction is active.
189: *
190: * @since JTA 1.1
191: */
192: void setRollbackOnly();
193:
194: /**
195: * Get the rollbackOnly status of the transaction bound to the
196: * current thread at the time this method is called.
197: *
198: * @return the rollbackOnly status.
199: * @exception IllegalStateException if no transaction is active.
200: *
201: * @since JTA 1.1
202: */
203: boolean getRollbackOnly();
204: }
|