001/*
002 * Copyright 2002-2018 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;
020
021import javax.resource.ResourceException;
022import javax.resource.cci.Record;
023
024import org.springframework.dao.DataAccessException;
025import org.springframework.lang.Nullable;
026
027/**
028 * Callback interface for extracting a result object from a CCI Record instance.
029 *
030 * <p>Used for output object creation in CciTemplate. Alternatively, output
031 * Records can also be returned to client code as-is. In case of a CCI ResultSet
032 * as execution result, you will almost always want to implement a RecordExtractor,
033 * to be able to read the ResultSet in a managed fashion, with the CCI Connection
034 * still open while reading the ResultSet.
035 *
036 * <p>Implementations of this interface perform the actual work of extracting
037 * results, but don't need to worry about exception handling. ResourceExceptions
038 * will be caught and handled correctly by the CciTemplate class.
039 *
040 * @author Thierry Templier
041 * @author Juergen Hoeller
042 * @since 1.2
043 * @param <T> the result type
044 * @see CciTemplate#execute(javax.resource.cci.InteractionSpec, Record, RecordExtractor)
045 * @see CciTemplate#execute(javax.resource.cci.InteractionSpec, RecordCreator, RecordExtractor)
046 * @see javax.resource.cci.ResultSet
047 */
048@FunctionalInterface
049public interface RecordExtractor<T> {
050
051        /**
052         * Process the data in the given Record, creating a corresponding result object.
053         * @param record the Record to extract data from
054         * (possibly a CCI ResultSet)
055         * @return an arbitrary result object, or {@code null} if none
056         * (the extractor will typically be stateful in the latter case)
057         * @throws ResourceException if thrown by a CCI method, to be auto-converted
058         * to a DataAccessException
059         * @throws SQLException if thrown by a ResultSet method, to be auto-converted
060         * to a DataAccessException
061         * @throws DataAccessException in case of custom exceptions
062         * @see javax.resource.cci.ResultSet
063         */
064        @Nullable
065        T extractData(Record record) throws ResourceException, SQLException, DataAccessException;
066
067}