01: /*
02: * Copyright 2002-2007 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. Used with {@link TransactionTemplate}'s
23: * <code>execute</code> method, often as anonymous class within a method implementation.
24: *
25: * <p>Typically used to assemble various calls to transaction-unaware data access
26: * services into a higher-level service method with transaction demarcation. As an
27: * alternative, consider the use of declarative transaction demarcation (e.g. through
28: * Spring's {@link org.springframework.transaction.annotation.Transactional} annotation).
29: *
30: * @author Juergen Hoeller
31: * @since 17.03.2003
32: * @see TransactionTemplate
33: * @see CallbackPreferringPlatformTransactionManager
34: */
35: public interface TransactionCallback {
36:
37: /**
38: * Gets called by {@link TransactionTemplate#execute} within a transactional context.
39: * Does not need to care about transactions itself, although it can retrieve
40: * and influence the status of the current transaction via the given status
41: * object, e.g. setting rollback-only.
42: *
43: * <p>Allows for returning a result object created within the transaction, i.e.
44: * a domain object or a collection of domain objects. A RuntimeException thrown
45: * by the callback is treated as application exception that enforces a rollback.
46: * An exception gets propagated to the caller of the template.
47: *
48: * @param status associated transaction status
49: * @return a result object, or <code>null</code>
50: * @see TransactionTemplate#execute
51: * @see CallbackPreferringPlatformTransactionManager#execute
52: */
53: Object doInTransaction(TransactionStatus status);
54:
55: }
|