001/*
002 * Copyright 2002-2016 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 javax.resource.ResourceException;
020import javax.resource.cci.Record;
021import javax.resource.cci.RecordFactory;
022
023import org.springframework.dao.DataAccessException;
024
025/**
026 * Callback interface for creating a CCI Record instance,
027 * usually based on the passed-in CCI RecordFactory.
028 *
029 * <p>Used for input Record creation in CciTemplate. Alternatively,
030 * Record instances can be passed into CciTemplate's corresponding
031 * {@code execute} methods directly, either instantiated manually
032 * or created through CciTemplate's Record factory methods.
033 *
034 * <P>Also used for creating default output Records in CciTemplate.
035 * This is useful when the JCA connector needs an explicit output Record
036 * instance, but no output Records should be passed into CciTemplate's
037 * {@code execute} methods.
038 *
039 * @author Thierry Templier
040 * @author Juergen Hoeller
041 * @since 1.2
042 * @see CciTemplate#execute(javax.resource.cci.InteractionSpec, RecordCreator)
043 * @see CciTemplate#execute(javax.resource.cci.InteractionSpec, RecordCreator, RecordExtractor)
044 * @see CciTemplate#createIndexedRecord(String)
045 * @see CciTemplate#createMappedRecord(String)
046 * @see CciTemplate#setOutputRecordCreator(RecordCreator)
047 */
048@FunctionalInterface
049public interface RecordCreator {
050
051        /**
052         * Create a CCI Record instance, usually based on the passed-in CCI RecordFactory.
053         * <p>For use as <i>input</i> creator with CciTemplate's {@code execute} methods,
054         * this method should create a <i>populated</i> Record instance. For use as
055         * <i>output</i> Record creator, it should return an <i>empty</i> Record instance.
056         * @param recordFactory the CCI RecordFactory (never {@code null}, but not guaranteed to be
057         * supported by the connector: its create methods might throw NotSupportedException)
058         * @return the Record instance
059         * @throws ResourceException if thrown by a CCI method, to be auto-converted
060         * to a DataAccessException
061         * @throws DataAccessException in case of custom exceptions
062         */
063        Record createRecord(RecordFactory recordFactory) throws ResourceException, DataAccessException;
064
065}