Package org.apache.cayenne.query

Examples of org.apache.cayenne.query.EntityResult


    }

    private EntityResult compileEntityResult(EJBQLExpression expression, int position) {
        String id = expression.getText().toLowerCase();
        ClassDescriptor descriptor = descriptorsById.get(id);
        final EntityResult entityResult = new EntityResult(descriptor.getObjectClass());
        final String prefix = "ec" + position + "_";
        final int[] index = {
            0
        };

        final Set<String> visited = new HashSet<String>();

        PropertyVisitor visitor = new PropertyVisitor() {

            public boolean visitAttribute(AttributeProperty property) {
                ObjAttribute oa = property.getAttribute();
                if (visited.add(oa.getDbAttributePath())) {
                    entityResult.addObjectField(
                            oa.getEntity().getName(),
                            oa.getName(),
                            prefix + index[0]++);
                }
                return true;
            }

            public boolean visitToMany(ToManyProperty property) {
                return true;
            }

            public boolean visitToOne(ToOneProperty property) {
                ObjRelationship rel = property.getRelationship();
                DbRelationship dbRel = rel.getDbRelationships().get(0);

                for (DbJoin join : dbRel.getJoins()) {
                    DbAttribute src = join.getSource();
                    if (src.isForeignKey() && visited.add(src.getName())) {
                        entityResult.addDbField(src.getName(), prefix + index[0]++);
                    }
                }

                return true;
            }
        };

        // EJBQL queries are polymorphic by definition - there is no distinction between
        // inheritance/no-inheritance fetch
        descriptor.visitAllProperties(visitor);

        // append id columns ... (some may have been appended already via relationships)
        DbEntity table = descriptor.getEntity().getDbEntity();
        for (DbAttribute pk : table.getPrimaryKeys()) {
            if (visited.add(pk.getName())) {
                entityResult.addDbField(pk.getName(), prefix + index[0]++);
            }
        }

        // append inheritance discriminator columns...
        Iterator<DbAttribute> discriminatorColumns = descriptor.getDiscriminatorColumns();
        while (discriminatorColumns.hasNext()) {
            DbAttribute column = discriminatorColumns.next();

            if (visited.add(column.getName())) {
                entityResult.addDbField(column.getName(), prefix + index[0]++);
            }
        }

        return entityResult;
    }
View Full Code Here


            // convert data rows to standardized format...
            SQLResultSetMapping rsMapping = metadata.getResultSetMapping();
            if (rsMapping != null) {
                // expect 1 and only 1 entityMapping...
                EntityResult entityMapping = rsMapping.getEntityResult(0);
                normalized = toNormalizedDataRows(entityMapping, mainRows);
            }
            else {
                normalized = mainRows;
            }
View Full Code Here

            // pass 2 - resolve individual object columns, and then update the rows...
            List[] resultLists = new List[entityPositions.length];
            for (int i = 0; i < entityPositions.length; i++) {
                int pos = entityPositions[i];
                EntityResult entityMapping = rsMapping.getEntityResult(pos);
                List<DataRow> normalized = toNormalizedDataRows(entityMapping, mainRows);

                List<Persistent> nextResult = toObjects(entityMapping
                        .getClassDescriptor(domain.getEntityResolver()), null, normalized);

                for (int j = 0; j < rowsLen; j++) {
                    objects.get(j)[pos] = nextResult.get(j);
                }
View Full Code Here

                mapping.addColumnResult(c.getName());
            }

            for (JpaEntityResult e : jpaMapping.getEntityResults()) {

                EntityResult result = new EntityResult(e.getEntityClassName());
                for (JpaFieldResult f : e.getFieldResults()) {
                    result.addObjectField(f.getName(), f.getColumn());
                }

                // TODO: andrus 2/23/2008 - discriminator column...
            }
View Full Code Here

                mapping.addColumnResult(c.getName());
            }

            for (JpaEntityResult e : jpaMapping.getEntityResults()) {

                EntityResult result = new EntityResult(e.getEntityClassName());
                for (JpaFieldResult f : e.getFieldResults()) {
                    result.addObjectField(f.getName(), f.getColumn());
                }

                // TODO: andrus 2/23/2008 - discriminator column...
            }
View Full Code Here

            // convert data rows to standardized format...
            SQLResultSetMapping rsMapping = metadata.getResultSetMapping();
            if (rsMapping != null) {
                // expect 1 and only 1 entityMapping...
                EntityResult entityMapping = rsMapping.getEntityResult(0);
                normalized = toNormalizedDataRows(entityMapping, mainRows);
            }
            else {
                normalized = mainRows;
            }
View Full Code Here

            // pass 2 - resolve individual object columns, and then update the rows...
            List[] resultLists = new List[entityPositions.length];
            for (int i = 0; i < entityPositions.length; i++) {
                int pos = entityPositions[i];
                EntityResult entityMapping = rsMapping.getEntityResult(pos);
                List<DataRow> normalized = toNormalizedDataRows(entityMapping, mainRows);

                List<Persistent> nextResult = toObjects(entityMapping
                        .getClassDescriptor(domain.getEntityResolver()), null, normalized);

                for (int j = 0; j < rowsLen; j++) {
                    objects.get(j)[pos] = nextResult.get(j);
                }
View Full Code Here

    }

    private EntityResult compileEntityResult(EJBQLExpression expression, int position) {
        String id = expression.getText().toLowerCase();
        ClassDescriptor descriptor = descriptorsById.get(id);
        final EntityResult entityResult = new EntityResult(descriptor.getObjectClass());
        final String prefix = "ec" + position + "_";
        final int[] index = {
            0
        };

        final Set<String> visited = new HashSet<String>();

        PropertyVisitor visitor = new PropertyVisitor() {

            public boolean visitAttribute(AttributeProperty property) {
                ObjAttribute oa = property.getAttribute();
                if (visited.add(oa.getDbAttributePath())) {
                    entityResult.addObjectField(
                            oa.getEntity().getName(),
                            oa.getName(),
                            prefix + index[0]++);
                }
                return true;
            }

            public boolean visitToMany(ToManyProperty property) {
                return true;
            }

            public boolean visitToOne(ToOneProperty property) {
                ObjRelationship rel = property.getRelationship();
                DbRelationship dbRel = rel.getDbRelationships().get(0);

                for (DbJoin join : dbRel.getJoins()) {
                    DbAttribute src = join.getSource();
                    if (src.isForeignKey() && visited.add(src.getName())) {
                        entityResult.addDbField(src.getName(), prefix + index[0]++);
                    }
                }

                return true;
            }
        };

        // EJBQL queries are polymorphic by definition - there is no distinction between
        // inheritance/no-inheritance fetch
        descriptor.visitAllProperties(visitor);

        // append id columns ... (some may have been appended already via relationships)
        for (String pkName : descriptor.getEntity().getPrimaryKeyNames()) {
            if (visited.add(pkName)) {
                entityResult.addDbField(pkName, prefix + index[0]++);
            }
        }

        // append inheritance discriminator columns...
        Iterator<DbAttribute> discriminatorColumns = descriptor.getDiscriminatorColumns();
        while (discriminatorColumns.hasNext()) {
            DbAttribute column = discriminatorColumns.next();

            if (visited.add(column.getName())) {
                entityResult.addDbField(column.getName(), prefix + index[0]++);
            }
        }

        return entityResult;
    }
View Full Code Here

TOP

Related Classes of org.apache.cayenne.query.EntityResult

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.