Package org.apache.cayenne.map

Examples of org.apache.cayenne.map.ObjRelationship


            this.idPath = newPath;
        }
    }

    protected void processIntermediatePathComponent() {
        ObjRelationship relationship = (ObjRelationship) currentEntity
                .getRelationship(lastPathComponent);
        if (relationship == null) {
            throw new EJBQLException("Unknown relationship '"
                    + lastPathComponent
                    + "' for entity '"
                    + currentEntity.getName()
                    + "'");
        }

        this.currentEntity = (ObjEntity) relationship.getTargetEntity();
    }
View Full Code Here


        if (attribute != null) {
            processTerminatingAttribute(attribute);
            return;
        }

        ObjRelationship relationship = (ObjRelationship) currentEntity
                .getRelationship(lastPathComponent);
        if (relationship != null) {
            processTerminatingRelationship(relationship);
            return;
        }
View Full Code Here

                visitRelationship(property);
                return true;
            }

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

                for (DbJoin join : dbRel.getJoins()) {
                    DbAttribute src = join.getSource();
                    appendColumn(idVar, null, src, fields);
                }
View Full Code Here

        }

        Iterator relationships = entity.getRelationshipMap().entrySet().iterator();
        while (relationships.hasNext()) {
            Map.Entry entry = (Map.Entry) relationships.next();
            ObjRelationship rel = (ObjRelationship) entry.getValue();

            // if target doesn't propagates its key value, skip it
            if (rel.isSourceIndependentFromTargetChange()) {
                continue;
            }

            Object targetObject = object.readPropertyDirectly(rel.getName());
            if (targetObject == null) {
                continue;
            }

            // if target is Fault, get id attributes from stored snapshot
            // to avoid unneeded fault triggering
            if (targetObject instanceof Fault) {
                DataRow storedSnapshot = getObjectStore().getSnapshot(
                        object.getObjectId());
                if (storedSnapshot == null) {
                    throw new CayenneRuntimeException(
                            "No matching objects found for ObjectId "
                                    + object.getObjectId()
                                    + ". Object may have been deleted externally.");
                }

                DbRelationship dbRel = (DbRelationship) rel.getDbRelationships().get(0);
                Iterator joins = dbRel.getJoins().iterator();
                while (joins.hasNext()) {
                    DbJoin join = (DbJoin) joins.next();
                    String key = join.getSourceName();
                    snapshot.put(key, storedSnapshot.get(key));
                }

                continue;
            }

            // target is resolved and we have an FK->PK to it,
            // so extract it from target...
            DataObject target = (DataObject) targetObject;
            Map idParts = target.getObjectId().getIdSnapshot();

            // this may happen in uncommitted objects - see the warning in the JavaDoc of
            // this method.
            if (idParts.isEmpty()) {
                continue;
            }

            DbRelationship dbRel = (DbRelationship) rel.getDbRelationships().get(0);
            Map fk = dbRel.srcFkSnapshotWithTargetSnapshot(idParts);
            snapshot.putAll(fk);
        }

        // process object id map
View Full Code Here

                        + "supported at the moment, this will be fixed soon. "
                        + "Unsupported path : "
                        + path);
            }

            ObjRelationship relationship = (ObjRelationship) entity.getRelationship(path);
            if (relationship == null) {
                throw new CayenneRuntimeException("Invalid relationship: " + path);
            }

            if (relationship.isToMany()) {
                throw new CayenneRuntimeException(
                        "Only to-one relationships are supported at the moment. "
                                + "Can't prefetch to-many: "
                                + path);
            }
View Full Code Here

                }
            }

            // only create obj relationship if it is a class property
            if (classProps.contains(relName)) {
                ObjRelationship rel = new ObjRelationship();
                rel.setName(relName);
                rel.setSourceEntity(objEntity);
                rel.setTargetEntity(target);
                objEntity.addRelationship(rel);

                if (dbRel != null) {
                    rel.addDbRelationship(dbRel);
                }
            }
        }
    }
View Full Code Here

            // ignore normal relationships
            if (targetPath == null) {
                continue;
            }

            ObjRelationship flatRel = new ObjRelationship();
            flatRel.setName((String) relMap.get("name"));
            flatRel.setSourceEntity(e);
            e.addRelationship(flatRel);

            DbEntity dbEntity = e.getDbEntity();
            if (dbEntity == null) {
                // not ready to handle inheritance from abstract entities...
                continue;
            }

            // determine DB relationship mapping...
            Expression exp = new ASTDbPath(targetPath);
            Iterator path = dbEntity.resolvePathComponents(exp);

            DbRelationship firstRel = null;
            DbRelationship lastRel = null;
            while (path.hasNext()) {
                lastRel = (DbRelationship) path.next();
                flatRel.addDbRelationship(lastRel);

                if (firstRel == null) {
                    firstRel = lastRel;
                }
            }

            if ((firstRel != null) && (lastRel != null)) {
                Collection potentialTargets = e.getDataMap().getMappedEntities(
                        (DbEntity) lastRel.getTargetEntity());

                // sanity check
                if (potentialTargets.size() != 1) {
                    throw new CayenneRuntimeException(
                            "One and only one entity should be mapped"
                                    + " to "
                                    + lastRel.getTargetEntity().getName()
                                    + ". Instead found : "
                                    + potentialTargets.size());
                }

                flatRel.setTargetEntity((ObjEntity) potentialTargets.iterator().next());
            }
            else {
                throw new CayenneRuntimeException("relationship in the path was null!");
            }
        }
View Full Code Here

    class JpaManyToOneVisitor extends JpaRelationshipVisitor {

        @Override
        Object createObject(ProjectPath path) {
            ObjRelationship objRelationship = (ObjRelationship) super.createObject(path);
            return objRelationship.getDbRelationships().get(0);
        }
View Full Code Here

    class JpaOneToManyVisitor extends JpaRelationshipVisitor {

        @Override
        Object createObject(ProjectPath path) {
            ObjRelationship objRelationship = (ObjRelationship) super.createObject(path);
            JpaDbRelationship relationship = (JpaDbRelationship) objRelationship
                    .getDbRelationships()
                    .get(0);

            if (relationship != null) {
                JpaOneToMany jpaRelationship = (JpaOneToMany) path.getObject();
                relationship.setMappedBy(jpaRelationship.getMappedBy());
                objRelationship.setMapKey(jpaRelationship.getMapKey());

                objRelationship.setCollectionType(jpaRelationship
                        .getPropertyDescriptor()
                        .getType()
                        .getName());
            }
            return relationship;
View Full Code Here

    class JpaOneToOneVisitor extends JpaRelationshipVisitor {

        @Override
        Object createObject(ProjectPath path) {
            ObjRelationship objRelationship = (ObjRelationship) super.createObject(path);
            JpaDbRelationship relationship = (JpaDbRelationship) objRelationship
                    .getDbRelationships()
                    .get(0);

            if (relationship != null) {
                JpaOneToOne jpaRelationship = (JpaOneToOne) path.getObject();
View Full Code Here

TOP

Related Classes of org.apache.cayenne.map.ObjRelationship

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.