use of org.eclipse.persistence.descriptors.InheritancePolicy in project eclipselink by eclipse-ee4j.
the class CommitOrderDependencyNode method withAllSubclasses.
// Return an enumeration of all mappings for my descriptor, including those inherited
public Vector withAllSubclasses(CommitOrderDependencyNode node) {
Vector results = new Vector();
results.addElement(node);
if (node.getDescriptor().hasInheritance()) {
InheritancePolicy policy = node.getDescriptor().getInheritancePolicy();
// For bug 3019934 replace getChildDescriptors with getAllChildDescriptors.
List<ClassDescriptor> childDescriptors = new ArrayList<>();
childDescriptors.addAll(policy.getAllChildDescriptors());
// Sort Child Descriptors before adding them to related nodes.
Collections.sort(childDescriptors, new DescriptorCompare());
for (ClassDescriptor child : childDescriptors) {
results.add(getOwner().nodeFor(child));
}
}
return results;
}
use of org.eclipse.persistence.descriptors.InheritancePolicy in project eclipselink by eclipse-ee4j.
the class EntityManagerJUnitTestSuite method testEnabledPersistNonEntitySubclass.
// bug 237281 - ensure seeting InheritancePolicy to allow non-entity subclasses to be persisted as their
// superclass works
public void testEnabledPersistNonEntitySubclass() {
EntityManager em = createEntityManager();
InheritancePolicy ip = getDatabaseSession().getDescriptor(Project.class).getInheritancePolicy();
boolean describesNonPersistentSubclasses = ip.getDescribesNonPersistentSubclasses();
ip.setDescribesNonPersistentSubclasses(true);
beginTransaction(em);
SuperLargeProject s1 = new SuperLargeProject("Super 1");
try {
em.persist(s1);
} catch (Exception e) {
if (isTransactionActive(em)) {
rollbackTransaction(em);
}
fail("Persist operation was not cascaded to related non-entity, thrown: " + e);
} finally {
rollbackTransaction(em);
ip.setDescribesNonPersistentSubclasses(describesNonPersistentSubclasses);
closeEntityManager(em);
}
}
use of org.eclipse.persistence.descriptors.InheritancePolicy in project eclipselink by eclipse-ee4j.
the class EntityMappingsMergeAdvancedJUnitTestCase method testInheritanceDiscriminatorFieldValue.
public void testInheritanceDiscriminatorFieldValue() {
InheritancePolicy projectInheritancePolicy = getServerSession().getDescriptor(Project.class).getInheritancePolicy();
// defined in xml
DatabaseField classIndicatorField = projectInheritancePolicy.getClassIndicatorField();
String classIndicatorFieldName = classIndicatorField.getName();
if (!classIndicatorFieldName.equals("XML_MERGE_PROJ_TYPE")) {
fail("Wrong classIndicatorField name '" + classIndicatorFieldName + "'");
}
Class<?> classIndicatorFieldType = classIndicatorField.getType();
if (!classIndicatorFieldType.equals(String.class)) {
fail("Wrong classIndicatorField type '" + classIndicatorFieldType.getName() + "'");
}
// defined in xml
String classIndicatorFieldTableName = classIndicatorField.getTableName();
if (!classIndicatorFieldTableName.equals("CMP3_XML_MERGE_PROJECT")) {
fail("Wrong classIndicatorField table '" + classIndicatorFieldTableName + "'");
}
Map classNameIndicators = projectInheritancePolicy.getClassNameIndicatorMapping();
// defined in xml
String projectIndicator = (String) classNameIndicators.get(packageName + "Project");
if (!projectIndicator.equals("XML_MERGE_P")) {
fail("Wrong classIndicatorField value for Project '" + projectIndicator + "'");
}
// defaulted in annotations
String smallProjectIndicator = (String) classNameIndicators.get(packageName + "SmallProject");
if (!smallProjectIndicator.equals("XMLMergeSmallProject")) {
fail("Wrong classIndicatorField value for SmallProject '" + smallProjectIndicator + "'");
}
String largeProjectIndicator = (String) classNameIndicators.get(packageName + "LargeProject");
if (!largeProjectIndicator.equals("XMLMergeLargeProject")) {
fail("Wrong classIndicatorField value for LargeProject '" + largeProjectIndicator + "'");
}
}
use of org.eclipse.persistence.descriptors.InheritancePolicy in project eclipselink by eclipse-ee4j.
the class ObjectBuilder method buildObjectsFromCursorInto.
/**
* Return a container which contains the instances of the receivers javaClass.
* Set the fields of the instance to the values stored in the database rows.
*/
public Object buildObjectsFromCursorInto(ReadAllQuery query, List databaseRows, Object domainObjects) {
AbstractSession session = query.getSession();
session.startOperationProfile(SessionProfiler.ObjectBuilding, query, SessionProfiler.ALL);
try {
InheritancePolicy inheritancePolicy = null;
if (this.descriptor.hasInheritance()) {
inheritancePolicy = this.descriptor.getInheritancePolicy();
}
boolean isUnitOfWork = session.isUnitOfWork();
boolean shouldCacheQueryResults = query.shouldCacheQueryResults();
boolean shouldUseWrapperPolicy = query.shouldUseWrapperPolicy();
// PERF: Avoid lazy init of join manager if no joining.
JoinedAttributeManager joinManager = null;
if (query.hasJoining()) {
joinManager = query.getJoinedAttributeManager();
}
ContainerPolicy policy = query.getContainerPolicy();
if (policy.shouldAddAll()) {
List domainObjectsIn = new ArrayList();
List<AbstractRecord> databaseRowsIn = new ArrayList();
for (Enumeration iterator = ((Vector) databaseRows).elements(); iterator.hasMoreElements(); ) {
AbstractRecord databaseRow = (AbstractRecord) iterator.nextElement();
// PERF: 1-m joining nulls out duplicate rows.
if (databaseRow != null) {
domainObjectsIn.add(buildObject(query, databaseRow, joinManager, session, this.descriptor, inheritancePolicy, isUnitOfWork, shouldCacheQueryResults, shouldUseWrapperPolicy));
databaseRowsIn.add(databaseRow);
}
}
policy.addAll(domainObjectsIn, domainObjects, session, databaseRowsIn, query, null, true);
} else {
boolean quickAdd = (domainObjects instanceof Collection) && !this.hasWrapperPolicy;
for (Enumeration iterator = ((Vector) databaseRows).elements(); iterator.hasMoreElements(); ) {
AbstractRecord databaseRow = (AbstractRecord) iterator.nextElement();
// PERF: 1-m joining nulls out duplicate rows.
if (databaseRow != null) {
Object domainObject = buildObject(query, databaseRow, joinManager, session, this.descriptor, inheritancePolicy, isUnitOfWork, shouldCacheQueryResults, shouldUseWrapperPolicy);
if (quickAdd) {
((Collection) domainObjects).add(domainObject);
} else {
policy.addInto(domainObject, domainObjects, session, databaseRow, query, null, true);
}
}
}
}
} finally {
session.endOperationProfile(SessionProfiler.ObjectBuilding, query, SessionProfiler.ALL);
}
return domainObjects;
}
use of org.eclipse.persistence.descriptors.InheritancePolicy in project eclipselink by eclipse-ee4j.
the class CascadeLockingPolicy method getParentDescriptorFromInheritancePolicy.
/**
* Get the descriptor that really represents this object
* In the case of inheritance, the object may represent a subclass of class the descriptor
* represents.
*
* If there is no InheritancePolicy, we return our parentDescriptor
* If there is inheritance we will search for a descriptor that represents parentObj and
* return that descriptor
*/
protected ClassDescriptor getParentDescriptorFromInheritancePolicy(Object parentObj) {
ClassDescriptor realParentDescriptor = m_parentDescriptor;
if (realParentDescriptor.hasInheritance()) {
InheritancePolicy inheritancePolicy = realParentDescriptor.getInheritancePolicy();
ClassDescriptor childDescriptor = inheritancePolicy.getDescriptor(parentObj.getClass());
if (childDescriptor != null) {
realParentDescriptor = childDescriptor;
}
}
return realParentDescriptor;
}
Aggregations