本文整理匯總了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;
}
示例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();
}
}