Package org.exolab.castor.persist

Examples of org.exolab.castor.persist.OID


            }
            while (removedItor.hasNext()) {
                // must be loaded thur transaction, so that the related object
                // is properly locked and updated before we delete it.
                Identity identity = (Identity) removedItor.next();
                if (!tx.isDeletedByOID(new OID(fieldClassMolder, identity))) {
                    ProposedEntity proposedValue = new ProposedEntity(fieldClassMolder);
                    Object reldel = tx.load(identity, proposedValue, null);
                    if (reldel != null && tx.isPersistent(reldel)) {
                        tx.writeLock(reldel, tx.getLockTimeout());
View Full Code Here


        CacheEntry ce = new CacheEntry();
        assertNull(ce.getOID());
        assertNull(ce.getEntry());
        assertEquals(TimeStampable.NO_TIMESTAMP, ce.getTimeStamp());

        OID oid = createOID();
        ce.setOID(oid);
        assertTrue(oid == ce.getOID());
        ce.setOID(null);
        assertNull(ce.getOID());
       
View Full Code Here

            final ClassMolder molder, final Identity identity,
            final AccessMode suggestedAccessMode)
    throws PersistenceException {

        Object objectInTx;
        OID oid;
        AccessMode accessMode;

        if (identity == null) {
            throw new PersistenceException("Identities can't be null!");
        }

        LockEngine engine = molder.getLockEngine();
       
        oid = new OID(molder, identity);
        accessMode = molder.getAccessMode(suggestedAccessMode);
        if (accessMode == AccessMode.ReadOnly) {
            objectInTx = _tracker.getObjectForOID(engine, oid, true);
        } else {
            objectInTx = _tracker.getObjectForOID(engine, oid, false);
View Full Code Here

            final ProposedEntity proposedObject, final AccessMode suggestedAccessMode,
            final QueryResults results)
    throws PersistenceException {
       
        Object objectInTx;
        OID oid;
        AccessMode accessMode;

        ClassMolder molder = proposedObject.getActualClassMolder();
        LockEngine engine = molder.getLockEngine();

        if (identity == null) {
            throw new PersistenceException("Identities can't be null!");
        }

        // Test that the object to be loaded (which we will fill in) is of an
        // appropriate type for our molder.
        if (proposedObject.getEntity() != null
                && !molder.getJavaClass(_db.getClassLoader()).isAssignableFrom(
                        proposedObject.getProposedEntityClass())) {
            throw new PersistenceException(Messages.format("persist.typeMismatch",
                    molder.getName(), proposedObject.getProposedEntityClass()));
        }
       
        oid = new OID(molder, identity);
        accessMode = molder.getAccessMode(suggestedAccessMode);
        if (accessMode == AccessMode.ReadOnly) {
            objectInTx = _tracker.getObjectForOID(engine, oid, true);
        } else {
            objectInTx = _tracker.getObjectForOID(engine, oid, false);
        }

        if (objectInTx != null) {
            // Object exists in this transaction.

            // If the object has been loaded, but the instance sugguested to
            // be loaded into is not the same as the loaded instance,
            // error is reported.
           
            // TODO [WG]: could read && propsedObject != objectInTransaction
            if (proposedObject.getEntity() != null
                    && proposedObject.getEntity() != objectInTx) {
                throw new PersistenceException(Messages.format(
                        "persist.multipleLoad", molder.getName(), identity));
            }

            // If the object has been loaded in this transaction from a
            // different engine this is an error. If the object has been
            // deleted in this transaction, it cannot be re-loaded. If the
            // object has been created in this transaction, it cannot be
            // re-loaded but no error is reported.
            if (engine != _tracker.getMolderForObject(objectInTx).getLockEngine()) {
                throw new PersistenceException(Messages.format(
                        "persist.multipleLoad", molder.getName(), identity));
            }

            // Objects marked deleted in the transaction therefore we
            // throw a ObjectNotFoundException to signal that object isn't
            // available any more.
            if (_tracker.isDeleted(objectInTx)) {
                throw new ObjectNotFoundException(Messages.format(
                        "persist.objectNotFound", molder.getName(), identity));
            }

            // ssa, multi classloader feature (note - this code appears to be
            // duplicated, yet different, in both cases. Why?)
            // ssa, FIXME : Are the two following statements equivalent ? (bug
            // 998)
            // if ( ! molder.getJavaClass().isAssignableFrom(
            // entry.object.getClass() ) )
            // if ( ! molder.getJavaClass( _db.getClassLoader()
            // ).isAssignableFrom( entry.object.getClass() ) )
            if (!molder.getJavaClass(_db.getClassLoader()).isAssignableFrom(
                    objectInTx.getClass())) {
                throw new PersistenceException(Messages.format(
                        "persist.typeMismatch", molder.getName(),
                        objectInTx.getClass()));
            }

            // If the object has been created in this transaction, don't bother
            // testing access mode.
            if (_tracker.isCreated(objectInTx)) {
                return objectInTx;
            }

            if ((accessMode == AccessMode.Exclusive || accessMode == AccessMode.DbLocked)
                    && !_tracker.getOIDForObject(objectInTx)
                            .isDbLock()) {
                // If we are in exclusive mode and object has not been
                // loaded in exclusive mode before, then we have a
                // problem. We cannot return an object that is not
                // synchronized with the database, but we cannot
                // synchronize a live object.
                throw new PersistenceException(Messages.format(
                        "persist.lockConflict", molder.getName(), identity));
            }

            return objectInTx;
        }

        // Load (or reload, in case the object is stored in a acache) the object
        // through the persistence engine with the requested lock. This might report
        // failure (object no longer exists), hold until a suitable lock is granted
        // (or fail to grant), or report error with the persistence engine.
        try {
            if (proposedObject.getEntity() != null) {
                objectInTx = proposedObject.getEntity();
            } else {
                // ssa, multi classloader feature
                // ssa, FIXME : No better way to do that ?
                // object = molder.newInstance();
                if (_instanceFactory != null) {
                    objectInTx = _instanceFactory.newInstance(molder
                            .getName(), _db.getClassLoader());
                } else {
                    objectInTx = molder.newInstance(_db
                            .getClassLoader());
                }
               
                proposedObject.setProposedEntityClass(objectInTx.getClass());
                proposedObject.setActualEntityClass(objectInTx.getClass());
                proposedObject.setEntity(objectInTx);
            }

            molder.setIdentity(this, objectInTx, identity);
            _tracker.trackObject(molder, oid, objectInTx);
            OID newoid = engine.load(this, oid, proposedObject,
                    suggestedAccessMode, _lockTimeout, results);
                   
            if (proposedObject.isExpanded()) {
                // Remove old OID from ObjectTracker
                _tracker.untrackObject(objectInTx);
               
                // Create new OID
                ClassMolder actualClassMolder = engine.getClassMolder(
                        proposedObject.getActualEntityClass());
                OID actualOID = new OID(actualClassMolder, identity);
                actualClassMolder.setIdentity(this, proposedObject.getEntity(), identity);

                // Create instance of 'expanded object'
                Object expandedObject = null;
                try {
View Full Code Here

        if (_autoStore && _tracker.isTracking(object)) {
            return;
        }

        if (_tracker.isDeleted(object)) {
            OID deletedoid = _tracker.getOIDForObject(object);
            throw new PersistenceException(Messages.format(
                    "persist.objectAlreadyPersistent", object.getClass()
                            .getName(), (deletedoid != null) ? deletedoid
                            .getIdentity() : null));
        }

        // Create the object. This can only happen once for each object in
        // all transactions running on the same engine, so after creation
        // add a new entry for this object and use this object as the view
        // Note that the oid which is created is for a dependent object;
        // this is not a change to the rootObjectOID, and therefore doesn't get
        // trackOIDChange()d.
        OID oid = new OID(molder, rootObjectOID, identity);

        // You shouldn't be able to modify an object marked read-only in this
        // transaction.
        Object trackedObject = _tracker.getObjectForOID(engine, oid, false);
        if (identity != null && trackedObject != null) {
View Full Code Here

        Iterator creatableIterator = createableObjects.iterator();
        while (creatableIterator.hasNext()) {
            // Must perform creation after object is recorded in transaction
            // to prevent circular references.
            Object toBeCreated = creatableIterator.next();
            OID toBeCreatedOID = _tracker.getOIDForObject(toBeCreated);
            ClassMolder toBeCreatedMolder = _tracker.getMolderForObject(toBeCreated);
            LockEngine toBeCreatedLockEngine = toBeCreatedMolder.getLockEngine();

            try {
                // Allow users to create inside the callback.
                // We do this by rechecking that the object is still marked
                // creatable;
                // this will tell us if another process got to it first.
                if (_tracker.isCreating(toBeCreated)) {

                    if (_callback != null) {
                        _callback.creating(toBeCreated, _db);
                    } else if (toBeCreatedMolder.getCallback() != null) {
                        toBeCreatedMolder.getCallback().creating(toBeCreated, _db);
                    }

                    OID oid = toBeCreatedLockEngine.create(this,
                            toBeCreatedOID, toBeCreated);

                    if (oid.getIdentity() == null) {
                        throw new IllegalStateException(
                                "oid.getIdentity() is null after create!");
                    }

                    // rehash the object entry, in case of oid changed
View Full Code Here

                .getObjectsWithUpdateCacheNeededState();
        Iterator it = objectsMarkedForUpdate.iterator();
        while (it.hasNext()) {
            Object toCacheUpdate = it.next();
            if (_tracker.isCreated(toCacheUpdate)) {
                OID toCacheUpdateOID = _tracker.getOIDForObject(toCacheUpdate);
                LockEngine toCacheUpdateLocker =
                    _tracker.getMolderForObject(toCacheUpdate).getLockEngine();
                toCacheUpdateLocker.updateCache(this, toCacheUpdateOID, toCacheUpdate);
                _tracker.unmarkUpdateCacheNeeded(toCacheUpdate);
            }
View Full Code Here

        LockEngine engine = molder.getLockEngine();
       
        Identity identity = molder.getActualIdentity(this, object);
        if (molder.isDefaultIdentity(identity)) { identity = null; }

        OID oid = new OID(molder, depended, identity);

        // Check the object is in the transaction.
        Object foundInTransaction = _tracker.getObjectForOID(engine, oid, false);
        if (_autoStore && foundInTransaction != null
                && foundInTransaction == object) {
View Full Code Here

                    "persist.objectNotPersistent", object.getClass().getName()));
        }

        ClassMolder molder = _tracker.getMolderForObject(object);
        LockEngine engine = molder.getLockEngine();
        OID oid = _tracker.getOIDForObject(object);

        // Cannot delete same object twice
        if (_tracker.isDeleted(object)) {
            throw new ObjectDeletedException(Messages.format(
                    "persist.objectDeleted", object.getClass().getName(), oid
                            .getIdentity()));
        }

        try {
            if (_callback != null) {
View Full Code Here

            throw new ObjectNotPersistentException(Messages.format(
                    "persist.objectNotPersistent", object.getClass().getName()));
        }

        LockEngine engine = _tracker.getMolderForObject(object).getLockEngine();
        OID oid = _tracker.getOIDForObject(object);

        if (_tracker.isDeleted(object)) {
            throw new ObjectDeletedException(Messages.format(
                    "persist.objectDeleted", object.getClass(), oid.getIdentity()));
        }

        try {

            engine.writeLock(this, oid, timeout);
View Full Code Here

TOP

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

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.