Package org.apache.cayenne

Examples of org.apache.cayenne.DataObject


            if (!((ObjectDiff) entry.getValue()).isNoop()) {

                noop = false;

                // accessing objectMap directly to avoid unneeded synchronization.
                DataObject object = (DataObject) objectStore.getNodeNoSync(entry.getKey());
                switch (object.getPersistenceState()) {
                    case PersistenceState.NEW:
                        object.validateForInsert(result);
                        break;
                    case PersistenceState.MODIFIED:
                        object.validateForUpdate(result);
                        break;
                    case PersistenceState.DELETED:
                        object.validateForDelete(result);
                        break;
                }
            }
        }
View Full Code Here


                            + ": this implementation of ObjectContext only supports full DataObjects. Object "
                            + object
                            + " is not supported.");
        }

        DataObject dataObject = (DataObject) object;

        if (dataObject.getDataContext() == null) {
            throw new CayenneRuntimeException(
                    "Attempt to delete unregistered non-TRANSIENT object: " + object);
        }

        if (dataObject.getDataContext() != dataContext) {
            throw new CayenneRuntimeException(
                    "Attempt to delete object regsitered in a different DataContext. Object: "
                            + object
                            + ", data context: "
                            + dataContext);
View Full Code Here

            // object graph
            if (processFlattened) {
                ObjectStore objectStore = dataContext.getObjectStore();
                Iterator iterator = relatedObjects.iterator();
                while (iterator.hasNext()) {
                    DataObject relatedObject = (DataObject) iterator.next();
                    objectStore.recordArcDeleted(
                            object,
                            relatedObject.getObjectId(),
                            relationship.getName());
                }
            }

            // process remaining rules
            switch (relationship.getDeleteRule()) {
                case DeleteRule.NO_ACTION:
                    break;
                case DeleteRule.NULLIFY:
                    ObjRelationship inverseRelationship = relationship
                            .getReverseRelationship();

                    if (inverseRelationship == null) {
                        // nothing we can do here
                        break;
                    }

                    if (inverseRelationship.isToMany()) {
                        Iterator iterator = relatedObjects.iterator();
                        while (iterator.hasNext()) {
                            DataObject relatedObject = (DataObject) iterator.next();
                            relatedObject.removeToManyTarget(inverseRelationship
                                    .getName(), object, true);
                        }
                    }
                    else {
                        // Inverse is to-one - find all related objects and
                        // nullify the reverse relationship
                        Iterator iterator = relatedObjects.iterator();
                        while (iterator.hasNext()) {
                            DataObject relatedObject = (DataObject) iterator.next();
                            relatedObject.setToOneTarget(
                                    inverseRelationship.getName(),
                                    null,
                                    true);
                        }
                    }

                    break;
                case DeleteRule.CASCADE:
                    // Delete all related objects
                    Iterator iterator = relatedObjects.iterator();
                    while (iterator.hasNext()) {
                        DataObject relatedObject = (DataObject) iterator.next();
                        new DataContextDeleteAction(this.dataContext)
                                .performDelete(relatedObject);
                    }

                    break;
View Full Code Here

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

    public List localObjects(List objects) {
        List localObjects = new ArrayList(objects.size());

        Iterator it = objects.iterator();
        while (it.hasNext()) {
            DataObject object = (DataObject) it.next();

            if (object == null) {
                throw new CayenneRuntimeException("Null object");
            }

            localObjects.add(localObject(object.getObjectId(), null));
        }

        return localObjects;
    }
View Full Code Here

                .getClassDescriptor(objEntityName);
        if (descriptor == null) {
            throw new IllegalArgumentException("Invalid entity name: " + objEntityName);
        }

        DataObject dataObject;
        try {
            dataObject = (DataObject) descriptor.createObject();
        }
        catch (Exception ex) {
            throw new CayenneRuntimeException("Error instantiating object.", ex);
        }

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

        dataObject.setObjectId(new ObjectId(objEntityName));
        dataObject.setDataContext(this);
        dataObject.setPersistenceState(PersistenceState.NEW);
        getObjectStore().recordObjectCreated(dataObject);

        return dataObject;
    }
View Full Code Here

                    Iterator it = ((Collection) property.readProperty(object)).iterator();
                    while (it.hasNext()) {
                        Object target = it.next();

                        if (target instanceof DataObject) {
                            DataObject targetDO = (DataObject) target;

                            // make sure it is registered
                            registerNewObject(targetDO);
                            getObjectStore().recordArcCreated(
                                    object,
                                    targetDO.getObjectId(),
                                    property.getName());
                        }
                    }
                }
                return true;
            }

            public boolean visitSingleObjectArc(SingleObjectArcProperty property) {
                Object target = property.readPropertyDirectly(object);

                if (target instanceof DataObject) {

                    DataObject targetDO = (DataObject) target;

                    // make sure it is registered
                    registerNewObject(targetDO);
                    getObjectStore().recordArcCreated(
                            object,
                            targetDO.getObjectId(),
                            property.getName());
                }
                return true;
            }
View Full Code Here

        // clone object list... this maybe a relationship collection with nullify delete
        // rule, so modifying
        Iterator it = new ArrayList(objects).iterator();
        while (it.hasNext()) {
            DataObject object = (DataObject) it.next();
            deleteObject(object);
        }
    }
View Full Code Here

                    + oid
                    + ", as it is a temporary id.");
        }

        synchronized (getObjectStore()) {
            DataObject object = (DataObject) objectStore.getNode(oid);

            // clean up any cached data for this object
            if (object != null) {
                this.invalidateObjects(Collections.singleton(object));
            }
        }

        DataObject object = (DataObject) DataObjectUtils.objectForQuery(
                this,
                new ObjectIdQuery(oid));

        if (object == null) {
            throw new CayenneRuntimeException(
View Full Code Here

        // If deserialized "otherwise", it will not have a datacontext (good)

        synchronized (getObjectStore()) {
            Iterator it = objectStore.getObjectIterator();
            while (it.hasNext()) {
                DataObject object = (DataObject) it.next();
                object.setDataContext(this);
            }
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.cayenne.DataObject

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.