Examples of EntityResult


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

Examples of org.apache.cayenne.query.EntityResult

            // 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

Examples of org.apache.cayenne.query.EntityResult

            // 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

Examples of org.apache.cayenne.query.EntityResult

                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

Examples of org.apache.cayenne.query.EntityResult

                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

Examples of org.apache.cayenne.query.EntityResult

            // 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

Examples of org.apache.cayenne.query.EntityResult

            // 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

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)
        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

Examples of org.broadleafcommerce.openadmin.dto.EntityResult

        }
        return strVal;
    }

    protected EntityResult update(PersistencePackage persistencePackage, Object primaryKey, boolean includeRealEntity) throws ServiceException {
        EntityResult entityResult = new EntityResult();
        Entity entity = persistencePackage.getEntity();
        PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective();
        ForeignKey foreignKey = (ForeignKey) persistencePerspective.getPersistencePerspectiveItems().get(PersistencePerspectiveItemType.FOREIGNKEY);
        if (foreignKey != null && !foreignKey.getMutable()) {
            throw new SecurityServiceException("Entity not mutable");
        }
        try {
            Class<?>[] entities = persistenceManager.getPolymorphicEntities(persistencePackage.getCeilingEntityFullyQualifiedClassname());
            Map<String, FieldMetadata> mergedProperties = persistenceManager.getDynamicEntityDao().getMergedProperties(
                persistencePackage.getCeilingEntityFullyQualifiedClassname(),
                entities,
                foreignKey,
                persistencePerspective.getAdditionalNonPersistentProperties(),
                persistencePerspective.getAdditionalForeignKeys(),
                MergedPropertyType.PRIMARY,
                persistencePerspective.getPopulateToOneFields(),
                persistencePerspective.getIncludeFields(),
                persistencePerspective.getExcludeFields(),
                persistencePerspective.getConfigurationKey(),
                ""
            );
            if (primaryKey == null) {
                primaryKey = getPrimaryKey(entity, mergedProperties);
            }
            Serializable instance = persistenceManager.getDynamicEntityDao().retrieve(Class.forName(entity.getType()[0]), primaryKey);

            Assert.isTrue(instance != null, "Entity not found");

            instance = createPopulatedInstance(instance, entity, mergedProperties, false, persistencePackage.isValidateUnsubmittedProperties());
            if (!entity.isValidationFailure()) {
                instance = persistenceManager.getDynamicEntityDao().merge(instance);
                if (includeRealEntity) {
                    entityResult.setEntityBackingObject(instance);
                }

                List<Serializable> entityList = new ArrayList<Serializable>(1);
                entityList.add(instance);

                entity = getRecords(mergedProperties, entityList, null, null)[0];
                entityResult.setEntity(entity);
                return entityResult;
            } else {
                entityResult.setEntity(entity);
                return entityResult;
            }
        } catch (Exception e) {
            throw new ServiceException("Problem updating entity : " + e.getMessage(), e);
        }
View Full Code Here

Examples of org.broadleafcommerce.openadmin.dto.EntityResult

        return update(persistencePackage, null, true);
    }

    @Override
    public Entity update(PersistencePackage persistencePackage) throws ServiceException {
        EntityResult er = update(persistencePackage, null, false);
        return er.getEntity();
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.