Package org.exolab.castor.jdo

Examples of org.exolab.castor.jdo.DuplicateIdentityException


        if ( entry != null ) {
            if ( entry.deleted )
                throw new ObjectDeletedException( Messages.format("persist.objectDeleted", object.getClass(), identity ) );
            else
                throw new DuplicateIdentityException( "update object which is already in the transaction" );
        }

        try {
            entry = addObjectEntry( oid, object );
            entry.creating = entry.engine.update( this, oid, object, null, 0 );
View Full Code Here


                return oid;
                // should catch some other exception if destory is not succeed
            } catch ( LockNotGrantedException except ) {
                // Someone else is using the object, definite duplicate key
                throw new DuplicateIdentityException( Messages.format(
                    "persist.duplicateIdentity", object.getClass().getName(),
                    oid.getIdentity() ) );
            } catch ( DuplicateIdentityException except ) {
                // we got a write lock and the persistence storage already
                // recorded. Should destory the lock
View Full Code Here

                        break;
                    }

                    if ( tx.isAutoStore() || _fhs[i].isDependent() )
                        if ( value != tx.fetch( fieldEngine, fieldClassMolder, fields[i], null ) )
                            throw new DuplicateIdentityException("");
                } else {
                    if ( _fhs[i].isStored() && _fhs[i].isCheckDirty() )
                        updatePersist = true;
                    updateCache = true;
View Full Code Here

            // Good way: let PersistenceFactory try to determine
            Boolean isDupKey;

            isDupKey = _factory.isDuplicateKeyException( except );
            if ( Boolean.TRUE.equals( isDupKey ) ) {
                throw new DuplicateIdentityException( Messages.format("persist.duplicateIdentity", _clsDesc.getJavaClass().getName(), identity ) );
            } else if ( Boolean.FALSE.equals( isDupKey ) ) {
                throw new PersistenceException( Messages.format("persist.nested", except), except );
            }
            // else unknown, let's check directly.

            // [oleg] Check for duplicate key the old fashioned way,
            //        after the INSERT failed to prevent race conditions
            //        and optimize INSERT times
            try {
                // Close the insert statement
                if ( stmt != null )
                    stmt.close();

                stmt = ( (Connection) conn ).prepareStatement( _pkLookup );
                if (_logger != null) _logger.println(_pkLookup);

                // bind the identity to the preparedStatement
                count = 1;
                if ( identity instanceof Complex ) {
                    Complex id = (Complex) identity;
                    if ( id.size() != _ids.length || _ids.length <= 1 )
                        throw new PersistenceException( "Size of complex field mismatched!");

                    for ( int i=0; i<_ids.length; i++ )
                        stmt.setObject( count++, idToSQL( i, id.get(i) ) );

                } else {
                    if ( _ids.length != 1 )
                        throw new PersistenceException( "Complex field expected!" );

                    stmt.setObject( count++, idToSQL( 0, identity ) );
                }

                if ( stmt.executeQuery().next() ) {
                    stmt.close();
                    throw new DuplicateIdentityException( Messages.format("persist.duplicateIdentity", _clsDesc.getJavaClass().getName(), identity ) );
                }
            } catch ( SQLException except2 ) {
                // Error at the stage indicates it wasn't a duplicate
                // primary key problem. But best if the INSERT error is
                // reported, not the SELECT error.
View Full Code Here

                return oid;
                // should catch some other exception if destory is not succeed
            } catch ( LockNotGrantedException except ) {
                // Someone else is using the object, definite duplicate key
                throw new DuplicateIdentityException( Messages.format(
                    "persist.duplicateIdentity", object.getClass().getName(),
                    oid.getIdentity() ) );
            } catch ( DuplicateIdentityException except ) {
                // we got a write lock and the persistence storage already
                // recorded. Should destory the lock
View Full Code Here

                        break;
                    }

                    if ( tx.isAutoStore() || _fhs[i].isDependent() )
                        if ( value != tx.fetch( fieldEngine, fieldClassMolder, fields[i], null ) )
                            throw new DuplicateIdentityException("");
                } else {
                    if ( _fhs[i].isStored() && _fhs[i].isCheckDirty() )
                        updatePersist = true;
                    updateCache = true;
View Full Code Here

        // add a new entry for this object and use this object as the view
        oid = new OID( engine, molder, depended, identity );
        entry = getObjectEntry( engine, oid );
        if ( identity != null && entry != null ) {
            if ( ! entry.deleted || entry.object != object )
                throw new DuplicateIdentityException( Messages.format( "persist.duplicateIdentity", object.getClass().getName(), identity ) );
            else {
                // If the object was already deleted in this transaction,
                // just undelete it.
                // Remove the entry from a FIFO linked list of deleted entries.
                if ( _deletedList != null ) {
                    ObjectEntry deleted;

                    if ( _deletedList == entry )
                        _deletedList = entry.nextDeleted;
                    else {
                        deleted = _deletedList;
                        while ( deleted.nextDeleted != null && deleted.nextDeleted != entry )
                            deleted = deleted.nextDeleted;
                        if ( deleted.nextDeleted == entry )
                            deleted.nextDeleted = entry.nextDeleted;
                        else
                            throw new PersistenceException( Messages.format("persist.deletedNotFound", identity) );
                    }
                }
            }
        }

        try {
            entry = addObjectEntry( oid, object );
            entry.creating = true;

            if ( _callback != null ) {
                _callback.creating( entry.object, _db );
            } else if ( entry.molder.getCallback() != null ) {
                entry.molder.getCallback().creating( entry.object, _db );
            }

            engine.markCreate( this, oid, object );
        } catch ( LockNotGrantedException lneg ) {
            // yip: do we need LockNotGrantedException, or should we
            // removed them?
            removeObjectEntry( object );
            throw new DuplicateIdentityException("");
        } catch ( PersistenceException pe ) {
            removeObjectEntry( object );
            throw pe;
        } catch ( Exception e ) {
            removeObjectEntry( object );
View Full Code Here

        if ( entry != null ) {
            if ( entry.deleted )
                throw new ObjectDeletedException( Messages.format("persist.objectDeleted", object.getClass(), identity ) );
            else
                throw new DuplicateIdentityException( "update object which is already in the transaction" );
        }

        try {
            entry = addObjectEntry( oid, object );
            entry.creating = entry.engine.update( this, oid, object, null, 0 );
View Full Code Here

TOP

Related Classes of org.exolab.castor.jdo.DuplicateIdentityException

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.