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;
}
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);
}
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);
}
}
}
Aggregations