Search in sources :

Example 51 with DatabasePlatform

use of org.eclipse.persistence.internal.databaseaccess.DatabasePlatform in project eclipselink by eclipse-ee4j.

the class JPAMetadataGenerator method loadDatabasePlatform.

/**
 * Attempt to load the DatabasePlatform using the given platform class name.  If the
 * platform cannot be loaded Oracle11Platform will be returned - if available.
 *
 * @param platformClassName class name of the DatabasePlatform to be loaded
 * @return DatabasePlatform loaded for the given platformClassname, or Oracle11Platform if not found
 * @see "org.eclipse.persistence.platform.database.oracle.Oracle11Platform"
 */
public static DatabasePlatform loadDatabasePlatform(String platformClassName) {
    DatabasePlatform dbPlatform = null;
    Class<?> platformClass = null;
    try {
        if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) {
            platformClass = AccessController.doPrivileged(new PrivilegedClassForName<>(platformClassName));
        } else {
            platformClass = PrivilegedAccessHelper.getClassForName(platformClassName);
        }
        dbPlatform = (DatabasePlatform) Helper.getInstanceFromClass(platformClass);
    } catch (PrivilegedActionException | ClassNotFoundException | NullPointerException e) {
        try {
            if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) {
                platformClass = AccessController.doPrivileged(new PrivilegedClassForName<>(DEFAULT_PLATFORM));
            } else {
                platformClass = PrivilegedAccessHelper.getClassForName(DEFAULT_PLATFORM);
            }
            dbPlatform = (DatabasePlatform) Helper.getInstanceFromClass(platformClass);
        } catch (PrivilegedActionException | ClassNotFoundException ex) {
        // at this point we can't load the default Oracle11Platform, so null will be returned
        }
    }
    return dbPlatform;
}
Also used : PrivilegedActionException(java.security.PrivilegedActionException) DatabasePlatform(org.eclipse.persistence.internal.databaseaccess.DatabasePlatform) PrivilegedClassForName(org.eclipse.persistence.internal.security.PrivilegedClassForName)

Example 52 with DatabasePlatform

use of org.eclipse.persistence.internal.databaseaccess.DatabasePlatform in project eclipselink by eclipse-ee4j.

the class JUnitTestCase method supportsStoredProcedures.

public static boolean supportsStoredProcedures(String puName) {
    DatabasePlatform platform = getDatabaseSession(puName).getPlatform();
    // TODO: DB2 should be in this list.
    if (platform.isOracle() || platform.isMySQL() || platform.isSQLServer()) {
        return true;
    }
    warning("This database does not support stored procedure creation.");
    return false;
}
Also used : DatabasePlatform(org.eclipse.persistence.internal.databaseaccess.DatabasePlatform)

Aggregations

DatabasePlatform (org.eclipse.persistence.internal.databaseaccess.DatabasePlatform)52 EntityManager (jakarta.persistence.EntityManager)12 DatabaseCall (org.eclipse.persistence.internal.databaseaccess.DatabaseCall)11 DatabaseException (org.eclipse.persistence.exceptions.DatabaseException)9 EntityManagerFactoryImpl (org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl)9 Test (org.junit.Test)9 GenericEntity (org.eclipse.persistence.jpa.test.property.model.GenericEntity)8 PersistenceException (jakarta.persistence.PersistenceException)6 Platform (org.eclipse.persistence.internal.databaseaccess.Platform)6 AbstractSession (org.eclipse.persistence.internal.sessions.AbstractSession)6 ResultSetMetaData (java.sql.ResultSetMetaData)5 DatabaseAccessor (org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor)5 FieldTypeDefinition (org.eclipse.persistence.internal.databaseaccess.FieldTypeDefinition)5 UnitOfWork (org.eclipse.persistence.sessions.UnitOfWork)5 IOException (java.io.IOException)4 ResultSet (java.sql.ResultSet)4 SQLException (java.sql.SQLException)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Vector (java.util.Vector)4