use of org.eclipse.persistence.sessions.Project in project eclipselink by eclipse-ee4j.
the class CMPDescriptorPessimisticLockingTest method test.
@Override
protected void test() {
// test run time project that should contains cusomtom sql queries
Project project = XMLProjectReader.read(PROJECT_FILE, getClass().getClassLoader());
ClassDescriptor employeeDescriptor = project.getDescriptors().get(Employee.class);
ClassDescriptor addressDescriptor = project.getDescriptors().get(Address.class);
if (!employeeDescriptor.hasPessimisticLockingPolicy()) {
throw new TestErrorException("'Employee descriptor was not written or read correctly");
} else if (employeeDescriptor.getCMPPolicy().getPessimisticLockingPolicy().getLockingMode() != ObjectLevelReadQuery.LOCK) {
throw new TestErrorException("'Employee descriptor was not written or read correctly with pessimistic locking LOCK mode");
}
if (!addressDescriptor.hasPessimisticLockingPolicy()) {
throw new TestErrorException("'Address descriptor was not written or read correctly");
} else if (addressDescriptor.getCMPPolicy().getPessimisticLockingPolicy().getLockingMode() != ObjectLevelReadQuery.LOCK_NOWAIT) {
throw new TestErrorException("'Address descriptor was not written or read correctly with pessimistic locking LOCK_NOWAIT mode");
}
}
use of org.eclipse.persistence.sessions.Project in project eclipselink by eclipse-ee4j.
the class ClassDescriptor method convertClassNamesToClasses.
/**
* INTERNAL:
* Convert all the class-name-based settings in this Descriptor to actual class-based
* settings. This method is used when converting a project that has been built
* with class names to a project with classes.
*/
public void convertClassNamesToClasses(ClassLoader classLoader) {
if (getJavaClassName() != null) {
final Class<?> descriptorClass = PrivilegedAccessHelper.callDoPrivilegedWithException(() -> org.eclipse.persistence.internal.security.PrivilegedAccessHelper.getClassForName(getJavaClassName(), true, classLoader), (ex) -> ValidationException.classNotFoundWhileConvertingClassNames(getJavaClassName(), ex));
setJavaClass(descriptorClass);
}
if (getAmendmentClassName() != null) {
final Class<?> amendmentClass = PrivilegedAccessHelper.callDoPrivilegedWithException(() -> org.eclipse.persistence.internal.security.PrivilegedAccessHelper.getClassForName(getAmendmentClassName(), true, classLoader), (ex) -> ValidationException.classNotFoundWhileConvertingClassNames(getAmendmentClassName(), ex));
setAmendmentClass(amendmentClass);
}
if (copyPolicy == null && getCopyPolicyClassName() != null) {
final Class<?> copyPolicyClass = PrivilegedAccessHelper.callDoPrivilegedWithException(() -> org.eclipse.persistence.internal.security.PrivilegedAccessHelper.getClassForName(getCopyPolicyClassName(), true, classLoader), (ex) -> ValidationException.classNotFoundWhileConvertingClassNames(getCopyPolicyClassName(), ex));
final CopyPolicy newCopyPolicy = PrivilegedAccessHelper.callDoPrivilegedWithException(() -> (CopyPolicy) org.eclipse.persistence.internal.security.PrivilegedAccessHelper.newInstanceFromClass(copyPolicyClass), (ex) -> ValidationException.reflectiveExceptionWhileCreatingClassInstance(getCopyPolicyClassName(), ex));
setCopyPolicy(newCopyPolicy);
}
if (this.serializedObjectPolicy != null && this.serializedObjectPolicy instanceof SerializedObjectPolicyWrapper) {
final String serializedObjectPolicyClassName = ((SerializedObjectPolicyWrapper) this.serializedObjectPolicy).getSerializedObjectPolicyClassName();
final Class<?> serializedObjectPolicyClass = PrivilegedAccessHelper.callDoPrivilegedWithException(() -> org.eclipse.persistence.internal.security.PrivilegedAccessHelper.getClassForName(serializedObjectPolicyClassName, true, classLoader), (ex) -> ValidationException.classNotFoundWhileConvertingClassNames(serializedObjectPolicyClassName, ex));
final SerializedObjectPolicy newSerializedObjectPolicy = PrivilegedAccessHelper.callDoPrivilegedWithException(() -> (SerializedObjectPolicy) org.eclipse.persistence.internal.security.PrivilegedAccessHelper.newInstanceFromClass(serializedObjectPolicyClass), (ex) -> ValidationException.reflectiveExceptionWhileCreatingClassInstance(serializedObjectPolicyClassName, ex));
newSerializedObjectPolicy.setField(this.serializedObjectPolicy.getField());
setSerializedObjectPolicy(newSerializedObjectPolicy);
}
// Create and set default QueryRedirector instances
if (this.defaultQueryRedirectorClassName != null) {
final Class<?> redirectorClass = PrivilegedAccessHelper.callDoPrivilegedWithException(() -> org.eclipse.persistence.internal.security.PrivilegedAccessHelper.getClassForName(defaultQueryRedirectorClassName, true, classLoader), (ex) -> ValidationException.classNotFoundWhileConvertingClassNames(defaultQueryRedirectorClassName, ex));
setDefaultQueryRedirector((QueryRedirector) PrivilegedAccessHelper.callDoPrivilegedWithException(() -> org.eclipse.persistence.internal.security.PrivilegedAccessHelper.newInstanceFromClass(redirectorClass), (ex) -> ValidationException.classNotFoundWhileConvertingClassNames(defaultQueryRedirectorClassName, ex)));
}
if (this.defaultReadObjectQueryRedirectorClassName != null) {
final Class<?> redirectorClass = PrivilegedAccessHelper.callDoPrivilegedWithException(() -> org.eclipse.persistence.internal.security.PrivilegedAccessHelper.getClassForName(defaultReadObjectQueryRedirectorClassName, true, classLoader), (ex) -> ValidationException.classNotFoundWhileConvertingClassNames(defaultReadObjectQueryRedirectorClassName, ex));
setDefaultReadObjectQueryRedirector((QueryRedirector) PrivilegedAccessHelper.callDoPrivilegedWithException(() -> org.eclipse.persistence.internal.security.PrivilegedAccessHelper.newInstanceFromClass(redirectorClass), (ex) -> ValidationException.classNotFoundWhileConvertingClassNames(defaultReadObjectQueryRedirectorClassName, ex)));
}
if (this.defaultReadAllQueryRedirectorClassName != null) {
final Class<?> redirectorClass = PrivilegedAccessHelper.callDoPrivilegedWithException(() -> org.eclipse.persistence.internal.security.PrivilegedAccessHelper.getClassForName(defaultReadAllQueryRedirectorClassName, true, classLoader), (ex) -> ValidationException.classNotFoundWhileConvertingClassNames(defaultReadAllQueryRedirectorClassName, ex));
setDefaultReadAllQueryRedirector((QueryRedirector) PrivilegedAccessHelper.callDoPrivilegedWithException(() -> org.eclipse.persistence.internal.security.PrivilegedAccessHelper.newInstanceFromClass(redirectorClass), (ex) -> ValidationException.classNotFoundWhileConvertingClassNames(defaultReadAllQueryRedirectorClassName, ex)));
}
if (this.defaultReportQueryRedirectorClassName != null) {
final Class<?> redirectorClass = PrivilegedAccessHelper.callDoPrivilegedWithException(() -> org.eclipse.persistence.internal.security.PrivilegedAccessHelper.getClassForName(defaultReportQueryRedirectorClassName, true, classLoader), (ex) -> ValidationException.classNotFoundWhileConvertingClassNames(defaultReportQueryRedirectorClassName, ex));
setDefaultReportQueryRedirector((QueryRedirector) PrivilegedAccessHelper.callDoPrivilegedWithException(() -> org.eclipse.persistence.internal.security.PrivilegedAccessHelper.newInstanceFromClass(redirectorClass), (ex) -> ValidationException.classNotFoundWhileConvertingClassNames(defaultReportQueryRedirectorClassName, ex)));
}
if (this.defaultInsertObjectQueryRedirectorClassName != null) {
final Class<?> redirectorClass = PrivilegedAccessHelper.callDoPrivilegedWithException(() -> org.eclipse.persistence.internal.security.PrivilegedAccessHelper.getClassForName(defaultInsertObjectQueryRedirectorClassName, true, classLoader), (ex) -> ValidationException.classNotFoundWhileConvertingClassNames(defaultInsertObjectQueryRedirectorClassName, ex));
setDefaultInsertObjectQueryRedirector((QueryRedirector) PrivilegedAccessHelper.callDoPrivilegedWithException(() -> org.eclipse.persistence.internal.security.PrivilegedAccessHelper.newInstanceFromClass(redirectorClass), (ex) -> ValidationException.classNotFoundWhileConvertingClassNames(defaultInsertObjectQueryRedirectorClassName, ex)));
}
if (this.defaultUpdateObjectQueryRedirectorClassName != null) {
final Class<?> redirectorClass = PrivilegedAccessHelper.callDoPrivilegedWithException(() -> org.eclipse.persistence.internal.security.PrivilegedAccessHelper.getClassForName(defaultUpdateObjectQueryRedirectorClassName, true, classLoader), (ex) -> ValidationException.classNotFoundWhileConvertingClassNames(defaultUpdateObjectQueryRedirectorClassName, ex));
setDefaultUpdateObjectQueryRedirector((QueryRedirector) PrivilegedAccessHelper.callDoPrivilegedWithException(() -> org.eclipse.persistence.internal.security.PrivilegedAccessHelper.newInstanceFromClass(redirectorClass), (ex) -> ValidationException.classNotFoundWhileConvertingClassNames(defaultUpdateObjectQueryRedirectorClassName, ex)));
}
if (this.defaultDeleteObjectQueryRedirectorClassName != null) {
final Class<?> redirectorClass = PrivilegedAccessHelper.callDoPrivilegedWithException(() -> org.eclipse.persistence.internal.security.PrivilegedAccessHelper.getClassForName(defaultDeleteObjectQueryRedirectorClassName, true, classLoader), (ex) -> ValidationException.classNotFoundWhileConvertingClassNames(defaultDeleteObjectQueryRedirectorClassName, ex));
setDefaultDeleteObjectQueryRedirector((QueryRedirector) PrivilegedAccessHelper.callDoPrivilegedWithException(() -> org.eclipse.persistence.internal.security.PrivilegedAccessHelper.newInstanceFromClass(redirectorClass), (ex) -> ValidationException.classNotFoundWhileConvertingClassNames(defaultDeleteObjectQueryRedirectorClassName, ex)));
}
Iterator<DatabaseMapping> mappings = getMappings().iterator();
while (mappings.hasNext()) {
mappings.next().convertClassNamesToClasses(classLoader);
}
if (this.inheritancePolicy != null) {
this.inheritancePolicy.convertClassNamesToClasses(classLoader);
}
if (this.interfacePolicy != null) {
this.interfacePolicy.convertClassNamesToClasses(classLoader);
}
if (this.instantiationPolicy != null) {
this.instantiationPolicy.convertClassNamesToClasses(classLoader);
}
if (hasCMPPolicy()) {
getCMPPolicy().convertClassNamesToClasses(classLoader);
}
if (this.queryManager != null) {
this.queryManager.convertClassNamesToClasses(classLoader);
}
if (this.cachePolicy != null) {
this.cachePolicy.convertClassNamesToClasses(classLoader);
}
if (hasUnconvertedProperties()) {
for (String propertyName : getUnconvertedProperties().keySet()) {
List<String> valuePair = getUnconvertedProperties().get(propertyName);
String value = valuePair.get(0);
String valueTypeName = valuePair.get(1);
Class<String> valueType = String.class;
if (valueTypeName != null) {
// Have to initialize the valueType now
valueType = PrivilegedAccessHelper.callDoPrivilegedWithException(() -> org.eclipse.persistence.internal.security.PrivilegedAccessHelper.getClassForName(valueTypeName, true, classLoader), (ex) -> ValidationException.classNotFoundWhileConvertingClassNames(valueTypeName, ex));
}
// Add the converted property. If the value type is the same
// as the source (value) type, no conversion is made.
getProperties().put(propertyName, ConversionManager.getDefaultManager().convertObject(value, valueType));
}
}
}
use of org.eclipse.persistence.sessions.Project in project eclipselink by eclipse-ee4j.
the class DataReadQueryContainerPolicyTest method setup.
@Override
protected void setup() throws IOException {
m_exceptionCaught = false;
Project project = XMLProjectReader.read("testDeployment.xml", getClass().getClassLoader());
m_session = project.createDatabaseSession();
m_session.setSessionLog(getSession().getSessionLog());
m_session.setLogin(getSession().getLogin());
m_session.login();
}
use of org.eclipse.persistence.sessions.Project in project eclipselink by eclipse-ee4j.
the class TestModel method resetEntity.
/**
* If setupEntity has been called then this must be called to reset the model again.
*/
@Override
public void resetEntity() {
if (isSetup()) {
setTests(getOriginalTests());
setIsSetup(false);
}
if (this.getSummary().didSetupWarn()) {
return;
}
reset();
// To improve test consistency cleanup the session and executor better.
getSession().getIdentityMapAccessor().initializeIdentityMaps();
if (shouldResetSystemAfterEachTestModel()) {
getExecutor().setConfiguredSystems(new Vector());
// Logout and clean/reset the session in case test model failed ungracefully.
if (getSession().isDatabaseSession()) {
try {
getDatabaseSession().logout();
} catch (Exception ignore) {
}
}
if (this.login == null) {
this.login = getSession().getDatasourceLogin();
this.sessionLog = getSession().getSessionLog();
}
// Check if login or log were corrupted.
if (this.login.getClass() != getSession().getDatasourceLogin().getClass()) {
System.out.println("Login changed by test model:" + this);
}
if (this.sessionLog.getLevel() != getSession().getSessionLog().getLevel()) {
System.out.println("Log level changed by test model:" + this);
}
if (this.login instanceof DatabaseLogin) {
DatabaseLogin login = (DatabaseLogin) this.login;
if (login.shouldBindAllParameters() != getSession().getLogin().shouldBindAllParameters()) {
System.out.println("Binding changed by test model:" + this);
}
if (login.shouldCacheAllStatements() != getSession().getLogin().shouldCacheAllStatements()) {
System.out.println("Statement caching changed by test model:" + this);
}
if (login.shouldUseBatchWriting() != getSession().getLogin().shouldUseBatchWriting()) {
System.out.println("Batch writing changed by test model:" + this);
}
if (login.shouldUseJDBCBatchWriting() != getSession().getLogin().shouldUseJDBCBatchWriting()) {
System.out.println("JDBC batch writing changed by test model:" + this);
}
if (login.shouldUseNativeSQL() != getSession().getLogin().shouldUseNativeSQL()) {
System.out.println("Native SQL changed by test model:" + this);
}
if (login.getTableQualifier() != getSession().getLogin().getTableQualifier()) {
System.out.println("Table qualifier changed by test model:" + this);
}
}
DatabaseSession session = new Project(this.login).createDatabaseSession();
session.setSessionLog(this.sessionLog);
getExecutor().setSession(session);
// Check if default conversion manager was corrupted.
if (!ConversionManager.getDefaultManager().shouldUseClassLoaderFromCurrentThread()) {
System.out.println("ConversionManager corrupted by test model:" + this);
}
ConversionManager.setDefaultManager(null);
getSession().getDatasourceLogin().getDatasourcePlatform().setConversionManager(null);
SessionManager.getManager().setSessions(new ConcurrentHashMap<String, Session>());
getDatabaseSession().login();
}
setIsSetup(false);
}
use of org.eclipse.persistence.sessions.Project in project eclipselink by eclipse-ee4j.
the class ChoiceCollectionReuseTestCases method getNewProject.
@Override
public Project getNewProject(Project originalProject, ClassLoader classLoader) {
Project project = super.getNewProject(originalProject, classLoader);
project.getDatasourceLogin().setPlatform(new SAXPlatform());
return project;
}
Aggregations