use of org.exoplatform.services.jdbc.impl.CloseableDataSource in project kernel by exoplatform.
the class SimpleContext method lookup.
/**
* {@inheritDoc}
*/
public Object lookup(String name) throws NamingException {
if (name.isEmpty()) {
throw new InvalidNameException("Cannot bind empty name");
}
Object obj = getBindings().get(name);
if (obj instanceof Reference) {
synchronized (obj) {
obj = getBindings().get(name);
if (obj instanceof Reference) {
try {
obj = NamingManager.getObjectInstance(obj, NAME_PARSER.parse(name), this, getInternalEnv());
if (obj instanceof DataSource) {
obj = new CloseableDataSource((DataSource) obj);
}
// Re-bind with the object with its new value to be able to return the same ins
bindRefValue(name, obj);
} catch (Exception e) {
LOG.error(e.getLocalizedMessage(), e);
NamingException ne = new NamingException("getObjectInstance failed");
ne.setRootCause(e);
throw ne;
}
}
}
} else if (obj == null) {
throw new NameNotFoundException("No object has been binded with the name '" + name + "'");
}
return obj;
}
Aggregations