Package org.apache.cayenne.map

Examples of org.apache.cayenne.map.ObjRelationship


    class JpaManyToManyVisitor extends JpaRelationshipVisitor {

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

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


        Object createObject(ProjectPath path) {

            JpaRelationship relationship = (JpaRelationship) path.getObject();

            ObjEntity cayenneSrcEntity = (ObjEntity) targetPath.getObject();
            ObjRelationship cayenneRelationship = new ObjRelationship(relationship
                    .getName());

            cayenneSrcEntity.addRelationship(cayenneRelationship);

            JpaEntity jpaTargetEntity = ((JpaEntityMap) path.getRoot())
                    .entityForClass(relationship.getTargetEntityName());

            if (jpaTargetEntity == null) {
                recordConflict(path, "Unknown target entity '"
                        + relationship.getTargetEntityName());
                return null;
            }

            cayenneRelationship.setTargetEntityName(jpaTargetEntity.getName());

            DbEntity cayenneSrcDbEntity = cayenneSrcEntity.getDbEntity();
            DbEntity cayenneTargetDbEntity = cayenneSrcEntity.getDataMap().getDbEntity(
                    jpaTargetEntity.getTable().getName());
            if (cayenneTargetDbEntity == null) {
                cayenneTargetDbEntity = new DbEntity(jpaTargetEntity.getTable().getName());
                cayenneSrcEntity.getDataMap().addDbEntity(cayenneTargetDbEntity);
            }

            JpaDbRelationship dbRelationship = new JpaDbRelationship(cayenneRelationship
                    .getName());
            dbRelationship.setTargetEntity(cayenneTargetDbEntity);
            dbRelationship.setToMany(relationship.isToMany());

            cayenneSrcDbEntity.addRelationship(dbRelationship);
            cayenneRelationship.addDbRelationship(dbRelationship);

            return cayenneRelationship;
        }
View Full Code Here

                    + relationshipName
                    + "' for temporary id: "
                    + objectId);
        }

        ObjRelationship relationship = getRelationship(resolver);

        // build executable select...
        Expression qualifier = ExpressionFactory.matchDbExp(relationship
                .getReverseDbRelationshipPath(), objectId);

        SelectQuery query = new SelectQuery(
                (ObjEntity) relationship.getTargetEntity(),
                qualifier);
        query.setRefreshingObjects(refreshing);
        return query;
    }
View Full Code Here

        }
    }

    public void arcCreated(Object nodeId, Object targetNodeId, Object arcId) {
        ObjEntity entity = resolver.getObjEntity(((ObjectId) nodeId).getEntityName());
        ObjRelationship relationship = (ObjRelationship) entity.getRelationship(arcId
                .toString());

        if (relationship.isSourceIndependentFromTargetChange()) {

            if (!((ObjectId) nodeId).isTemporary()) {
                indirectModifications.add(nodeId);
            }

            if (relationship.isFlattened()) {
                if (relationship.isReadOnly()) {
                    throw new CayenneRuntimeException(
                            "Cannot set the read-only flattened relationship '"
                                + relationship.getName() + "' in ObjEntity '" + relationship.getSourceEntity().getName() + "'.");
                }

                // Register this combination (so we can remove it later if an insert
                // occurs before commit)
                FlattenedArcKey key = new FlattenedArcKey(
View Full Code Here

    }

    public void arcDeleted(Object nodeId, Object targetNodeId, Object arcId) {

        ObjEntity entity = resolver.getObjEntity(((ObjectId) nodeId).getEntityName());
        ObjRelationship relationship = (ObjRelationship) entity.getRelationship(arcId
                .toString());

        if (relationship.isSourceIndependentFromTargetChange()) {
            // do not record temporary id mods...
            if (!((ObjectId) nodeId).isTemporary()) {
                indirectModifications.add(nodeId);
            }

            if (relationship.isFlattened()) {
                if (relationship.isReadOnly()) {
                    throw new CayenneRuntimeException(
                            "Cannot unset the read-only flattened relationship "
                                    + relationship.getName());
                }

                // Register this combination (so we can remove it later if an insert
                // occurs before commit)
                FlattenedArcKey key = new FlattenedArcKey(
View Full Code Here

                declaredIdProperties.add(property);
            }
        }
        else if (property instanceof ArcProperty) {
            ObjRelationship relationship = ((ArcProperty) property).getRelationship();
            ObjRelationship reverseRelationship = relationship.getReverseRelationship();
            if (reverseRelationship != null
                    && "java.util.Map".equals(reverseRelationship.getCollectionType())) {

                if (declaredMapArcProperties == null) {
                    declaredMapArcProperties = new ArrayList<ArcProperty>(2);
                }
View Full Code Here

                // noop - nothing to merge
                return true;
            }

            public boolean visitToOne(ToOneProperty property) {
                ObjRelationship relationship = property.getRelationship();
                if (relationship.isToPK()) {
                    // TODO: will this work for flattened, how do we save snapshots for
                    // them?

                    // if value not modified, update it from snapshot,
                    // otherwise leave it alone
                    if (!isToOneTargetModified(property, object, diff)) {

                        DbRelationship dbRelationship = relationship
                                .getDbRelationships()
                                .get(0);

                        // must check before creating ObjectId because of partial
                        // snapshots
                        if (hasFK(dbRelationship, snapshot)) {
                            ObjectId id = snapshot.createTargetObjectId(relationship
                                    .getTargetEntityName(), dbRelationship);

                            if (diff == null
                                    || !diff.containsArcSnapshot(relationship.getName())
                                    || !Util.nullSafeEquals(id, diff
                                            .getArcSnapshotValue(relationship.getName()))) {

                                if (id == null) {
                                    property.writeProperty(object, null, null);
                                }
                                else {
                                    // if inheritance is involved, we can't use
                                    // 'localObject'
                                    // .. must turn to fault instead
                                    ObjEntity targetEntity = (ObjEntity) relationship
                                            .getTargetEntity();
                                    if (context
                                            .getEntityResolver()
                                            .lookupInheritanceTree(targetEntity) != null) {
                                        property.invalidate(object);
View Full Code Here

                // do nothing
                return true;
            }

            public boolean visitToOne(ToOneProperty property) {
                ObjRelationship rel = property.getRelationship();

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

                Object targetObject = property.readPropertyDirectly(object);
                if (targetObject == null) {
                    return true;
                }

                // 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 = rel.getDbRelationships().get(0);
                    for (DbJoin join : dbRel.getJoins()) {
                        String key = join.getSourceName();
                        snapshot.put(key, storedSnapshot.get(key));
                    }

                    return true;
                }

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

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

                DbRelationship dbRel = rel.getDbRelationships().get(0);
                Map<String, Object> fk = dbRel.srcFkSnapshotWithTargetSnapshot(idParts);
                snapshot.putAll(fk);
                return true;
            }
        });
View Full Code Here

            this.idPath = newPath;
        }
    }

    private 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

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.