Search in sources :

Example 1 with DefaultEmbeddableResultSegment

use of org.apache.cayenne.query.DefaultEmbeddableResultSegment in project cayenne by apache.

the class SQLResult method getResolvedComponents.

public List<Object> getResolvedComponents(EntityResolver resolver) {
    if (resultDescriptors == null) {
        return Collections.emptyList();
    }
    List<Object> resolvedComponents = new ArrayList<>(resultDescriptors.size());
    int offset = 0;
    for (Object component : getComponents()) {
        if (component instanceof String) {
            resolvedComponents.add(new DefaultScalarResultSegment((String) component, offset));
            offset = offset + 1;
        } else if (component instanceof EntityResult) {
            EntityResult entityResult = (EntityResult) component;
            Map<String, String> fields = entityResult.getDbFields(resolver);
            String entityName = entityResult.getEntityName();
            if (entityName == null) {
                entityName = resolver.getObjEntity(entityResult.getEntityClass()).getName();
            }
            ClassDescriptor classDescriptor = resolver.getClassDescriptor(entityName);
            resolvedComponents.add(new DefaultEntityResultSegment(classDescriptor, fields, offset));
            offset = offset + fields.size();
        } else if (component instanceof EmbeddedResult) {
            EmbeddedResult embeddedResult = (EmbeddedResult) component;
            Map<String, String> fields = embeddedResult.getFields();
            resolvedComponents.add(new DefaultEmbeddableResultSegment(embeddedResult.getEmbeddable(), fields, offset));
            offset = offset + fields.size();
        } else {
            throw new IllegalArgumentException("Unsupported result descriptor component: " + component);
        }
    }
    return resolvedComponents;
}
Also used : DefaultEmbeddableResultSegment(org.apache.cayenne.query.DefaultEmbeddableResultSegment) ClassDescriptor(org.apache.cayenne.reflect.ClassDescriptor) ArrayList(java.util.ArrayList) Map(java.util.Map)

Aggregations

ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 DefaultEmbeddableResultSegment (org.apache.cayenne.query.DefaultEmbeddableResultSegment)1 ClassDescriptor (org.apache.cayenne.reflect.ClassDescriptor)1