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.object; 018 019import javax.resource.cci.ConnectionFactory; 020import javax.resource.cci.InteractionSpec; 021import javax.resource.cci.Record; 022 023import org.springframework.dao.DataAccessException; 024import org.springframework.lang.Nullable; 025import org.springframework.util.Assert; 026 027/** 028 * EIS operation object that accepts a passed-in CCI input Record 029 * and returns a corresponding CCI output Record. 030 * 031 * @author Juergen Hoeller 032 * @since 1.2 033 */ 034public class SimpleRecordOperation extends EisOperation { 035 036 /** 037 * Constructor that allows use as a JavaBean. 038 */ 039 public SimpleRecordOperation() { 040 } 041 042 /** 043 * Convenient constructor with ConnectionFactory and specifications 044 * (connection and interaction). 045 * @param connectionFactory the ConnectionFactory to use to obtain connections 046 */ 047 public SimpleRecordOperation(ConnectionFactory connectionFactory, InteractionSpec interactionSpec) { 048 getCciTemplate().setConnectionFactory(connectionFactory); 049 setInteractionSpec(interactionSpec); 050 } 051 052 053 /** 054 * Execute the CCI interaction encapsulated by this operation object. 055 * <p>This method will call CCI's {@code Interaction.execute} variant 056 * that returns an output Record. 057 * @param inputRecord the input record 058 * @return the output record 059 * @throws DataAccessException if there is any problem 060 * @see javax.resource.cci.Interaction#execute(javax.resource.cci.InteractionSpec, Record) 061 */ 062 @Nullable 063 public Record execute(Record inputRecord) throws DataAccessException { 064 InteractionSpec interactionSpec = getInteractionSpec(); 065 Assert.state(interactionSpec != null, "No InteractionSpec set"); 066 return getCciTemplate().execute(interactionSpec, inputRecord); 067 } 068 069 /** 070 * Execute the CCI interaction encapsulated by this operation object. 071 * <p>This method will call CCI's {@code Interaction.execute} variant 072 * with a passed-in output Record. 073 * @param inputRecord the input record 074 * @param outputRecord the output record 075 * @throws DataAccessException if there is any problem 076 * @see javax.resource.cci.Interaction#execute(javax.resource.cci.InteractionSpec, Record, Record) 077 */ 078 public void execute(Record inputRecord, Record outputRecord) throws DataAccessException { 079 InteractionSpec interactionSpec = getInteractionSpec(); 080 Assert.state(interactionSpec != null, "No InteractionSpec set"); 081 getCciTemplate().execute(interactionSpec, inputRecord, outputRecord); 082 } 083 084}