javax.resource.spi.ManagedConnectionFactory Java Examples

The following examples show how to use javax.resource.spi.ManagedConnectionFactory. 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: Main.java    From ironjacamar with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * hasMcfTransactionSupport
 *
 * @param out output stream
 * @param error output stream
 * @param classname classname
 * @param cl classloader
 */
private static void hasMcfTransactionSupport(PrintStream out, PrintStream error, String classname, URLClassLoader cl)
{
   try
   {
      out.print("  TransactionSupport: ");
      
      Class<?> mcfClz = Class.forName(classname, true, cl);
      ManagedConnectionFactory mcf = (ManagedConnectionFactory)mcfClz.newInstance();

      if (hasInterface(mcf.getClass(),  "javax.resource.spi.TransactionSupport"))
      {
         out.println("Yes");
      } 
      else
      {
         out.println("No");
      }
   }
   catch (Throwable t)
   {
      // Nothing we can do
      t.printStackTrace(error);
      out.println("Unknown");
   }
}
 
Example #2
Source File: MCFConfigProperties.java    From ironjacamar with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Validate
 * @param v The validate object
 * @param rb The resource bundle
 * @return The list of failures found; <code>null</code> if none
 */
@SuppressWarnings("unchecked")
public List<Failure> validate(Validate v, ResourceBundle rb)
{
   if (v != null &&
       Key.MANAGED_CONNECTION_FACTORY == v.getKey() &&
       v.getClazz() != null &&
       ManagedConnectionFactory.class.isAssignableFrom(v.getClazz()))
   {
      ValidateClass vo = (ValidateClass)v;
      if (vo.getConfigProperties() != null && !vo.getConfigProperties().isEmpty())
      {
         return ConfigPropertiesHelper.validateConfigPropertiesType(vo, SECTION,
            rb.getString("mcf.MCFConfigProperties"));
      }
   }

   return null;
}
 
Example #3
Source File: AbstractConnectionManager.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Get a subject
 * @return The subject
 */
private Subject getSubject()
{
   Subject subject = null;

   if (subjectFactory != null && securityDomain != null)
   {
      subject = SecurityActions.createSubject(subjectFactory, securityDomain);

      Set<PasswordCredential> credentials = SecurityActions.getPasswordCredentials(subject);
      if (credentials != null && credentials.size() > 0)
      {
         ManagedConnectionFactory pcMcf = getManagedConnectionFactory();
         for (PasswordCredential pc : credentials)
         {
            pc.setManagedConnectionFactory(pcMcf);
         }
      }
   }

   log.tracef("Subject: %s", subject);

   return subject;
}
 
Example #4
Source File: AbstractConnectionManager.java    From ironjacamar with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Object allocateConnection(ManagedConnectionFactory mcf, ConnectionRequestInfo cri) throws ResourceException
{
   if (shutdown.get())
      throw new ResourceException();
   Credential credential;
   if (subjectFactory == null || cmConfiguration.getSecurityDomain() == null)
   {
      credential = new Credential(null, cri);
   }
   else
   {
      credential = new Credential(SecurityActions.createSubject(subjectFactory,
                                                                cmConfiguration.getSecurityDomain(),
                                                                mcf),
                                  cri);
   }
   org.ironjacamar.core.connectionmanager.listener.ConnectionListener cl = getConnectionListener(credential);
   Object connection = cl.getConnection();

   if (ccm != null)
      ccm.registerConnection(this, cl, connection);

   return connection;
}
 
Example #5
Source File: ManagedPoolCacheImpl.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor initializes the ConnectionPoolCacheImpl properties.
 */
public ManagedPoolCacheImpl(ManagedConnectionFactory connFac,
    Subject subject, ConnectionRequestInfo connReq,
    javax.resource.spi.ConnectionEventListener eventListner,
    ConfiguredDataSourceProperties configs) throws PoolException {
  super(eventListner, configs);
  connFactory = connFac;
  sub = subject;
  connReqInfo = connReq;
  initializePool();
}
 
Example #6
Source File: AbstractTransactionalConnectionManager.java    From ironjacamar with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Constructor
 * @param mcf The managed connection factory
 * @param ccm The cached connection manager
 * @param cmc The connection manager configuration
 * @param ti The transaction integration
 */
public AbstractTransactionalConnectionManager(ManagedConnectionFactory mcf,
                                              CachedConnectionManager ccm,
                                              ConnectionManagerConfiguration cmc,
                                              TransactionIntegration ti)
{
   super(mcf, ccm, cmc);
   this.ti = ti;
}
 
Example #7
Source File: LocalConnectionFactoryBeanTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testCreatesVanillaConnectionFactoryIfNoConnectionManagerHasBeenConfigured() throws Exception {
	final Object CONNECTION_FACTORY = new Object();
	ManagedConnectionFactory managedConnectionFactory = mock(ManagedConnectionFactory.class);
	given(managedConnectionFactory.createConnectionFactory()).willReturn(CONNECTION_FACTORY);
	LocalConnectionFactoryBean factory = new LocalConnectionFactoryBean();
	factory.setManagedConnectionFactory(managedConnectionFactory);
	factory.afterPropertiesSet();
	assertEquals(CONNECTION_FACTORY, factory.getObject());
}
 
Example #8
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 #9
Source File: ManagedConnectionPoolFactory.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create a managed connection pool using a specific implementation strategy
 * 
 * @param strategy Fullt qualified class name for the managed connection pool strategy
 * @param mcf the managed connection factory
 * @param cm the connection manager
 * @param subject the subject
 * @param cri the connection request info
 * @param pc the pool configuration
 * @param p The pool
 * @return The initialized managed connection pool
 * @exception Throwable Thrown in case of an error
 */
public ManagedConnectionPool create(String strategy, 
                                    ManagedConnectionFactory mcf, ConnectionManager cm, Subject subject,
                                    ConnectionRequestInfo cri, PoolConfiguration pc, Pool p)
   throws Throwable
{
   Class<?> clz = Class.forName(strategy, 
                                true, 
                                SecurityActions.getClassLoader(ManagedConnectionPoolFactory.class));
   
   ManagedConnectionPool mcp = (ManagedConnectionPool)clz.newInstance();
   
   return init(mcp, mcf, cm, subject, cri, pc, p);
}
 
Example #10
Source File: AbstractConnectionManager.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Gets managed connection factory.
 * @return managed connection factory
 */
public javax.resource.spi.ManagedConnectionFactory getManagedConnectionFactory()
{
   if (pool == null)
   {
      log.tracef("No pooling strategy found! for connection manager : %s", this);
      return null;
   }
   else
   {
      return pool.getManagedConnectionFactory();
   }

}
 
Example #11
Source File: AbstractConnectionManager.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public ManagedConnection associateManagedConnection(Object connection, ManagedConnectionFactory mcf,
                                                    ConnectionRequestInfo cri)
   throws ResourceException
{
   // Check for pooling!
   if (pool == null || shutdown.get())
   {
      throw new ResourceException(bundle.tryingUseConnectionFactoryShutDown(jndiName));
   }

   // It is an explicit spec requirement that equals be used for matching rather than ==.
   if (!pool.getManagedConnectionFactory().equals(mcf))
   {
      throw new ResourceException(
         bundle.wrongManagedConnectionFactorySentToAllocateConnection(pool.getManagedConnectionFactory(), mcf));
   }

   if (connection == null)
      throw new ResourceException(bundle.connectionIsNull());

   // Pick a managed connection from the pool
   Subject subject = getSubject();
   ConnectionListener cl = getManagedConnection(subject, cri);

   // Tell each connection manager the managed connection is active
   reconnectManagedConnection(cl);

   // Associate managed connection with the connection
   cl.getManagedConnection().associateConnection(connection);
   registerAssociation(cl, connection);

   if (cachedConnectionManager != null)
   {
      cachedConnectionManager.registerConnection(this, cl, connection);
   }

   return cl.getManagedConnection();
}
 
Example #12
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 #13
Source File: LocalConnectionFactoryBeanTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreatesVanillaConnectionFactoryIfNoConnectionManagerHasBeenConfigured() throws Exception {
	final Object CONNECTION_FACTORY = new Object();
	ManagedConnectionFactory managedConnectionFactory = mock(ManagedConnectionFactory.class);
	given(managedConnectionFactory.createConnectionFactory()).willReturn(CONNECTION_FACTORY);
	LocalConnectionFactoryBean factory = new LocalConnectionFactoryBean();
	factory.setManagedConnectionFactory(managedConnectionFactory);
	factory.afterPropertiesSet();
	assertEquals(CONNECTION_FACTORY, factory.getObject());
}
 
Example #14
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 #15
Source File: JCAConnectionManagerImpl.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public JCAConnectionManagerImpl(ManagedConnectionFactory mcf,
    ConfiguredDataSourceProperties configs) {
  // Get the security info and form the Subject
  // Initialize the Pool.
  try {
    isActive = true;
    mannPoolCache = new ManagedPoolCacheImpl(mcf, null, null, this, configs);
  }
  catch (Exception ex) { 
    LogWriterI18n writer = TransactionUtils.getLogWriterI18n();
    if (writer.severeEnabled()) writer.severe(LocalizedStrings.JCAConnectionManagerImpl_EXCEPTION_CAUGHT_WHILE_INITIALIZING, ex.getLocalizedMessage(), ex);
  }
}
 
Example #16
Source File: JCAConnectionManagerImpl.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public JCAConnectionManagerImpl(ManagedConnectionFactory mcf,
    ConfiguredDataSourceProperties configs) {
  // Get the security info and form the Subject
  // Initialize the Pool.
  try {
    isActive = true;
    mannPoolCache = new ManagedPoolCacheImpl(mcf, null, null, this, configs);
  }
  catch (Exception ex) { 
    LogWriterI18n writer = TransactionUtils.getLogWriterI18n();
    if (writer.severeEnabled()) writer.severe(LocalizedStrings.JCAConnectionManagerImpl_EXCEPTION_CAUGHT_WHILE_INITIALIZING, ex.getLocalizedMessage(), ex);
  }
}
 
Example #17
Source File: FacetsJCAConnectionManagerImpl.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public FacetsJCAConnectionManagerImpl(ManagedConnectionFactory mcf,
    ConfiguredDataSourceProperties configs) {
  // Get the security info and form the Subject
  // Initialize the Pool.
  try {
    isActive = true;
    mannPoolCache = new ManagedPoolCacheImpl(mcf, null, null, this, configs);
  }
  catch (Exception ex) {
    LogWriterI18n writer = TransactionUtils.getLogWriterI18n();
    if (writer.severeEnabled()) writer.severe(LocalizedStrings.FacetsJCAConnectionManagerImpl_FACETSJCACONNECTIONMANAGERIMPL_CONSTRUCTOR_AN_EXCEPTION_WAS_CAUGHT_WHILE_INITIALIZING_DUE_TO_0, ex.getMessage(), ex);
  }
}
 
Example #18
Source File: LocalConnectionFactoryBeanTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testCreatesVanillaConnectionFactoryIfNoConnectionManagerHasBeenConfigured() throws Exception {
	final Object CONNECTION_FACTORY = new Object();
	ManagedConnectionFactory managedConnectionFactory = mock(ManagedConnectionFactory.class);
	given(managedConnectionFactory.createConnectionFactory()).willReturn(CONNECTION_FACTORY);
	LocalConnectionFactoryBean factory = new LocalConnectionFactoryBean();
	factory.setManagedConnectionFactory(managedConnectionFactory);
	factory.afterPropertiesSet();
	assertEquals(CONNECTION_FACTORY, factory.getObject());
}
 
Example #19
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 #20
Source File: ActiveMQRACredential.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
/**
 * Get credentials
 *
 * @param mcf     The managed connection factory
 * @param subject The subject
 * @param info    The connection request info
 * @return The credentials
 * @throws SecurityException Thrown if the credentials can't be retrieved
 */
public static ActiveMQRACredential getCredential(final ManagedConnectionFactory mcf,
                                                 final Subject subject,
                                                 final ConnectionRequestInfo info) throws SecurityException {
   if (ActiveMQRALogger.LOGGER.isTraceEnabled()) {
      ActiveMQRALogger.LOGGER.trace("getCredential(" + mcf + ", " + subject + ", " + info + ")");
   }

   ActiveMQRACredential jc = new ActiveMQRACredential();
   if (subject == null && info != null) {
      jc.setUserName(((ActiveMQRAConnectionRequestInfo) info).getUserName());
      jc.setPassword(((ActiveMQRAConnectionRequestInfo) info).getPassword());
   } else if (subject != null) {
      PasswordCredential pwdc = GetCredentialAction.getCredential(subject, mcf);

      if (pwdc == null) {
         throw new SecurityException("No password credentials found");
      }

      jc.setUserName(pwdc.getUserName());
      jc.setPassword(new String(pwdc.getPassword()));
   } else {
      throw new SecurityException("No Subject or ConnectionRequestInfo set, could not get credentials");
   }

   return jc;
}
 
Example #21
Source File: ActiveMQRACredential.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor
 *
 * @param subject The subject
 * @param mcf     The managed connection factory
 */
GetCredentialAction(final Subject subject, final ManagedConnectionFactory mcf) {
   if (ActiveMQRALogger.LOGGER.isTraceEnabled()) {
      ActiveMQRALogger.LOGGER.trace("constructor(" + subject + ", " + mcf + ")");
   }

   this.subject = subject;
   this.mcf = mcf;
}
 
Example #22
Source File: AbstractConnectionManager.java    From ironjacamar with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public boolean dissociateManagedConnection(Object connection, ManagedConnection mc, ManagedConnectionFactory mcf)
   throws ResourceException
{
   log.tracef("dissociateManagedConnection(%s, %s, %s)", connection, mc, mcf);
   
   if (connection == null || mc == null || mcf == null)
      throw new ResourceException();

   org.ironjacamar.core.connectionmanager.listener.ConnectionListener cl =
      pool.findConnectionListener(mc, connection);

   if (cl != null)
   {
      if (ccm != null)
      {
         ccm.unregisterConnection(this, cl, connection);
      }

      cl.removeConnection(connection);

      if (cl.getConnections().isEmpty())
      {
         pool.delist(cl);
         returnConnectionListener(cl, false);

         return true;
      }
   }
   else
   {
      throw new ResourceException();
   }

   return false;
}
 
Example #23
Source File: DefaultConnectionManager.java    From cxf with Apache License 2.0 5 votes vote down vote up
public Object allocateConnection(ManagedConnectionFactory mcf,
        ConnectionRequestInfo cxRequestInfo) throws ResourceException {

    if (LOG.isLoggable(Level.FINEST)) {
        LOG.finest("allocateConnection cxRequestInfo = " + cxRequestInfo);
    }

    ManagedConnection mc = mcf.createManagedConnection(null, cxRequestInfo);
    mc.addConnectionEventListener(this);
    return mc.getConnection(null, cxRequestInfo);
}
 
Example #24
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 #25
Source File: OutBoundConnectionTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
@org.junit.Ignore
public void testBasicConnection() throws Exception {
    URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
    assertNotNull(wsdl);

    SOAPService service = new SOAPService(wsdl, serviceName);
    assertNotNull(service);

    CXFConnectionRequestInfo cri = new CXFConnectionRequestInfo(Greeter.class,
                                       wsdl,
                                       service.getServiceName(),
                                       portName);
    cri.setAddress("http://localhost:" + PORT + "/SoapContext/SoapPort");
    ManagedConnectionFactory managedFactory = new ManagedConnectionFactoryImpl();
    Subject subject = new Subject();
    ManagedConnection mc = managedFactory.createManagedConnection(subject, cri);
    Object o = mc.getConnection(subject, cri);

    // test for the Object hash()
    try {
        o.hashCode();
        o.toString();
    } catch (WebServiceException ex) {
        fail("The connection object should support Object method");
    }

    verifyResult(o);
}
 
Example #26
Source File: NoTransactionConnectionManager.java    From ironjacamar with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Constructor
 * @param mcf The managed connection factory
 * @param ccm The cached connection manager
 * @param cmc The connection manager configuration
 */
public NoTransactionConnectionManager(ManagedConnectionFactory mcf,
                                      CachedConnectionManager ccm,
                                      ConnectionManagerConfiguration cmc)
{
   super(mcf, ccm, cmc);
}
 
Example #27
Source File: LocalTransactionConnectionManager.java    From ironjacamar with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Constructor
 * @param mcf The managed connection factory
 * @param ccm The cached connection manager
 * @param cmc The connection manager configuration
 * @param ti The transaction integration
 */
public LocalTransactionConnectionManager(ManagedConnectionFactory mcf,
                                         CachedConnectionManager ccm,
                                         ConnectionManagerConfiguration cmc,
                                         TransactionIntegration ti)
{
   super(mcf, ccm, cmc, ti);
}
 
Example #28
Source File: TransactionIntegrationImpl.java    From ironjacamar with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public XAResourceRecovery createXAResourceRecovery(ManagedConnectionFactory mcf,
                                                   Boolean pad, Boolean override, 
                                                   Boolean wrapXAResource,
                                                   String recoverSecurityDomain,
                                                   SubjectFactory subjectFactory,
                                                   RecoveryPlugin plugin,
                                                   XAResourceStatistics xastat)
{
   return new XAResourceRecoveryImpl(this, mcf, pad, override, wrapXAResource,
                                     recoverSecurityDomain,
                                     subjectFactory, plugin, xastat);
}
 
Example #29
Source File: XAResourceRecoveryImpl.java    From ironjacamar with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Constructor
 * @param mcf The ManagedConnectionFactory
 * @param sd The security domain
 * @param subjectFactory The subject factory
 */
public XAResourceRecoveryImpl(ManagedConnectionFactory mcf, String sd, SubjectFactory subjectFactory)
{
   this.mcf = mcf;
   this.mc = null;
   this.securityDomain = sd;
   this.subjectFactory = subjectFactory;
}
 
Example #30
Source File: AbstractConnectionManager.java    From ironjacamar with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public ManagedConnection associateManagedConnection(Object connection, ManagedConnectionFactory mcf,
                                                    ConnectionRequestInfo cri)
   throws ResourceException
{
   log.tracef("associateManagedConnection(%s, %s, %s)", connection, mcf, cri);
   
   if (!this.mcf.equals(mcf))
   {
      throw new ResourceException();
   }

   if (connection == null)
      throw new ResourceException();

   Credential credential = null;
   if (getSubjectFactory() == null || cmConfiguration.getSecurityDomain() == null)
   {
      credential = new Credential(null, cri);
   }
   else
   {
      credential = new Credential(SecurityActions.createSubject(subjectFactory,
                                                                cmConfiguration.getSecurityDomain(),
                                                                mcf),
                                  cri);
   }

   return associateConnectionListener(credential, connection).getManagedConnection();
}