1 16 17 package org.springframework.jca.cci.object; 18 19 import java.sql.SQLException ; 20 21 import javax.resource.ResourceException ; 22 import javax.resource.cci.ConnectionFactory ; 23 import javax.resource.cci.InteractionSpec ; 24 import javax.resource.cci.Record ; 25 import javax.resource.cci.RecordFactory ; 26 27 import org.springframework.dao.DataAccessException; 28 import org.springframework.jca.cci.core.RecordCreator; 29 import org.springframework.jca.cci.core.RecordExtractor; 30 31 47 public abstract class MappingRecordOperation extends EisOperation { 48 49 52 public MappingRecordOperation() { 53 } 54 55 60 public MappingRecordOperation(ConnectionFactory connectionFactory, InteractionSpec interactionSpec) { 61 getCciTemplate().setConnectionFactory(connectionFactory); 62 setInteractionSpec(interactionSpec); 63 } 64 65 76 public void setOutputRecordCreator(RecordCreator creator) { 77 getCciTemplate().setOutputRecordCreator(creator); 78 } 79 80 89 public Object execute(Object inputObject) throws DataAccessException { 90 return getCciTemplate().execute( 91 getInteractionSpec(), new RecordCreatorImpl(inputObject), new RecordExtractorImpl()); 92 } 93 94 95 104 protected abstract Record createInputRecord(RecordFactory recordFactory, Object inputObject) 105 throws ResourceException , DataAccessException; 106 107 116 protected abstract Object extractOutputData(Record outputRecord) 117 throws ResourceException , SQLException , DataAccessException; 118 119 120 124 protected class RecordCreatorImpl implements RecordCreator { 125 126 private final Object inputObject; 127 128 public RecordCreatorImpl(Object inObject) { 129 this.inputObject = inObject; 130 } 131 132 public Record createRecord(RecordFactory recordFactory) throws ResourceException , DataAccessException { 133 return createInputRecord(recordFactory, this.inputObject); 134 } 135 } 136 137 138 142 protected class RecordExtractorImpl implements RecordExtractor { 143 144 public Object extractData(Record record) throws ResourceException , SQLException , DataAccessException { 145 return extractOutputData(record); 146 } 147 } 148 149 } 150 | Popular Tags |