Search in sources :

Example 1 with JDOFatalUserException

use of com.sun.jdo.api.persistence.support.JDOFatalUserException in project Payara by payara.

the class DBVendorType method newSpecialDBOperationInstance.

/**
 * Returns new instance of class specified by specialDBOpClassName.
 * The class is required to implement interface SpecialDBOperation.
 * If specialDBOpClassName is null or cannot be loaded, then an instance
 * of BaseSpecialDBOperation is returned.
 * @param specialDBOpClassName Name of a class that implements
 * SpecialDBOperation
 * @param databaseMetaData DatabaseMetaData for the connection for which
 * this SpecialDBOperation is created
 * @param identifier Identifier of pmf used to obtain databaseMetaData.
 * This can be null in non managed environment.
 * @return An instance of SpecialDBOperation specified by specialDBOpClassName.
 */
private SpecialDBOperation newSpecialDBOperationInstance(final String specialDBOpClassName, DatabaseMetaData databaseMetaData, String identifier) {
    SpecialDBOperation retInstance = null;
    if (specialDBOpClassName != null) {
        final ClassLoader loader = DBVendorType.class.getClassLoader();
        Class clz = (Class) java.security.AccessController.doPrivileged(new java.security.PrivilegedAction() {

            public Object run() {
                try {
                    if (loader != null) {
                        return Class.forName(specialDBOpClassName, true, loader);
                    } else {
                        return Class.forName(specialDBOpClassName);
                    }
                } catch (Exception ex) {
                    if (logger.isLoggable()) {
                        logger.log(Logger.INFO, // NOI18N
                        "core.configuration.cantloadclass", specialDBOpClassName);
                    }
                    return null;
                }
            }
        });
        if (clz != null) {
            try {
                retInstance = (SpecialDBOperation) clz.newInstance();
                retInstance.initialize(databaseMetaData, identifier);
            } catch (Exception ex) {
                throw new JDOFatalUserException(I18NHelper.getMessage(messages, // NOI18N
                "sqlstore.database.dbvendor.cantinstantiateclass", specialDBOpClassName), ex);
            }
        }
    }
    return (retInstance != null) ? retInstance : DEFAULT_SPECIAL_DB_OPERATION;
}
Also used : JDOFatalUserException(com.sun.jdo.api.persistence.support.JDOFatalUserException) SpecialDBOperation(com.sun.jdo.api.persistence.support.SpecialDBOperation) JDOFatalUserException(com.sun.jdo.api.persistence.support.JDOFatalUserException) JDOUserException(com.sun.jdo.api.persistence.support.JDOUserException) IOException(java.io.IOException) SQLException(java.sql.SQLException) JDOFatalInternalException(com.sun.jdo.api.persistence.support.JDOFatalInternalException)

Example 2 with JDOFatalUserException

use of com.sun.jdo.api.persistence.support.JDOFatalUserException in project Payara by payara.

the class DeploymentHelper method getConnection.

/**
 * Get a Connection from the resource specified by the JNDI name
 * of a CMP resource.
 * This connection is aquired from a non-transactional resource which does not
 * go through transaction enlistment/delistment.
 * The deployment processing is required to use only those connections.
 *
 * @param name JNDI name of a cmp-resource for the connection.
 * @return a Connection.
 * @throws JDOFatalUserException if name cannot be looked up, or we
 * cannot get a connection based on the name.
 * @throws SQLException if can not get a Connection.
 */
public static Connection getConnection(String name) throws SQLException {
    if (logger.isLoggable(logger.FINE)) {
        // NOI18N
        logger.fine("ejb.DeploymentHelper.getconnection", name);
    }
    // TODO - pass Habitat or ConnectorRuntime as an argument.
    ServiceLocator habitat = Globals.getDefaultHabitat();
    DataSource ds = null;
    try {
        ConnectorRuntime connectorRuntime = habitat.getService(ConnectorRuntime.class);
        ds = DataSource.class.cast(connectorRuntime.lookupNonTxResource(name, true));
    } catch (Exception e) {
        throw new JDOFatalUserException(I18NHelper.getMessage(messages, "ejb.jndi.lookupfailed", // NOI18N
        name));
    }
    return ds.getConnection();
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator) JDOFatalUserException(com.sun.jdo.api.persistence.support.JDOFatalUserException) JDOFatalUserException(com.sun.jdo.api.persistence.support.JDOFatalUserException) SQLException(java.sql.SQLException) DataSource(javax.sql.DataSource) ConnectorRuntime(com.sun.appserv.connectors.internal.api.ConnectorRuntime)

Example 3 with JDOFatalUserException

use of com.sun.jdo.api.persistence.support.JDOFatalUserException 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)

Example 4 with JDOFatalUserException

use of com.sun.jdo.api.persistence.support.JDOFatalUserException in project Payara by payara.

the class FieldDesc method setupDesc.

// 
// ------------ Initialisation methods ------------
// 
void setupDesc(final Class classType, final String name) {
    Field f = (Field) java.security.AccessController.doPrivileged(new java.security.PrivilegedAction() {

        public Object run() {
            try {
                return classType.getDeclaredField(name);
            } catch (NoSuchFieldException e) {
                throw new JDOFatalUserException(I18NHelper.getMessage(messages, // NOI18N
                "core.configuration.loadfailed.field", name, classType.getName()), e);
            }
        }
    });
    setupDesc(f);
}
Also used : JDOFatalUserException(com.sun.jdo.api.persistence.support.JDOFatalUserException) Field(java.lang.reflect.Field)

Aggregations

JDOFatalUserException (com.sun.jdo.api.persistence.support.JDOFatalUserException)4 SQLException (java.sql.SQLException)2 DataSource (javax.sql.DataSource)2 ConnectorRuntime (com.sun.appserv.connectors.internal.api.ConnectorRuntime)1 Container (com.sun.ejb.Container)1 JDOFatalInternalException (com.sun.jdo.api.persistence.support.JDOFatalInternalException)1 JDOUserException (com.sun.jdo.api.persistence.support.JDOUserException)1 SpecialDBOperation (com.sun.jdo.api.persistence.support.SpecialDBOperation)1 PersistenceManagerFactoryImpl (com.sun.jdo.spi.persistence.support.sqlstore.impl.PersistenceManagerFactoryImpl)1 IOException (java.io.IOException)1 Field (java.lang.reflect.Field)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 ServiceLocator (org.glassfish.hk2.api.ServiceLocator)1