Search in sources :

Example 1 with EntityInheritanceTree

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;
}
Also used : EntityInheritanceTree(org.apache.cayenne.map.EntityInheritanceTree) ObjectId(org.apache.cayenne.ObjectId) DataRow(org.apache.cayenne.DataRow)

Example 2 with EntityInheritanceTree

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;
}
Also used : ObjRelationship(org.apache.cayenne.map.ObjRelationship) EntityInheritanceTree(org.apache.cayenne.map.EntityInheritanceTree) ObjAttribute(org.apache.cayenne.map.ObjAttribute) EmbeddedAttribute(org.apache.cayenne.map.EmbeddedAttribute)

Example 3 with EntityInheritanceTree

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);
        }
    }
}
Also used : EntityInheritanceTree(org.apache.cayenne.map.EntityInheritanceTree) ObjEntity(org.apache.cayenne.map.ObjEntity)

Example 4 with EntityInheritanceTree

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);
        }
    }
}
Also used : EntityInheritanceTree(org.apache.cayenne.map.EntityInheritanceTree) ObjEntity(org.apache.cayenne.map.ObjEntity)

Example 5 with EntityInheritanceTree

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;
}
Also used : EntityInheritanceTree(org.apache.cayenne.map.EntityInheritanceTree)

Aggregations

EntityInheritanceTree (org.apache.cayenne.map.EntityInheritanceTree)8 DataRow (org.apache.cayenne.DataRow)2 ObjectId (org.apache.cayenne.ObjectId)2 ObjEntity (org.apache.cayenne.map.ObjEntity)2 EmbeddedAttribute (org.apache.cayenne.map.EmbeddedAttribute)1 EntityResolver (org.apache.cayenne.map.EntityResolver)1 ObjAttribute (org.apache.cayenne.map.ObjAttribute)1 ObjRelationship (org.apache.cayenne.map.ObjRelationship)1