01: /*
02: * Copyright 2002-2005 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.springframework.transaction.support;
18:
19: import org.springframework.transaction.TransactionStatus;
20:
21: /**
22: * Callback interface for transactional code. To be used with TransactionTemplate's
23: * execute method, assumably often as anonymous class within a method implementation.
24: *
25: * <p>Typically used to gather various calls to transaction-unaware low-level
26: * services into a higher-level method implementation with transaction demarcation.
27: *
28: * @author Juergen Hoeller
29: * @since 17.03.2003
30: * @see TransactionTemplate
31: */
32: public interface TransactionCallback {
33:
34: /**
35: * Gets called by TransactionTemplate.execute within a transactional context.
36: * Does not need to care about transactions itself, although it can retrieve
37: * and influence the status of the current transaction via the given status
38: * object, e.g. setting rollback-only.
39: *
40: * <p>Allows for returning a result object created within the transaction, i.e.
41: * a domain object or a collection of domain objects. A RuntimeException thrown
42: * by the callback is treated as application exception that enforces a rollback.
43: * An exception gets propagated to the caller of the template.
44: *
45: * <p>Note when using JTA: JTA transactions only work with transactional
46: * JNDI resources, so implementations need to use such resources if they
47: * want transaction support.
48: *
49: * @param status associated transaction status
50: * @return a result object, or <code>null</code>
51: * @see TransactionTemplate#execute
52: */
53: Object doInTransaction(TransactionStatus status);
54:
55: }
|