Search in sources :

Example 1 with CloseableDataSource

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;
}
Also used : InvalidNameException(javax.naming.InvalidNameException) NameNotFoundException(javax.naming.NameNotFoundException) Reference(javax.naming.Reference) NamingException(javax.naming.NamingException) CloseableDataSource(org.exoplatform.services.jdbc.impl.CloseableDataSource) NameAlreadyBoundException(javax.naming.NameAlreadyBoundException) NamingException(javax.naming.NamingException) OperationNotSupportedException(javax.naming.OperationNotSupportedException) InvalidNameException(javax.naming.InvalidNameException) NameNotFoundException(javax.naming.NameNotFoundException) CloseableDataSource(org.exoplatform.services.jdbc.impl.CloseableDataSource) DataSource(javax.sql.DataSource)

Aggregations

InvalidNameException (javax.naming.InvalidNameException)1 NameAlreadyBoundException (javax.naming.NameAlreadyBoundException)1 NameNotFoundException (javax.naming.NameNotFoundException)1 NamingException (javax.naming.NamingException)1 OperationNotSupportedException (javax.naming.OperationNotSupportedException)1 Reference (javax.naming.Reference)1 DataSource (javax.sql.DataSource)1 CloseableDataSource (org.exoplatform.services.jdbc.impl.CloseableDataSource)1