use of org.eclipse.persistence.internal.sessions.DatabaseSessionImpl in project eclipselink by eclipse-ee4j.
the class EntityMappingsAdvancedJUnitTestCase method testSexObjectTypeConverterDefaultValue.
/**
* Verifies a default object type value is set from metadata processing.
*/
public void testSexObjectTypeConverterDefaultValue() {
DatabaseSessionImpl session = getDatabaseSession();
ClassDescriptor employeeDescriptor = session.getDescriptor(Employee.class);
DirectToFieldMapping mapping = (DirectToFieldMapping) employeeDescriptor.getMappingForAttributeName("gender");
assertNotNull("Gender mapping from Employee not found.", mapping);
assertTrue("No object type converter found on the gender mapping.", ObjectTypeConverter.class.isAssignableFrom(mapping.getConverter().getClass()));
assertTrue("Default object value on the object type converter for gender was not set to Male.", ((ObjectTypeConverter) mapping.getConverter()).getDefaultAttributeValue().equals(Employee.Gender.Male.name()));
}
use of org.eclipse.persistence.internal.sessions.DatabaseSessionImpl in project eclipselink by eclipse-ee4j.
the class EntityManagerJUnitTestSuite method testObjectReferencedInBothEmAndSharedCache_AggregateObjectMapping.
// Bug 336280 - Same object referenced from both EM cache and shared cache
public void testObjectReferencedInBothEmAndSharedCache_AggregateObjectMapping() {
EntityManager em = createEntityManager();
DatabaseSessionImpl dbs = null;
// persist a new Employee object
Employee emp = new Employee();
emp.setFirstName("A");
EmploymentPeriod period = new EmploymentPeriod(Helper.dateFromYearMonthDate(1993, 0, 1), Helper.dateFromYearMonthDate(1996, 11, 31));
emp.setPeriod(period);
beginTransaction(em);
em.persist(emp);
// in JTA case transaction required to obtain ServerSession through getServersession method.
dbs = getDatabaseSession();
commitTransaction(em);
closeEntityManager(em);
// using query by example read empShared corresponding to emp in ghe share cache
Employee empShared = (Employee) dbs.readObject(emp);
// these are really to distinct objects
assertTrue(emp != empShared);
// they should not share the aggragate
assertTrue(emp.getPeriod() != empShared.getPeriod());
}
use of org.eclipse.persistence.internal.sessions.DatabaseSessionImpl in project eclipselink by eclipse-ee4j.
the class EntityManagerJUnitTestSuite method testClearEntityManagerWithoutPersistenceContextSimulateJTA.
// gf2074: EM.clear throws NPE (JTA case)
public void testClearEntityManagerWithoutPersistenceContextSimulateJTA() {
EntityManager em = createEntityManager();
DatabaseSessionImpl dbs = getDatabaseSession();
closeEntityManager(em);
// in non-JTA case session doesn't have external transaction controller
boolean hasExternalTransactionController = dbs.hasExternalTransactionController();
if (!hasExternalTransactionController) {
// simulate JTA case
dbs.setExternalTransactionController(new DummyExternalTransactionController());
}
try {
testClearEntityManagerWithoutPersistenceContext();
} finally {
if (!hasExternalTransactionController) {
// remove the temporary set TransactionController
dbs.setExternalTransactionController(null);
}
}
}
use of org.eclipse.persistence.internal.sessions.DatabaseSessionImpl in project eclipselink by eclipse-ee4j.
the class EntityManagerJUnitTestSuite method testAggregateObjectMappingReferenceDescriptor.
public void testAggregateObjectMappingReferenceDescriptor() {
Set<String> errors = new HashSet();
DatabaseSessionImpl dbs = getDatabaseSession();
for (ClassDescriptor descriptor : dbs.getDescriptors().values()) {
if (!descriptor.isDescriptorTypeAggregate()) {
String path = descriptor.getJavaClassName();
verifyAggregateObjectMappingReferenceDescriptor(descriptor, path, errors);
}
}
if (!errors.isEmpty()) {
String errorMsg = "The following AggregateObjectMappings have ReferenceDescriptors without any mappings:\n";
for (String errorStr : errors) {
errorMsg += errorStr + "\n";
}
fail(errorMsg);
}
}
use of org.eclipse.persistence.internal.sessions.DatabaseSessionImpl in project eclipselink by eclipse-ee4j.
the class EntityManagerJUnitTestSuite method testObjectReferencedInBothEmAndSharedCache_ObjectReferenceMappingVH.
// Bug 336280 - Same object referenced from both EM cache and shared cache
public void testObjectReferencedInBothEmAndSharedCache_ObjectReferenceMappingVH() {
EntityManager em = createEntityManager();
Employee emp = new Employee();
emp.setFirstName("Manager");
Employee emp1 = new Employee();
emp1.setFirstName("1");
emp.addManagedEmployee(emp1);
Employee emp2 = new Employee();
emp2.setFirstName("2");
emp.addManagedEmployee(emp2);
DatabaseSessionImpl dbs = null;
beginTransaction(em);
em.persist(emp);
// in JTA case transaction required to obtain ServerSession through getServersession method.
dbs = getDatabaseSession();
commitTransaction(em);
CopyGroup copyGroup = new CopyGroup();
copyGroup.cascadeAllParts();
dbs.copy(emp, copyGroup);
Set originalObjects = copyGroup.getCopies().keySet();
// copyGroup cascades through all mappings.
// originalObjects should consist of just three objects: emp, emp1, emp2.
// However if manager_vh is wrapped around manager instance from the shared cache (empShared),
// the size will be 6: emp, emp1, emp2 and empShared, emp1Shared, emp2Shared.
assertTrue(originalObjects.size() == 3);
}
Aggregations