javax.resource.spi.ConnectionManager Java Examples

The following examples show how to use javax.resource.spi.ConnectionManager. 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: ActiveMQRASessionFactoryImpl.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
/**
 * Constructor
 *
 * @param mcf  The managed connection factory
 * @param cm   The connection manager
 * @param type The connection type
 */
public ActiveMQRASessionFactoryImpl(final ActiveMQRAManagedConnectionFactory mcf,
                                    final ConnectionManager cm,
                                    final TransactionManager tm,
                                    final int type) {
   this.mcf = mcf;

   this.tm = tm;

   if (cm == null) {
      this.cm = new ActiveMQRAConnectionManager();
   } else {
      this.cm = cm;
   }

   this.type = type;

   if (ActiveMQRALogger.LOGGER.isTraceEnabled()) {
      ActiveMQRALogger.LOGGER.trace("constructor(" + mcf + ", " + cm + ", " + type);
   }
}
 
Example #2
Source File: LazyManagedConnection.java    From ironjacamar with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Default constructor
 * @param localTransaction Support local transaction
 * @param xaTransaction Support XA transaction
 * @param mcf The managed connection factory
 * @param cm The connection manager
 */
public LazyManagedConnection(boolean localTransaction, boolean xaTransaction,
                             LazyManagedConnectionFactory mcf, ConnectionManager cm)
{
   this.localTransaction = localTransaction;
   this.xaTransaction = xaTransaction;
   this.enlisted = false;
   this.mcf = mcf;
   this.cm = cm;
   this.logwriter = null;
   this.listeners = Collections.synchronizedList(new ArrayList<ConnectionEventListener>(1));
   this.connection = null;
   this.lazyLocalTransaction = null;
   this.lazyXAResource = null;

   if (localTransaction)
      this.lazyLocalTransaction = new LazyLocalTransaction(this);

   if (xaTransaction)
      this.lazyXAResource = new LazyXAResource(this);
}
 
Example #3
Source File: ActiveMQRAConnectionFactoryImpl.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
/**
 * Constructor
 *
 * @param mcf The managed connection factory
 * @param cm  The connection manager
 */
public ActiveMQRAConnectionFactoryImpl(final ActiveMQRAManagedConnectionFactory mcf, final ConnectionManager cm) {
   if (ActiveMQRALogger.LOGGER.isTraceEnabled()) {
      ActiveMQRALogger.LOGGER.trace("constructor(" + mcf + ", " + cm + ")");
   }

   this.mcf = mcf;

   if (cm == null) {
      // This is standalone usage, no appserver
      this.cm = new ActiveMQRAConnectionManager();
      if (ActiveMQRALogger.LOGGER.isTraceEnabled()) {
         ActiveMQRALogger.LOGGER.trace("Created new ConnectionManager=" + this.cm);
      }
   } else {
      this.cm = cm;
   }

   if (ActiveMQRALogger.LOGGER.isTraceEnabled()) {
      ActiveMQRALogger.LOGGER.trace("Using ManagedConnectionFactory=" + mcf + ", ConnectionManager=" + cm);
   }
}
 
Example #4
Source File: ActiveMQRAManagedConnectionFactory.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a Connection Factory instance
 *
 * @param cxManager The connection manager
 * @return javax.resource.cci.ConnectionFactory instance
 * @throws ResourceException Thrown if a connection factory can't be created
 */
@Override
public Object createConnectionFactory(final ConnectionManager cxManager) throws ResourceException {
   if (ActiveMQRALogger.LOGGER.isTraceEnabled()) {
      ActiveMQRALogger.LOGGER.trace("createConnectionFactory(" + cxManager + ")");
   }

   cm = cxManager;

   ActiveMQRAConnectionFactory cf = new ActiveMQRAConnectionFactoryImpl(this, cm);

   if (ActiveMQRALogger.LOGGER.isTraceEnabled()) {
      ActiveMQRALogger.LOGGER.trace("Created connection factory: " + cf +
                                       ", using connection manager: " +
                                       cm);
   }
   return cf;
}
 
Example #5
Source File: HelloWorldConnectionFactoryImpl.java    From ironjacamar with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Default constructor
 * @param mcf ManagedConnectionFactory
 * @param cxManager ConnectionManager
 */
public HelloWorldConnectionFactoryImpl(HelloWorldManagedConnectionFactory mcf,
                                       ConnectionManager cxManager)
{
   this.mcf = mcf;
   this.connectionManager = cxManager;
}
 
Example #6
Source File: LocalConnectionFactoryBeanTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreatesManagedConnectionFactoryIfAConnectionManagerHasBeenConfigured() throws Exception {
	ManagedConnectionFactory managedConnectionFactory = mock(ManagedConnectionFactory.class);
	ConnectionManager connectionManager = mock(ConnectionManager.class);
	LocalConnectionFactoryBean factory = new LocalConnectionFactoryBean();
	factory.setManagedConnectionFactory(managedConnectionFactory);
	factory.setConnectionManager(connectionManager);
	factory.afterPropertiesSet();
	verify(managedConnectionFactory).createConnectionFactory(connectionManager);
}
 
Example #7
Source File: HelloWorldConnectionFactoryImpl.java    From ci.maven with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor for HelloWorldConnectionFactoryImpl
 */
public HelloWorldConnectionFactoryImpl(
	ManagedConnectionFactory mcf,
	ConnectionManager cm) {

	super();
	this.mcf = mcf;
	this.cm = cm;
}
 
Example #8
Source File: LocalConnectionFactoryBeanTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testCreatesManagedConnectionFactoryIfAConnectionManagerHasBeenConfigured() throws Exception {
	ManagedConnectionFactory managedConnectionFactory = mock(ManagedConnectionFactory.class);
	ConnectionManager connectionManager = mock(ConnectionManager.class);
	LocalConnectionFactoryBean factory = new LocalConnectionFactoryBean();
	factory.setManagedConnectionFactory(managedConnectionFactory);
	factory.setConnectionManager(connectionManager);
	factory.afterPropertiesSet();
	verify(managedConnectionFactory).createConnectionFactory(connectionManager);
}
 
Example #9
Source File: MiniContainer.java    From genericconnector with Apache License 2.0 5 votes vote down vote up
/** sets up the resource adapter and associated classes in the same way that the real container does it */
public MiniContainer(boolean handleRecoveryInternally, String minAgeOfTransactionBeforeRelevantForRecovery) throws ResourceException {
	adapter.start(null); //TODO parameters
	adapter.endpointActivation(null, null); //TODO parameters
	
	mtaf = new ManagedTransactionAssistanceFactory();
	if(handleRecoveryInternally){
		mtaf.setHandleRecoveryInternally("true");
		mtaf.setRecoveryStatePersistenceDirectory(System.getProperty("java.io.tmpdir"));
	}else{
		mtaf.setHandleRecoveryInternally("false");
	}
	mtaf.setMinAgeOfTransactionBeforeRelevantForRecovery(minAgeOfTransactionBeforeRelevantForRecovery);
	mtaf.setResourceAdapter(adapter);
	mtaf.setId("A");

	cm = new ConnectionManager() {
		private static final long serialVersionUID = 1L;
		@Override
		public Object allocateConnection(ManagedConnectionFactory arg0,
				ConnectionRequestInfo arg1) throws ResourceException {

			if(tx.get() == null) throw new IllegalStateException("please start a transaction before opening a connection");

			ManagedTransactionAssistance mta = (ManagedTransactionAssistance) mtaf.createManagedConnection(null, null);
			
			XAResource xa = mta.getXAResource();
			tx.get().xaResources.add(xa);
			try {
				xa.start(tx.get().xid, 0);
			} catch (XAException e) {
				e.printStackTrace();
				throw new ResourceException(e);
			}
			
			return new TransactionAssistantImpl(mta);
		}
	};
}
 
Example #10
Source File: ManagedConnectionFactoryImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
public Object createConnectionFactory(ConnectionManager connMgr) throws ResourceException {
    LOG.info("connManager=" + connMgr);
    if (connMgr == null) {
        throw new ResourceAdapterInternalException(
                        new Message("NON_MANAGED_CONNECTION_IS_NOT_SUPPORTED", BUNDLE).toString());
    }
    init(connMgr.getClass().getClassLoader());
    LOG.fine("Setting AppServer classloader in jcaBusFactory. " + connMgr.getClass().getClassLoader());
    return new ConnectionFactoryImpl(this, connMgr);
}
 
Example #11
Source File: ManagedConnectionFactoryImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
public Object createConnectionFactory(ConnectionManager connMgr)
    throws ResourceException {
    if (LOG.isLoggable(Level.FINER)) {
        LOG.finer("Create connection factory by app server connMgr " + connMgr);
    }
    return new ConnectionFactoryImpl(this,
            connMgr == null ? defaultConnectionManager : connMgr);
}
 
Example #12
Source File: ConnectionFactoryImplTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    mockConnectionFactory = EasyMock.createMock(ManagedConnectionFactory.class);
    mockConnectionManager = EasyMock.createMock(ConnectionManager.class);

    param = new CXFConnectionRequestInfo();
    param.setInterface(Runnable.class);

    cf = new ConnectionFactoryImpl(mockConnectionFactory, mockConnectionManager);
}
 
Example #13
Source File: LocalConnectionFactoryBeanTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testCreatesManagedConnectionFactoryIfAConnectionManagerHasBeenConfigured() throws Exception {
	ManagedConnectionFactory managedConnectionFactory = mock(ManagedConnectionFactory.class);
	ConnectionManager connectionManager = mock(ConnectionManager.class);
	LocalConnectionFactoryBean factory = new LocalConnectionFactoryBean();
	factory.setManagedConnectionFactory(managedConnectionFactory);
	factory.setConnectionManager(connectionManager);
	factory.afterPropertiesSet();
	verify(managedConnectionFactory).createConnectionFactory(connectionManager);
}
 
Example #14
Source File: HelloWorldManagedConnection.java    From ironjacamar with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Constructor
 * @param cm The connection manager
 * @param mcf The managed connection factory
 */
public HelloWorldManagedConnection(ConnectionManager cm,
                                   HelloWorldManagedConnectionFactory mcf)
{
   this.cm = cm;
   this.mcf = mcf;
   this.logWriter = null;
   this.listeners = Collections.synchronizedList(new ArrayList<ConnectionEventListener>(1));
   this.connections = new HashSet<HelloWorldConnectionImpl>();
}
 
Example #15
Source File: HelloWorldConnectionImpl.java    From ironjacamar with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Default constructor
 * @param mc HelloWorldManagedConnection
 * @param mcf HelloWorldManagedConnectionFactory
 * @param cm The connection manager
 * @param cri The connection request info
 */
public HelloWorldConnectionImpl(HelloWorldManagedConnection mc,
                                HelloWorldManagedConnectionFactory mcf,
                                ConnectionManager cm,
                                ConnectionRequestInfo cri)
{
   this.mc = mc;
   this.mcf = mcf;
   this.cm = cm;
   this.cri = cri;
}
 
Example #16
Source File: HelloWorldConnectionFactoryImpl.java    From ironjacamar with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Default constructor
 * @param mcf ManagedConnectionFactory
 * @param cxManager ConnectionManager
 */
public HelloWorldConnectionFactoryImpl(HelloWorldManagedConnectionFactory mcf,
                                       ConnectionManager cxManager)
{
   this.mcf = mcf;
   this.connectionManager = cxManager;
}
 
Example #17
Source File: HelloWorldConnectionFactoryImpl.java    From ironjacamar with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Default constructor
 * @param mcf ManagedConnectionFactory
 * @param cxManager ConnectionManager
 */
public HelloWorldConnectionFactoryImpl(HelloWorldManagedConnectionFactory mcf,
                                       ConnectionManager cxManager)
{
   this.mcf = mcf;
   this.connectionManager = cxManager;
}
 
Example #18
Source File: LazyConnectionImpl.java    From ironjacamar with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Close managed connection
 * @return boolean
 */
public boolean closeManagedConnection()
{
   log.tracef("%s: closeManagedConnection()", this);

   if (mc != null)
   {
      try
      {
         if (cm instanceof org.ironjacamar.core.api.connectionmanager.ConnectionManager)
         {
            org.ironjacamar.core.api.connectionmanager.ConnectionManager ijCm =
               (org.ironjacamar.core.api.connectionmanager.ConnectionManager)cm;

            boolean result = ijCm.dissociateManagedConnection(this, mc, mcf);
            log.trace("Result=" + result);

            mc = null;
            return true;
         }
      }
      catch (Throwable t)
      {
         log.error("CloseManagedConnection", t);
      }
   }

   return false;
}
 
Example #19
Source File: LazyConnectionImpl.java    From ironjacamar with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Default constructor
 * @param mc LazyManagedConnection
 * @param mcf LazyManagedConnectionFactory
 * @param cm ConnectionManager
 * @param cri ConnectionRequestInfo
 */
public LazyConnectionImpl(LazyManagedConnection mc, LazyManagedConnectionFactory mcf,
                          ConnectionManager cm, ConnectionRequestInfo cri)
{
   this.mc = mc;
   this.mcf = mcf;
   this.cm = cm;
   this.cri = cri;
}
 
Example #20
Source File: LazyManagedConnectionFactory.java    From ironjacamar with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates a Connection Factory instance. 
 *
 * @param cxManager ConnectionManager to be associated with created EIS connection factory instance
 * @return EIS-specific Connection Factory instance or javax.resource.cci.ConnectionFactory instance
 * @throws ResourceException Generic exception
 */
public Object createConnectionFactory(ConnectionManager cxManager) throws ResourceException
{
   log.trace("createConnectionFactory()");

   this.cm = cxManager;

   return new LazyConnectionFactoryImpl(this, cxManager);
}
 
Example #21
Source File: ManagedConnectionFactoryImplTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateConnectionFactoryCM() throws Exception {
    ManagedConnectionFactoryImplTester mcit = new ManagedConnectionFactoryImplTester();
    ConnectionManager connManager = EasyMock.createMock(ConnectionManager.class);
    assertTrue("We get a CF back",
               mcit.createConnectionFactory(connManager) instanceof CXFConnectionFactory);
    assertEquals("init was called once", 1, mcit.initCalledCount);
}
 
Example #22
Source File: SampleConnectionFactoryImpl.java    From tomee with Apache License 2.0 4 votes vote down vote up
public SampleConnectionFactoryImpl(SampleManagedConnectionFactory mcf, ConnectionManager cxManager) {
    this.mcf = mcf;
    this.connectionManager = cxManager;
}
 
Example #23
Source File: SampleManagedConnectionFactory.java    From tomee with Apache License 2.0 4 votes vote down vote up
public Object createConnectionFactory(ConnectionManager cxManager) throws ResourceException {
    log.finest("createConnectionFactory()");
    return new SampleConnectionFactoryImpl(this, cxManager);
}
 
Example #24
Source File: SampleConnectionFactoryImpl.java    From tomee with Apache License 2.0 4 votes vote down vote up
public SampleConnectionFactoryImpl(SampleManagedConnectionFactory mcf, ConnectionManager cxManager) {
    this.mcf = mcf;
    this.connectionManager = cxManager;
}
 
Example #25
Source File: ConnectorProxyTest.java    From tomee with Apache License 2.0 4 votes vote down vote up
@Override
public Object createConnectionFactory(final ConnectionManager cxManager) throws ResourceException {
    return new MyCf(this, cxManager);
}
 
Example #26
Source File: AnnotationDeployerTest.java    From tomee with Apache License 2.0 4 votes vote down vote up
public Object createConnectionFactory(final ConnectionManager connectionManager) throws ResourceException {
    return null;
}
 
Example #27
Source File: HelloWorldManagedConnectionFactoryImpl.java    From ci.maven with Apache License 2.0 4 votes vote down vote up
/**
 * @see ManagedConnectionFactory#createConnectionFactory(ConnectionManager)
 */
public Object createConnectionFactory(ConnectionManager cm)
	throws ResourceException {

	return new HelloWorldConnectionFactoryImpl(this, cm);
}
 
Example #28
Source File: JcaExecutorServiceManagedConnectionFactory.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public Object createConnectionFactory(ConnectionManager cxManager) throws ResourceException {
  return new JcaExecutorServiceConnectionFactoryImpl(this, cxManager);
}
 
Example #29
Source File: JcaExecutorServiceConnectionFactoryImpl.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public JcaExecutorServiceConnectionFactoryImpl(JcaExecutorServiceManagedConnectionFactory mcf, ConnectionManager cxManager) {
  this.mcf = mcf;
  this.connectionManager = cxManager;
}
 
Example #30
Source File: SampleConnectionFactoryImpl.java    From tomee with Apache License 2.0 4 votes vote down vote up
public SampleConnectionFactoryImpl(SampleManagedConnectionFactory mcf, ConnectionManager cxManager) {
    this.mcf = mcf;
    this.connectionManager = cxManager;
}