Package org.apache.cayenne

Examples of org.apache.cayenne.Persistent


        // have to scan through all entries
        while (entries.hasNext()) {
            Map.Entry<Object, Persistent> entry = entries.next();

            Persistent object = entry.getValue();

            switch (object.getPersistenceState()) {
                case PersistenceState.DELETED:
                    entries.remove();
                    object.setObjectContext(null);
                    object.setPersistenceState(PersistenceState.TRANSIENT);
                    break;
                case PersistenceState.NEW:
                case PersistenceState.MODIFIED:
                    object.setPersistenceState(PersistenceState.COMMITTED);
                    break;
            }
        }

        // re-register changed object ids
View Full Code Here


    public void resolveHollow(Persistent object) {
        context.prepareForAccess(object, null, false);
    }

    void processIdChange(Object nodeId, Object newId) {
        Persistent object = objectMap.remove(nodeId);

        if (object != null) {
            object.setObjectId((ObjectId) newId);
            objectMap.put(newId, object);

            ObjectDiff change = changes.remove(nodeId);
            if (change != null) {
                changes.put(newId, change);
View Full Code Here

     */
    void processDeletedID(Object nodeId) {

        // access object map directly - the method should be called in a synchronized
        // context...
        Persistent object = objectMap.get(nodeId);

        if (object != null) {

            DataObject dataObject = (object instanceof DataObject)
                    ? (DataObject) object
                    : null;

            DataContextDelegate delegate;

            switch (object.getPersistenceState()) {
                case PersistenceState.COMMITTED:
                case PersistenceState.HOLLOW:
                case PersistenceState.DELETED:

                    // consult delegate
                    delegate = context.nonNullDelegate();

                    if (dataObject == null || delegate.shouldProcessDelete(dataObject)) {
                        objectMap.remove(nodeId);
                        changes.remove(nodeId);

                        // setting DataContext to null will also set
                        // state to transient
                        object.setObjectContext(null);

                        if (dataObject != null) {
                            delegate.finishedProcessDelete(dataObject);
                        }
                    }

                    break;

                case PersistenceState.MODIFIED:

                    // consult delegate
                    delegate = context.nonNullDelegate();
                    if (dataObject != null && delegate.shouldProcessDelete(dataObject)) {
                        object.setPersistenceState(PersistenceState.NEW);
                        changes.remove(nodeId);
                        registerNode(nodeId, object);
                        nodeCreated(nodeId);

                        delegate.finishedProcessDelete(dataObject);
View Full Code Here

            while (it.hasNext()) {
                Map.Entry entry = (Map.Entry) it.next();

                ObjectId id = (ObjectId) entry.getKey();

                Persistent object = (Persistent) objectStore.getNode(id);

                // address manual id override.
                ObjectId objectId = object.getObjectId();
                if (!id.equals(objectId)) {

                    if (objectId != null) {
                        Map<String, Object> replacement = id.getReplacementIdMap();
                        replacement.clear();
                        replacement.putAll(objectId.getIdSnapshot());
                    }

                    object.setObjectId(id);
                }
            }
        }
    }
View Full Code Here

            if (entity == null) {
                throw new IllegalArgumentException("Entity not mapped with Cayenne: "
                        + id);
            }

            Persistent dataObject = null;
            try {
                dataObject = (Persistent) entity.getJavaClass().newInstance();
            }
            catch (Exception ex) {
                throw new CayenneRuntimeException("Error instantiating object.", ex);
            }

            dataObject.setObjectId(id);
            context.registerNewObject(dataObject);
        }
        finally {
            setExternalChange(Boolean.FALSE);
        }
View Full Code Here

            Object oldValue,
            Object newValue) {

        // this change is for simple property, so no need to convert targets to server
        // objects...
        Persistent object = findObject(nodeId);
        ClassDescriptor descriptor = context.getEntityResolver().getClassDescriptor(
                ((ObjectId) nodeId).getEntityName());

        setExternalChange(Boolean.TRUE);
        try {
View Full Code Here

        }
    }

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

        final Persistent source = findObject(nodeId);
        final Persistent target = findObject(targetNodeId);

        // if a target was later deleted, the diff for arcCreated is still preserved and
        // can result in NULL target here.
        if (target == null) {
            return;
View Full Code Here

            setExternalChange(Boolean.FALSE);
        }
    }

    public void arcDeleted(Object nodeId, final Object targetNodeId, Object arcId) {
        final Persistent source = findObject(nodeId);

        // needed as sometime temporary objects are evoked from the context before
        // changing their relationships
        if (source == null) {
            return;
        }

        ClassDescriptor descriptor = context.getEntityResolver().getClassDescriptor(
                ((ObjectId) nodeId).getEntityName());
        Property property = descriptor.getProperty(arcId.toString());

        setExternalChange(Boolean.TRUE);
        try {
            property.visit(new PropertyVisitor() {

                public boolean visitAttribute(AttributeProperty property) {
                    return false;
                }

                public boolean visitToMany(ToManyProperty property) {
                    // connect reverse arc if the relationship is marked as "runtime"
                    ArcProperty reverseArc = property.getComplimentaryReverseArc();
                    boolean autoConnectReverse = reverseArc != null
                            && reverseArc.getRelationship().isRuntime();

                    Persistent target = findObject(targetNodeId);

                    if (target == null) {

                        // this is usually the case when a NEW object was deleted and then
                        // its
View Full Code Here

    Persistent findObject(Object nodeId) {
        // first do a lookup in ObjectStore; if even a hollow object is found, return it;
        // if not - fetch.

        Persistent object = (Persistent) context.getGraphManager().getNode(nodeId);
        if (object != null) {
            return object;
        }

        ObjectId id = (ObjectId) nodeId;
View Full Code Here

        Collection c = (toManyHolder instanceof Map)
                ? ((Map) toManyHolder).values()
                : (Collection) toManyHolder;
        Iterator it = c.iterator();
        while (it.hasNext()) {
            Persistent o = (Persistent) it.next();
            if (nodeId.equals(o.getObjectId())) {
                return o;
            }
        }

        return null;
View Full Code Here

TOP

Related Classes of org.apache.cayenne.Persistent

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.