当前位置: 首页>>代码示例>>Java>>正文


Java Storable.tryInsert方法代码示例

本文整理汇总了Java中com.amazon.carbonado.Storable.tryInsert方法的典型用法代码示例。如果您正苦于以下问题:Java Storable.tryInsert方法的具体用法?Java Storable.tryInsert怎么用?Java Storable.tryInsert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.amazon.carbonado.Storable的用法示例。


在下文中一共展示了Storable.tryInsert方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: insertIndexEntry

import com.amazon.carbonado.Storable; //导入方法依赖的package包/类
/** Assumes caller is in a transaction */
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;
}
 
开发者ID:Carbonado,项目名称:Carbonado,代码行数:37,代码来源:ManagedIndex.java

示例2: updateValues

import com.amazon.carbonado.Storable; //导入方法依赖的package包/类
private void updateValues(S storable, Object state) throws PersistException {
    if (state == null) {
        return;
    }

    List<Storable> oldIndexEntries = (List<Storable>) state;
    int size = oldIndexEntries.size();

    List<Storable> newIndexEntries = new ArrayList<Storable>(size);
    createDependentIndexEntries(storable, newIndexEntries);

    if (size != newIndexEntries.size()) {
        // This is not expected to happen.
        throw new PersistException("Amount of affected dependent indexes changed: " +
                                   size + " != " + newIndexEntries.size());
    }

    for (int i=0; i<size; i++) {
        Storable oldIndexEntry = oldIndexEntries.get(i);
        Storable newIndexEntry = newIndexEntries.get(i);
        if (!oldIndexEntry.equalProperties(newIndexEntry)) {
            // Try delete old entry, just in case it is missing.
            oldIndexEntry.tryDelete();
        }
        // Always try to insert index entry, just in case it is missing.
        newIndexEntry.tryInsert();
    }
}
 
开发者ID:Carbonado,项目名称:Carbonado,代码行数:29,代码来源:DerivedIndexesTrigger.java


注:本文中的com.amazon.carbonado.Storable.tryInsert方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。