use of org.apache.cayenne.map.EntityInheritanceTree in project cayenne by apache.
the class DataDomainQueryAction method polymorphicRowFromCache.
private DataRow polymorphicRowFromCache(EntityInheritanceTree superNode, Map<String, ?> idSnapshot) {
for (EntityInheritanceTree child : superNode.getChildren()) {
ObjectId id = new ObjectId(child.getEntity().getName(), idSnapshot);
DataRow row = cache.getCachedSnapshot(id);
if (row != null) {
return row;
}
row = polymorphicRowFromCache(child, idSnapshot);
if (row != null) {
return row;
}
}
return null;
}
use of org.apache.cayenne.map.EntityInheritanceTree in project cayenne by apache.
the class PersistentDescriptorFactory method getDescriptor.
protected ClassDescriptor getDescriptor(ObjEntity entity, Class<?> entityClass) {
String superEntityName = entity.getSuperEntityName();
ClassDescriptor superDescriptor = (superEntityName != null) ? descriptorMap.getDescriptor(superEntityName) : null;
PersistentDescriptor descriptor = createDescriptor();
descriptor.setEntity(entity);
descriptor.setSuperclassDescriptor(superDescriptor);
descriptor.setObjectClass(entityClass);
descriptor.setPersistenceStateAccessor(new BeanAccessor(entityClass, "persistenceState", Integer.TYPE));
// only include this entity attributes and skip superclasses...
for (ObjAttribute attribute : descriptor.getEntity().getDeclaredAttributes()) {
if (attribute instanceof EmbeddedAttribute) {
EmbeddedAttribute embedded = (EmbeddedAttribute) attribute;
for (ObjAttribute objAttribute : embedded.getAttributes()) {
createEmbeddedAttributeProperty(descriptor, embedded, objAttribute);
}
} else {
createAttributeProperty(descriptor, attribute);
}
}
// only include this entity relationships and skip superclasses...
for (ObjRelationship relationship : descriptor.getEntity().getDeclaredRelationships()) {
if (relationship.isToMany()) {
String collectionType = relationship.getCollectionType();
if (collectionType == null || ObjRelationship.DEFAULT_COLLECTION_TYPE.equals(collectionType)) {
createToManyListProperty(descriptor, relationship);
} else if ("java.util.Map".equals(collectionType)) {
createToManyMapProperty(descriptor, relationship);
} else if ("java.util.Set".equals(collectionType)) {
createToManySetProperty(descriptor, relationship);
} else if ("java.util.Collection".equals(collectionType)) {
createToManyCollectionProperty(descriptor, relationship);
} else {
throw new IllegalArgumentException("Unsupported to-many collection type: " + collectionType);
}
} else {
createToOneProperty(descriptor, relationship);
}
}
EntityInheritanceTree inheritanceTree = descriptorMap.getResolver().getInheritanceTree(descriptor.getEntity().getName());
descriptor.setEntityInheritanceTree(inheritanceTree);
indexSubclassDescriptors(descriptor, inheritanceTree);
indexQualifiers(descriptor, inheritanceTree);
appendDeclaredRootDbEntity(descriptor, descriptor.getEntity());
indexRootDbEntities(descriptor, inheritanceTree);
indexSuperclassProperties(descriptor);
descriptor.sortProperties();
return descriptor;
}
use of org.apache.cayenne.map.EntityInheritanceTree in project cayenne by apache.
the class PersistentDescriptorFactory method indexSubclassDescriptors.
protected void indexSubclassDescriptors(PersistentDescriptor descriptor, EntityInheritanceTree inheritanceTree) {
if (inheritanceTree != null) {
for (EntityInheritanceTree child : inheritanceTree.getChildren()) {
ObjEntity childEntity = child.getEntity();
descriptor.addSubclassDescriptor(childEntity.getClassName(), descriptorMap.getDescriptor(childEntity.getName()));
indexSubclassDescriptors(descriptor, child);
}
}
}
use of org.apache.cayenne.map.EntityInheritanceTree in project cayenne by apache.
the class PersistentDescriptorFactory method indexRootDbEntities.
protected void indexRootDbEntities(PersistentDescriptor descriptor, EntityInheritanceTree inheritanceTree) {
if (inheritanceTree != null) {
for (EntityInheritanceTree child : inheritanceTree.getChildren()) {
ObjEntity childEntity = child.getEntity();
appendDeclaredRootDbEntity(descriptor, childEntity);
indexRootDbEntities(descriptor, child);
}
}
}
use of org.apache.cayenne.map.EntityInheritanceTree in project cayenne by apache.
the class ObjectContextQueryAction method polymorphicObjectFromCache.
// TODO: bunch of copy/paset from DataDomainQueryAction
protected Object polymorphicObjectFromCache(ObjectId superOid) {
Object object = actingContext.getGraphManager().getNode(superOid);
if (object != null) {
return object;
}
EntityInheritanceTree inheritanceTree = actingContext.getEntityResolver().getInheritanceTree(superOid.getEntityName());
if (!inheritanceTree.getChildren().isEmpty()) {
object = polymorphicObjectFromCache(inheritanceTree, superOid.getIdSnapshot());
}
return object;
}
Aggregations