Package org.apache.cayenne

Examples of org.apache.cayenne.ObjectId


        return resolver.getObjEntity(oid.getEntityName()).isClientAllowed();
    }

    private boolean isClientArc(Object id, Object targetId, Object arcId) {

        ObjectId oid = (ObjectId) id;
        ObjEntity entity = resolver.getObjEntity(oid.getEntityName());

        if(!entity.isClientAllowed()) {
            return false;
        }
       
        if(entity.getRelationship(arcId.toString()).isRuntime()) {
            return false;
        }
       
        ObjectId targetOid = (ObjectId) targetId;
        ObjEntity targetEntity = resolver.getObjEntity(targetOid.getEntityName());
        if(!targetEntity.isClientAllowed()) {
            return false;
        }

        return true;
View Full Code Here


        }

        // encode only ObjectId for Persistent, ensure that the order of keys is
        // predictable....
        if (scalar instanceof Persistent) {
            ObjectId id = ((Persistent) scalar).getObjectId();
            if (id != null) {
                scalar = id;
            }
        }
View Full Code Here

                    .entrySet()) {

                ClassDescriptor descriptor = entry.getKey();

                for (Persistent object : entry.getValue()) {
                    ObjectId id = object.getObjectId();

                    ObjectId finalId;

                    // record id change and update attributes for generated ids
                    if (id.isReplacementIdAttached()) {

                        Map<String, Object> replacement = id.getReplacementIdMap();
                        Iterator<Property> idProperties = descriptor.getIdProperties();
                        while (idProperties.hasNext()) {
                            AttributeProperty property = (AttributeProperty) idProperties
                                    .next();
                            Object value = replacement.get(property
                                    .getAttribute()
                                    .getDbAttributeName());

                            // TODO: andrus, 11/28/2006: this operation may be redundant
                            // if the id wasn't generated. We may need to optimize it...
                            if (value != null) {
                                property.writePropertyDirectly(object, null, value);
                            }
                        }

                        ObjectId replacementId = id.createReplacementId();

                        result.add(new NodeIdChangeOperation(id, replacementId));

                        // classify replaced permanent ids as "deleted", as
                        // DataRowCache has no notion of replaced id...
View Full Code Here

        if (val == null) {
            out.append("NULL");
        }
        else if (val instanceof Persistent) {
            ObjectId id = ((Persistent) val).getObjectId();

            // check if this id is acceptable to be a parameter
            if (id == null) {
                throw new CayenneRuntimeException(
                        "Can't use TRANSIENT object as a query parameter.");
            }

            if (id.isTemporary()) {
                throw new CayenneRuntimeException(
                        "Can't use NEW object as a query parameter.");
            }

            Map<String, Object> snap = id.getIdSnapshot();
            if (snap.size() != 1) {
                StringBuilder msg = new StringBuilder();
                msg
                        .append("Object must have a single primary key column ")
                        .append("to serve as a query parameter. ")
View Full Code Here

            for (final DbAttribute attribute : descriptor.getDbEntity().getPrimaryKeys()) {
                attributes.add(attribute);
                valueTransformers.add(new Transformer() {

                    public Object transform(Object input) {
                        ObjectId id = (ObjectId) ((ObjectDiff) input).getNodeId();
                        return id.getIdSnapshot().get(attribute.getName());
                    }
                });
            }
        }
        else {

            // TODO: andrus 12/23/2007 - only one step relationship is supported...
            if (descriptor.getPathFromMaster().size() != 1) {
                throw new CayenneRuntimeException(
                        "Only single step dependent relationships are currently supported. Actual path length: "
                                + descriptor.getPathFromMaster().size());
            }
           
            DbRelationship masterDependentDbRel = descriptor.getPathFromMaster().get(0);

            if (masterDependentDbRel != null) {
                for (final DbJoin dbAttrPair : masterDependentDbRel.getJoins()) {
                    DbAttribute dbAttribute = dbAttrPair.getTarget();
                    if (!attributes.contains(dbAttribute)) {

                        attributes.add(dbAttribute);
                        valueTransformers.add(new Transformer() {

                            public Object transform(Object input) {
                                ObjectId id = (ObjectId) ((ObjectDiff) input).getNodeId();
                                return id.getIdSnapshot().get(dbAttrPair.getSourceName());
                            }
                        });
                    }
                }
            }
        }

        if (usingOptimisticLocking) {

            for (final ObjAttribute attribute : descriptor.getEntity().getAttributes()) {

                if (attribute.isUsedForLocking()) {
                    // only care about first step in a flattened attribute
                    DbAttribute dbAttribute = (DbAttribute) attribute
                            .getDbPathIterator()
                            .next();

                    if (!attributes.contains(dbAttribute)) {
                        attributes.add(dbAttribute);

                        valueTransformers.add(new Transformer() {

                            public Object transform(Object input) {
                                return ((ObjectDiff) input).getSnapshotValue(attribute
                                        .getName());
                            }
                        });
                    }
                }
            }

            for (final ObjRelationship relationship : descriptor
                    .getEntity()
                    .getRelationships()) {

                if (relationship.isUsedForLocking()) {
                    // only care about the first DbRelationship
                    DbRelationship dbRelationship = relationship
                            .getDbRelationships()
                            .get(0);

                    for (final DbJoin dbAttrPair : dbRelationship.getJoins()) {
                        DbAttribute dbAttribute = dbAttrPair.getSource();

                        // relationship transformers override attribute transformers for
                        // meaningful FK's... why meaningful FKs can go out of sync is
                        // another story (CAY-595)
                        int index = attributes.indexOf(dbAttribute);
                        if (index >= 0 && !dbAttribute.isForeignKey()) {
                            continue;
                        }

                        Transformer transformer = new Transformer() {

                            public Object transform(Object input) {
                                ObjectId targetId = ((ObjectDiff) input)
                                        .getArcSnapshotValue(relationship.getName());
                                return targetId != null ? targetId.getIdSnapshot().get(
                                        dbAttrPair.getTargetName()) : null;
                            }
                        };

                        if (index < 0) {
View Full Code Here

                        // relationship name.

                        DataRow snapshot = objectStore.getSnapshot(destinationObject
                                .getObjectId());

                        ObjectId id = processorNode.getResolver().createObjectId(
                                snapshot,
                                sourceObjEntity,
                                relatedIdPrefix);

                        sourceObject = (Persistent) objectStore.getNode(id);
View Full Code Here

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

        }

        // this will initialize to-many lists
        descriptor.injectValueHolders(object);

        ObjectId id = new ObjectId(entityName);

        // note that the order of initialization of persistence artifacts below is
        // important - do not change it lightly
        object.setObjectId(id);
        object.setObjectContext(this);
View Full Code Here

                        "Persistent is already registered with another DataContext. "
                                + "Try using 'localObjects()' instead.");
            }
        }
        else {
            persistent.setObjectId(new ObjectId(entity.getName()));
        }

        persistent.setObjectContext(this);
        persistent.setPersistenceState(PersistenceState.NEW);
View Full Code Here

            Iterator it = serverObjects.iterator();
            PrefetchTreeNode prefetchTree = serverMetadata.getPrefetchTree();

            while (it.hasNext()) {
                Persistent object = (Persistent) it.next();
                ObjectId id = object.getObjectId();

                // sanity check
                if (id == null) {
                    throw new CayenneRuntimeException(
                            "Server returned an object without an id: " + object);
                }

                // have to resolve descriptor here for every object, as
                // often a query will not have any info indicating the
                // entity type
                ClassDescriptor serverDescriptor = serverResolver.getClassDescriptor(id
                        .getEntityName());

                clientObjects.add(op.detach(object, serverDescriptor, prefetchTree));
            }
        }
View Full Code Here

TOP

Related Classes of org.apache.cayenne.ObjectId

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.