private boolean insertIndexEntry(final S userStorable, final Storable indexEntry)
        throws PersistException
    {
        if (indexEntry.tryInsert()) {
            return true;
        }

        // If index entry already exists, then index might be corrupt.
        try {
            Storable freshIndexEntry = mIndexEntryStorage.prepare();
            mAccessor.copyFromMaster(freshIndexEntry, userStorable);
            freshIndexEntry.load();
            indexEntry.copyVersionProperty(freshIndexEntry);
            if (freshIndexEntry.equals(indexEntry)) {
                // Existing entry is fine.
                return true;

            } else {
                S freshMasterEntry = mMasterStorage.prepare();
                mAccessor.copyToMasterPrimaryKey(freshIndexEntry, freshMasterEntry);
                
                if (!freshMasterEntry.tryLoad()) {
                    // Existing entry for alternate key is bogus. Delete it.
                    freshIndexEntry.delete();
                    indexEntry.insert();
                    return true;
                }
            }

        } catch (FetchException e) {
            throw e.toPersistException();
        }

        return false;
    }
private boolean insertIndexEntry ( final S userStorable , final Storable indexEntry ) throws PersistException { if ( indexEntry . tryInsert ( ) ) { return true ; } try { Storable freshIndexEntry = mIndexEntryStorage . prepare ( ) ; mAccessor . copyFromMaster ( freshIndexEntry , userStorable ) ; freshIndexEntry . load ( ) ; indexEntry . copyVersionProperty ( freshIndexEntry ) ; if ( freshIndexEntry . equals ( indexEntry ) ) { return true ; } else { S freshMasterEntry = mMasterStorage . prepare ( ) ; mAccessor . copyToMasterPrimaryKey ( freshIndexEntry , freshMasterEntry ) ; if ( ! freshMasterEntry . tryLoad ( ) ) { freshIndexEntry . delete ( ) ; indexEntry . insert ( ) ; return true ; } } } catch ( FetchException e ) { throw e . toPersistException ( ) ; } return false ; }
Assumes caller is in a transaction