本文整理汇总了Java中javax.resource.cci.ConnectionFactory类的典型用法代码示例。如果您正苦于以下问题:Java ConnectionFactory类的具体用法?Java ConnectionFactory怎么用?Java ConnectionFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ConnectionFactory类属于javax.resource.cci包,在下文中一共展示了ConnectionFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doGetConnection
import javax.resource.cci.ConnectionFactory; //导入依赖的package包/类
/**
* Actually obtain a CCI Connection from the given ConnectionFactory.
* Same as {@link #getConnection}, but throwing the original ResourceException.
* <p>Is aware of a corresponding Connection bound to the current thread, for example
* when using {@link CciLocalTransactionManager}. Will bind a Connection to the thread
* if transaction synchronization is active (e.g. if in a JTA transaction).
* <p>Directly accessed by {@link TransactionAwareConnectionFactoryProxy}.
* @param cf the ConnectionFactory to obtain Connection from
* @return a CCI Connection from the given ConnectionFactory
* @throws ResourceException if thrown by CCI API methods
* @see #doReleaseConnection
*/
public static Connection doGetConnection(ConnectionFactory cf) throws ResourceException {
Assert.notNull(cf, "No ConnectionFactory specified");
ConnectionHolder conHolder = (ConnectionHolder) TransactionSynchronizationManager.getResource(cf);
if (conHolder != null) {
return conHolder.getConnection();
}
logger.debug("Opening CCI Connection");
Connection con = cf.getConnection();
if (TransactionSynchronizationManager.isSynchronizationActive()) {
logger.debug("Registering transaction synchronization for CCI Connection");
conHolder = new ConnectionHolder(con);
conHolder.setSynchronizedWithTransaction(true);
TransactionSynchronizationManager.registerSynchronization(new ConnectionSynchronization(conHolder, cf));
TransactionSynchronizationManager.bindResource(cf, conHolder);
}
return con;
}
示例2: execute
import javax.resource.cci.ConnectionFactory; //导入依赖的package包/类
@Override
public <T> T execute(final InteractionCallback<T> action) throws DataAccessException {
Assert.notNull(action, "Callback object must not be null");
return execute(new ConnectionCallback<T>() {
@Override
public T doInConnection(Connection connection, ConnectionFactory connectionFactory)
throws ResourceException, SQLException, DataAccessException {
Interaction interaction = connection.createInteraction();
try {
return action.doInInteraction(interaction, connectionFactory);
}
finally {
closeInteraction(interaction);
}
}
});
}
示例3: testSimpleRecordOperation
import javax.resource.cci.ConnectionFactory; //导入依赖的package包/类
@Test
public void testSimpleRecordOperation() throws ResourceException {
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
Connection connection = mock(Connection.class);
Interaction interaction = mock(Interaction.class);
Record inputRecord = mock(Record.class);
Record outputRecord = mock(Record.class);
InteractionSpec interactionSpec = mock(InteractionSpec.class);
SimpleRecordOperation query = new SimpleRecordOperation(connectionFactory, interactionSpec);
given(connectionFactory.getConnection()).willReturn(connection);
given(connection.createInteraction()).willReturn(interaction);
given(interaction.execute(interactionSpec, inputRecord)).willReturn(outputRecord);
query.execute(inputRecord);
verify(interaction).execute(interactionSpec, inputRecord);
verify(interaction).close();
verify(connection).close();
}
示例4: testSimpleRecordOperationWithExplicitOutputRecord
import javax.resource.cci.ConnectionFactory; //导入依赖的package包/类
@Test
public void testSimpleRecordOperationWithExplicitOutputRecord() throws ResourceException {
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
Connection connection = mock(Connection.class);
Interaction interaction = mock(Interaction.class);
Record inputRecord = mock(Record.class);
Record outputRecord = mock(Record.class);
InteractionSpec interactionSpec = mock(InteractionSpec.class);
SimpleRecordOperation operation = new SimpleRecordOperation(connectionFactory, interactionSpec);
given(connectionFactory.getConnection()).willReturn(connection);
given(connection.createInteraction()).willReturn(interaction);
given(interaction.execute(interactionSpec, inputRecord, outputRecord)).willReturn(true);
operation.execute(inputRecord, outputRecord);
verify(interaction).execute(interactionSpec, inputRecord, outputRecord);
verify(interaction).close();
verify(connection).close();
}
示例5: testSimpleRecordOperationWithInputOutputRecord
import javax.resource.cci.ConnectionFactory; //导入依赖的package包/类
@Test
public void testSimpleRecordOperationWithInputOutputRecord() throws ResourceException {
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
Connection connection = mock(Connection.class);
Interaction interaction = mock(Interaction.class);
Record inputOutputRecord = mock(Record.class);
InteractionSpec interactionSpec = mock(InteractionSpec.class);
SimpleRecordOperation query = new SimpleRecordOperation(connectionFactory, interactionSpec);
given(connectionFactory.getConnection()).willReturn(connection);
given(connection.createInteraction()).willReturn(interaction);
given(interaction.execute(interactionSpec, inputOutputRecord, inputOutputRecord)).willReturn(true);
query.execute(inputOutputRecord, inputOutputRecord);
verify(interaction).execute(interactionSpec, inputOutputRecord, inputOutputRecord);
verify(interaction).close();
verify(connection).close();
}
示例6: testTemplateExecuteInputOutput
import javax.resource.cci.ConnectionFactory; //导入依赖的package包/类
@Test
public void testTemplateExecuteInputOutput() throws ResourceException {
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
Connection connection = mock(Connection.class);
Interaction interaction = mock(Interaction.class);
Record inputRecord = mock(Record.class);
Record outputRecord = mock(Record.class);
InteractionSpec interactionSpec = mock(InteractionSpec.class);
given(connectionFactory.getConnection()).willReturn(connection);
given(connection.createInteraction()).willReturn(interaction);
given(interaction.execute(interactionSpec, inputRecord, outputRecord)).willReturn(true);
CciTemplate ct = new CciTemplate(connectionFactory);
ct.execute(interactionSpec, inputRecord, outputRecord);
verify(interaction).execute(interactionSpec, inputRecord, outputRecord);
verify(interaction).close();
verify(connection).close();
}
示例7: testTemplateExecuteInputFalse
import javax.resource.cci.ConnectionFactory; //导入依赖的package包/类
@Test
public void testTemplateExecuteInputFalse() throws ResourceException {
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
Connection connection = mock(Connection.class);
Interaction interaction = mock(Interaction.class);
Record inputRecord = mock(Record.class);
Record outputRecord = mock(Record.class);
InteractionSpec interactionSpec = mock(InteractionSpec.class);
given(connectionFactory.getConnection()).willReturn(connection);
given(connection.createInteraction()).willReturn(interaction);
given(interaction.execute(interactionSpec, inputRecord)).willReturn(outputRecord);
CciTemplate ct = new CciTemplate(connectionFactory);
ct.execute(interactionSpec, inputRecord);
verify(interaction).execute(interactionSpec, inputRecord);
verify(interaction).close();
verify(connection).close();
}
示例8: testTemplateExecuteInputExtractorFalse
import javax.resource.cci.ConnectionFactory; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void testTemplateExecuteInputExtractorFalse()
throws ResourceException, SQLException {
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
Connection connection = mock(Connection.class);
Interaction interaction = mock(Interaction.class);
RecordExtractor<Object> extractor = mock(RecordExtractor.class);
Record inputRecord = mock(Record.class);
Record outputRecord = mock(Record.class);
InteractionSpec interactionSpec = mock(InteractionSpec.class);
given(connectionFactory.getConnection()).willReturn(connection);
given(connection.createInteraction()).willReturn(interaction);
given(interaction.execute(interactionSpec, inputRecord)).willReturn(outputRecord);
given(extractor.extractData(outputRecord)).willReturn(new Object());
CciTemplate ct = new CciTemplate(connectionFactory);
ct.execute(interactionSpec, inputRecord, extractor);
verify(extractor).extractData(outputRecord);
verify(interaction).close();
verify(connection).close();
}
示例9: testTemplateExecuteInputOutputConnectionSpec
import javax.resource.cci.ConnectionFactory; //导入依赖的package包/类
@Test
public void testTemplateExecuteInputOutputConnectionSpec() throws ResourceException {
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
ConnectionSpec connectionSpec = mock(ConnectionSpec.class);
Connection connection = mock(Connection.class);
Interaction interaction = mock(Interaction.class);
Record inputRecord = mock(Record.class);
Record outputRecord = mock(Record.class);
InteractionSpec interactionSpec = mock(InteractionSpec.class);
given(connectionFactory.getConnection(connectionSpec)).willReturn(connection);
given(connection.createInteraction()).willReturn(interaction);
given(interaction.execute(interactionSpec, inputRecord, outputRecord)).willReturn(true);
ConnectionSpecConnectionFactoryAdapter adapter = new ConnectionSpecConnectionFactoryAdapter();
adapter.setTargetConnectionFactory(connectionFactory);
adapter.setConnectionSpec(connectionSpec);
CciTemplate ct = new CciTemplate(adapter);
ct.execute(interactionSpec, inputRecord, outputRecord);
verify(interaction).execute(interactionSpec, inputRecord, outputRecord);
verify(interaction).close();
verify(connection).close();
}
示例10: testTemplateExecuteConnectionCallback
import javax.resource.cci.ConnectionFactory; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void testTemplateExecuteConnectionCallback()
throws ResourceException, SQLException {
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
Connection connection = mock(Connection.class);
ConnectionCallback<Object> connectionCallback = mock(ConnectionCallback.class);
given(connectionFactory.getConnection()).willReturn(connection);
given(connectionCallback.doInConnection(connection, connectionFactory)).willReturn(new Object());
CciTemplate ct = new CciTemplate(connectionFactory);
ct.execute(connectionCallback);
verify(connectionCallback).doInConnection(connection, connectionFactory);
verify(connection).close();
}
示例11: testTemplateExecuteInteractionCallback
import javax.resource.cci.ConnectionFactory; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void testTemplateExecuteInteractionCallback()
throws ResourceException, SQLException {
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
Connection connection = mock(Connection.class);
Interaction interaction = mock(Interaction.class);
InteractionCallback<Object> interactionCallback = mock(InteractionCallback.class);
given(connectionFactory.getConnection()).willReturn(connection);
given(connection.createInteraction()).willReturn(interaction);
given(interactionCallback.doInInteraction(interaction,connectionFactory)).willReturn(new Object());
CciTemplate ct = new CciTemplate(connectionFactory);
ct.execute(interactionCallback);
verify(interactionCallback).doInInteraction(interaction,connectionFactory);
verify(interaction).close();
verify(connection).close();
}
示例12: testTemplateExecuteInputTrueTrueWithCreator
import javax.resource.cci.ConnectionFactory; //导入依赖的package包/类
@Test
public void testTemplateExecuteInputTrueTrueWithCreator()
throws ResourceException {
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
Connection connection = mock(Connection.class);
Interaction interaction = mock(Interaction.class);
RecordCreator creator = mock(RecordCreator.class);
Record inputOutputRecord = mock(Record.class);
InteractionSpec interactionSpec = mock(InteractionSpec.class);
given(connectionFactory.getConnection()).willReturn(connection);
given(connection.createInteraction()).willReturn(interaction);
given(interaction.execute(interactionSpec, inputOutputRecord, inputOutputRecord)).willReturn(true);
CciTemplate ct = new CciTemplate(connectionFactory);
ct.setOutputRecordCreator(creator);
ct.execute(interactionSpec, inputOutputRecord, inputOutputRecord);
verify(interaction).execute(interactionSpec, inputOutputRecord, inputOutputRecord);
verify(interaction).close();
verify(connection).close();
}
示例13: testTemplateExecuteInputTrueTrue
import javax.resource.cci.ConnectionFactory; //导入依赖的package包/类
@Test
public void testTemplateExecuteInputTrueTrue() throws ResourceException {
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
Connection connection = mock(Connection.class);
Interaction interaction = mock(Interaction.class);
Record inputOutputRecord = mock(Record.class);
InteractionSpec interactionSpec = mock(InteractionSpec.class);
given(connectionFactory.getConnection()).willReturn(connection);
given(connection.createInteraction()).willReturn(interaction);
given(interaction.execute(interactionSpec, inputOutputRecord, inputOutputRecord)).willReturn(true);
CciTemplate ct = new CciTemplate(connectionFactory);
ct.execute(interactionSpec, inputOutputRecord, inputOutputRecord);
verify(interaction).execute(interactionSpec, inputOutputRecord, inputOutputRecord);
verify(interaction).close();
verify(connection).close();
}
示例14: testTemplateExecuteInputFalseTrue
import javax.resource.cci.ConnectionFactory; //导入依赖的package包/类
@Test
public void testTemplateExecuteInputFalseTrue() throws ResourceException {
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
Connection connection = mock(Connection.class);
Interaction interaction = mock(Interaction.class);
Record inputOutputRecord = mock(Record.class);
InteractionSpec interactionSpec = mock(InteractionSpec.class);
given(connectionFactory.getConnection()).willReturn(connection);
given(connection.createInteraction()).willReturn(interaction);
given(interaction.execute(interactionSpec, inputOutputRecord)).willReturn(null);
CciTemplate ct = new CciTemplate(connectionFactory);
Record tmpOutputRecord = ct.execute(interactionSpec,
inputOutputRecord);
assertNull(tmpOutputRecord);
verify(interaction).execute(interactionSpec, inputOutputRecord);
verify(interaction).close();
verify(connection).close();
}
示例15: getConnection
import javax.resource.cci.ConnectionFactory; //导入依赖的package包/类
/**
* Return a connection object from the given connection factory.
*
* The default implementation assumes a JCA {@link ConnectionFactory}. Subclasses should override, if they use
* another type of connection factory.
*
* @deprecated
* @see #getConnection(Object, ExecutionContext)
* @param factory
* @return a connection
* @throws TranslatorException
*/
@Deprecated
@SuppressWarnings("unchecked")
public C getConnection(F factory) throws TranslatorException {
if (factory == null) {
return null;
}
if (factory instanceof ConnectionFactory) {
try {
return (C) ((ConnectionFactory)factory).getConnection();
} catch (ResourceException e) {
throw new TranslatorException(DataPlugin.Event.TEIID60000, e);
}
}
throw new AssertionError(factory.getClass().getName() + " is was not a ConnectionFactory implementation"); //$NON-NLS-1$
}