package org.springframework.jca.cci.connection;
import javax.naming.NamingException;
import javax.naming.Reference;
import javax.resource.ResourceException;
import javax.resource.cci.Connection;
import javax.resource.cci.ConnectionFactory;
import javax.resource.cci.ConnectionSpec;
import javax.resource.cci.RecordFactory;
import javax.resource.cci.ResourceAdapterMetaData;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
@SuppressWarnings("serial")
public class DelegatingConnectionFactory implements ConnectionFactory, InitializingBean {
@Nullable
private ConnectionFactory targetConnectionFactory;
public void setTargetConnectionFactory(@Nullable ConnectionFactory targetConnectionFactory) {
this.targetConnectionFactory = targetConnectionFactory;
}
@Nullable
public ConnectionFactory getTargetConnectionFactory() {
return this.targetConnectionFactory;
}
protected ConnectionFactory obtainTargetConnectionFactory() {
ConnectionFactory connectionFactory = getTargetConnectionFactory();
Assert.state(connectionFactory != null, "No 'targetConnectionFactory' set");
return connectionFactory;
}
@Override
public void afterPropertiesSet() {
if (getTargetConnectionFactory() == null) {
throw new IllegalArgumentException("Property 'targetConnectionFactory' is required");
}
}
@Override
public Connection getConnection() throws ResourceException {
return obtainTargetConnectionFactory().getConnection();
}
@Override
public Connection getConnection(ConnectionSpec connectionSpec) throws ResourceException {
return obtainTargetConnectionFactory().getConnection(connectionSpec);
}
@Override
public RecordFactory getRecordFactory() throws ResourceException {
return obtainTargetConnectionFactory().getRecordFactory();
}
@Override
public ResourceAdapterMetaData getMetaData() throws ResourceException {
return obtainTargetConnectionFactory().getMetaData();
}
@Override
public Reference getReference() throws NamingException {
return obtainTargetConnectionFactory().getReference();
}
@Override
public void setReference(Reference reference) {
obtainTargetConnectionFactory().setReference(reference);
}
}