diff options
author | Brian S. O'Neill <bronee@gmail.com> | 2006-10-31 06:47:36 +0000 |
---|---|---|
committer | Brian S. O'Neill <bronee@gmail.com> | 2006-10-31 06:47:36 +0000 |
commit | 482c0c75a53ecb21325adde950438f879baf0e50 (patch) | |
tree | 9fe5f9a14a378df5358728f440c82d947fe9113c /src/main/java/com/amazon/carbonado/repo/indexed | |
parent | adb506cf387e5ce857f18c5a725f5f93c445b239 (diff) |
Index records no longer use join property to link to master and instead copy key property values. This allows IndexedRepository to properly load master records from the master storage.
Diffstat (limited to 'src/main/java/com/amazon/carbonado/repo/indexed')
4 files changed, 36 insertions, 31 deletions
diff --git a/src/main/java/com/amazon/carbonado/repo/indexed/IndexEntryAccessor.java b/src/main/java/com/amazon/carbonado/repo/indexed/IndexEntryAccessor.java index 16a980d..b107a6e 100644 --- a/src/main/java/com/amazon/carbonado/repo/indexed/IndexEntryAccessor.java +++ b/src/main/java/com/amazon/carbonado/repo/indexed/IndexEntryAccessor.java @@ -40,12 +40,13 @@ public interface IndexEntryAccessor<S extends Storable> extends IndexInfo { Storage<?> getIndexEntryStorage();
/**
- * Loads the master object referenced by the given index entry.
+ * Sets all the primary key properties of the given master, using the
+ * applicable properties of the given index entry.
*
- * @param indexEntry index entry which points to master
- * @return master or null if missing
+ * @param indexEntry source of property values
+ * @param master master whose primary key properties will be set
*/
- S loadMaster(Storable indexEntry) throws FetchException;
+ void copyToMasterPrimaryKey(Storable indexEntry, S master);
/**
* Sets all the properties of the given index entry, using the applicable
@@ -54,7 +55,7 @@ public interface IndexEntryAccessor<S extends Storable> extends IndexInfo { * @param indexEntry index entry whose properties will be set
* @param master source of property values
*/
- void setAllProperties(Storable indexEntry, S master);
+ void copyFromMaster(Storable indexEntry, S master);
/**
* Returns true if the properties of the given index entry match those
diff --git a/src/main/java/com/amazon/carbonado/repo/indexed/IndexEntryGenerator.java b/src/main/java/com/amazon/carbonado/repo/indexed/IndexEntryGenerator.java index 3da1a5b..4059ac3 100644 --- a/src/main/java/com/amazon/carbonado/repo/indexed/IndexEntryGenerator.java +++ b/src/main/java/com/amazon/carbonado/repo/indexed/IndexEntryGenerator.java @@ -132,13 +132,14 @@ class IndexEntryGenerator <S extends Storable> { }
/**
- * Loads the master object referenced by the given index entry.
+ * Sets all the primary key properties of the given master, using the
+ * applicable properties of the given index entry.
*
- * @param indexEntry index entry which points to master
- * @return master or null if missing
+ * @param indexEntry source of property values
+ * @param master master whose primary key properties will be set
*/
- public S loadMaster(Storable ref) throws FetchException {
- return mBuilder.loadMaster(ref);
+ public void copyToMasterPrimaryKey(Storable indexEntry, S master) {
+ mBuilder.copyToMasterPrimaryKey(indexEntry, master);
}
/**
@@ -148,8 +149,8 @@ class IndexEntryGenerator <S extends Storable> { * @param indexEntry index entry whose properties will be set
* @param master source of property values
*/
- public void setAllProperties(Storable indexEntry, S master) {
- mBuilder.setAllProperties(indexEntry, master);
+ public void copyFromMaster(Storable indexEntry, S master) {
+ mBuilder.copyFromMaster(indexEntry, master);
}
/**
diff --git a/src/main/java/com/amazon/carbonado/repo/indexed/IndexedCursor.java b/src/main/java/com/amazon/carbonado/repo/indexed/IndexedCursor.java index 3a50a84..892af49 100644 --- a/src/main/java/com/amazon/carbonado/repo/indexed/IndexedCursor.java +++ b/src/main/java/com/amazon/carbonado/repo/indexed/IndexedCursor.java @@ -65,8 +65,11 @@ class IndexedCursor<S extends Storable> extends AbstractCursor<S> { }
while (mCursor.hasNext()) {
final Storable indexEntry = mCursor.next();
- S master = mGenerator.loadMaster(indexEntry);
- if (master == null) {
+
+ S master = mStorage.mMasterStorage.prepare();
+ mGenerator.copyToMasterPrimaryKey(indexEntry, master);
+
+ if (!master.tryLoad()) {
LogFactory.getLog(getClass()).warn
("Master is missing for index entry: " + indexEntry);
} else {
@@ -83,7 +86,7 @@ class IndexedCursor<S extends Storable> extends AbstractCursor<S> { final Storage<?> indexEntryStorage =
repo.getIndexEntryStorageFor(mGenerator.getIndexEntryClass());
Storable newIndexEntry = indexEntryStorage.prepare();
- mGenerator.setAllProperties(newIndexEntry, master);
+ mGenerator.copyFromMaster(newIndexEntry, master);
if (newIndexEntry.tryLoad()) {
// Good, the correct index entry exists. We'll see
@@ -103,18 +106,18 @@ class IndexedCursor<S extends Storable> extends AbstractCursor<S> { Transaction txn = repo.enterTransaction();
try {
// Reload master and verify inconsistency.
- S master = mGenerator.loadMaster(indexEntry);
- if (mGenerator.isConsistent(indexEntry, master)) {
- return;
- }
+ S master = mStorage.mMasterStorage.prepare();
+ mGenerator.copyToMasterPrimaryKey(indexEntry, master);
- Storable newIndexEntry = indexEntryStorage.prepare();
- mGenerator.setAllProperties(newIndexEntry, master);
+ if (master.tryLoad()) {
+ Storable newIndexEntry = indexEntryStorage.prepare();
+ mGenerator.copyFromMaster(newIndexEntry, master);
- newIndexEntry.tryInsert();
+ newIndexEntry.tryInsert();
- indexEntry.tryDelete();
- txn.commit();
+ indexEntry.tryDelete();
+ txn.commit();
+ }
} catch (FetchException fe) {
LogFactory.getLog(IndexedCursor.class).warn
("Unable to check if repair required for " +
diff --git a/src/main/java/com/amazon/carbonado/repo/indexed/ManagedIndex.java b/src/main/java/com/amazon/carbonado/repo/indexed/ManagedIndex.java index cfc399b..80ad172 100644 --- a/src/main/java/com/amazon/carbonado/repo/indexed/ManagedIndex.java +++ b/src/main/java/com/amazon/carbonado/repo/indexed/ManagedIndex.java @@ -126,13 +126,13 @@ class ManagedIndex<S extends Storable> implements IndexEntryAccessor<S> { }
// Required by IndexEntryAccessor interface.
- public S loadMaster(Storable indexEntry) throws FetchException {
- return mGenerator.loadMaster(indexEntry);
+ public void copyToMasterPrimaryKey(Storable indexEntry, S master) {
+ mGenerator.copyToMasterPrimaryKey(indexEntry, master);
}
// Required by IndexEntryAccessor interface.
- public void setAllProperties(Storable indexEntry, S master) {
- mGenerator.setAllProperties(indexEntry, master);
+ public void copyFromMaster(Storable indexEntry, S master) {
+ mGenerator.copyFromMaster(indexEntry, master);
}
// Required by IndexEntryAccessor interface.
@@ -388,7 +388,7 @@ class ManagedIndex<S extends Storable> implements IndexEntryAccessor<S> { private Storable makeIndexEntry(S userStorable) {
Storable indexEntry = mIndexEntryStorage.prepare();
- mGenerator.setAllProperties(indexEntry, userStorable);
+ mGenerator.copyFromMaster(indexEntry, userStorable);
return indexEntry;
}
@@ -403,7 +403,7 @@ class ManagedIndex<S extends Storable> implements IndexEntryAccessor<S> { // If index entry already exists, then index might be corrupt.
{
Storable freshEntry = mIndexEntryStorage.prepare();
- mGenerator.setAllProperties(freshEntry, userStorable);
+ mGenerator.copyFromMaster(freshEntry, userStorable);
indexEntry.copyVersionProperty(freshEntry);
if (freshEntry.equals(indexEntry)) {
// Existing entry is exactly what we expect. Return false
@@ -433,7 +433,7 @@ class ManagedIndex<S extends Storable> implements IndexEntryAccessor<S> { }
Storable freshEntry = mIndexEntryStorage.prepare();
- mGenerator.setAllProperties(freshEntry, freshUserStorable);
+ mGenerator.copyFromMaster(freshEntry, freshUserStorable);
// Blow it away entry and re-insert. Don't simply update
// the entry, since record version number may prevent
|