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.jca.cci.core;
18:
19: import java.sql.SQLException;
20:
21: import javax.resource.ResourceException;
22: import javax.resource.cci.Connection;
23: import javax.resource.cci.ConnectionFactory;
24:
25: import org.springframework.dao.DataAccessException;
26:
27: /**
28: * Generic callback interface for code that operates on a CCI Connection.
29: * Allows to execute any number of operations on a single Connection,
30: * using any type and number of Interaction.
31: *
32: * <p>This is particularly useful for delegating to existing data access code
33: * that expects a Connection to work on and throws ResourceException. For newly
34: * written code, it is strongly recommended to use CciTemplate's more specific
35: * <code>execute</code> variants.
36: *
37: * @author Thierry Templier
38: * @author Juergen Hoeller
39: * @since 1.2
40: * @see CciTemplate#execute(ConnectionCallback)
41: * @see CciTemplate#execute(javax.resource.cci.InteractionSpec, javax.resource.cci.Record)
42: * @see CciTemplate#execute(javax.resource.cci.InteractionSpec, RecordCreator, RecordExtractor)
43: */
44: public interface ConnectionCallback {
45:
46: /**
47: * Gets called by <code>CciTemplate.execute</code> with an active CCI Connection.
48: * Does not need to care about activating or closing the Connection, or handling
49: * transactions.
50: *
51: * <p>If called without a thread-bound CCI transaction (initiated by
52: * CciLocalTransactionManager), the code will simply get executed on the CCI
53: * Connection with its transactional semantics. If CciTemplate is configured
54: * to use a JTA-aware ConnectionFactory, the CCI Connection and thus the callback
55: * code will be transactional if a JTA transaction is active.
56: *
57: * <p>Allows for returning a result object created within the callback, i.e.
58: * a domain object or a collection of domain objects. Note that there's special
59: * support for single step actions: see the <code>CciTemplate.execute</code>
60: * variants. A thrown RuntimeException is treated as application exception:
61: * it gets propagated to the caller of the template.
62: *
63: * @param connection active CCI Connection
64: * @param connectionFactory the CCI ConnectionFactory that the Connection was
65: * created with (gives access to RecordFactory and ResourceAdapterMetaData)
66: * @return a result object, or <code>null</code> if none
67: * @throws ResourceException if thrown by a CCI method, to be auto-converted
68: * to a DataAccessException
69: * @throws SQLException if thrown by a ResultSet method, to be auto-converted
70: * to a DataAccessException
71: * @throws DataAccessException in case of custom exceptions
72: * @see javax.resource.cci.ConnectionFactory#getRecordFactory()
73: * @see javax.resource.cci.ConnectionFactory#getMetaData()
74: * @see CciTemplate#execute(javax.resource.cci.InteractionSpec, RecordCreator, RecordExtractor)
75: */
76: Object doInConnection(Connection connection,
77: ConnectionFactory connectionFactory)
78: throws ResourceException, SQLException, DataAccessException;
79:
80: }
|