Search in sources :

Example 1 with SpecialDBOperation

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

Aggregations

JDOFatalInternalException (com.sun.jdo.api.persistence.support.JDOFatalInternalException)1 JDOFatalUserException (com.sun.jdo.api.persistence.support.JDOFatalUserException)1 JDOUserException (com.sun.jdo.api.persistence.support.JDOUserException)1 SpecialDBOperation (com.sun.jdo.api.persistence.support.SpecialDBOperation)1 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1