javax.resource.cci.ConnectionSpec Java Examples

The following examples show how to use javax.resource.cci.ConnectionSpec. 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: CciTemplateTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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();
}
 
Example #2
Source File: CciTemplateTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@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();
}
 
Example #3
Source File: CciTemplateTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@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();
}
 
Example #4
Source File: SapBapiJcaAdapterConnectionSpecFactory.java    From hibersap with Apache License 2.0 6 votes vote down vote up
public ConnectionSpec createConnectionSpec(final Credentials credentials) {
    Class<?> connSpecClass;
    try {
        connSpecClass = getConnectionSpecClass(CONNECTION_SPEC_IMPL_CLASS_NAME);

        Object[] arguments = new Object[]{
                credentials.getUser(),
                credentials.getPassword(),
                credentials.getLanguage()};
        Class<?>[] parameterTypes = new Class<?>[]{String.class, String.class, String.class};

        return newConnectionSpecInstance(connSpecClass, parameterTypes, arguments);
    } catch (IllegalArgumentException | ClassNotFoundException e) {
        throw new InternalHiberSapException(e.getMessage(), e);
    }
}
 
Example #5
Source File: CuckooJcaAdapterConnectionSpecFactory.java    From hibersap with Apache License 2.0 6 votes vote down vote up
public ConnectionSpec createConnectionSpec(Credentials credentials) {
        try {
            Object[] arguments = {
                    credentials.getUser(),
                    credentials.getPassword()
//                    ,
//                    credentials.getLanguage(),
//                    credentials.getClient(),
//                    credentials.getAliasUser(),
//                    credentials.getSsoTicket(),
//                    credentials.getX509Certificate()
            };

            Class<?>[] parameterTypes = new Class<?>[arguments.length];
            Arrays.fill(parameterTypes, String.class);

            Class<?> connSpecClass = getConnectionSpecClass(CONNECTION_SPEC_IMPL_CLASS_NAME);
            return newConnectionSpecInstance(connSpecClass, parameterTypes, arguments);
        } catch (IllegalArgumentException | ClassNotFoundException e) {
            throw new InternalHiberSapException(e.getMessage(), e);
        }
    }
 
Example #6
Source File: AbstractConnectionSpecFactory.java    From hibersap with Apache License 2.0 5 votes vote down vote up
/**
 * Looks up and returns the specified class. First, it will try to get the class from the
 * context class loader, if not found, it will try to get it from the current class loader.
 *
 * @param connectionSpecClass The fully qualified class name of the ConnectionSpec
 * implementation.
 * @return The Class object of the ConnectionSpec implementation
 * @throws ClassNotFoundException - if the class could not be found.
 * @throws IllegalArgumentException - if the class does not implement
 * javax.resource.cci.ConnectionSpec.
 */
protected Class<? extends ConnectionSpec> getConnectionSpecClass(final String connectionSpecClass)
        throws ClassNotFoundException {
    Class<?> connSpecClass = ReflectionHelper.getClassForName(connectionSpecClass);

    if (!ConnectionSpec.class.isAssignableFrom(connSpecClass)) {
        throw new IllegalArgumentException(
                connSpecClass.getName() + " does not implement " + ConnectionSpec.class);
    }

    //noinspection unchecked
    return (Class<? extends ConnectionSpec>) connSpecClass;
}
 
Example #7
Source File: ConnectionSpecConnectionFactoryAdapter.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Determine whether there is currently a thread-bound ConnectionSpec,
 * using it if available, falling back to the statically specified
 * "connectionSpec" property else.
 * @see #doGetConnection
 */
@Override
public final Connection getConnection() throws ResourceException {
	ConnectionSpec threadSpec = this.threadBoundSpec.get();
	if (threadSpec != null) {
		return doGetConnection(threadSpec);
	}
	else {
		return doGetConnection(this.connectionSpec);
	}
}
 
Example #8
Source File: ConnectionSpecConnectionFactoryAdapter.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Determine whether there is currently a thread-bound ConnectionSpec,
 * using it if available, falling back to the statically specified
 * "connectionSpec" property else.
 * @see #doGetConnection
 */
@Override
public final Connection getConnection() throws ResourceException {
	ConnectionSpec threadSpec = this.threadBoundSpec.get();
	if (threadSpec != null) {
		return doGetConnection(threadSpec);
	}
	else {
		return doGetConnection(this.connectionSpec);
	}
}
 
Example #9
Source File: ConnectionSpecConnectionFactoryAdapter.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * This implementation delegates to the {@code getConnection(ConnectionSpec)}
 * method of the target ConnectionFactory, passing in the specified user credentials.
 * If the specified username is empty, it will simply delegate to the standard
 * {@code getConnection()} method of the target ConnectionFactory.
 * @param spec the ConnectionSpec to apply
 * @return the Connection
 * @see javax.resource.cci.ConnectionFactory#getConnection(javax.resource.cci.ConnectionSpec)
 * @see javax.resource.cci.ConnectionFactory#getConnection()
 */
protected Connection doGetConnection(ConnectionSpec spec) throws ResourceException {
	if (getTargetConnectionFactory() == null) {
		throw new IllegalStateException("targetConnectionFactory is required");
	}
	if (spec != null) {
		return getTargetConnectionFactory().getConnection(spec);
	}
	else {
		return getTargetConnectionFactory().getConnection();
	}
}
 
Example #10
Source File: CciTemplate.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Construct a new CciTemplate, given a ConnectionFactory to obtain Connections from.
 * Note: This will trigger eager initialization of the exception translator.
 * @param connectionFactory the JCA ConnectionFactory to obtain Connections from
 * @param connectionSpec the CCI ConnectionSpec to obtain Connections for
 * (may be {@code null})
 */
public CciTemplate(ConnectionFactory connectionFactory, @Nullable ConnectionSpec connectionSpec) {
	setConnectionFactory(connectionFactory);
	if (connectionSpec != null) {
		setConnectionSpec(connectionSpec);
	}
	afterPropertiesSet();
}
 
Example #11
Source File: CciTemplate.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Construct a new CciTemplate, given a ConnectionFactory to obtain Connections from.
 * Note: This will trigger eager initialization of the exception translator.
 * @param connectionFactory the JCA ConnectionFactory to obtain Connections from
 * @param connectionSpec the CCI ConnectionSpec to obtain Connections for
 * (may be {@code null})
 */
public CciTemplate(ConnectionFactory connectionFactory, @Nullable ConnectionSpec connectionSpec) {
	setConnectionFactory(connectionFactory);
	if (connectionSpec != null) {
		setConnectionSpec(connectionSpec);
	}
	afterPropertiesSet();
}
 
Example #12
Source File: ConnectionProvider.java    From hibersap with Apache License 2.0 5 votes vote down vote up
private Connection newConnection() {
    try {
        if (credentials == null) {
            return connectionFactory.getConnection();
        } else {
            ConnectionSpec connectionSpec = newConnectionSpecFactory(connectionSpecFactoryName)
                    .createConnectionSpec(credentials);
            return connectionFactory.getConnection(connectionSpec);
        }
    } catch (ResourceException e) {
        throw new HibersapException("Problem creating Connection", e);
    }
}
 
Example #13
Source File: ConnectionSpecConnectionFactoryAdapter.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Determine whether there is currently a thread-bound ConnectionSpec,
 * using it if available, falling back to the statically specified
 * "connectionSpec" property else.
 * @see #doGetConnection
 */
@Override
public final Connection getConnection() throws ResourceException {
	ConnectionSpec threadSpec = this.threadBoundSpec.get();
	if (threadSpec != null) {
		return doGetConnection(threadSpec);
	}
	else {
		return doGetConnection(this.connectionSpec);
	}
}
 
Example #14
Source File: ConnectionSpecConnectionFactoryAdapter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Determine whether there is currently a thread-bound ConnectionSpec,
 * using it if available, falling back to the statically specified
 * "connectionSpec" property else.
 * @see #doGetConnection
 */
@Override
public final Connection getConnection() throws ResourceException {
	ConnectionSpec threadSpec = this.threadBoundSpec.get();
	if (threadSpec != null) {
		return doGetConnection(threadSpec);
	}
	else {
		return doGetConnection(this.connectionSpec);
	}
}
 
Example #15
Source File: SingleConnectionFactory.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Connection getConnection(ConnectionSpec connectionSpec) throws ResourceException {
	throw new NotSupportedException(
			"SingleConnectionFactory does not support custom ConnectionSpec");
}
 
Example #16
Source File: CciTemplate.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Return the CCI ConnectionSpec used by this template, if any.
 */
public ConnectionSpec getConnectionSpec() {
	return this.connectionSpec;
}
 
Example #17
Source File: ConnectionFactoryUtils.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Obtain a Connection from the given ConnectionFactory. Translates ResourceExceptions
 * into the Spring hierarchy of unchecked generic data access exceptions, simplifying
 * calling code and making any exception that is thrown more meaningful.
 * <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).
 * @param cf the ConnectionFactory to obtain Connection from
 * @param spec the ConnectionSpec for the desired Connection (may be {@code null}).
 * Note: If this is specified, a new Connection will be obtained for every call,
 * without participating in a shared transactional Connection.
 * @return a CCI Connection from the given ConnectionFactory
 * @throws org.springframework.jca.cci.CannotGetCciConnectionException
 * if the attempt to get a Connection failed
 * @see #releaseConnection
 */
public static Connection getConnection(ConnectionFactory cf, ConnectionSpec spec)
		throws CannotGetCciConnectionException {
	try {
		if (spec != null) {
			Assert.notNull(cf, "No ConnectionFactory specified");
			return cf.getConnection(spec);
		}
		else {
			return doGetConnection(cf);
		}
	}
	catch (ResourceException ex) {
		throw new CannotGetCciConnectionException("Could not get CCI Connection", ex);
	}
}
 
Example #18
Source File: DelegatingConnectionFactory.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
public Connection getConnection(ConnectionSpec connectionSpec) throws ResourceException {
	return getTargetConnectionFactory().getConnection(connectionSpec);
}
 
Example #19
Source File: SingleConnectionFactory.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public Connection getConnection(ConnectionSpec connectionSpec) throws ResourceException {
	throw new NotSupportedException(
			"SingleConnectionFactory does not support custom ConnectionSpec");
}
 
Example #20
Source File: SingleConnectionFactory.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
public Connection getConnection(ConnectionSpec connectionSpec) throws ResourceException {
	throw new NotSupportedException(
			"SingleConnectionFactory does not support custom ConnectionSpec");
}
 
Example #21
Source File: ConnectionFactoryUtils.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
/**
 * Obtain a Connection from the given ConnectionFactory. Translates ResourceExceptions
 * into the Spring hierarchy of unchecked generic data access exceptions, simplifying
 * calling code and making any exception that is thrown more meaningful.
 * <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).
 * @param cf the ConnectionFactory to obtain Connection from
 * @param spec the ConnectionSpec for the desired Connection (may be {@code null}).
 * Note: If this is specified, a new Connection will be obtained for every call,
 * without participating in a shared transactional Connection.
 * @return a CCI Connection from the given ConnectionFactory
 * @throws org.springframework.jca.cci.CannotGetCciConnectionException
 * if the attempt to get a Connection failed
 * @see #releaseConnection
 */
public static Connection getConnection(ConnectionFactory cf, ConnectionSpec spec)
		throws CannotGetCciConnectionException {
	try {
		if (spec != null) {
			Assert.notNull(cf, "No ConnectionFactory specified");
			return cf.getConnection(spec);
		}
		else {
			return doGetConnection(cf);
		}
	}
	catch (ResourceException ex) {
		throw new CannotGetCciConnectionException("Could not get CCI Connection", ex);
	}
}
 
Example #22
Source File: CciTemplate.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
/**
 * Return the CCI ConnectionSpec used by this template, if any.
 */
public ConnectionSpec getConnectionSpec() {
	return this.connectionSpec;
}
 
Example #23
Source File: AbstractConnectionSpecFactory.java    From hibersap with Apache License 2.0 4 votes vote down vote up
private ConnectionSpec throwInternalHibersapException(final Class<?> connectionSpecClass,
                                                      final Class<?>[] constructorParameterTypes, Exception e,
                                                      final String msg) {
    throw new InternalHiberSapException(msg + getSignature(connectionSpecClass, constructorParameterTypes), e);
}
 
Example #24
Source File: AbstractConnectionSpecFactoryTest.java    From hibersap with Apache License 2.0 4 votes vote down vote up
public ConnectionSpec createConnectionSpec(Credentials credentials)
        throws InternalHiberSapException {
    // implementation not tested here
    return null;
}
 
Example #25
Source File: ConnectorProxyNoNoArgConstructorTest.java    From tomee with Apache License 2.0 4 votes vote down vote up
@Override
public Connection getConnection(ConnectionSpec properties) throws ResourceException {
    return getConnection();
}
 
Example #26
Source File: ConnectorProxyTest.java    From tomee with Apache License 2.0 4 votes vote down vote up
@Override
public Connection getConnection(ConnectionSpec properties) throws ResourceException {
    return getConnection();
}
 
Example #27
Source File: HelloWorldConnectionFactoryImpl.java    From ci.maven with Apache License 2.0 4 votes vote down vote up
/**
 * @see ConnectionFactory#getConnection(ConnectionSpec)
 */
public Connection getConnection(ConnectionSpec connectionSpec) throws ResourceException {

	return getConnection();
}
 
Example #28
Source File: ConnectionFactoryUtils.java    From java-technology-stack with MIT License 4 votes vote down vote up
/**
 * Obtain a Connection from the given ConnectionFactory. Translates ResourceExceptions
 * into the Spring hierarchy of unchecked generic data access exceptions, simplifying
 * calling code and making any exception that is thrown more meaningful.
 * <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).
 * @param cf the ConnectionFactory to obtain Connection from
 * @param spec the ConnectionSpec for the desired Connection (may be {@code null}).
 * Note: If this is specified, a new Connection will be obtained for every call,
 * without participating in a shared transactional Connection.
 * @return a CCI Connection from the given ConnectionFactory
 * @throws org.springframework.jca.cci.CannotGetCciConnectionException
 * if the attempt to get a Connection failed
 * @see #releaseConnection
 */
public static Connection getConnection(ConnectionFactory cf, @Nullable ConnectionSpec spec)
		throws CannotGetCciConnectionException {
	try {
		if (spec != null) {
			Assert.notNull(cf, "No ConnectionFactory specified");
			return cf.getConnection(spec);
		}
		else {
			return doGetConnection(cf);
		}
	}
	catch (ResourceException ex) {
		throw new CannotGetCciConnectionException("Could not get CCI Connection", ex);
	}
}
 
Example #29
Source File: DelegatingConnectionFactory.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public Connection getConnection(ConnectionSpec connectionSpec) throws ResourceException {
	return obtainTargetConnectionFactory().getConnection(connectionSpec);
}
 
Example #30
Source File: ConnectionFactoryUtils.java    From spring-analysis-note with MIT License 4 votes vote down vote up
/**
 * Obtain a Connection from the given ConnectionFactory. Translates ResourceExceptions
 * into the Spring hierarchy of unchecked generic data access exceptions, simplifying
 * calling code and making any exception that is thrown more meaningful.
 * <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).
 * @param cf the ConnectionFactory to obtain Connection from
 * @param spec the ConnectionSpec for the desired Connection (may be {@code null}).
 * Note: If this is specified, a new Connection will be obtained for every call,
 * without participating in a shared transactional Connection.
 * @return a CCI Connection from the given ConnectionFactory
 * @throws org.springframework.jca.cci.CannotGetCciConnectionException
 * if the attempt to get a Connection failed
 * @see #releaseConnection
 */
public static Connection getConnection(ConnectionFactory cf, @Nullable ConnectionSpec spec)
		throws CannotGetCciConnectionException {
	try {
		if (spec != null) {
			Assert.notNull(cf, "No ConnectionFactory specified");
			return cf.getConnection(spec);
		}
		else {
			return doGetConnection(cf);
		}
	}
	catch (ResourceException ex) {
		throw new CannotGetCciConnectionException("Could not get CCI Connection", ex);
	}
}