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;
|
package org.hibernate.internal;
|
||||||
|
|
||||||
import javax.naming.InvalidNameException;
|
|
||||||
import javax.naming.NameNotFoundException;
|
import javax.naming.NameNotFoundException;
|
||||||
import javax.naming.NamingException;
|
import javax.naming.NamingException;
|
||||||
import javax.transaction.Synchronization;
|
import javax.transaction.Synchronization;
|
||||||
|
@ -439,10 +438,6 @@ public interface CoreMessageLogger extends BasicLogger {
|
||||||
@Message( value = "Could not bind JNDI listener", id = 127 )
|
@Message( value = "Could not bind JNDI listener", id = 127 )
|
||||||
void couldNotBindJndiListener();
|
void couldNotBindJndiListener();
|
||||||
|
|
||||||
@LogMessage( level = WARN )
|
|
||||||
@Message( value = "InitialContext did not implement EventContext", id = 128 )
|
|
||||||
void initialContextDoesNotImplementEventContext();
|
|
||||||
|
|
||||||
@LogMessage( level = INFO )
|
@LogMessage( level = INFO )
|
||||||
@Message( value = "Instantiating explicit connection provider: %s", id = 130 )
|
@Message( value = "Instantiating explicit connection provider: %s", id = 130 )
|
||||||
void instantiatingExplicitConnectionProvider(String providerClassName);
|
void instantiatingExplicitConnectionProvider(String providerClassName);
|
||||||
|
@ -900,7 +895,7 @@ public interface CoreMessageLogger extends BasicLogger {
|
||||||
|
|
||||||
@LogMessage( level = WARN )
|
@LogMessage( level = WARN )
|
||||||
@Message( value = "Could not bind Ejb3Configuration to JNDI", id = 276 )
|
@Message( value = "Could not bind Ejb3Configuration to JNDI", id = 276 )
|
||||||
void unableToBindEjb3ConfigurationToJndi( @Cause NamingException e );
|
void unableToBindEjb3ConfigurationToJndi( @Cause JndiException e );
|
||||||
|
|
||||||
@LogMessage( level = WARN )
|
@LogMessage( level = WARN )
|
||||||
@Message( value = "Could not bind factory to JNDI", id = 277 )
|
@Message( value = "Could not bind factory to JNDI", id = 277 )
|
||||||
|
|
|
@ -22,19 +22,19 @@
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.ejb.util;
|
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.NamespaceChangeListener;
|
||||||
import javax.naming.event.NamingEvent;
|
import javax.naming.event.NamingEvent;
|
||||||
import javax.naming.event.NamingExceptionEvent;
|
import javax.naming.event.NamingExceptionEvent;
|
||||||
import javax.naming.event.NamingListener;
|
|
||||||
|
import org.jboss.logging.Logger;
|
||||||
|
|
||||||
import org.hibernate.ejb.AvailableSettings;
|
import org.hibernate.ejb.AvailableSettings;
|
||||||
import org.hibernate.ejb.Ejb3Configuration;
|
import org.hibernate.ejb.Ejb3Configuration;
|
||||||
import org.hibernate.ejb.internal.EntityManagerMessageLogger;
|
import org.hibernate.ejb.internal.EntityManagerMessageLogger;
|
||||||
import org.hibernate.internal.util.jndi.JndiHelper;
|
import org.hibernate.service.jndi.JndiException;
|
||||||
import org.jboss.logging.Logger;
|
import org.hibernate.service.jndi.JndiNameException;
|
||||||
|
import org.hibernate.service.jndi.internal.JndiServiceImpl;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
|
@ -44,32 +44,36 @@ public class NamingHelper {
|
||||||
|
|
||||||
private static final EntityManagerMessageLogger LOG = Logger.getMessageLogger(EntityManagerMessageLogger.class, NamingHelper.class.getName());
|
private static final EntityManagerMessageLogger LOG = Logger.getMessageLogger(EntityManagerMessageLogger.class, NamingHelper.class.getName());
|
||||||
|
|
||||||
/** bind the configuration to the JNDI */
|
|
||||||
public static void bind(Ejb3Configuration cfg) {
|
public static void bind(Ejb3Configuration cfg) {
|
||||||
String name = cfg.getHibernateConfiguration().getProperty( AvailableSettings.CONFIGURATION_JNDI_NAME );
|
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 {
|
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 {
|
try {
|
||||||
Context ctx = JndiHelper.getInitialContext( cfg.getProperties() );
|
jndiService.bind( name, cfg );
|
||||||
JndiHelper.bind( ctx, name, cfg );
|
LOG.boundEjb3ConfigurationToJndiName( name );
|
||||||
LOG.boundEjb3ConfigurationToJndiName(name);
|
try {
|
||||||
( (EventContext) ctx ).addNamingListener( name, EventContext.OBJECT_SCOPE, LISTENER );
|
jndiService.addListener( name, LISTENER );
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
LOG.couldNotBindJndiListener();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (InvalidNameException ine) {
|
catch (JndiNameException e) {
|
||||||
LOG.invalidJndiName(name, ine);
|
LOG.invalidJndiName( name, e );
|
||||||
}
|
}
|
||||||
catch (NamingException ne) {
|
catch (JndiException e) {
|
||||||
LOG.unableToBindEjb3ConfigurationToJndi(ne);
|
LOG.unableToBindEjb3ConfigurationToJndi( e );
|
||||||
}
|
|
||||||
catch (ClassCastException cce) {
|
|
||||||
LOG.initialContextDoesNotImplementEventContext();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final NamingListener LISTENER = new NamespaceChangeListener() {
|
private static final NamespaceChangeListener LISTENER = new NamespaceChangeListener() {
|
||||||
public void objectAdded(NamingEvent evt) {
|
public void objectAdded(NamingEvent evt) {
|
||||||
LOG.debugf("An Ejb3Configuration was successfully bound to name: %s", evt.getNewBinding().getName());
|
LOG.debugf("An Ejb3Configuration was successfully bound to name: %s", evt.getNewBinding().getName());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue