001/*
002 * Copyright 2002-2012 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.jca.cci.core;
018
019import java.sql.SQLException;
020import javax.resource.ResourceException;
021import javax.resource.cci.Record;
022
023import org.springframework.dao.DataAccessException;
024
025/**
026 * Callback interface for extracting a result object from a CCI Record instance.
027 *
028 * <p>Used for output object creation in CciTemplate. Alternatively, output
029 * Records can also be returned to client code as-is. In case of a CCI ResultSet
030 * as execution result, you will almost always want to implement a RecordExtractor,
031 * to be able to read the ResultSet in a managed fashion, with the CCI Connection
032 * still open while reading the ResultSet.
033 *
034 * <p>Implementations of this interface perform the actual work of extracting
035 * results, but don't need to worry about exception handling. ResourceExceptions
036 * will be caught and handled correctly by the CciTemplate class.
037 *
038 * @author Thierry Templier
039 * @author Juergen Hoeller
040 * @since 1.2
041 * @see CciTemplate#execute(javax.resource.cci.InteractionSpec, Record, RecordExtractor)
042 * @see CciTemplate#execute(javax.resource.cci.InteractionSpec, RecordCreator, RecordExtractor)
043 * @see javax.resource.cci.ResultSet
044 */
045public interface RecordExtractor<T> {
046
047        /**
048         * Process the data in the given Record, creating a corresponding result object.
049         * @param record the Record to extract data from
050         * (possibly a CCI ResultSet)
051         * @return an arbitrary result object, or {@code null} if none
052         * (the extractor will typically be stateful in the latter case)
053         * @throws ResourceException if thrown by a CCI method, to be auto-converted
054         * to a DataAccessException
055         * @throws SQLException if thrown by a ResultSet method, to be auto-converted
056         * to a DataAccessException
057         * @throws DataAccessException in case of custom exceptions
058         * @see javax.resource.cci.ResultSet
059         */
060        T extractData(Record record) throws ResourceException, SQLException, DataAccessException;
061
062}