javax.resource.cci.ResultSet Java Examples

The following examples show how to use javax.resource.cci.ResultSet. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CciTemplate.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Execute the specified interaction on an EIS with CCI.
 * All other interaction execution methods go through this.
 * @param spec the CCI InteractionSpec instance that defines
 * the interaction (connector-specific)
 * @param inputRecord the input record
 * @param outputRecord output record (can be {@code null})
 * @param outputExtractor object to convert the output record to a result object
 * @return the output data extracted with the RecordExtractor object
 * @throws DataAccessException if there is any problem
 */
@Nullable
protected <T> T doExecute(
		final InteractionSpec spec, final Record inputRecord, @Nullable final Record outputRecord,
		@Nullable final RecordExtractor<T> outputExtractor) throws DataAccessException {

	return execute((InteractionCallback<T>) (interaction, connectionFactory) -> {
		Record outputRecordToUse = outputRecord;
		try {
			if (outputRecord != null || getOutputRecordCreator() != null) {
				// Use the CCI execute method with output record as parameter.
				if (outputRecord == null) {
					RecordFactory recordFactory = getRecordFactory(connectionFactory);
					outputRecordToUse = getOutputRecordCreator().createRecord(recordFactory);
				}
				interaction.execute(spec, inputRecord, outputRecordToUse);
			}
			else {
				outputRecordToUse = interaction.execute(spec, inputRecord);
			}
			return (outputExtractor != null ? outputExtractor.extractData(outputRecordToUse) : null);
		}
		finally {
			if (outputRecordToUse instanceof ResultSet) {
				closeResultSet((ResultSet) outputRecordToUse);
			}
		}
	});
}
 
Example #2
Source File: CciTemplateTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void testTemplateExecuteInputOutputResultsSetFalse()
		throws ResourceException, SQLException {
	ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
	RecordFactory recordFactory = mock(RecordFactory.class);
	Connection connection = mock(Connection.class);
	Interaction interaction = mock(Interaction.class);
	Record record = mock(Record.class);
	ResultSet resultset = mock(ResultSet.class);
	RecordCreator generator = mock(RecordCreator.class);
	RecordExtractor<Object> extractor = mock(RecordExtractor.class);

	InteractionSpec interactionSpec = mock(InteractionSpec.class);

	given(connectionFactory.getRecordFactory()).willReturn(recordFactory);
	given(connectionFactory.getConnection()).willReturn(connection);
	given(connection.createInteraction()).willReturn(interaction);
	given(generator.createRecord(recordFactory)).willReturn(record);
	given(interaction.execute(interactionSpec, record)).willReturn(resultset);
	given(extractor.extractData(resultset)).willReturn(new Object());

	CciTemplate ct = new CciTemplate(connectionFactory);
	ct.execute(interactionSpec, generator, extractor);

	verify(extractor).extractData(resultset);
	verify(resultset).close();
	verify(interaction).close();
	verify(connection).close();
}
 
Example #3
Source File: CciTemplate.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Execute the specified interaction on an EIS with CCI.
 * All other interaction execution methods go through this.
 * @param spec the CCI InteractionSpec instance that defines
 * the interaction (connector-specific)
 * @param inputRecord the input record
 * @param outputRecord output record (can be {@code null})
 * @param outputExtractor object to convert the output record to a result object
 * @return the output data extracted with the RecordExtractor object
 * @throws DataAccessException if there is any problem
 */
@Nullable
protected <T> T doExecute(
		final InteractionSpec spec, final Record inputRecord, @Nullable final Record outputRecord,
		@Nullable final RecordExtractor<T> outputExtractor) throws DataAccessException {

	return execute((InteractionCallback<T>) (interaction, connectionFactory) -> {
		Record outputRecordToUse = outputRecord;
		try {
			if (outputRecord != null || getOutputRecordCreator() != null) {
				// Use the CCI execute method with output record as parameter.
				if (outputRecord == null) {
					RecordFactory recordFactory = getRecordFactory(connectionFactory);
					outputRecordToUse = getOutputRecordCreator().createRecord(recordFactory);
				}
				interaction.execute(spec, inputRecord, outputRecordToUse);
			}
			else {
				outputRecordToUse = interaction.execute(spec, inputRecord);
			}
			return (outputExtractor != null ? outputExtractor.extractData(outputRecordToUse) : null);
		}
		finally {
			if (outputRecordToUse instanceof ResultSet) {
				closeResultSet((ResultSet) outputRecordToUse);
			}
		}
	});
}
 
Example #4
Source File: CciTemplateTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void testTemplateExecuteInputOutputResultsSetFalse()
		throws ResourceException, SQLException {
	ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
	RecordFactory recordFactory = mock(RecordFactory.class);
	Connection connection = mock(Connection.class);
	Interaction interaction = mock(Interaction.class);
	Record record = mock(Record.class);
	ResultSet resultset = mock(ResultSet.class);
	RecordCreator generator = mock(RecordCreator.class);
	RecordExtractor<Object> extractor = mock(RecordExtractor.class);

	InteractionSpec interactionSpec = mock(InteractionSpec.class);

	given(connectionFactory.getRecordFactory()).willReturn(recordFactory);
	given(connectionFactory.getConnection()).willReturn(connection);
	given(connection.createInteraction()).willReturn(interaction);
	given(generator.createRecord(recordFactory)).willReturn(record);
	given(interaction.execute(interactionSpec, record)).willReturn(resultset);
	given(extractor.extractData(resultset)).willReturn(new Object());

	CciTemplate ct = new CciTemplate(connectionFactory);
	ct.execute(interactionSpec, generator, extractor);

	verify(extractor).extractData(resultset);
	verify(resultset).close();
	verify(interaction).close();
	verify(connection).close();
}
 
Example #5
Source File: CciTemplate.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Execute the specified interaction on an EIS with CCI.
 * All other interaction execution methods go through this.
 * @param spec the CCI InteractionSpec instance that defines
 * the interaction (connector-specific)
 * @param inputRecord the input record
 * @param outputRecord output record (can be {@code null})
 * @param outputExtractor object to convert the output record to a result object
 * @return the output data extracted with the RecordExtractor object
 * @throws DataAccessException if there is any problem
 */
protected <T> T doExecute(
		final InteractionSpec spec, final Record inputRecord, final Record outputRecord,
		final RecordExtractor<T> outputExtractor) throws DataAccessException {

	return execute(new InteractionCallback<T>() {
		@Override
		public T doInInteraction(Interaction interaction, ConnectionFactory connectionFactory)
				throws ResourceException, SQLException, DataAccessException {
			Record outputRecordToUse = outputRecord;
			try {
				if (outputRecord != null || getOutputRecordCreator() != null) {
					// Use the CCI execute method with output record as parameter.
					if (outputRecord == null) {
						RecordFactory recordFactory = getRecordFactory(connectionFactory);
						outputRecordToUse = getOutputRecordCreator().createRecord(recordFactory);
					}
					interaction.execute(spec, inputRecord, outputRecordToUse);
				}
				else {
					outputRecordToUse = interaction.execute(spec, inputRecord);
				}
				return (outputExtractor != null ? outputExtractor.extractData(outputRecordToUse) : null);
			}
			finally {
				if (outputRecordToUse instanceof ResultSet) {
					closeResultSet((ResultSet) outputRecordToUse);
				}
			}
		}
	});
}
 
Example #6
Source File: CciTemplate.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Execute the specified interaction on an EIS with CCI.
 * All other interaction execution methods go through this.
 * @param spec the CCI InteractionSpec instance that defines
 * the interaction (connector-specific)
 * @param inputRecord the input record
 * @param outputRecord output record (can be {@code null})
 * @param outputExtractor object to convert the output record to a result object
 * @return the output data extracted with the RecordExtractor object
 * @throws DataAccessException if there is any problem
 */
protected <T> T doExecute(
		final InteractionSpec spec, final Record inputRecord, final Record outputRecord,
		final RecordExtractor<T> outputExtractor) throws DataAccessException {

	return execute(new InteractionCallback<T>() {
		@Override
		public T doInInteraction(Interaction interaction, ConnectionFactory connectionFactory)
				throws ResourceException, SQLException, DataAccessException {
			Record outputRecordToUse = outputRecord;
			try {
				if (outputRecord != null || getOutputRecordCreator() != null) {
					// Use the CCI execute method with output record as parameter.
					if (outputRecord == null) {
						RecordFactory recordFactory = getRecordFactory(connectionFactory);
						outputRecordToUse = getOutputRecordCreator().createRecord(recordFactory);
					}
					interaction.execute(spec, inputRecord, outputRecordToUse);
				}
				else {
					outputRecordToUse = interaction.execute(spec, inputRecord);
				}
				return (outputExtractor != null ? outputExtractor.extractData(outputRecordToUse) : null);
			}
			finally {
				if (outputRecordToUse instanceof ResultSet) {
					closeResultSet((ResultSet) outputRecordToUse);
				}
			}
		}
	});
}
 
Example #7
Source File: CciTemplateTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void testTemplateExecuteInputOutputResultsSetFalse()
		throws ResourceException, SQLException {
	ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
	RecordFactory recordFactory = mock(RecordFactory.class);
	Connection connection = mock(Connection.class);
	Interaction interaction = mock(Interaction.class);
	Record record = mock(Record.class);
	ResultSet resultset = mock(ResultSet.class);
	RecordCreator generator = mock(RecordCreator.class);
	RecordExtractor<Object> extractor = mock(RecordExtractor.class);

	InteractionSpec interactionSpec = mock(InteractionSpec.class);

	given(connectionFactory.getRecordFactory()).willReturn(recordFactory);
	given(connectionFactory.getConnection()).willReturn(connection);
	given(connection.createInteraction()).willReturn(interaction);
	given(generator.createRecord(recordFactory)).willReturn(record);
	given(interaction.execute(interactionSpec, record)).willReturn(resultset);
	given(extractor.extractData(resultset)).willReturn(new Object());

	CciTemplate ct = new CciTemplate(connectionFactory);
	ct.execute(interactionSpec, generator, extractor);

	verify(extractor).extractData(resultset);
	verify(resultset).close();
	verify(interaction).close();
	verify(connection).close();
}