Package org.apache.cayenne.map

Examples of org.apache.cayenne.map.EntityResult


        DataMap map = context.getEntityResolver().getDataMap("testmap");
        SQLTemplate query = new SQLTemplate(map, sql, false);
        query.setColumnNamesCapitalization(CapsStrategy.UPPER);

        EntityResult artistResult = new EntityResult(Artist.class);
        artistResult.addDbField(Artist.ARTIST_ID_PK_COLUMN, "X");
        artistResult.addObjectField(Artist.ARTIST_NAME_PROPERTY, "Y");
        artistResult.addObjectField(Artist.DATE_OF_BIRTH_PROPERTY, "Z");

        SQLResult rsMap = new SQLResult();
        rsMap.addEntityResult(artistResult);
        rsMap.addColumnResult("C");
        query.setResult(rsMap);
View Full Code Here


        String id = expression.getText().toLowerCase();
        ClassDescriptor descriptor = descriptorsById.get(id);
        if (descriptor == null) {
            descriptor = descriptorsById.get(expression.getText());
        }
        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;
            }
        };

        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<ObjAttribute> discriminatorColumns = descriptor
                .getDiscriminatorColumns();
        while (discriminatorColumns.hasNext()) {
            ObjAttribute column = discriminatorColumns.next();

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

        return entityResult;
    }
View Full Code Here

                Object nextMapping = resultComponents.get(i);
                if (nextMapping instanceof String) {
                    mapping.addColumnResult((String) nextMapping);
                }
                else if (nextMapping instanceof EJBQLExpression) {
                    EntityResult compileEntityResult = compileEntityResult(
                            (EJBQLExpression) nextMapping,
                            i);
                    if (prefetchTree != null) {
                        for (PrefetchTreeNode prefetch : prefetchTree.getChildren()) {
                            if (((EJBQLExpression) nextMapping).getText().equals(
View Full Code Here

        return compiled;
    }

    private EntityResult compileEntityResultWithPrefetch(EntityResult compiledResult, EJBQLExpression prefetchExpression){
        final EntityResult result = compiledResult;
        String id = prefetchExpression.getText().toLowerCase();
        ClassDescriptor descriptor = descriptorsById.get(id);
        if (descriptor == null) {
            descriptor = descriptorsById.get(prefetchExpression.getText());
        }
        final String prefix = prefetchExpression.getText().substring(prefetchExpression.getText().indexOf(".")+1);
     
        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())) {
                    result.addObjectField(
                            oa.getEntity().getName(),
                            "fetch."+prefix+"."+oa.getName(),
                            prefix +"."+ oa.getDbAttributeName());
                }
                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())) {
                        result.addDbField("fetch."+prefix+"."+src.getName(), prefix +"."+ src.getName());
                    }
                }

                return true;
            }
        };

        descriptor.visitAllProperties(visitor);

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

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

            if (visited.add(column.getName())) {
                result.addDbField("fetch."+prefix+"."+column.getDbAttributePath(), prefix +"."+ column.getDbAttributePath());
            }
        }

        return result;
    }
View Full Code Here

        String id = expression.getText().toLowerCase();
        ClassDescriptor descriptor = descriptorsById.get(id);
        if (descriptor == null) {
            descriptor = descriptorsById.get(expression.getText());
        }
        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;
            }
        };

        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<ObjAttribute> discriminatorColumns = descriptor
                .getDiscriminatorColumns();
        while (discriminatorColumns.hasNext()) {
            ObjAttribute column = discriminatorColumns.next();

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

        return entityResult;
    }
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;
            }
        };

        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<ObjAttribute> discriminatorColumns = descriptor.getDiscriminatorColumns();
        while (discriminatorColumns.hasNext()) {
            ObjAttribute column = discriminatorColumns.next();

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

        return entityResult;
    }
View Full Code Here

        DataMap map = getDomain().getMap("testmap");
        SQLTemplate query = new SQLTemplate(map, sql);
        query.setColumnNamesCapitalization(CapsStrategy.UPPER);

        EntityResult artistResult = new EntityResult(Artist.class);
        artistResult.addDbField(Artist.ARTIST_ID_PK_COLUMN, "X");
        artistResult.addObjectField(Artist.ARTIST_NAME_PROPERTY, "Y");
        artistResult.addObjectField(Artist.DATE_OF_BIRTH_PROPERTY, "Z");

        SQLResult rsMap = new SQLResult();
        rsMap.addEntityResult(artistResult);
        rsMap.addColumnResult("C");
        query.setResult(rsMap);
View Full Code Here

                Object nextMapping = resultComponents.get(i);
                if (nextMapping instanceof String) {
                    mapping.addColumnResult((String) nextMapping);
                }
                else if (nextMapping instanceof EJBQLExpression) {
                    EntityResult compileEntityResult = compileEntityResult(
                            (EJBQLExpression) nextMapping,
                            i);
                    if (prefetchTree != null) {
                        for (PrefetchTreeNode prefetch : prefetchTree.getChildren()) {
                            if (((EJBQLExpression) nextMapping).getText().equals(
View Full Code Here

    }

    private EntityResult compileEntityResultWithPrefetch(
            EntityResult compiledResult,
            EJBQLExpression prefetchExpression) {
        final EntityResult result = compiledResult;
        String id = prefetchExpression.getText().toLowerCase();
        ClassDescriptor descriptor = descriptorsById.get(id);
        if (descriptor == null) {
            descriptor = descriptorsById.get(prefetchExpression.getText());
        }
        final String prefix = prefetchExpression.getText().substring(
                prefetchExpression.getText().indexOf(".") + 1);

        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())) {
                    result.addObjectField(oa.getEntity().getName(), "fetch."
                            + prefix
                            + "."
                            + oa.getName(), prefix + "." + oa.getDbAttributeName());
                }
                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())) {
                        result.addDbField("fetch." + prefix + "." + src.getName(), prefix
                                + "."
                                + src.getName());
                    }
                }

                return true;
            }
        };

        descriptor.visitAllProperties(visitor);

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

        // append inheritance discriminator columns...
        for (ObjAttribute column : descriptor.getDiscriminatorColumns()) {

            if (visited.add(column.getName())) {
                result.addDbField(
                        "fetch." + prefix + "." + column.getDbAttributePath(),
                        prefix + "." + column.getDbAttributePath());
            }
        }
View Full Code Here

        String id = expression.getText().toLowerCase();
        ClassDescriptor descriptor = descriptorsById.get(id);
        if (descriptor == null) {
            descriptor = descriptorsById.get(expression.getText());
        }
        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;
            }
        };

        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...
        for (ObjAttribute column : descriptor.getDiscriminatorColumns()) {

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

        return entityResult;
    }
View Full Code Here

TOP

Related Classes of org.apache.cayenne.map.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.