Package javax.resource.spi

Examples of javax.resource.spi.ManagedConnection


        transactionManager = (TransactionManager) props.get(TransactionManager.class.getName());
    }

    public Object allocateConnection(ManagedConnectionFactory factory, ConnectionRequestInfo cxRequestInfo) throws ResourceException {
        ConnectionCache connectionCache = null;
        ManagedConnection conn = null;
        if (!(factory instanceof JdbcManagedConnectionFactory) || !((JdbcManagedConnectionFactory) factory).isUnmanaged()) {
            connectionCache = threadConnectionCache.get();
            conn = connectionCache.getConnection(factory);
        }
        if (conn == null) {
            conn = factory.matchManagedConnections(connSet, null, cxRequestInfo);
            if (conn != null) {
                connSet.remove(conn);
            } else {
                conn = factory.createManagedConnection(null, cxRequestInfo);
                conn.addConnectionEventListener(this);
            }
            conn.getLocalTransaction().begin();

            try {
                /*
                * The transaction manager has a  wrapper that ensures that any Synchronization
                * objects are handled after the EntityBean.ejbStore and SessionSynchronization methods of beans.
                * In the StatefulContainer and EntityContainer enterprise beans are wrapped
                * Synchronization wrappers, which must be handled
                * before the LocalTransaction objects in this connection manager.
                */
                Transaction tx = getTransactionManager().getTransaction();
                if (tx != null) {
                    tx.registerSynchronization(new Synchronizer(conn.getLocalTransaction()));
                }
            } catch (SystemException se) {
                throw new ApplicationServerInternalException("Can not obtain a Transaction object from TransactionManager. " + se.getMessage(), se);
            } catch (RollbackException re) {
                throw new ApplicationServerInternalException("Can not register org.apache.openejb.resource.LocalTransacton with transaciton manager. Transaction has already been rolled back" + re.getMessage(), re);
            }

            if (connectionCache != null) {
                connectionCache.putConnection(factory, conn);
            }
        }

        Object handle = conn.getConnection(null, cxRequestInfo);
        return handle;
    }
View Full Code Here


    }

    public void connectionClosed(ConnectionEvent event) {
        try {
            if (getTransactionManager().getTransaction() == null) {
                ManagedConnection conn = (ManagedConnection) event.getSource();
                conn.getLocalTransaction().commit();
                this.cleanup(conn);
            }
        } catch (SystemException se) {

        } catch (ResourceException re) {
View Full Code Here

        }
    }

    public void connectionErrorOccurred(ConnectionEvent event) {
        ManagedConnection conn = (ManagedConnection) event.getSource();

        try {
            conn.destroy();

            threadConnectionCache.get().removeConnection(conn);
        } catch (ResourceException re) {

        }
View Full Code Here

    }

    public ManagedConnection matchManagedConnections(Set connectionSet, Subject subject, ConnectionRequestInfo cxRequestInfo) throws ResourceException {
        if (reauthentication) {
            for (Iterator iterator = connectionSet.iterator(); iterator.hasNext();) {
                ManagedConnection managedConnection = (ManagedConnection) iterator.next();
                if (managedConnections.contains(managedConnection)) {
                    return managedConnection;
                }
            }
        } else {
            for (Iterator iterator = connectionSet.iterator(); iterator.hasNext();) {
                ManagedConnection managedConnection = (ManagedConnection) iterator.next();
//                return managedConnection;
                if (managedConnections.contains(managedConnection)) {
                    MockManagedConnection mockManagedConnection = (MockManagedConnection) managedConnection;
                    if ((subject == null ? mockManagedConnection.getSubject() == null : subject.equals(mockManagedConnection.getSubject())
                            && (cxRequestInfo == null ? mockManagedConnection.getConnectionRequestInfo() == null : cxRequestInfo.equals(mockManagedConnection.getConnectionRequestInfo())))) {
View Full Code Here

   private ConnectionListener createConnectionEventListener(Subject subject, ConnectionRequestInfo cri)
      throws ResourceException
   {
      long start = statistics.isEnabled() ? System.currentTimeMillis() : 0L;

      ManagedConnection mc = mcf.createManagedConnection(subject, cri);

      if (statistics.isEnabled())
      {
         statistics.deltaTotalCreationTime(System.currentTimeMillis() - start);
         statistics.deltaCreatedCount();
      }
      try
      {
         return clf.createConnectionListener(mc, this);
      }
      catch (ResourceException re)
      {
         if (statistics.isEnabled())
            statistics.deltaDestroyedCount();
         mc.destroy();
         throw re;
      }
   }
View Full Code Here

      if (statistics.isEnabled())
         statistics.deltaDestroyedCount();
      cl.setState(ConnectionState.DESTROYED);

      ManagedConnection mc = cl.getManagedConnection();
      try
      {
         mc.destroy();
      }
      catch (Throwable t)
      {
         log.debug("Exception destroying ManagedConnection " + cl, t);
      }

      mc.removeConnectionEventListener(cl);
   }
View Full Code Here

   private ConnectionListener createConnectionEventListener(Subject subject, ConnectionRequestInfo cri)
      throws ResourceException
   {
      long start = statistics.isEnabled() ? System.currentTimeMillis() : 0L;

      ManagedConnection mc = mcf.createManagedConnection(subject, cri);

      if (statistics.isEnabled())
      {
         statistics.deltaTotalCreationTime(System.currentTimeMillis() - start);
         statistics.deltaCreatedCount();
      }
      try
      {
         return clf.createConnectionListener(mc, this);
      }
      catch (ResourceException re)
      {
         statistics.deltaDestroyedCount();
         mc.destroy();
         throw re;
      }
   }
View Full Code Here

      }

      statistics.deltaDestroyedCount();
      cl.setState(ConnectionState.DESTROYED);

      ManagedConnection mc = cl.getManagedConnection();
      try
      {
         mc.destroy();
      }
      catch (Throwable t)
      {
         log.debug("Exception destroying ManagedConnection " + cl, t);
      }

      mc.removeConnectionEventListener(cl);
   }
View Full Code Here

     * @return true if a connection for which a permit was issued was returned (so the permit should be released),
     * false if no permit was issued (for instance if the connection was already in the pool and we are destroying it).
     */
    protected boolean internalReturn(ConnectionInfo connectionInfo, ConnectionReturnAction connectionReturnAction) {
        ManagedConnectionInfo mci = connectionInfo.getManagedConnectionInfo();
        ManagedConnection mc = mci.getManagedConnection();
        try {
            mc.cleanup();
        } catch (ResourceException e) {
            connectionReturnAction = ConnectionReturnAction.DESTROY;
        }

        boolean releasePermit;
        synchronized (getPool()) {
            // a bit redundant, but this closes a small timing hole...
            if (destroyed) {
                try {
                    mc.destroy();
                }
                catch (ResourceException re) {
                    //ignore
                }
                return doRemove(mci);
View Full Code Here

        if (mci.getManagedConnection() != null) {
            return;
        }

        try {
            ManagedConnection mc = mci.getManagedConnectionFactory().createManagedConnection(
                    mci.getSubject(),
                    mci.getConnectionRequestInfo());
            mci.setManagedConnection(mc);
            GeronimoConnectionEventListener listener = new GeronimoConnectionEventListener(stack, mci);
            mci.setConnectionEventListener(listener);
            mc.addConnectionEventListener(listener);
        } catch (ResourceException re) {
            log.error("Error occurred creating ManagedConnection for " + connectionInfo, re);
            throw re;
        }
    }
View Full Code Here

TOP

Related Classes of javax.resource.spi.ManagedConnection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.