SessionFactoryObjectFactorypublic class SessionFactoryObjectFactory extends Object implements ObjectFactoryResolves SessionFactory JNDI lookups and deserialization |
Fields Summary |
---|
private static final SessionFactoryObjectFactory | INSTANCE | private static final Log | log | private static final org.hibernate.util.FastHashMap | INSTANCES | private static final org.hibernate.util.FastHashMap | NAMED_INSTANCES | private static final NamingListener | LISTENER |
Methods Summary |
---|
public static void | addInstance(java.lang.String uid, java.lang.String name, org.hibernate.SessionFactory instance, java.util.Properties properties)
log.debug("registered: " + uid + " (" + ( (name==null) ? "unnamed" : name ) + ')");
INSTANCES.put(uid, instance);
if (name!=null) NAMED_INSTANCES.put(name, instance);
//must add to JNDI _after_ adding to HashMaps, because some JNDI servers use serialization
if (name==null) {
log.info("Not binding factory to JNDI, no JNDI name configured");
}
else {
log.info("Factory name: " + name);
try {
Context ctx = NamingHelper.getInitialContext(properties);
NamingHelper.bind(ctx, name, instance);
log.info("Bound factory to JNDI name: " + name);
( (EventContext) ctx ).addNamingListener(name, EventContext.OBJECT_SCOPE, LISTENER);
}
catch (InvalidNameException ine) {
log.error("Invalid JNDI name: " + name, ine);
}
catch (NamingException ne) {
log.warn("Could not bind factory to JNDI", ne);
}
catch(ClassCastException cce) {
log.warn("InitialContext did not implement EventContext");
}
}
| public static java.lang.Object | getInstance(java.lang.String uid)
log.debug("lookup: uid=" + uid);
Object result = INSTANCES.get(uid);
if (result==null) {
log.debug("Not found: " + uid);
log.debug(INSTANCES);
}
return result;
| public static java.lang.Object | getNamedInstance(java.lang.String name)
log.debug("lookup: name=" + name);
Object result = NAMED_INSTANCES.get(name);
if (result==null) {
log.debug("Not found: " + name);
log.debug(NAMED_INSTANCES);
}
return result;
| public java.lang.Object | getObjectInstance(java.lang.Object reference, javax.naming.Name name, javax.naming.Context ctx, java.util.Hashtable env)
log.debug("JNDI lookup: " + name);
String uid = (String) ( (Reference) reference ).get(0).getContent();
return getInstance(uid);
| public static void | removeInstance(java.lang.String uid, java.lang.String name, java.util.Properties properties)
//TODO: theoretically non-threadsafe...
if (name!=null) {
log.info("Unbinding factory from JNDI name: " + name);
try {
Context ctx = NamingHelper.getInitialContext(properties);
ctx.unbind(name);
log.info("Unbound factory from JNDI name: " + name);
}
catch (InvalidNameException ine) {
log.error("Invalid JNDI name: " + name, ine);
}
catch (NamingException ne) {
log.warn("Could not unbind factory from JNDI", ne);
}
NAMED_INSTANCES.remove(name);
}
INSTANCES.remove(uid);
|
|