类 CciTemplate
- java.lang.Object
- org.springframework.jca.cci.core.CciTemplate
- 所有已实现的接口:
CciOperations
public class CciTemplate extends Object implements CciOperations
This is the central class in the CCI core package. It simplifies the use of CCI and helps to avoid common errors. It executes core CCI workflow, leaving application code to provide parameters to CCI and extract results. This class executes EIS queries or updates, catching ResourceExceptions and translating them to the generic exception hierarchy defined in theorg.springframework.dao
package.Code using this class can pass in and receive
Record
instances, or alternatively implement callback interfaces for creating input Records and extracting result objects from output Records (or CCI ResultSets).Can be used within a service implementation via direct instantiation with a ConnectionFactory reference, or get prepared in an application context and given to services as bean reference. Note: The ConnectionFactory should always be configured as a bean in the application context, in the first case given to the service directly, in the second case to the prepared template.
- 从以下版本开始:
- 1.2
- 作者:
- Thierry Templier, Juergen Hoeller
- 另请参阅:
RecordCreator
,RecordExtractor
构造器概要
构造器 构造器 说明 CciTemplate()
Construct a new CciTemplate for bean usage.CciTemplate(ConnectionFactory connectionFactory)
Construct a new CciTemplate, given a ConnectionFactory to obtain Connections from.CciTemplate(ConnectionFactory connectionFactory, ConnectionSpec connectionSpec)
Construct a new CciTemplate, given a ConnectionFactory to obtain Connections from.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 void
afterPropertiesSet()
IndexedRecord
createIndexedRecord(String name)
Create an indexed Record through the ConnectionFactory's RecordFactory.MappedRecord
createMappedRecord(String name)
Create a mapped Record from the ConnectionFactory's RecordFactory.protected Record
createRecord(RecordCreator recordCreator)
Invoke the given RecordCreator, converting JCA ResourceExceptions to Spring's DataAccessException hierarchy.protected <T> T
doExecute(InteractionSpec spec, Record inputRecord, Record outputRecord, RecordExtractor<T> outputExtractor)
Execute the specified interaction on an EIS with CCI.Record
execute(InteractionSpec spec, Record inputRecord)
Execute the specified interaction on an EIS with CCI.void
execute(InteractionSpec spec, Record inputRecord, Record outputRecord)
Execute the specified interaction on an EIS with CCI.<T> T
execute(InteractionSpec spec, Record inputRecord, RecordExtractor<T> outputExtractor)
Execute the specified interaction on an EIS with CCI.Record
execute(InteractionSpec spec, RecordCreator inputCreator)
Execute the specified interaction on an EIS with CCI.<T> T
execute(InteractionSpec spec, RecordCreator inputCreator, RecordExtractor<T> outputExtractor)
Execute the specified interaction on an EIS with CCI.<T> T
execute(ConnectionCallback<T> action)
Execute a request on an EIS with CCI, implemented as callback action working on a CCI Connection.<T> T
execute(InteractionCallback<T> action)
Execute a request on an EIS with CCI, implemented as callback action working on a CCI Interaction.ConnectionFactory
getConnectionFactory()
Return the CCI ConnectionFactory used by this template.ConnectionSpec
getConnectionSpec()
Return the CCI ConnectionSpec used by this template, if any.CciTemplate
getDerivedTemplate(ConnectionSpec connectionSpec)
Create a template derived from this template instance, inheriting the ConnectionFactory and other settings but overriding the ConnectionSpec used for obtaining Connections.RecordCreator
getOutputRecordCreator()
Return a RecordCreator that should be used for creating default output Records.protected RecordFactory
getRecordFactory(ConnectionFactory connectionFactory)
Return a RecordFactory for the given ConnectionFactory.void
setConnectionFactory(ConnectionFactory connectionFactory)
Set the CCI ConnectionFactory to obtain Connections from.void
setConnectionSpec(ConnectionSpec connectionSpec)
Set the CCI ConnectionSpec that this template instance is supposed to obtain Connections for.void
setOutputRecordCreator(RecordCreator creator)
Set a RecordCreator that should be used for creating default output Records.
构造器详细资料
CciTemplate
public CciTemplate()
Construct a new CciTemplate for bean usage.Note: The ConnectionFactory has to be set before using the instance.
CciTemplate
public CciTemplate(ConnectionFactory connectionFactory)
Construct a new CciTemplate, given a ConnectionFactory to obtain Connections from. Note: This will trigger eager initialization of the exception translator.- 参数:
connectionFactory
- the JCA ConnectionFactory to obtain Connections from
CciTemplate
public CciTemplate(ConnectionFactory connectionFactory, @Nullable ConnectionSpec connectionSpec)
Construct a new CciTemplate, given a ConnectionFactory to obtain Connections from. Note: This will trigger eager initialization of the exception translator.- 参数:
connectionFactory
- the JCA ConnectionFactory to obtain Connections fromconnectionSpec
- the CCI ConnectionSpec to obtain Connections for (may benull
)
方法详细资料
setConnectionFactory
public void setConnectionFactory(@Nullable ConnectionFactory connectionFactory)
Set the CCI ConnectionFactory to obtain Connections from.
getConnectionFactory
@Nullable public ConnectionFactory getConnectionFactory()
Return the CCI ConnectionFactory used by this template.
setConnectionSpec
public void setConnectionSpec(@Nullable ConnectionSpec connectionSpec)
Set the CCI ConnectionSpec that this template instance is supposed to obtain Connections for.
getConnectionSpec
@Nullable public ConnectionSpec getConnectionSpec()
Return the CCI ConnectionSpec used by this template, if any.
setOutputRecordCreator
public void setOutputRecordCreator(@Nullable RecordCreator creator)
Set a RecordCreator that should be used for creating default output Records.Default is none: When no explicit output Record gets passed into an
execute
method, CCI'sInteraction.execute
variant that returns an output Record will be called.Specify a RecordCreator here if you always need to call CCI's
Interaction.execute
variant with a passed-in output Record. Unless there is an explicitly specified output Record, CciTemplate will then invoke this RecordCreator to create a default output Record instance.
getOutputRecordCreator
@Nullable public RecordCreator getOutputRecordCreator()
Return a RecordCreator that should be used for creating default output Records.
afterPropertiesSet
public void afterPropertiesSet()
getDerivedTemplate
public CciTemplate getDerivedTemplate(ConnectionSpec connectionSpec)
Create a template derived from this template instance, inheriting the ConnectionFactory and other settings but overriding the ConnectionSpec used for obtaining Connections.- 参数:
connectionSpec
- the CCI ConnectionSpec that the derived template instance is supposed to obtain Connections for- 返回:
- the derived template instance
- 另请参阅:
setConnectionSpec(javax.resource.cci.ConnectionSpec)
execute
@Nullable public <T> T execute(ConnectionCallback<T> action) throws DataAccessException
从接口复制的说明:CciOperations
Execute a request on an EIS with CCI, implemented as callback action working on a CCI Connection. This allows for implementing arbitrary data access operations, within Spring's managed CCI environment: that is, participating in Spring-managed transactions and converting JCA ResourceExceptions into Spring's DataAccessException hierarchy.The callback action can return a result object, for example a domain object or a collection of domain objects.
- 指定者:
execute
在接口中CciOperations
- 参数:
action
- the callback object that specifies the action- 返回:
- the result object returned by the action, if any
- 抛出:
DataAccessException
- if there is any problem
execute
@Nullable public <T> T execute(InteractionCallback<T> action) throws DataAccessException
从接口复制的说明:CciOperations
Execute a request on an EIS with CCI, implemented as callback action working on a CCI Interaction. This allows for implementing arbitrary data access operations on a single Interaction, within Spring's managed CCI environment: that is, participating in Spring-managed transactions and converting JCA ResourceExceptions into Spring's DataAccessException hierarchy.The callback action can return a result object, for example a domain object or a collection of domain objects.
- 指定者:
execute
在接口中CciOperations
- 参数:
action
- the callback object that specifies the action- 返回:
- the result object returned by the action, if any
- 抛出:
DataAccessException
- if there is any problem
execute
@Nullable public Record execute(InteractionSpec spec, Record inputRecord) throws DataAccessException
从接口复制的说明:CciOperations
Execute the specified interaction on an EIS with CCI.- 指定者:
execute
在接口中CciOperations
- 参数:
spec
- the CCI InteractionSpec instance that defines the interaction (connector-specific)inputRecord
- the input record- 返回:
- the output record
- 抛出:
DataAccessException
- if there is any problem
execute
public void execute(InteractionSpec spec, Record inputRecord, Record outputRecord) throws DataAccessException
从接口复制的说明:CciOperations
Execute the specified interaction on an EIS with CCI.- 指定者:
execute
在接口中CciOperations
- 参数:
spec
- the CCI InteractionSpec instance that defines the interaction (connector-specific)inputRecord
- the input recordoutputRecord
- the output record- 抛出:
DataAccessException
- if there is any problem
execute
public Record execute(InteractionSpec spec, RecordCreator inputCreator) throws DataAccessException
从接口复制的说明:CciOperations
Execute the specified interaction on an EIS with CCI.- 指定者:
execute
在接口中CciOperations
- 参数:
spec
- the CCI InteractionSpec instance that defines the interaction (connector-specific)inputCreator
- object that creates the input record to use- 返回:
- the output record
- 抛出:
DataAccessException
- if there is any problem
execute
public <T> T execute(InteractionSpec spec, Record inputRecord, RecordExtractor<T> outputExtractor) throws DataAccessException
从接口复制的说明:CciOperations
Execute the specified interaction on an EIS with CCI.- 指定者:
execute
在接口中CciOperations
- 参数:
spec
- the CCI InteractionSpec instance that defines the interaction (connector-specific)inputRecord
- the input recordoutputExtractor
- object to convert the output record to a result object- 返回:
- the output data extracted with the RecordExtractor object
- 抛出:
DataAccessException
- if there is any problem
execute
public <T> T execute(InteractionSpec spec, RecordCreator inputCreator, RecordExtractor<T> outputExtractor) throws DataAccessException
从接口复制的说明:CciOperations
Execute the specified interaction on an EIS with CCI.- 指定者:
execute
在接口中CciOperations
- 参数:
spec
- the CCI InteractionSpec instance that defines the interaction (connector-specific)inputCreator
- object that creates the input record to useoutputExtractor
- object to convert the output record to a result object- 返回:
- the output data extracted with the RecordExtractor object
- 抛出:
DataAccessException
- if there is any problem
doExecute
@Nullable protected <T> T doExecute(InteractionSpec spec, Record inputRecord, @Nullable Record outputRecord, @Nullable RecordExtractor<T> outputExtractor) throws DataAccessException
Execute the specified interaction on an EIS with CCI. All other interaction execution methods go through this.- 参数:
spec
- the CCI InteractionSpec instance that defines the interaction (connector-specific)inputRecord
- the input recordoutputRecord
- output record (can benull
)outputExtractor
- object to convert the output record to a result object- 返回:
- the output data extracted with the RecordExtractor object
- 抛出:
DataAccessException
- if there is any problem
createIndexedRecord
public IndexedRecord createIndexedRecord(String name) throws DataAccessException
Create an indexed Record through the ConnectionFactory's RecordFactory.- 参数:
name
- the name of the record- 返回:
- the Record
- 抛出:
DataAccessException
- if creation of the Record failed- 另请参阅:
getRecordFactory(javax.resource.cci.ConnectionFactory)
,RecordFactory.createIndexedRecord(String)
createMappedRecord
public MappedRecord createMappedRecord(String name) throws DataAccessException
Create a mapped Record from the ConnectionFactory's RecordFactory.- 参数:
name
- record name- 返回:
- the Record
- 抛出:
DataAccessException
- if creation of the Record failed- 另请参阅:
getRecordFactory(javax.resource.cci.ConnectionFactory)
,RecordFactory.createMappedRecord(String)
createRecord
protected Record createRecord(RecordCreator recordCreator) throws DataAccessException
Invoke the given RecordCreator, converting JCA ResourceExceptions to Spring's DataAccessException hierarchy.- 参数:
recordCreator
- the RecordCreator to invoke- 返回:
- the created Record
- 抛出:
DataAccessException
- if creation of the Record failed- 另请参阅:
getRecordFactory(javax.resource.cci.ConnectionFactory)
,RecordCreator.createRecord(javax.resource.cci.RecordFactory)
getRecordFactory
protected RecordFactory getRecordFactory(ConnectionFactory connectionFactory) throws ResourceException
Return a RecordFactory for the given ConnectionFactory.Default implementation returns the connector's RecordFactory if available, falling back to a NotSupportedRecordFactory placeholder. This allows to invoke a RecordCreator callback with a non-null RecordFactory reference in any case.
- 参数:
connectionFactory
- the CCI ConnectionFactory- 返回:
- the CCI RecordFactory for the ConnectionFactory
- 抛出:
ResourceException
- if thrown by CCI methods- 另请参阅:
NotSupportedRecordFactory