HHH-6117 - Figure out best way to handle SessionFactoryObjectFactory dealing with JNDI
This commit is contained in:
parent
d631671761
commit
88172d1fb0
|
@ -23,7 +23,6 @@
|
|||
*/
|
||||
package org.hibernate.internal;
|
||||
|
||||
import javax.naming.InvalidNameException;
|
||||
import javax.naming.NameNotFoundException;
|
||||
import javax.naming.NamingException;
|
||||
import javax.transaction.Synchronization;
|
||||
|
@ -439,10 +438,6 @@ public interface CoreMessageLogger extends BasicLogger {
|
|||
@Message( value = "Could not bind JNDI listener", id = 127 )
|
||||
void couldNotBindJndiListener();
|
||||
|
||||
@LogMessage( level = WARN )
|
||||
@Message( value = "InitialContext did not implement EventContext", id = 128 )
|
||||
void initialContextDoesNotImplementEventContext();
|
||||
|
||||
@LogMessage( level = INFO )
|
||||
@Message( value = "Instantiating explicit connection provider: %s", id = 130 )
|
||||
void instantiatingExplicitConnectionProvider(String providerClassName);
|
||||
|
@ -900,7 +895,7 @@ public interface CoreMessageLogger extends BasicLogger {
|
|||
|
||||
@LogMessage( level = WARN )
|
||||
@Message( value = "Could not bind Ejb3Configuration to JNDI", id = 276 )
|
||||
void unableToBindEjb3ConfigurationToJndi( @Cause NamingException e );
|
||||
void unableToBindEjb3ConfigurationToJndi( @Cause JndiException e );
|
||||
|
||||
@LogMessage( level = WARN )
|
||||
@Message( value = "Could not bind factory to JNDI", id = 277 )
|
||||
|
|
|
@ -22,19 +22,19 @@
|
|||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.ejb.util;
|
||||
import javax.naming.Context;
|
||||
import javax.naming.InvalidNameException;
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.event.EventContext;
|
||||
|
||||
import javax.naming.event.NamespaceChangeListener;
|
||||
import javax.naming.event.NamingEvent;
|
||||
import javax.naming.event.NamingExceptionEvent;
|
||||
import javax.naming.event.NamingListener;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import org.hibernate.ejb.AvailableSettings;
|
||||
import org.hibernate.ejb.Ejb3Configuration;
|
||||
import org.hibernate.ejb.internal.EntityManagerMessageLogger;
|
||||
import org.hibernate.internal.util.jndi.JndiHelper;
|
||||
import org.jboss.logging.Logger;
|
||||
import org.hibernate.service.jndi.JndiException;
|
||||
import org.hibernate.service.jndi.JndiNameException;
|
||||
import org.hibernate.service.jndi.internal.JndiServiceImpl;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
|
@ -44,32 +44,36 @@ public class NamingHelper {
|
|||
|
||||
private static final EntityManagerMessageLogger LOG = Logger.getMessageLogger(EntityManagerMessageLogger.class, NamingHelper.class.getName());
|
||||
|
||||
/** bind the configuration to the JNDI */
|
||||
public static void bind(Ejb3Configuration cfg) {
|
||||
String name = cfg.getHibernateConfiguration().getProperty( AvailableSettings.CONFIGURATION_JNDI_NAME );
|
||||
if (name == null) LOG.debugf("No JNDI name configured for binding Ejb3Configuration");
|
||||
if ( name == null ) {
|
||||
LOG.debug( "No JNDI name configured for binding Ejb3Configuration" );
|
||||
}
|
||||
else {
|
||||
LOG.ejb3ConfigurationName(name);
|
||||
LOG.ejb3ConfigurationName( name );
|
||||
|
||||
// todo : instantiating the JndiService here is temporary until HHH-6159 is resolved.
|
||||
JndiServiceImpl jndiService = new JndiServiceImpl( cfg.getProperties() );
|
||||
try {
|
||||
Context ctx = JndiHelper.getInitialContext( cfg.getProperties() );
|
||||
JndiHelper.bind( ctx, name, cfg );
|
||||
LOG.boundEjb3ConfigurationToJndiName(name);
|
||||
( (EventContext) ctx ).addNamingListener( name, EventContext.OBJECT_SCOPE, LISTENER );
|
||||
jndiService.bind( name, cfg );
|
||||
LOG.boundEjb3ConfigurationToJndiName( name );
|
||||
try {
|
||||
jndiService.addListener( name, LISTENER );
|
||||
}
|
||||
catch (InvalidNameException ine) {
|
||||
LOG.invalidJndiName(name, ine);
|
||||
catch (Exception e) {
|
||||
LOG.couldNotBindJndiListener();
|
||||
}
|
||||
catch (NamingException ne) {
|
||||
LOG.unableToBindEjb3ConfigurationToJndi(ne);
|
||||
}
|
||||
catch (ClassCastException cce) {
|
||||
LOG.initialContextDoesNotImplementEventContext();
|
||||
catch (JndiNameException e) {
|
||||
LOG.invalidJndiName( name, e );
|
||||
}
|
||||
catch (JndiException e) {
|
||||
LOG.unableToBindEjb3ConfigurationToJndi( e );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static final NamingListener LISTENER = new NamespaceChangeListener() {
|
||||
private static final NamespaceChangeListener LISTENER = new NamespaceChangeListener() {
|
||||
public void objectAdded(NamingEvent evt) {
|
||||
LOG.debugf("An Ejb3Configuration was successfully bound to name: %s", evt.getNewBinding().getName());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue