Package org.apache.cayenne.reflect

Examples of org.apache.cayenne.reflect.ClassDescriptor


        EJBQLPath path = (EJBQLPath) expression.getChild(0);

        String id = path.getAbsolutePath();

        String correlatedEntityId = path.getId();
        ClassDescriptor correlatedEntityDescriptor = context
                .getEntityDescriptor(correlatedEntityId);
        String correlatedTableName = correlatedEntityDescriptor
                .getEntity()
                .getDbEntity()
                .getFullyQualifiedName();
        String correlatedTableAlias = context.getTableAlias(
                correlatedEntityId,
                correlatedTableName);

        String subqueryId = context.createIdAlias(id);
        ClassDescriptor targetDescriptor = context.getEntityDescriptor(subqueryId);

        if (expression.isNegated()) {
            context.append(" NOT");
        }

        context.append(" EXISTS (SELECT 1 FROM ");

        String subqueryTableName = targetDescriptor
                .getEntity()
                .getDbEntity()
                .getFullyQualifiedName();
        String subqueryRootAlias = context.getTableAlias(subqueryId, subqueryTableName);
View Full Code Here


        // make sure the ID for the path does not overlap with other condition
        // joins...
        String id = path.getAbsolutePath();

        String correlatedEntityId = path.getId();
        ClassDescriptor correlatedEntityDescriptor = context
                .getEntityDescriptor(correlatedEntityId);
        String correlatedTableName = correlatedEntityDescriptor
                .getEntity()
                .getDbEntity()
                .getFullyQualifiedName();
        String correlatedTableAlias = context.getTableAlias(
                correlatedEntityId,
                correlatedTableName);

        String subqueryId = context.createIdAlias(id);
        ClassDescriptor targetDescriptor = context.getEntityDescriptor(subqueryId);

        if (expression.isNegated()) {
            context.append(" NOT");
        }

        context.append(" EXISTS (SELECT 1 FROM ");

        String subqueryTableName = targetDescriptor
                .getEntity()
                .getDbEntity()
                .getFullyQualifiedName();
        String subqueryRootAlias = context.getTableAlias(subqueryId, subqueryTableName);
View Full Code Here

    @Override
    public boolean visitIdentificationVariable(EJBQLExpression expression) {
        // this is a match on a variable, like "x = :x"

        ClassDescriptor descriptor = context.getEntityDescriptor(expression.getText());
        if (descriptor == null) {
            throw new EJBQLException("Invalid identification variable: "
                    + expression.getText());
        }

        DbEntity table = descriptor.getEntity().getDbEntity();
        String alias = context.getTableAlias(expression.getText(), table
                .getFullyQualifiedName());

        Collection<DbAttribute> pks = table.getPrimaryKeys();
View Full Code Here

            translator.visitPath(parent, parent.getChildrenCount());

            String id = translator.idPath;
            if (id != null) {

                ClassDescriptor descriptor = context.getEntityDescriptor(id);
                if (descriptor == null) {
                    throw new EJBQLException("Unmapped id variable: " + id);
                }
                String pathChunk = translator.lastPathComponent;

                Property property = descriptor.getProperty(pathChunk);
                if (property instanceof AttributeProperty) {
                    String atrType = ((AttributeProperty) property)
                            .getAttribute()
                            .getType();
View Full Code Here

        return results;
    }

    Persistent objectFromDataRow(DataRow row) {
        // determine entity to use
        ClassDescriptor classDescriptor = descriptorResolutionStrategy
                .descriptorForRow(row);

        // not using DataRow.createObjectId for performance reasons - ObjectResolver
        // has all needed metadata already cached.
        ObjectId anId = createObjectId(row, classDescriptor.getEntity(), null);
        return objectFromDataRow(row, anId, classDescriptor);
    }
View Full Code Here

        // * class properties
        // * PK
        // * FK used in relationship
        // * joined prefetch PK

        ClassDescriptor descriptor = queryMetadata.getClassDescriptor();
        ObjEntity oe = descriptor.getEntity();

        PropertyVisitor visitor = new PropertyVisitor() {

            public boolean visitAttribute(AttributeProperty property) {
                ObjAttribute oa = property.getAttribute();

                resetJoinStack();
                Iterator<CayenneMapEntry> dbPathIterator = oa.getDbPathIterator();
                while (dbPathIterator.hasNext()) {
                    Object pathPart = dbPathIterator.next();

                    if (pathPart == null) {
                        throw new CayenneRuntimeException(
                                "ObjAttribute has no component: " + oa.getName());
                    }
                    else if (pathPart instanceof DbRelationship) {
                        DbRelationship rel = (DbRelationship) pathPart;
                        dbRelationshipAdded(rel, JoinType.LEFT_OUTER, null);
                    }
                    else if (pathPart instanceof DbAttribute) {
                        DbAttribute dbAttr = (DbAttribute) pathPart;

                        appendColumn(columns, oa, dbAttr, attributes, null);
                    }
                }
                return true;
            }

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

            public boolean visitToOne(ToOneProperty property) {
                visitRelationship(property);
                return true;
            }

            private void visitRelationship(ArcProperty property) {
                resetJoinStack();
               
                ObjRelationship rel = property.getRelationship();
                DbRelationship dbRel = rel.getDbRelationships().get(0);

                List<DbJoin> joins = dbRel.getJoins();
                int len = joins.size();
                for (int i = 0; i < len; i++) {
                    DbJoin join = joins.get(i);
                    DbAttribute src = join.getSource();
                    appendColumn(columns, null, src, attributes, null);
                }
            }
        };

        descriptor.visitAllProperties(visitor);
       
        //stack should be reset, because all root table attributes go with "t0" table alias
        resetJoinStack();

        // add remaining needed attrs from DbEntity
View Full Code Here

            final List<ColumnDescriptor> columns,
            SelectQuery query) {

        Set<ColumnTracker> skipSet = new HashSet<ColumnTracker>();

        ClassDescriptor descriptor = queryMetadata.getClassDescriptor();
        ObjEntity oe = descriptor.getEntity();
        DbEntity dbEntity = oe.getDbEntity();
        for (ObjAttribute attribute : oe.getPrimaryKeys()) {

            // synthetic objattributes can't reliably lookup their DbAttribute, so do
            // it manually..
View Full Code Here

public class PrefetchProcessorTreeBuilderTest extends CayenneCase {

    public void testBuildTreeNoPrefetches() {

        final ClassDescriptor descriptor = getDomain()
                .getEntityResolver()
                .getClassDescriptor("Artist");
        List dataRows = new ArrayList();
        dataRows.add(new DataRow(4));
        dataRows.add(new DataRow(4));

        QueryMetadata metadata = new MockQueryMetadata() {

            @Override
            public ClassDescriptor getClassDescriptor() {
                return descriptor;
            }

            @Override
            public ObjEntity getObjEntity() {
                return descriptor.getEntity();
            }

            @Override
            public DbEntity getDbEntity() {
                return getObjEntity().getDbEntity();
            }

            @Override
            public DataMap getDataMap() {
                return getObjEntity().getDataMap();
            }

            @Override
            public boolean isRefreshingObjects() {
                return true;
            }

            @Override
            public boolean isResolvingInherited() {
                return true;
            }
        };

        PrefetchTreeNode tree = new PrefetchTreeNode();
        HierarchicalObjectResolver resolver = new HierarchicalObjectResolver(
                createDataContext(),
                metadata);
        PrefetchProcessorTreeBuilder builder = new PrefetchProcessorTreeBuilder(
                resolver,
                dataRows,
                new HashMap());

        PrefetchProcessorNode processingTree = builder.buildTree(tree);

        assertTrue(processingTree.getChildren().isEmpty());
        assertFalse(processingTree.isPhantom());
        assertFalse(processingTree.isPartitionedByParent());
        assertTrue(processingTree.isDisjointPrefetch());
        assertSame(dataRows, processingTree.getDataRows());
        assertSame(descriptor.getEntity(), processingTree.getResolver().getEntity());
        assertNull(processingTree.getIncoming());
    }
View Full Code Here

        assertNull(processingTree.getIncoming());
    }

    public void testBuildTreeWithPrefetches() {

        final ClassDescriptor descriptor = getDomain()
                .getEntityResolver()
                .getClassDescriptor("Artist");
        ObjEntity e2 = getObjEntity("Painting");
        ObjEntity e3 = getObjEntity("Gallery");
        ObjEntity e4 = getObjEntity("Exhibit");
        ObjEntity e5 = getObjEntity("ArtistExhibit");

        List mainRows = new ArrayList();
        Map extraRows = new HashMap();

        PrefetchTreeNode tree = new PrefetchTreeNode();
        tree.addPath(Artist.PAINTING_ARRAY_PROPERTY).setPhantom(false);
        tree.addPath(
                Artist.PAINTING_ARRAY_PROPERTY
                        + "."
                        + Painting.TO_GALLERY_PROPERTY
                        + "."
                        + Gallery.EXHIBIT_ARRAY_PROPERTY).setPhantom(false);
        tree.addPath(Artist.ARTIST_EXHIBIT_ARRAY_PROPERTY).setPhantom(false);

        QueryMetadata metadata = new MockQueryMetadata() {

            @Override
            public ClassDescriptor getClassDescriptor() {
                return descriptor;
            }

            @Override
            public ObjEntity getObjEntity() {
                return descriptor.getEntity();
            }

            @Override
            public DbEntity getDbEntity() {
                return getObjEntity().getDbEntity();
            }

            @Override
            public DataMap getDataMap() {
                return getObjEntity().getDataMap();
            }

            @Override
            public boolean isRefreshingObjects() {
                return true;
            }

            @Override
            public boolean isResolvingInherited() {
                return true;
            }
        };

        HierarchicalObjectResolver resolver = new HierarchicalObjectResolver(
                createDataContext(),
                metadata);
        PrefetchProcessorTreeBuilder builder = new PrefetchProcessorTreeBuilder(
                resolver,
                mainRows,
                extraRows);

        PrefetchProcessorNode n1 = builder.buildTree(tree);

        assertSame(mainRows, n1.getDataRows());
        assertSame(descriptor.getEntity(), n1.getResolver().getEntity());

        PrefetchProcessorNode n2 = (PrefetchProcessorNode) n1.getNode("paintingArray");
        assertNotNull(n2);
        assertSame(e2, n2.getResolver().getEntity());
        assertFalse(n2.isPhantom());
View Full Code Here

            return getObjectStore().getSnapshot(object.getObjectId());
        }

        ObjEntity entity = getEntityResolver().lookupObjEntity(object);
        final ClassDescriptor descriptor = getEntityResolver().getClassDescriptor(
                entity.getName());
        final DataRow snapshot = new DataRow(10);

        descriptor.visitProperties(new PropertyVisitor() {

            public boolean visitAttribute(AttributeProperty property) {
                ObjAttribute objAttr = property.getAttribute();

                // processing compound attributes correctly
View Full Code Here

TOP

Related Classes of org.apache.cayenne.reflect.ClassDescriptor

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.