From: <db...@us...> - 2003-05-01 01:59:27
|
Update of /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/jca In directory sc8-pr-cvs1:/tmp/cvs-serv29680/src/net/sf/hibernate/jca Modified Files: JCASessionImpl.java JCASessionFactoryImpl.java ManagedConnectionImpl.java ManagedConnectionFactoryImpl.java MetaDataImpl.java Removed Files: ConnectionRequestInfoImpl.java LocalTransactionImpl.java Log Message: JCA rework from Igor Fedorenko that relies on preconfigured datasources Index: JCASessionImpl.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/jca/JCASessionImpl.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** JCASessionImpl.java 21 Apr 2003 06:28:18 -0000 1.7 --- JCASessionImpl.java 1 May 2003 01:59:23 -0000 1.8 *************** *** 17,66 **** import net.sf.hibernate.type.Type; public class JCASessionImpl implements Session { ! private Session session; private ManagedConnectionImpl mc; ! public JCASessionImpl(Session session, ManagedConnectionImpl mc){ ! this.session = session; this.mc = mc; } ! public void flush() throws HibernateException { ! session.flush(); } ! public void setFlushMode(FlushMode flushMode) { ! session.setFlushMode(flushMode); } public FlushMode getFlushMode() { ! return session.getFlushMode(); } public Connection connection() throws HibernateException { ! return session.connection(); } public Connection disconnect() throws HibernateException { ! return session.disconnect(); } public void reconnect() throws HibernateException { ! session.reconnect(); } ! public void reconnect(Connection connection) throws HibernateException { ! session.reconnect(connection); } public Connection close() throws HibernateException { mc.closeHandle(this); ! mc = null; ! return session.close(); } public boolean isOpen() { ! return session.isOpen(); } --- 17,97 ---- import net.sf.hibernate.type.Type; + /** + * A logical session handle, all real work is deligated to underlying physical + * session represented by ManagedConnectionImpl instance. + */ public class JCASessionImpl implements Session { ! /* ! * JCA 1.0 5.5.1 ! * A connection implementation class implements its methods in a ! * resource adapter implementation-specific way. It must use ! * javax.resource.spi.ManagedConnection instance as its ! * underlying physical connection. ! */ private ManagedConnectionImpl mc; ! public JCASessionImpl(final ManagedConnectionImpl mc) ! { this.mc = mc; } ! ! private Session getSession() { ! return mc.getSession(this); ! } ! ! ManagedConnectionImpl getManagedConnextion() { ! return mc; ! } ! ! void setManagedConnection(ManagedConnectionImpl mc) { ! this.mc = mc; ! } ! ! // ! // Session implementation goes below. ! // ! public void flush() throws HibernateException { ! getSession().flush(); } ! public void setFlushMode(final FlushMode flushMode) { ! getSession().setFlushMode(flushMode); } public FlushMode getFlushMode() { ! return getSession().getFlushMode(); } public Connection connection() throws HibernateException { ! return getSession().connection(); } public Connection disconnect() throws HibernateException { ! throw new UnsupportedOperationException(); } public void reconnect() throws HibernateException { ! throw new UnsupportedOperationException(); } ! public void reconnect(final Connection connection) ! throws HibernateException ! { ! throw new UnsupportedOperationException(); } public Connection close() throws HibernateException { mc.closeHandle(this); ! return null; // never let clients mess with database connections } public boolean isOpen() { ! try { ! return getSession().isOpen(); ! } catch (IllegalStateException expected) { ! return false; ! } } *************** *** 69,73 **** */ public boolean isConnected() { ! return session.isConnected(); } --- 100,104 ---- */ public boolean isConnected() { ! return getSession().isConnected(); } *************** *** 75,81 **** * @see net.sf.hibernate.Session#getIdentifier(Object) */ ! public Serializable getIdentifier(Object object) ! throws HibernateException { ! return session.getIdentifier(object); } --- 106,113 ---- * @see net.sf.hibernate.Session#getIdentifier(Object) */ ! public Serializable getIdentifier(final Object object) ! throws HibernateException ! { ! return getSession().getIdentifier(object); } *************** *** 83,89 **** * @see net.sf.hibernate.Session#load(Class, Serializable, LockMode) */ ! public Object load(Class theClass, Serializable id, LockMode lockMode) ! throws HibernateException { ! return session.load(theClass, id, lockMode); } --- 115,122 ---- * @see net.sf.hibernate.Session#load(Class, Serializable, LockMode) */ ! public Object load(final Class theClass, final Serializable id, ! final LockMode lockMode) throws HibernateException ! { ! return getSession().load(theClass, id, lockMode); } *************** *** 91,97 **** * @see net.sf.hibernate.Session#load(Class, Serializable) */ ! public Object load(Class theClass, Serializable id) ! throws HibernateException { ! return session.load(theClass, id); } --- 124,131 ---- * @see net.sf.hibernate.Session#load(Class, Serializable) */ ! public Object load(final Class theClass, final Serializable id) ! throws HibernateException ! { ! return getSession().load(theClass, id); } *************** *** 99,105 **** * @see net.sf.hibernate.Session#load(Object, Serializable) */ ! public void load(Object object, Serializable id) ! throws HibernateException { ! session.load(object, id); } --- 133,140 ---- * @see net.sf.hibernate.Session#load(Object, Serializable) */ ! public void load(final Object object, final Serializable id) ! throws HibernateException ! { ! getSession().load(object, id); } *************** *** 107,112 **** * @see net.sf.hibernate.Session#save(Object) */ ! public Serializable save(Object object) throws HibernateException { ! return session.save(object); } --- 142,147 ---- * @see net.sf.hibernate.Session#save(Object) */ ! public Serializable save(final Object object) throws HibernateException { ! return getSession().save(object); } *************** *** 114,120 **** * @see net.sf.hibernate.Session#save(Object, Serializable) */ ! public void save(Object object, Serializable id) ! throws HibernateException { ! session.save(object, id); } --- 149,156 ---- * @see net.sf.hibernate.Session#save(Object, Serializable) */ ! public void save(final Object object, final Serializable id) ! throws HibernateException ! { ! getSession().save(object, id); } *************** *** 122,127 **** * @see net.sf.hibernate.Session#saveOrUpdate(Object) */ ! public void saveOrUpdate(Object object) throws HibernateException { ! session.saveOrUpdate(object); } --- 158,163 ---- * @see net.sf.hibernate.Session#saveOrUpdate(Object) */ ! public void saveOrUpdate(final Object object) throws HibernateException { ! getSession().saveOrUpdate(object); } *************** *** 129,134 **** * @see net.sf.hibernate.Session#update(Object) */ ! public void update(Object object) throws HibernateException { ! session.update(object); } --- 165,170 ---- * @see net.sf.hibernate.Session#update(Object) */ ! public void update(final Object object) throws HibernateException { ! getSession().update(object); } *************** *** 136,262 **** * @see net.sf.hibernate.Session#update(Object, Serializable) */ ! public void update(Object object, Serializable id) ! throws HibernateException { ! session.update(object, id); } ! public void delete(Object object) throws HibernateException { ! session.delete(object); } ! public List find(String query) throws HibernateException { ! return session.find(query); } ! public List find(String query, Object value, Type type) ! throws HibernateException { ! return session.find(query, value, type); } ! public List find(String query, Object[] values, Type[] types) ! throws HibernateException { ! return session.find(query, values, types); } ! public Iterator iterate(String query) throws HibernateException { ! return session.iterate(query); } ! public Iterator iterate(String query, Object value, Type type) ! throws HibernateException { ! return session.iterate(query, value, type); } ! public Iterator iterate(String query, Object[] values, Type[] types) ! throws HibernateException { ! return session.iterate(query, values, types); } ! public Collection filter(Object collection, String filter) ! throws HibernateException { ! return session.filter(collection, filter); } ! public Collection filter( ! Object collection, ! String filter, ! Object value, ! Type type) ! throws HibernateException { return null; } ! public Collection filter( ! Object collection, ! String filter, ! Object[] values, ! Type[] types) ! throws HibernateException { ! return session.filter(collection, filter, values, types); } ! public int delete(String query) throws HibernateException { ! return session.delete(query); } ! public int delete(String query, Object value, Type type) ! throws HibernateException { ! return session.delete(query, value, type); } ! public int delete(String query, Object[] values, Type[] types) ! throws HibernateException { ! return session.delete(query, values, types); } ! public void lock(Object object, LockMode lockMode) ! throws HibernateException { ! session.lock(object, lockMode); } ! public void refresh(Object object) throws HibernateException { ! session.refresh(object); } ! public LockMode getCurrentLockMode(Object object) ! throws HibernateException { ! return session.getCurrentLockMode(object); } public Transaction beginTransaction() throws HibernateException { ! return session.beginTransaction(); } public Query createQuery(String queryString) throws HibernateException { ! return session.createQuery(queryString); } ! public Query createFilter(Object collection, String queryString) ! throws HibernateException { ! return session.createFilter(collection, queryString); } ! public Query getNamedQuery(String queryName) throws HibernateException { ! return session.getNamedQuery(queryName); ! } ! ! void setManagedConnection(ManagedConnectionImpl mc){ ! this.mc = mc; } ! public Criteria createCriteria(Class persistentClass) { ! return session.createCriteria(persistentClass); } ! public void refresh(Object object, LockMode lockMode) throws HibernateException { ! session.refresh(object, lockMode); } ! public boolean contains(Object object) { ! return session.contains(object); } public void evict(Object object) throws HibernateException { ! session.evict(object); } --- 172,303 ---- * @see net.sf.hibernate.Session#update(Object, Serializable) */ ! public void update(final Object object, final Serializable id) ! throws HibernateException ! { ! getSession().update(object, id); } ! public void delete(final Object object) throws HibernateException { ! getSession().delete(object); } ! public List find(final String query) throws HibernateException { ! return getSession().find(query); } ! public List find(final String query, final Object value, final Type type) ! throws HibernateException ! { ! return getSession().find(query, value, type); } ! public List find(final String query, final Object[] values, ! final Type[] types) throws HibernateException ! { ! return getSession().find(query, values, types); } ! public Iterator iterate(final String query) throws HibernateException { ! return getSession().iterate(query); } ! public Iterator iterate(final String query, final Object value, ! final Type type) throws HibernateException ! { ! return getSession().iterate(query, value, type); } ! public Iterator iterate(final String query, final Object[] values, ! final Type[] types) throws HibernateException ! { ! return getSession().iterate(query, values, types); } ! public Collection filter(final Object collection, final String filter) ! throws HibernateException ! { ! return getSession().filter(collection, filter); } ! public Collection filter(final Object collection, final String filter, ! final Object value, final Type type) throws HibernateException ! { return null; } ! public Collection filter(final Object collection, final String filter, ! final Object[] values, final Type[] types) throws HibernateException ! { ! return getSession().filter(collection, filter, values, types); } ! public int delete(final String query) throws HibernateException { ! return getSession().delete(query); } ! public int delete(final String query, final Object value, final Type type) ! throws HibernateException ! { ! return getSession().delete(query, value, type); } ! public int delete(final String query, final Object[] values, ! final Type[] types) throws HibernateException ! { ! return getSession().delete(query, values, types); } ! public void lock(final Object object, final LockMode lockMode) ! throws HibernateException ! { ! getSession().lock(object, lockMode); } ! public void refresh(final Object object) throws HibernateException { ! getSession().refresh(object); } ! public LockMode getCurrentLockMode(final Object object) ! throws HibernateException ! { ! return getSession().getCurrentLockMode(object); } public Transaction beginTransaction() throws HibernateException { ! throw new UnsupportedOperationException(); } public Query createQuery(String queryString) throws HibernateException { ! return getSession().createQuery(queryString); } ! public Query createFilter(final Object collection, final String queryString) ! throws HibernateException ! { ! return getSession().createFilter(collection, queryString); } ! public Query getNamedQuery(final String queryName) ! throws HibernateException ! { ! return getSession().getNamedQuery(queryName); } ! public Criteria createCriteria(final Class persistentClass) { ! return getSession().createCriteria(persistentClass); } ! public void refresh(final Object object, final LockMode lockMode) ! throws HibernateException ! { ! getSession().refresh(object, lockMode); } ! public boolean contains(final Object object) { ! return getSession().contains(object); } public void evict(Object object) throws HibernateException { ! getSession().evict(object); } Index: JCASessionFactoryImpl.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/jca/JCASessionFactoryImpl.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** JCASessionFactoryImpl.java 8 Mar 2003 09:53:35 -0000 1.2 --- JCASessionFactoryImpl.java 1 May 2003 01:59:23 -0000 1.3 *************** *** 4,8 **** import java.sql.Connection; import java.util.Map; - import java.util.Properties; import javax.naming.NamingException; --- 4,7 ---- *************** *** 11,16 **** import javax.resource.ResourceException; import javax.resource.spi.ConnectionManager; - import javax.resource.spi.ConnectionRequestInfo; - import javax.resource.spi.ManagedConnectionFactory; import net.sf.hibernate.Databinder; --- 10,13 ---- *************** *** 19,27 **** import net.sf.hibernate.Session; import net.sf.hibernate.SessionFactory; - import net.sf.hibernate.cfg.Configuration; - import net.sf.hibernate.cfg.Environment; import net.sf.hibernate.metadata.ClassMetadata; import net.sf.hibernate.metadata.CollectionMetadata; - import net.sf.hibernate.util.PropertiesHelper; import org.apache.commons.logging.Log; --- 16,21 ---- *************** *** 30,99 **** public final class JCASessionFactoryImpl implements SessionFactory, Referenceable { private static final Log log = LogFactory.getLog(JCASessionFactoryImpl.class); ! private SessionFactory factory; ! private ManagedConnectionFactory managedFactory; ! private ConnectionManager cxManager; private Reference reference; - public JCASessionFactoryImpl(ManagedConnectionFactory mcf, String dialect, String mapResources) - throws HibernateException { - this(mcf, null, dialect, mapResources); - } - public JCASessionFactoryImpl( ! ManagedConnectionFactory managedFactory, ! ConnectionManager cxManager, String dialect, String mapResources) ! throws HibernateException { ! ! Properties hibProperties = new Properties(); ! hibProperties.setProperty(Environment.DIALECT, dialect); ! ! Configuration cfg = new Configuration().addProperties(hibProperties); ! ! // taken from HibernateService, maybe factor out for JCA 1.5 ! String[] mappingFiles = PropertiesHelper.toStringArray(mapResources, " ,\n\t\r\f"); ! for ( int i=0; i<mappingFiles.length; i++ ) { ! cfg.addResource( mappingFiles[i], Thread.currentThread().getContextClassLoader() ); ! } ! this.managedFactory = managedFactory; - this.factory = cfg.buildSessionFactory(); this.cxManager = cxManager; } public void close() throws HibernateException { ! factory.close(); } public Map getAllClassMetadata() throws HibernateException { ! return factory.getAllClassMetadata(); } public Map getAllCollectionMetadata() throws HibernateException { ! return factory.getAllCollectionMetadata(); } public ClassMetadata getClassMetadata(Class persistentClass) ! throws HibernateException { ! return factory.getClassMetadata(persistentClass); } public CollectionMetadata getCollectionMetadata(String roleName) ! throws HibernateException { ! return factory.getCollectionMetadata(roleName); } public Databinder openDatabinder() throws HibernateException { ! return factory.openDatabinder(); } public Session openSession() throws HibernateException { ! Session result = null; try { ! ConnectionRequestInfo info = new ConnectionRequestInfoImpl(factory); ! result = ! (Session) cxManager.allocateConnection(managedFactory, info); } catch (ResourceException re) { throw new HibernateException(re); --- 24,90 ---- public final class JCASessionFactoryImpl implements SessionFactory, Referenceable { + + /* + * @todo JCA 1.0, 5.10.1 + * A resource adapter is required to provide support for basic error + * logging and tracing by implementing the following methods: + * - ManagedConnectionFactory.set/getLogWriter + * - ManagedConnection.set/getLogWriter + */ private static final Log log = LogFactory.getLog(JCASessionFactoryImpl.class); ! private final ManagedConnectionFactoryImpl managedFactory; ! private final ConnectionManager cxManager; private Reference reference; public JCASessionFactoryImpl( ! final ManagedConnectionFactoryImpl managedFactory, ! final ConnectionManager cxManager) throws HibernateException ! { this.managedFactory = managedFactory; this.cxManager = cxManager; } public void close() throws HibernateException { ! // don't want crazy clients to destroy the factory ! // JCA 1.5 will have adapter lifecycle management ! throw new UnsupportedOperationException(); } public Map getAllClassMetadata() throws HibernateException { ! return getSessionFactory().getAllClassMetadata(); } public Map getAllCollectionMetadata() throws HibernateException { ! return getSessionFactory().getAllCollectionMetadata(); } public ClassMetadata getClassMetadata(Class persistentClass) ! throws HibernateException ! { ! return getSessionFactory().getClassMetadata(persistentClass); } public CollectionMetadata getCollectionMetadata(String roleName) ! throws HibernateException ! { ! return getSessionFactory().getCollectionMetadata(roleName); } public Databinder openDatabinder() throws HibernateException { ! return getSessionFactory().openDatabinder(); } public Session openSession() throws HibernateException { ! JCASessionImpl result = null; try { ! // JCA 1.0, 5.5.1 ! // resource adapter implementation is not required to support the ! // mechanism for passing resource adapter-specific connection ! // request information. It can choose to pass null for ! // ConnectionRequestInfo in the allocateConnection invocation. ! result = (JCASessionImpl) ! cxManager.allocateConnection(managedFactory, null); } catch (ResourceException re) { throw new HibernateException(re); *************** *** 102,118 **** } ! public Session openSession( ! Connection connection, ! Interceptor interceptor) { ! return factory.openSession(connection, interceptor); } public Session openSession(Connection connection) { ! return factory.openSession(connection); } public Session openSession(Interceptor interceptor) ! throws HibernateException { ! return factory.openSession(interceptor); } --- 93,110 ---- } ! public Session openSession(final Connection connection, ! final Interceptor interceptor) ! { ! return getSessionFactory().openSession(connection, interceptor); } public Session openSession(Connection connection) { ! return getSessionFactory().openSession(connection); } public Session openSession(Interceptor interceptor) ! throws HibernateException ! { ! return getSessionFactory().openSession(interceptor); } *************** *** 123,126 **** --- 115,122 ---- public void setReference(Reference ref) { reference = ref; + } + + private SessionFactory getSessionFactory() { + return managedFactory.getSessionFactory(); } } Index: ManagedConnectionImpl.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/jca/ManagedConnectionImpl.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ManagedConnectionImpl.java 8 Mar 2003 09:53:35 -0000 1.2 --- ManagedConnectionImpl.java 1 May 2003 01:59:23 -0000 1.3 *************** *** 7,14 **** import java.util.ArrayList; import java.util.Collection; - import java.util.HashSet; import java.util.Iterator; ! import java.util.Properties; ! import java.util.Set; import javax.resource.NotSupportedException; --- 7,12 ---- import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; ! import java.util.LinkedList; import javax.resource.NotSupportedException; *************** *** 17,21 **** import javax.resource.spi.ConnectionEventListener; import javax.resource.spi.ConnectionRequestInfo; - import javax.resource.spi.IllegalStateException; import javax.resource.spi.LocalTransaction; import javax.resource.spi.ManagedConnection; --- 15,18 ---- *************** *** 23,96 **** import javax.resource.spi.ManagedConnectionMetaData; import javax.security.auth.Subject; import javax.transaction.xa.XAResource; import net.sf.hibernate.Session; ! import net.sf.hibernate.SessionFactory; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** ! * Implementation of JCA Managed Connection. The underlying connection is a java.sql.Connecion object ! * which is passed to a Hibernate session object for the client to use. ! * ! * This is based on a JBoss LPGL generic JDBC JCA implementation ! * ! * Currently only supports LocalTransactions (XA should follow at some stage) ! * */ ! public class ManagedConnectionImpl implements ManagedConnection { private static final Log log = LogFactory.getLog(ManagedConnectionImpl.class); - // true if connection has been destroyed - private boolean destroyed; - // the factory that created this managed connection ! private ManagedConnectionFactory mcf; ! // as per JCA 1.0 spec 5.6 when this is not null then logging has been enabled ! // by the application server and we log to this writer private PrintWriter logWriter; - // factory to create sessions - private SessionFactory sessions; - - // underlying connection to the database - private Connection connection; - // registered listeners from the application server private final Collection listeners = new ArrayList(); ! // a set of JCASessionImpl handles associated with this managed connection ! private final Set handles = new HashSet(); ! ! private Properties props; ! ManagedConnectionImpl( ! ManagedConnectionFactory mcf, ! String user, ! Properties props, ! SessionFactory sessions, ! Connection connection) { ! log.trace("Constructor called with user " + user); this.mcf = mcf; - this.sessions = sessions; - this.connection = connection; - this.props = props; } /** ! * Creates and returns a new Hibernate Session * ! * Will throw a ResourceException if the session factory * fails to create a session */ ! public Object getConnection( ! Subject subject, ! ConnectionRequestInfo connectionRequestInfo) ! throws ResourceException { log.trace( --- 20,92 ---- import javax.resource.spi.ManagedConnectionMetaData; import javax.security.auth.Subject; + import javax.transaction.xa.XAException; import javax.transaction.xa.XAResource; + import javax.transaction.xa.Xid; + import net.sf.hibernate.HibernateException; import net.sf.hibernate.Session; ! import net.sf.hibernate.engine.SessionImplementor; ! import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** ! * Implementation of JCA Managed Connection. */ ! public class ManagedConnectionImpl implements ManagedConnection, XAResource { + /* + * @todo JCA 1.0, 5.10.1 + * A resource adapter is required to provide support for basic error + * logging and tracing by implementing the following methods: + * - ManagedConnectionFactory.set/getLogWriter + * - ManagedConnection.set/getLogWriter + */ private static final Log log = LogFactory.getLog(ManagedConnectionImpl.class); // the factory that created this managed connection ! private ManagedConnectionFactoryImpl mcf; ! // as per JCA 1.0 spec 5.6 when this is not null then logging has been ! // enabled by the application server and we log to this writer private PrintWriter logWriter; // registered listeners from the application server private final Collection listeners = new ArrayList(); ! /** ! * A set (actually a linked list) of JCASessionImpl handles associated with ! * this managed connection. First element of the list is the currect active ! * handle. ! * ! * <p>It is necessary to synchronize access to this list becase ! * <code>dissociateConnection</code> can be called asynchronously ! * from a context of a different transaction.</p> ! */ ! private final LinkedList handles = new LinkedList(); ! // a (logical handle to) database connection ! private Connection connection; ! // Hibernate session ! private SessionImplementor session; ! ! ManagedConnectionImpl(final ManagedConnectionFactoryImpl mcf) { ! log.trace("Constructor called"); this.mcf = mcf; } /** ! * Creates and returns a new Hibernate Session. * ! * Will throw a ResourceException if the session factory * fails to create a session */ ! public Object getConnection(final Subject subject, ! final ConnectionRequestInfo connectionRequestInfo) ! throws ResourceException ! { log.trace( *************** *** 101,122 **** + "]"); ! // maybe should check the credentials match up with the current connection? ! ! // create session from the session factory ! Session session = null; ! try { ! session = sessions.openSession(connection); ! } catch (Exception hbe) { ! log.error( ! "Error opening session with connection " + connection, ! hbe); ! throw new ResourceException(hbe.getMessage()); ! } ! JCASessionImpl jcaSession = new JCASessionImpl(session, this); ! // add the session handle to the collection of handles on this connection synchronized (handles) { ! handles.add(jcaSession); } --- 97,109 ---- + "]"); ! // make sure we have a session ! initializeSession(); ! final JCASessionImpl active = new JCASessionImpl(this); ! // add the session handle to the collection of handles ! // on this connection synchronized (handles) { ! handles.addFirst(active); } *************** *** 124,133 **** log.debug( "Added session handle - " ! + jcaSession + " to handles now at size " + handles.size()); } ! return jcaSession; } --- 111,160 ---- log.debug( "Added session handle - " ! + active + " to handles now at size " + handles.size()); } ! return active; ! } ! ! /** ! * Creates a session from the session factory ! */ ! private void initializeSession() throws ResourceException { ! // single threaded, no need to synchronize ! if (session == null) { ! initializeConnection(); ! session = (SessionImplementor) ! mcf.getSessionFactory().openSession(connection); ! } ! } ! ! /** ! * JDBC connection is lazy-inilialized during this call. A caller must ! * ensure proper thread context, i.e. context of original component ! * called into Hibernate session. ! */ ! private void initializeConnection() throws ResourceException { ! // single threaded, no need to synchronize ! if (connection == null) { ! try { ! connection = mcf.getDatasource().getConnection(); ! } catch (SQLException e) { ! final String message = "Cannot allocate database connection!"; ! throw newResourceException(message, e); ! } ! } ! } ! ! /** ! * Returns new ResourceException. ! */ ! private ResourceException newResourceException(final String message, ! final Exception e) ! { ! final ResourceException re = new ResourceException(message); ! re.setLinkedException(e); ! return re; } *************** *** 141,163 **** log.trace("destroy called on " + this); } - - if (connection == null) - throw new IllegalStateException("Resource cannot be destroyed because it is null"); - - try { - if (connection.isClosed()) - throw new IllegalStateException("Resource cannot be destroyed because it is already closed"); - - connection.close(); - connection = null; - } catch (SQLException ex) { - log.error("Error closing connection - " + connection, ex); - ResourceException re = - new ResourceException("Exception trying to close connection"); - re.setLinkedException(ex); - throw re; - } finally { - destroyed = true; - } } --- 168,171 ---- *************** *** 171,174 **** --- 179,185 ---- } + // JCA 1.0, 5.5.4 + // The cleanup is required to invalidate all connection + // handles created using this ManagedConnection instance. synchronized (handles) { for (Iterator i = handles.iterator(); i.hasNext();) { *************** *** 178,181 **** --- 189,218 ---- handles.clear(); } + + ResourceException re = null; + + try { + session.close(); + } catch (HibernateException e) { + final String message = + "Exception closing Hibernate session " + session; + re = newResourceException(message, e); + } finally { + session = null; + } + + try { + connection.close(); + } catch (SQLException e) { + final String message = + "Exception closing database connection " + connection; + re = newResourceException(message, e); + } finally { + connection = null; + } + + if (re != null) { + throw re; + } } *************** *** 183,219 **** * Associates the session handle with this managed connection */ ! public void associateConnection(Object handle) throws ResourceException { ! if (!(handle instanceof JCASessionImpl)) { throw new ResourceException( ! "Wrong kind of connection handle to associate " + handle); } ! ((JCASessionImpl) handle).setManagedConnection(this); synchronized (handles) { ! handles.add(handle); } } public void addConnectionEventListener(ConnectionEventListener listener) { ! synchronized (listeners) { ! listeners.add(listener); ! } } public void removeConnectionEventListener(ConnectionEventListener listener) { ! synchronized (listeners) { ! listeners.remove(listener); ! } } - /** - * NOT SUPPORTED - * @throws NotSupportedException - */ public XAResource getXAResource() throws ResourceException { ! throw new NotSupportedException("XA transaction not supported"); } public LocalTransaction getLocalTransaction() throws ResourceException { ! return new LocalTransactionImpl(this); } --- 220,266 ---- * Associates the session handle with this managed connection */ ! public void associateConnection(final Object object) ! throws ResourceException ! { ! if (!(object instanceof JCASessionImpl)) { throw new ResourceException( ! "Wrong kind of connection handle to associate " + object); } ! final JCASessionImpl handle = (JCASessionImpl) object; ! if (handle.getManagedConnextion() != this) { ! handle.getManagedConnextion().dissociateConnection(handle); ! handle.setManagedConnection(this); ! synchronized (handles) { ! handles.addFirst(handle); ! } ! } ! } ! ! private void dissociateConnection(final JCASessionImpl handle) { synchronized (handles) { ! handles.remove(handle); } } public void addConnectionEventListener(ConnectionEventListener listener) { ! listeners.add(listener); } public void removeConnectionEventListener(ConnectionEventListener listener) { ! listeners.remove(listener); } public XAResource getXAResource() throws ResourceException { ! return this; } public LocalTransaction getLocalTransaction() throws ResourceException { ! // JCA 1.0, section 6.1.10 ! // both LocalTransaction and XATransaction resource adapters ! // support local transactions ! // At the same time all transactions will enlist at least Hibernate ! // session and database connection, so support for local transactions ! // is really redundant. ! throw new NotSupportedException("LocalTransaction is not supported!"); } *************** *** 229,243 **** return logWriter; } - - public Properties getProps() { - return props; - } ! public void setProps(Properties props) { ! this.props = props; } - // package private level methods ManagedConnectionFactory getManagedConnectionFactory() { --- 276,323 ---- return logWriter; } ! // ! // XAResource implementation ! // ! ! // @todo ! // Currently, XAResource implementation does nothing. In the future, ! // in order to support JCS read-write cache it will be necessary ! // to implement prepare/commit/rollback protocol. ! ! // @todo JCA 6.6.2 ! // RM must ensure that TM invokes XAResource calls in the legal sequence, ! // and must return XAER_PROTO or other suitable error if the caller TM ! // violates the state tables (as defined in Chapter 6 of the XA ! // specification (refer [4]). ! public void commit(Xid arg0, boolean arg1) throws XAException { ! } ! public void end(Xid arg0, int arg1) throws XAException { ! } ! public void forget(Xid arg0) throws XAException { ! } ! public int getTransactionTimeout() throws XAException { ! return 0; ! } ! public boolean isSameRM(XAResource arg0) throws XAException { ! return false; ! } ! public int prepare(Xid arg0) throws XAException { ! return XAResource.XA_RDONLY; ! } ! public Xid[] recover(int arg0) throws XAException { ! return new Xid[0]; ! } ! public void rollback(Xid arg0) throws XAException { ! } ! public boolean setTransactionTimeout(int arg0) throws XAException { ! return false; ! } ! public void start(Xid arg0, int arg1) throws XAException { } + // // package private level methods + // ManagedConnectionFactory getManagedConnectionFactory() { *************** *** 249,253 **** // remove the handle from the collection safely synchronized (handles) { ! handles.remove(handle); } --- 329,333 ---- // remove the handle from the collection safely synchronized (handles) { ! handles.remove(handle); } *************** *** 260,267 **** } - Connection getConnection() { - return connection; - } - void sendEvent(final ConnectionEvent event) { int type = event.getId(); --- 340,343 ---- *************** *** 303,306 **** --- 379,407 ---- } } + } + + Session getSession(JCASessionImpl handle) { + // JCA 1.0, 5.5.4 + // Ensure that there is at most one connection handle associated + // actively with a ManagedConnection instance. [skiped] Any operations + // on the ManagedConnection from any previously created connection + // handles should result in an application level exception. + + // this might be pretty bad for performance, profile and find a + // better way if it is really bad + synchronized (handles) { + if (handles.get(0) == handle) { + return session; + } else { + final String message = "Inactive logical session handle called"; + // cannot throw HibernateException because not all Session + // methods throws it. This is incompatible with the spec! + throw new IllegalStateException(message); + } + } + } + + Connection getConnection() { + return connection; } } Index: ManagedConnectionFactoryImpl.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/jca/ManagedConnectionFactoryImpl.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ManagedConnectionFactoryImpl.java 8 Mar 2003 09:53:35 -0000 1.2 --- ManagedConnectionFactoryImpl.java 1 May 2003 01:59:23 -0000 1.3 *************** *** 3,13 **** import java.io.PrintWriter; import java.io.Serializable; - import java.sql.Connection; - import java.sql.Driver; - import java.sql.DriverManager; import java.util.Iterator; import java.util.Properties; import java.util.Set; import javax.resource.NotSupportedException; import javax.resource.ResourceException; --- 3,13 ---- import java.io.PrintWriter; import java.io.Serializable; import java.util.Iterator; import java.util.Properties; import java.util.Set; + import javax.naming.Context; + import javax.naming.InitialContext; + import javax.naming.NamingException; import javax.resource.NotSupportedException; import javax.resource.ResourceException; *************** *** 16,23 **** import javax.resource.spi.ManagedConnection; import javax.resource.spi.ManagedConnectionFactory; - import javax.resource.spi.security.PasswordCredential; import javax.security.auth.Subject; import net.sf.hibernate.HibernateException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; --- 16,28 ---- import javax.resource.spi.ManagedConnection; import javax.resource.spi.ManagedConnectionFactory; import javax.security.auth.Subject; + import javax.sql.DataSource; import net.sf.hibernate.HibernateException; + import net.sf.hibernate.SessionFactory; + import net.sf.hibernate.cfg.Configuration; + import net.sf.hibernate.cfg.Environment; + import net.sf.hibernate.util.PropertiesHelper; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; *************** *** 31,72 **** implements ManagedConnectionFactory, Serializable { private static final Log log = LogFactory.getLog(ManagedConnectionFactoryImpl.class); ! private String connectionURL; ! private String driverClass; ! private String userName; ! private String password; ! private int transactionIsolation = -1; private String dialect; private String mapResources; - - private Properties connectionProperties = new Properties(); ! private PrintWriter out; ! private boolean driverLoaded; ! public ManagedConnectionFactoryImpl() { ! } /** * Creates a Hibernate SessionFactory for the container * ! * @throws ResourceException can't create Session Factory (thrown with linked exception) */ ! public Object createConnectionFactory(ConnectionManager cxManager) ! throws ResourceException { log("createConnectionFactory with connection manager - " + cxManager); Object obj = null; try { ! obj = new JCASessionFactoryImpl(this, cxManager, dialect, mapResources); } catch (HibernateException hbe) { ! log( ! "Got Hibernate exception when trying to create Connection Factory", ! hbe); ! ResourceException re = ! new ResourceException("Got Hibernate exception when trying to create Connection Factory"); re.setLinkedException(hbe); throw re; --- 36,98 ---- implements ManagedConnectionFactory, Serializable { + /* + * @todo JCA 1.0, 5.10.1 + * A resource adapter is required to provide support for basic error + * logging and tracing by implementing the following methods: + * - ManagedConnectionFactory.set/getLogWriter + * ManagedConnection.set/getLogWriter + */ private static final Log log = LogFactory.getLog(ManagedConnectionFactoryImpl.class); ! // ! // Resource adaptor configuration properties ! // ! ! /** SQL dialect */ private String dialect; + + /** O/R mappings */ private String mapResources; ! /** JNDI name of a datasource */ ! private String datasourceJndi; ! /** Hibernate properties */ ! private String properties; ! // ! // ! // ! private PrintWriter out; ! ! private DataSource datasource; ! ! private SessionFactory sessionFactory; /** * Creates a Hibernate SessionFactory for the container * ! * @throws ResourceException can't create Session Factory ! * (thrown with linked exception) */ ! public Object createConnectionFactory(final ConnectionManager cxManager) ! throws ResourceException ! { log("createConnectionFactory with connection manager - " + cxManager); + + // initialize datasource and session factory + initialize(); + Object obj = null; try { ! obj = new JCASessionFactoryImpl(this, cxManager); } catch (HibernateException hbe) { ! final String message = ! "Got Hibernate exception when trying to create " + ! "Connection Factory"; ! log(message, hbe); ! final ResourceException re = new ResourceException(message); re.setLinkedException(hbe); throw re; *************** *** 76,79 **** --- 102,159 ---- /** + * Initializes datasource (a.k.a JDBC connection factory) and Hibernate + * session factory. This method is synchonized, because a container does + * not have to serialize createConnectionFactory/createManagedConnection + * calls. + */ + private synchronized void initialize() throws ResourceException + { + // locate datasource + if (datasource == null) { + try { + Context ctx = new InitialContext(); + try { + datasource = (DataSource) ctx.lookup(datasourceJndi); + } finally { + ctx.close(); + } + } catch (NamingException e) { + final String message = + "Cannot locate DataSource " + datasourceJndi; + log(message, e); + final ResourceException re = new ResourceException(message); + re.setLinkedException(e); + throw re; + } + } + + // initialize session factory + if (sessionFactory == null) { + try { + final String delim = " ,\n\t\r\f"; + final Properties hibProperties = new Properties(); + // @todo load this.properties + hibProperties.setProperty(Environment.DIALECT, dialect); + + Configuration cfg = new Configuration().addProperties(hibProperties); + + // taken from HibernateService, maybe factor out for JCA 1.5 + String[] mappingFiles = PropertiesHelper.toStringArray(mapResources, delim); + for ( int i=0; i<mappingFiles.length; i++ ) { + cfg.addResource( mappingFiles[i], Thread.currentThread().getContextClassLoader() ); + } + sessionFactory = cfg.buildSessionFactory(); + } catch (HibernateException e) { + final String message = + "Cannot create Hibernate session factory"; + log(message, e); + final ResourceException re = new ResourceException(message); + re.setLinkedException(e); + throw re; + } + } + } + + /** * NOT SUPPORTED * *************** *** 81,139 **** */ public Object createConnectionFactory() throws ResourceException { ! throw new NotSupportedException("Resource Adapter does not support an un-managed environment"); } /** ! * Creates a ManagedConnection and physically a connection to the database ! * ! * Currently only uses username, password, driver class and URL ! * ! * Need to include mapping files, isolation level, dialect etc ! * ! * @throws ResourceException cannot get connection to database */ public ManagedConnection createManagedConnection( ! Subject subject, ! ConnectionRequestInfo info) ! throws ResourceException { ! log("createManagedConnection called"); ! try { ! ! // Also taken from JBoss JDBC JCA Impl ! Properties props = getConnectionProperties(subject, info); ! // Some friendly drivers (Oracle, you guessed right) modify the props you supply. ! // Since we use our copy to identify compatibility in matchManagedConnection, we need ! // a pristine copy for our own use. So give the friendly driver a copy. ! Properties copy = new Properties(); ! copy.putAll(props); ! ! String url = internalGetConnectionURL(); ! checkDriver(url); ! ! Connection con = DriverManager.getConnection(url, copy); ! ! // wait for the begin transaction to turn auto commit off? ! //con.setAutoCommit(false); ! ! return new ManagedConnectionImpl( ! this, ! userName, ! props, ! ((ConnectionRequestInfoImpl) info).getSessionFactory(), ! con); ! ! } catch (Exception ex) { ! log("Got exception when trying to create Managed Connection", ex); ! ResourceException re = ! new ResourceException("Got exception when trying to create Managed Connection"); ! re.setLinkedException(ex); ! throw re; ! } ! } ! public void setLogWriter(PrintWriter out) throws ResourceException { this.out = out; } --- 161,180 ---- */ public Object createConnectionFactory() throws ResourceException { ! throw new NotSupportedException("Resource Adapter does not support " + ! "an un-managed environment"); } /** ! * Creates a ManagedConnection */ public ManagedConnection createManagedConnection( ! final Subject subject, final ConnectionRequestInfo info) ! { log("createManagedConnection called"); ! return new ManagedConnectionImpl(this); } ! public void setLogWriter(final PrintWriter out) throws ResourceException { this.out = out; } *************** *** 143,251 **** } ! public ManagedConnection matchManagedConnections( ! Set mcs, ! Subject subject, ! ConnectionRequestInfo cri) ! throws ResourceException { ! Properties newProps = getConnectionProperties(subject, cri); for (Iterator i = mcs.iterator(); i.hasNext();) { Object o = i.next(); if (o instanceof ManagedConnectionImpl) { ! ManagedConnectionImpl mc = (ManagedConnectionImpl) o; ! if (mc.getProps().equals(newProps) /*&& mc.checkValid()*/ ! ) // JBoss method to check validity of connection by executing some SQL ! { ! return mc; ! } // end of if () ! ! } // end of if () ! } // end of for () return null; } /** ! * * @return hashcode computed according to recommendations in Effective Java. */ public int hashCode() { int result = 17; ! result = ! result * 37 ! + ((connectionURL == null) ? 0 : connectionURL.hashCode()); ! result = ! result * 37 + ((driverClass == null) ? 0 : driverClass.hashCode()); ! result = result * 37 + ((userName == null) ? 0 : userName.hashCode()); ! result = result * 37 + ((password == null) ? 0 : password.hashCode()); result = result * 37 + ((dialect == null) ? 0 : dialect.hashCode()); result = result * 37 + ((mapResources == null) ? 0 : mapResources.hashCode()); ! result = result * 37 + transactionIsolation; return result; } /** ! * ! * @param param1 <description> ! * @return <description> */ ! public boolean equals(Object other) { ! if (this == other) { return true; ! } // end of if () ! if (getClass() != other.getClass()) { ! return false; ! } // end of if () ! ManagedConnectionFactoryImpl otherMcf = ! (ManagedConnectionFactoryImpl) other; ! return this.connectionURL.equals(otherMcf.connectionURL) ! && this.driverClass.equals(otherMcf.driverClass) ! && ((this.mapResources == null) ! ? otherMcf.mapResources == null ! : this.mapResources.equals(otherMcf.mapResources)) ! && ((this.dialect == null) ! ? otherMcf.dialect == null ! : this.dialect.equals(otherMcf.dialect)) ! && ((this.userName == null) ! ? otherMcf.userName == null ! : this.userName.equals(otherMcf.userName)) ! && ((this.password == null) ! ? otherMcf.password == null ! : this.password.equals(otherMcf.password)) ! && this.transactionIsolation == otherMcf.transactionIsolation; ! ! } ! ! public String getDriverClass() { ! return driverClass; ! } ! ! public String getPassword() { ! return password; ! } ! ! public String getUserName() { ! return userName; ! } ! ! public void setDriverClass(String driverClass) { ! this.driverClass = driverClass; ! this.driverLoaded = false; ! } ! ! public void setPassword(String password) { ! this.password = password; } ! public void setUserName(String username) { ! this.userName = username; } ! public String getConnectionURL() { ! return connectionURL; } - public void setConnectionURL(String url) { - this.connectionURL = url; - } - public String getDialect() { return dialect; --- 184,251 ---- } ! public ManagedConnection matchManagedConnections(final Set mcs, ! final Subject subject, final ConnectionRequestInfo cri) ! throws ResourceException ! { for (Iterator i = mcs.iterator(); i.hasNext();) { Object o = i.next(); if (o instanceof ManagedConnectionImpl) { ! // all idle connections are identical ! return (ManagedConnectionImpl) o; ! } ! } return null; } /** ! * JCA 1.0, 5.5.3 ! * It is required that the ManagedConnectionFactory implementation class ! * extend the implementation of the hashCode and equals methods defined ! * in the java.lang.Object class. ! * * @return hashcode computed according to recommendations in Effective Java. */ public int hashCode() { int result = 17; ! result = result * 37 + ((datasourceJndi == null) ? 0 : datasourceJndi.hashCode()); result = result * 37 + ((dialect == null) ? 0 : dialect.hashCode()); result = result * 37 + ((mapResources == null) ? 0 : mapResources.hashCode()); ! result = result * 37 + ((properties == null) ? 0 : properties.hashCode()); return result; } /** ! * JCA 1.0, 5.5.3 ! * It is required that the ManagedConnectionFactory implementation class ! * extend the implementation of the hashCode and equals methods defined ! * in the java.lang.Object class. ! * ! * @return if object is equals based on a complete set of configuration ! * properties. */ ! public boolean equals(final Object object) { ! if (this == object) { return true; ! } ! boolean result = false; ! if (object instanceof ManagedConnectionFactoryImpl) { ! final ManagedConnectionFactoryImpl other = ! (ManagedConnectionFactoryImpl) object; ! result = equals(datasourceJndi, other.datasourceJndi) && ! equals(dialect, other.dialect) && ! equals(mapResources, other.mapResources) && ! equals(properties, other.properties); ! } ! return result; } ! public void setDatasourceJndi(String datasourceJndi) { ! this.datasourceJndi = datasourceJndi; } ! public String getDatasourceJndi() { ! return datasourceJndi; } public String getDialect() { return dialect; *************** *** 264,319 **** } ! public Properties getConnectionProperties() { ! return connectionProperties; } ! public void setConnectionProperties(Properties connectionProperties) { ! this.connectionProperties = connectionProperties; } ! public String getTransactionIsolation() { ! switch (this.transactionIsolation) { ! case Connection.TRANSACTION_NONE : ! return "TRANSACTION_NONE"; ! case Connection.TRANSACTION_READ_COMMITTED : ! return "TRANSACTION_READ_COMMITTED"; ! case Connection.TRANSACTION_READ_UNCOMMITTED : ! return "TRANSACTION_READ_UNCOMMITTED"; ! case Connection.TRANSACTION_REPEATABLE_READ : ! return "TRANSACTION_REPEATABLE_READ"; ! case Connection.TRANSACTION_SERIALIZABLE : ! return "TRANSACTION_SERIALIZABLE"; ! case -1 : ! return "DEFAULT"; ! default : ! return Integer.toString(transactionIsolation); ! } } ! public void setTransactionIsolation(String transactionIsolation) { ! if (transactionIsolation.equals("TRANSACTION_NONE")) { ! this.transactionIsolation = Connection.TRANSACTION_NONE; ! } else if (transactionIsolation.equals("TRANSACTION_READ_COMMITTED")) { ! this.transactionIsolation = Connection.TRANSACTION_READ_COMMITTED; ! } else if ( ! transactionIsolation.equals("TRANSACTION_READ_UNCOMMITTED")) { ! this.transactionIsolation = Connection.TRANSACTION_READ_UNCOMMITTED; ! } else if ( ! transactionIsolation.equals("TRANSACTION_REPEATABLE_READ")) { ! this.transactionIsolation = Connection.TRANSACTION_REPEATABLE_READ; ! } else if (transactionIsolation.equals("TRANSACTION_SERIALIZABLE")) { ! this.transactionIsolation = Connection.TRANSACTION_SERIALIZABLE; ! } else { ! try { ! this.transactionIsolation = ! Integer.parseInt(transactionIsolation); ! } catch (NumberFormatException nfe) { ! throw new IllegalArgumentException( ! "Setting Isolation level to unknown state: " ! + transactionIsolation); ! } ! } } private void log(String message) { log(message, null); --- 264,291 ---- } ! public String getHibernateProperties() { ! return properties; } ! public void setHibernateProperties(final String properties) { ! this.properties = properties; } ! // ! // Package private methods ! // ! ! DataSource getDatasource() { ! return datasource; } ! SessionFactory getSessionFactory() { ! return sessionFactory; } + // + // Private methods + // + private void log(String message) { log(message, null); *************** *** 321,325 **** private void log(String message, Throwable t) { - // log to provided output if set by app server // assumes to log error if an exception is provided --- 293,296 ---- *************** *** 335,474 **** log.info(message); } - - } - - // taken from JBoss JCA impl - - /** - * Check the driver for the given URL. If it is not registered already - * then register it. - * - * @param url The JDBC URL which we need a driver for. - */ - protected void checkDriver(final String url) throws ResourceException { - // don't bother if it is loaded already - if (driverLoaded) { - return; - } - log.debug("Checking driver for URL: " + url); - - if (driverClass == null) { - throw new ResourceException("No Driver class specified!"); - } - - // Check if the driver is already loaded, if not then try to load it - - if (isDriverLoadedForURL(url)) { - driverLoaded = true; - return; - } // end of if () - - try { - //try to load the class... this should register with DriverManager. - Class clazz = - Thread.currentThread().getContextClassLoader().loadClass( - driverClass); - if (isDriverLoadedForURL(url)) { - driverLoaded = true; - //return immediately, some drivers (Cloudscape) do not let you create an instance. - return; - } // end of if () - //We loaded the class, but either it didn't register - //and is not spec compliant, or is the wrong class. - Driver driver = (Driver) clazz.newInstance(); - DriverManager.registerDriver(driver); - if (isDriverLoadedForURL(url)) { - driverLoaded = true; - return; - } // end of if () - //We can even instantiate one, it must be the wrong class for the URL. - } catch (Exception e) { - ResourceException re = - new ResourceException( - "Failed to register driver for: " + driverClass); - re.setLinkedException(e); - throw re; - } - - throw new ResourceException( - "Apparently wrong driver class specified for URL: class: " - + driverClass - + ", url: " - + url); - } - - private boolean isDriverLoadedForURL(String url) { - try { - DriverManager.getDriver(url); - log.debug("Driver already registered for url: " + url); - return true; - } catch (Exception e) { - log.debug("Driver not yet registered for url: " + url); - return false; - } // end of try-catch - } - - protected String internalGetConnectionURL() { - return connectionURL; } /** ! * Gets full set of connection properties, i.e. whatever is provided ! * in config plus "user" and "password" from subject/cri. ! * ! * <p>Note that the set is used to match connections to datasources as well ! * as to create new managed connections. ! * ! * <p>In fact, we have a problem here. Theoretically, there is a possible ! * name collision between config properties and "user"/"password". */ ! protected Properties getConnectionProperties( ! Subject subject, ! ConnectionRequestInfo cri) ! throws ResourceException { ! if (cri != null && cri.getClass() != ConnectionRequestInfoImpl.class) { ! throw new ResourceException( ! "Wrong kind of ConnectionRequestInfo: " + cri.getClass()); ! } // end of if () ! ! Properties props = new Properties(); ! props.putAll(connectionProperties); ! if (subject != null) { ! for (Iterator i = subject.getPrivateCredentials().iterator(); ! i.hasNext(); ! ) { ! Object o = i.next(); ! if (o instanceof PasswordCredential ! && ((PasswordCredential) o) ! .getManagedConnectionFactory() ! .equals( ! this)) { ! PasswordCredential cred = (PasswordCredential) o; ! props.setProperty( ! "user", ! (cred.getUserName() == null) ? "" : cred.getUserName()); ! props.setProperty( ! "password", ! new String(cred.getPassword())); ! return props; ! } // end of if () ! } // end of for () ! throw new ResourceException("No matching credentials in Subject!"); ! } // end of if () ! ConnectionRequestInfoImpl lcri = (ConnectionRequestInfoImpl) cri; ! if (lcri != null) { ! props.setProperty( ! "user", ! (lcri.getUserName() == null) ? "" : lcri.getUserName()); ! props.setProperty( ! "password", ! (lcri.getPassword() == null) ? "" : lcri.getPassword()); ! return props; ! } // end of if () ! if (userName != null) { ! props.setProperty("user", userName); ! props.setProperty("password", (password == null) ? "" : password); } - return props; } } --- 306,323 ---- log.info(message); } } /** ! * Compares two objects assuming that <code>null</code> equals to ! * <code>null</code> */ ! private boolean equals(final Object o1, final Object o2) { ! if (o1 == o2) { ! return true; ! } else if (o1 != null) { ! return o1.equals(o2); ! } else { ! re... [truncated message content] |