Search in sources :

Example 1 with ArchiveFactory

use of org.eclipse.persistence.jpa.ArchiveFactory in project eclipselink by eclipse-ee4j.

the class PersistenceUnitProcessor method getArchiveFactory.

public static ArchiveFactory getArchiveFactory(ClassLoader loader, Map properties) {
    if (ARCHIVE_FACTORY != null) {
        return ARCHIVE_FACTORY;
    }
    ArchiveFactory factory = null;
    String factoryClassName = PrivilegedAccessHelper.shouldUsePrivilegedAccess() ? AccessController.doPrivileged(new PrivilegedGetSystemProperty(SystemProperties.ARCHIVE_FACTORY)) : System.getProperty(SystemProperties.ARCHIVE_FACTORY);
    if (factoryClassName == null && properties != null) {
        Object name = properties.get(SystemProperties.ARCHIVE_FACTORY);
        if (name instanceof String) {
            factoryClassName = (String) name;
        }
    }
    if (factoryClassName == null) {
        return new ArchiveFactoryImpl();
    } else {
        try {
            if (loader != null) {
                Class<?> archiveClass = loader.loadClass(factoryClassName);
                if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) {
                    try {
                        factory = (ArchiveFactory) AccessController.doPrivileged(new PrivilegedNewInstanceFromClass(archiveClass));
                    } catch (PrivilegedActionException exception) {
                        throw PersistenceUnitLoadingException.exceptionCreatingArchiveFactory(factoryClassName, exception);
                    }
                } else {
                    factory = (ArchiveFactory) PrivilegedAccessHelper.newInstanceFromClass(archiveClass);
                }
            }
        } catch (ClassNotFoundException cnfe) {
            throw PersistenceUnitLoadingException.exceptionCreatingArchiveFactory(factoryClassName, cnfe);
        } catch (IllegalAccessException iae) {
            throw PersistenceUnitLoadingException.exceptionCreatingArchiveFactory(factoryClassName, iae);
        } catch (InstantiationException ie) {
            throw PersistenceUnitLoadingException.exceptionCreatingArchiveFactory(factoryClassName, ie);
        }
    }
    return factory;
}
Also used : ArchiveFactory(org.eclipse.persistence.jpa.ArchiveFactory) PrivilegedNewInstanceFromClass(org.eclipse.persistence.internal.security.PrivilegedNewInstanceFromClass) PrivilegedActionException(java.security.PrivilegedActionException) PrivilegedGetSystemProperty(org.eclipse.persistence.internal.security.PrivilegedGetSystemProperty)

Example 2 with ArchiveFactory

use of org.eclipse.persistence.jpa.ArchiveFactory in project eclipselink by eclipse-ee4j.

the class PersistenceUnitProcessorTest method testGetArchiveFactory.

public void testGetArchiveFactory() {
    Map<String, Object> props = new HashMap<>();
    props.put(SystemProperties.ARCHIVE_FACTORY, AF1.class.getName());
    ArchiveFactory af = PersistenceUnitProcessor.getArchiveFactory(PersistenceUnitProcessorTest.class.getClassLoader(), props);
    Assert.assertTrue("Property should be used", af instanceof AF1);
}
Also used : ArchiveFactory(org.eclipse.persistence.jpa.ArchiveFactory) HashMap(java.util.HashMap)

Example 3 with ArchiveFactory

use of org.eclipse.persistence.jpa.ArchiveFactory in project eclipselink by eclipse-ee4j.

the class PersistenceUnitProcessorTest method testGetArchiveFactoryOverride.

public void testGetArchiveFactoryOverride() {
    EntityManagerFactory emf = null;
    String orig = System.getProperty(SystemProperties.ARCHIVE_FACTORY, "--noval--");
    try {
        System.setProperty(SystemProperties.ARCHIVE_FACTORY, AF2.class.getName());
        Map<String, Object> props = new HashMap<>();
        props.put(SystemProperties.ARCHIVE_FACTORY, AF1.class.getName());
        ArchiveFactory af = PersistenceUnitProcessor.getArchiveFactory(PersistenceUnitProcessorTest.class.getClassLoader(), props);
        Assert.assertTrue("System property should be used", af instanceof AF2);
    } finally {
        if ("--noval--".equals(orig)) {
            System.clearProperty(SystemProperties.ARCHIVE_FACTORY);
        } else {
            System.setProperty(SystemProperties.ARCHIVE_FACTORY, orig);
        }
    }
}
Also used : ArchiveFactory(org.eclipse.persistence.jpa.ArchiveFactory) HashMap(java.util.HashMap) EntityManagerFactory(jakarta.persistence.EntityManagerFactory)

Aggregations

ArchiveFactory (org.eclipse.persistence.jpa.ArchiveFactory)3 HashMap (java.util.HashMap)2 EntityManagerFactory (jakarta.persistence.EntityManagerFactory)1 PrivilegedActionException (java.security.PrivilegedActionException)1 PrivilegedGetSystemProperty (org.eclipse.persistence.internal.security.PrivilegedGetSystemProperty)1 PrivilegedNewInstanceFromClass (org.eclipse.persistence.internal.security.PrivilegedNewInstanceFromClass)1