use of org.eclipse.persistence.sessions.CopyGroup in project eclipselink by eclipse-ee4j.
the class AttributeGroup method toCopyGroup.
/**
* INTERNAL:
* This method is used internally when converting to a copy group.
*/
public CopyGroup toCopyGroup(Map<AttributeGroup, CopyGroup> cloneMap, Map copies) {
CopyGroup clone = cloneMap.get(this);
if (clone != null) {
return clone;
}
clone = new CopyGroup(this.name);
clone.cascadeTree();
clone.setCopies(copies);
clone.type = this.type;
clone.typeName = this.typeName;
clone.isValidated = this.isValidated;
cloneMap.put(this, clone);
if (this.allsubclasses != null) {
for (CoreAttributeGroup group : this.allsubclasses.values()) {
clone.getSubClassGroups().put(group.getType(), ((AttributeGroup) group).toCopyGroup(cloneMap, copies));
}
}
if (this.superClassGroup != null) {
clone.superClassGroup = ((AttributeGroup) this.superClassGroup).toCopyGroup(cloneMap, copies);
}
if (this.subClasses != null) {
clone.subClasses = new HashSet<>();
for (CoreAttributeGroup group : this.subClasses) {
clone.subClasses.add(((AttributeGroup) group).toCopyGroup(cloneMap, copies));
}
}
// all attributes and nested groups should be cloned, too
clone.items = null;
if (hasItems()) {
clone.items = new HashMap<>();
for (AttributeItem item : this.items.values()) {
clone.items.put(item.getAttributeName(), item.toCopyGroup(cloneMap, clone, copies));
}
}
return clone;
}
use of org.eclipse.persistence.sessions.CopyGroup in project eclipselink by eclipse-ee4j.
the class AdvancedCompositePKJunitTest method testCopyAggregateCollection.
// Bug 406957 - Copy fails on AggregateCollectionMapping and on map with @MapKeyColumn
public void testCopyAggregateCollection() {
Department department = new Department();
department.setName("DEPT AggregateCollection");
department.setRole("ROLE AggregateCollection");
department.setLocation("LOCATION AggregateCollection");
Competency competency = new Competency();
competency.description = "Manage groups";
competency.rating = 9;
department.addCompetency(competency);
EntityManager em = createEntityManager();
CopyGroup privatelyOwned = new CopyGroup();
Department departmentCopy = (Department) JpaHelper.getEntityManager(em).copy(department, privatelyOwned);
if (departmentCopy.getCompetencies().size() != department.getCompetencies().size()) {
fail("departmentCopy.getCompetencies().size() = " + departmentCopy.getCompetencies().size() + "; " + department.getCompetencies().size() + " was expected");
}
if (departmentCopy.getCompetencies() == department.getCompetencies()) {
fail("departmentCopy.getCompetencies() == department.getCompetencies()");
}
Competency copmetencyCopy = departmentCopy.getCompetencies().iterator().next();
if (!competency.description.equals(copmetencyCopy.description)) {
fail("competency.descripton = " + competency.description + "; but copmetencyCopy.description = " + copmetencyCopy.description);
}
}
use of org.eclipse.persistence.sessions.CopyGroup in project eclipselink by eclipse-ee4j.
the class AdvancedJunitTest method testLazyToInterface.
/**
* Test that instantiating a lazy relationship to an interface works.
* This requires that the weaving indirection policy find to real field correctly.
*/
public void testLazyToInterface() {
EntityManager em = createEntityManager();
beginTransaction(em);
Parent parent = null;
Child child = null;
try {
parent = new Parent(false);
child = parent.getChildren().get(0);
em.persist(parent);
commitTransaction(em);
} finally {
closeEntityManagerAndTransaction(em);
}
clearCache();
em = createEntityManager();
beginTransaction(em);
try {
child = em.find(Child.class, child.getId());
((JpaEntityManager) em.getDelegate()).copy(child, new CopyGroup());
commitTransaction(em);
} finally {
closeEntityManagerAndTransaction(em);
}
}
use of org.eclipse.persistence.sessions.CopyGroup 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);
AbstractSession ss = null;
beginTransaction(em);
em.persist(emp);
// in JTA case transaction required to obtain ServerSession through getServersession method.
ss = getDatabaseSession();
commitTransaction(em);
CopyGroup copyGroup = new CopyGroup();
copyGroup.cascadeAllParts();
ss.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