Search in sources :

Example 1 with PersistenceManagerFactoryImpl

use of com.sun.jdo.spi.persistence.support.sqlstore.impl.PersistenceManagerFactoryImpl in project Payara by payara.

the class SunContainerHelper method getPersistenceManagerFactory.

/**
 * Called in a CMP environment to lookup PersistenceManagerFactory
 * referenced by this Container instance as the CMP resource.
 *
 * This is SunContainerHelper specific code.
 *
 * @see getContainer(Object)
 * @param container a Container instance for the request.
 */
public PersistenceManagerFactory getPersistenceManagerFactory(Object container) {
    Object rc = null;
    PersistenceManagerFactoryImpl pmf = null;
    ResourceReferenceDescriptor cmpResource = ((Container) container).getEjbDescriptor().getEjbBundleDescriptor().getCMPResourceReference();
    String name = cmpResource.getJndiName();
    try {
        InitialContext ic = new InitialContext();
        rc = ic.lookup(name);
        if (rc instanceof PersistenceManagerFactoryImpl) {
            pmf = (PersistenceManagerFactoryImpl) rc;
        } else if (rc instanceof javax.sql.DataSource) {
            pmf = new PersistenceManagerFactoryImpl();
            pmf.setConnectionFactoryName(ConnectorsUtil.getPMJndiName(name));
            Iterator it = cmpResource.getProperties();
            if (it != null) {
                while (it.hasNext()) {
                    NameValuePairDescriptor prop = (NameValuePairDescriptor) it.next();
                    String n = prop.getName();
                    // Any value that is not "true" is treated as "false":
                    boolean value = Boolean.valueOf(prop.getValue()).booleanValue();
                    pmf.setBooleanProperty(n, value);
                }
            }
        } else {
            RuntimeException e = new JDOFatalUserException(I18NHelper.getMessage(// NOI18N
            messages, // NOI18N
            "ejb.jndi.unexpectedinstance", name, rc.getClass().getName()));
            logger.severe(e.toString());
            throw e;
        }
    } catch (javax.naming.NamingException ex) {
        RuntimeException e = new JDOFatalUserException(I18NHelper.getMessage(messages, "ejb.jndi.lookupfailed", name), // NOI18N
        ex);
        logger.severe(e.toString());
        throw e;
    }
    return pmf;
}
Also used : JDOFatalUserException(com.sun.jdo.api.persistence.support.JDOFatalUserException) NamingException(javax.naming.NamingException) InitialContext(javax.naming.InitialContext) PersistenceManagerFactoryImpl(com.sun.jdo.spi.persistence.support.sqlstore.impl.PersistenceManagerFactoryImpl) Container(com.sun.ejb.Container) DataSource(javax.sql.DataSource) Iterator(java.util.Iterator) EJBObject(javax.ejb.EJBObject) EJBLocalObject(javax.ejb.EJBLocalObject)

Aggregations

Container (com.sun.ejb.Container)1 JDOFatalUserException (com.sun.jdo.api.persistence.support.JDOFatalUserException)1 PersistenceManagerFactoryImpl (com.sun.jdo.spi.persistence.support.sqlstore.impl.PersistenceManagerFactoryImpl)1 Iterator (java.util.Iterator)1 EJBLocalObject (javax.ejb.EJBLocalObject)1 EJBObject (javax.ejb.EJBObject)1 InitialContext (javax.naming.InitialContext)1 NamingException (javax.naming.NamingException)1 DataSource (javax.sql.DataSource)1