diff options
Diffstat (limited to 'src/main')
4 files changed, 29 insertions, 8 deletions
diff --git a/src/main/java/com/amazon/carbonado/layout/Layout.java b/src/main/java/com/amazon/carbonado/layout/Layout.java index 0c7ab83..98df22c 100644 --- a/src/main/java/com/amazon/carbonado/layout/Layout.java +++ b/src/main/java/com/amazon/carbonado/layout/Layout.java @@ -518,13 +518,17 @@ public class Layout { }
// Assumes caller is in a transaction.
- void insert(int generation) throws PersistException {
+ void insert(boolean readOnly, int generation) throws PersistException {
if (mAllProperties == null) {
throw new IllegalStateException();
}
mStoredLayout.setGeneration(generation);
+ if (readOnly) {
+ return;
+ }
+
try {
mStoredLayout.insert();
} catch (UniqueConstraintException e) {
diff --git a/src/main/java/com/amazon/carbonado/layout/LayoutFactory.java b/src/main/java/com/amazon/carbonado/layout/LayoutFactory.java index 92099dd..7b7953b 100644 --- a/src/main/java/com/amazon/carbonado/layout/LayoutFactory.java +++ b/src/main/java/com/amazon/carbonado/layout/LayoutFactory.java @@ -102,6 +102,21 @@ public class LayoutFactory implements LayoutCapability { public Layout layoutFor(Class<? extends Storable> type, LayoutOptions options)
throws FetchException, PersistException
{
+ return layoutFor(false, type, options);
+ }
+
+ /**
+ * Returns the layout matching the current definition of the given type.
+ *
+ * @param readOnly if true, don't attempt to persist new generation because
+ * underlying repository is read-only
+ * @throws PersistException if type represents a new generation, but
+ * persisting this information failed
+ */
+ public Layout layoutFor(boolean readOnly,
+ Class<? extends Storable> type, LayoutOptions options)
+ throws FetchException, PersistException
+ {
if (options != null) {
// Make side-effect consistently applied.
options.readOnly();
@@ -132,7 +147,7 @@ public class LayoutFactory implements LayoutCapability { txn = mRepository.enterTransaction(IsolationLevel.READ_COMMITTED);
}
- txn.setForUpdate(true);
+ txn.setForUpdate(!readOnly);
try {
// If type represents a new generation, then a new layout needs to
// be inserted.
@@ -207,7 +222,7 @@ public class LayoutFactory implements LayoutCapability { cursor.close();
}
- newLayout.insert(generation);
+ newLayout.insert(readOnly, generation);
layout = newLayout;
txn.commit();
@@ -247,7 +262,7 @@ public class LayoutFactory implements LayoutCapability { }
}
- if (resyncCap != null) {
+ if (!readOnly && resyncCap != null) {
// Make sure that all layout records are sync'd.
try {
resyncCap.resync(StoredLayoutProperty.class, 1.0, null);
diff --git a/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBRepository.java b/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBRepository.java index b423ab9..eb10042 100644 --- a/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBRepository.java +++ b/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBRepository.java @@ -354,7 +354,7 @@ abstract class BDBRepository<Txn> extends AbstractRepository<Txn> throws FetchException, PersistException
{
try {
- return ((BDBStorage) storageFor(type)).getLayout(mStorableCodecFactory);
+ return ((BDBStorage) storageFor(type)).getLayout(true, mStorableCodecFactory);
} catch (PersistException e) {
throw e;
} catch (RepositoryException e) {
diff --git a/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBStorage.java b/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBStorage.java index 66e8475..f4d8f24 100644 --- a/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBStorage.java +++ b/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBStorage.java @@ -419,7 +419,7 @@ abstract class BDBStorage<Txn, S extends Storable> implements Storage<S>, Storag {
StorableInfo<S> info = StorableIntrospector.examine(getStorableType());
StorableCodecFactory codecFactory = mRepository.getStorableCodecFactory();
- final Layout layout = getLayout(codecFactory);
+ final Layout layout = getLayout(readOnly, codecFactory);
// Open primary database.
Object primaryDatabase;
@@ -766,7 +766,9 @@ abstract class BDBStorage<Txn, S extends Storable> implements Storage<S>, Storag }
}
- Layout getLayout(StorableCodecFactory codecFactory) throws RepositoryException {
+ Layout getLayout(boolean readOnly, StorableCodecFactory codecFactory)
+ throws RepositoryException
+ {
if (Unevolvable.class.isAssignableFrom(getStorableType())) {
// Don't record generation for storables marked as unevolvable.
return null;
@@ -782,7 +784,7 @@ abstract class BDBStorage<Txn, S extends Storable> implements Storage<S>, Storag }
Class<S> type = getStorableType();
- return factory.layoutFor(type, codecFactory.getLayoutOptions(type));
+ return factory.layoutFor(readOnly, type, codecFactory.getLayoutOptions(type));
}
/**
|