Examples of ObjRelationship


Examples of org.apache.cayenne.map.ObjRelationship

    private int changeDeleteRule(int deleteRule) {
        ObjEntity entity = context.getEntityResolver().lookupObjEntity(
                DeleteRuleFlatA.class);

        ObjRelationship relationship = (ObjRelationship) entity
                .getRelationship(DeleteRuleFlatA.FLAT_B_PROPERTY);
        int oldRule = relationship.getDeleteRule();
        relationship.setDeleteRule(deleteRule);
        return oldRule;
    }
View Full Code Here

Examples of org.apache.cayenne.map.ObjRelationship

    private ObjRelationship unsetReverse() {
        ObjEntity entity = context.getEntityResolver().lookupObjEntity(
                DeleteRuleFlatA.class);

        ObjRelationship relationship = (ObjRelationship) entity
                .getRelationship(DeleteRuleFlatA.FLAT_B_PROPERTY);
        ObjRelationship reverse = relationship.getReverseRelationship();

        if (reverse != null) {
            reverse.getSourceEntity().removeRelationship(reverse.getName());
            context.getEntityResolver().getClassDescriptorMap().removeDescriptor(
                    "DeleteRuleFlatA");
            context.getEntityResolver().getClassDescriptorMap().removeDescriptor(
                    "DeleteRuleFlatB");
        }
View Full Code Here

Examples of org.apache.cayenne.map.ObjRelationship

    private void restoreReverse(ObjRelationship reverse) {
        ObjEntity entity = context.getEntityResolver().lookupObjEntity(
                DeleteRuleFlatA.class);

        ObjRelationship relationship = (ObjRelationship) entity
                .getRelationship(DeleteRuleFlatA.FLAT_B_PROPERTY);
        relationship.getTargetEntity().addRelationship(reverse);
        context.getEntityResolver().getClassDescriptorMap().removeDescriptor(
                "DeleteRuleFlatA");
        context.getEntityResolver().getClassDescriptorMap().removeDescriptor(
                "DeleteRuleFlatB");
    }
View Full Code Here

Examples of org.apache.cayenne.map.ObjRelationship

                entityName);

        descriptor.visitProperties(new PropertyVisitor() {

            public boolean visitToMany(ToManyProperty property) {
                ObjRelationship relationship = (ObjRelationship) entity
                        .getRelationship(property.getName());

                processRules(object, property, relationship.getDeleteRule(), oldState);
                return true;
            }

            public boolean visitToOne(ToOneProperty property) {
                ObjRelationship relationship = (ObjRelationship) entity
                        .getRelationship(property.getName());

                processRules(object, property, relationship.getDeleteRule(), oldState);
                return true;
            }

            public boolean visitAttribute(AttributeProperty property) {
                return true;
View Full Code Here

Examples of org.apache.cayenne.map.ObjRelationship

    public ClassDescriptor getRootDescriptor() {
        return rootId != null ? getEntityDescriptor(rootId) : null;
    }

    public List<DbRelationship> getIncomingRelationships(String identifier) {
        ObjRelationship relationship = incomingById.get(identifier);
        if (relationship == null) {
            return Collections.emptyList();
        }

        return relationship.getDbRelationships();
    }
View Full Code Here

Examples of org.apache.cayenne.map.ObjRelationship

                    throw new EJBQLException("Unmapped id variable: " + id);
                }

                StringBuilder buffer = new StringBuilder(id);

                ObjRelationship incoming = null;
                String pathRelationshipString = "";

                for (int i = 1; i < path.getChildrenCount(); i++) {

                    String pathChunk = path.getChild(i).getText();
View Full Code Here

Examples of org.apache.cayenne.map.ObjRelationship

            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]++);
View Full Code Here

Examples of org.apache.cayenne.map.ObjRelationship

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

Examples of org.apache.cayenne.map.ObjRelationship

            RelationshipQuery relationshipQuery = (RelationshipQuery) query;
            if (relationshipQuery.isRefreshing()) {
                return !DONE;
            }

            ObjRelationship relationship = relationshipQuery.getRelationship(domain
                    .getEntityResolver());

            // check if we can derive target PK from FK... this implies that the
            // relationship is to-one
            if (relationship.isSourceIndependentFromTargetChange()) {
                return !DONE;
            }

            if (cache == null) {
                return !DONE;
            }

            DataRow sourceRow = cache.getCachedSnapshot(relationshipQuery.getObjectId());
            if (sourceRow == null) {
                return !DONE;
            }

            // we can assume that there is one and only one DbRelationship as
            // we previously checked that "!isSourceIndependentFromTargetChange"
            DbRelationship dbRelationship = relationship.getDbRelationships().get(0);

            ObjectId targetId = sourceRow.createTargetObjectId(relationship
                    .getTargetEntityName(), dbRelationship);

            // null id means that FK is null...
            if (targetId == null) {
                this.response = new GenericResponse(Collections.EMPTY_LIST);
                return DONE;
            }

            DataRow targetRow = cache.getCachedSnapshot(targetId);

            if (targetRow != null) {
                this.response = new GenericResponse(Collections.singletonList(targetRow));
                return DONE;
            }

            // check whether a non-null FK is enough to assume non-null target, and if so,
            // create a fault
            if (context != null
                    && relationship.isSourceDefiningTargetPrecenseAndType(domain
                            .getEntityResolver())) {

                // prevent passing partial snapshots to ObjectResolver per CAY-724.
                // Create
                // a hollow object right here and skip object conversion downstream
View Full Code Here

Examples of org.apache.cayenne.map.ObjRelationship

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