Package org.exolab.castor.persist

Examples of org.exolab.castor.persist.ClassMolder


    public boolean markCreate(final TransactionContext tx, final OID oid,
            final Object object)
    throws PersistenceException {
        boolean updateCache = false;
        // create dependent objects if exists
        ClassMolder fieldClassMolder = _fieldMolder.getFieldClassMolder();
        Object o = _fieldMolder.getValue(object, tx.getClassLoader());
        if (o != null) {
            Iterator itor = ClassMolderHelper.getIterator(o);
            while (itor.hasNext()) {
                Object oo = itor.next();
                if (_fieldMolder.isDependent()) {
                    if (!tx.isRecorded(oo)) {
                        // autoCreated = true;
                        tx.markCreate(fieldClassMolder, oo, oid);
                        if (fieldClassMolder.isKeyGenUsed()) {
                            updateCache = true;
                        }
                    } else
                    // fail-fast principle: if the object depend on another
                    // object,
                    // throw exception
                    if (!tx.isDepended(oid, oo)) {
                        throw new PersistenceException(
                                "Dependent object may not change its master");
                    }
                } else if (tx.isAutoStore()) {
                    if (!tx.isRecorded(oo)) {
                        tx.markCreate(fieldClassMolder, oo, null);
                        if (fieldClassMolder.isKeyGenUsed()) {
                            updateCache = true;
                        }
                    }
                }
            }
View Full Code Here


     *      java.lang.Object)
     */
    public void markDelete(final TransactionContext tx, final Object object,
            final Object field)
    throws PersistenceException {
        ClassMolder fieldClassMolder = _fieldMolder.getFieldClassMolder();
        // markDelete mix with prestore
        // so, store is not yet called, and only the loaded (or created)
        // relation have to be deleted.
        // not really. cus, the other created relation, may already
        // has reference to this object. so, how to deal with that?
        if (_fieldMolder.isDependent()) {
            ArrayList alist = (ArrayList) field;
            if (field != null) {
                for (int j = 0; j < alist.size(); j++) {
                    Identity fid = (Identity) alist.get(j);
                    Object fetched = null;
                    if (fid != null) {
                        fetched = tx.fetch(fieldClassMolder, fid, null);
                        if (fetched != null) {
                            tx.delete(fetched);
                        }
                    }
                }

                Iterator itor = ClassMolderHelper.getIterator(_fieldMolder
                        .getValue(object, tx.getClassLoader()));
                while (itor.hasNext()) {
                    Object fobject = itor.next();
                    if (fobject != null && tx.isPersistent(fobject)) {
                        tx.delete(fobject);
                    }
                }
            }
        } else {
            if (field != null) {
                ArrayList alist = (ArrayList) field;
                for (int j = 0; j < alist.size(); j++) {
                    Identity fid = (Identity) alist.get(j);
                    Object fetched = null;
                    if (fid != null) {
                        fetched = tx.fetch(fieldClassMolder, fid, null);
                        if (fetched != null) {
                            fieldClassMolder.removeRelation(tx, fetched,
                                    fieldClassMolder, object);
                        }
                    }
                }

                Iterator itor = ClassMolderHelper.getIterator(_fieldMolder
                        .getValue(object, tx.getClassLoader()));
                while (itor.hasNext()) {
                    Object fobject = itor.next();
                    if (fobject != null && tx.isPersistent(fobject)) {
                        fieldClassMolder.removeRelation(tx, fobject,
                                fieldClassMolder, object);
                    }
                }
            }
        }
View Full Code Here

     */
    public UpdateFlags preStore(final TransactionContext tx, final OID oid,
            final Object object, final int timeout, final Object field)
    throws PersistenceException {
        UpdateFlags flags = new UpdateFlags();
        ClassMolder fieldClassMolder = _fieldMolder.getFieldClassMolder();
        Object value = _fieldMolder.getValue(object, tx.getClassLoader());
        ArrayList orgFields = (ArrayList) field;
        if (!(value instanceof Lazy)) {
            Collection removed = ClassMolderHelper.getRemovedIdsList(tx,
                    orgFields, value, fieldClassMolder);
            Iterator removedItor = removed.iterator();
            if (removedItor.hasNext()) {
                if (_fieldMolder.isStored() && _fieldMolder.isCheckDirty()) {
                    flags.setUpdatePersist(true);
                }
                flags.setUpdateCache(true);
            }
            while (removedItor.hasNext()) {
                Identity removedId = (Identity) removedItor.next();
                Object reldel = tx.fetch(fieldClassMolder, removedId, null);
                if (reldel != null) {
                    if (_fieldMolder.isDependent()) {
                        tx.delete(reldel);
                    } else {
                        fieldClassMolder.removeRelation(tx, reldel,
                                this._classMolder, object);
                    }
//                } else {
//                    // should i notify user that the object does not exist?
//                    // user can't delete dependent object himself. So, must
//                    // error.
                }
            }

            Collection added = ClassMolderHelper.getAddedValuesList(tx,
                    orgFields, value, fieldClassMolder);
            Iterator addedItor = added.iterator();
            if (addedItor.hasNext()) {
                if (_fieldMolder.isStored() && _fieldMolder.isCheckDirty()) {
                    flags.setUpdatePersist(true);
                }
                flags.setUpdateCache(true);
            }
            while (addedItor.hasNext()) {
                Object addedValue = addedItor.next();
                if (_fieldMolder.isDependent()) {
                    if (!tx.isRecorded(addedValue)) {
                        tx.markCreate(fieldClassMolder, addedValue, oid);
//                    } else {
//                        // should i notify user that the object does not exist?
//                        // user can't create dependent object himself. So, must
//                        // be
//                        // an error.
                    }
                } else if (tx.isAutoStore()) {
                    if (!tx.isRecorded(addedValue)) {
                        tx.markCreate(fieldClassMolder, addedValue, null);
                    }
                }
            }

            // it would be good if we also compare the new field element with
            // the element in the transaction, when debug is set true
        } else {
            RelationCollection lazy = (RelationCollection) value;

            // this RelationCollection has to clean up its state at the end of
            // the
            // transaction
            tx.addTxSynchronizable(lazy);

            ArrayList deleted = lazy.getDeleted();
            if (!deleted.isEmpty()) {
                if (_fieldMolder.isStored() && _fieldMolder.isCheckDirty()) {
                    flags.setUpdatePersist(true);
                }
                flags.setUpdateCache(true);

                // if ( fieldMolder.isDependent() ) {
                Iterator itor = deleted.iterator();
                while (itor.hasNext()) {
                    flags.setUpdateCache(true);
                    Object toBeDeleted = lazy.find(itor.next());
                    if (toBeDeleted != null && tx.isPersistent(toBeDeleted)) {
                        if (_fieldMolder.isDependent()) {
                            tx.delete(toBeDeleted);
                        } else {
                            fieldClassMolder.removeRelation(tx, toBeDeleted,
                                    this._classMolder, object);
                        }
//                    } else {
//                        // what to do if it happens?
                    }
View Full Code Here

    public void update(final TransactionContext tx, final OID oid,
            final Object object, final AccessMode suggestedAccessMode,
            final Object field)
    throws PersistenceException {
        ArrayList v = (ArrayList) field;
        ClassMolder fieldClassMolder = _fieldMolder.getFieldClassMolder();
        ArrayList newSetOfIds = new ArrayList();
        Iterator itor = ClassMolderHelper.getIterator(_fieldMolder
                .getValue(object, tx.getClassLoader()));

        // iterate the collection of this data object field
        while (itor.hasNext()) {
            Object element = itor.next();
            Object actualIdentity = fieldClassMolder.getActualIdentity(tx, element);
            newSetOfIds.add(actualIdentity);
            if (!tx.isRecorded(element)) {
                if (_fieldMolder.isDependent() && !_fieldMolder.isLazy()) {
                    if (v != null && v.contains(actualIdentity)) {
                        tx.markUpdate(fieldClassMolder, element, oid);
View Full Code Here

            final Object object,
            final AccessMode suggestedAccessMode)
    throws PersistenceException {
        boolean updateCache = false;
        // create dependent objects if exists
        ClassMolder fieldClassMolder = _fieldMolder.getFieldClassMolder();
        Object o = _fieldMolder.getValue(object, tx.getClassLoader());
        if (o != null) {
            Iterator itor = ClassMolderHelper.getIterator(o);
            while (itor.hasNext()) {
                Object oo = itor.next();
View Full Code Here

     *      #create(org.castor.persist.TransactionContext,
     *      java.lang.Object)
     */
    public final Object create(final TransactionContext tx, final Object object) {
        Object field = null;
        ClassMolder fieldClassMolder = _fieldMolder.getFieldClassMolder();
        Object o = _fieldMolder.getValue(object, tx.getClassLoader());
        if (o != null) {
            ArrayList fids =
                ClassMolderHelper.extractIdentityList(tx, fieldClassMolder, o);
            field = fids;
View Full Code Here

     *      java.lang.Object)
     */
    public final Object updateCache(final TransactionContext tx, final OID oid,
            final Object object) {
        Object field = null;
        ClassMolder fieldClassMolder = _fieldMolder.getFieldClassMolder();
        Object value = _fieldMolder.getValue(object, tx.getClassLoader());
        if (value != null) {
            ArrayList fids;
            if (!(value instanceof Lazy)) {
                fids = ClassMolderHelper.extractIdentityList(tx,
View Full Code Here

    throws PersistenceException {
        Object o = field;
        if (o == null) {
            _fieldMolder.setValue(object, null, tx.getClassLoader());
        } else if (!_fieldMolder.isLazy()) { // <-- fix for bug #1046
            ClassMolder fieldClassMolder = _fieldMolder.getFieldClassMolder();
            Class collectionType = _fieldMolder.getCollectionType();

            ArrayList v = (ArrayList) field;
            if (v != null) {
                if (collectionType.isArray()) {
                    Object[] arrayValue = (Object[]) java.lang.reflect.Array
                            .newInstance(collectionType.getComponentType(), v
                                    .size());
                    for (int j = 0; j < v.size(); j++) {
                        arrayValue[j] = tx.fetch(fieldClassMolder, (Identity) v.get(j), null);
                    }
                    _fieldMolder.setValue(object, arrayValue, tx
                            .getClassLoader());
                } else {
                    CollectionProxy cp = CollectionProxy.create(_fieldMolder,
                            object, tx.getClassLoader());
                    // clear collection
                    _fieldMolder.setValue(object, cp.getCollection(), tx
                            .getClassLoader());

                    for (int j = 0; j < v.size(); j++) {
                        Object obj = tx.fetch(fieldClassMolder, (Identity) v.get(j), null);
                        if (obj != null) {
                            cp.add((Identity) v.get(j), obj);
                        }
                    }
                    cp.close();
                    // fieldMolder.setValue( object, cp.getCollection() );
                }
            } else {
                _fieldMolder.setValue(object, null, tx.getClassLoader());
            }
        } else {
            ArrayList list = (ArrayList) field;
            ClassMolder fieldClassMolder = _fieldMolder.getFieldClassMolder();

            RelationCollection relcol = new RelationCollection(tx, oid,
                    fieldClassMolder, null, list);
            _fieldMolder.setValue(object, relcol, tx.getClassLoader());
        }
View Full Code Here

    public final void expireCache(final TransactionContext tx, final Object field)
    throws PersistenceException {
        // field is one-to-many and many-to-many type. All the related
        // objects will be expired

        ClassMolder fieldClassMolder = _fieldMolder.getFieldClassMolder();

        ArrayList v = (ArrayList) field;
        if (v != null) {
            for (int j = 0; j < v.size(); j++) {
                tx.expireCache(fieldClassMolder, (Identity) v.get(j));
View Full Code Here

            final AccessMode suggestedAccessMode)
    throws PersistenceException {
        // field is one-to-many and many-to-many type. All the related
        // object will be loaded and put in a Collection. And, the
        // collection will be set as the field.
        ClassMolder fieldClassMolder = _fieldMolder.getFieldClassMolder();

        if (!_fieldMolder.isLazy()) {
            // lazy loading is not specified, load all objects into
            // the collection and set the Collection as the data object
            // field.
View Full Code Here

TOP

Related Classes of org.exolab.castor.persist.ClassMolder

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.