summaryrefslogtreecommitdiff
path: root/src/main/java/com/amazon/carbonado/repo
diff options
context:
space:
mode:
authorBrian S. O'Neill <bronee@gmail.com>2008-05-09 06:03:46 +0000
committerBrian S. O'Neill <bronee@gmail.com>2008-05-09 06:03:46 +0000
commit06d5dbc5313f2c1686cff1664460f1eced7510f2 (patch)
tree2ce7ad6e6717e9469eb80638a6f13fe41a0754bf /src/main/java/com/amazon/carbonado/repo
parentef26374e59193718c443f3a50f62d52f307a6453 (diff)
JDBC repository now correctly works in non-master mode.
Diffstat (limited to 'src/main/java/com/amazon/carbonado/repo')
-rw-r--r--src/main/java/com/amazon/carbonado/repo/jdbc/JDBCRepository.java4
-rw-r--r--src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorableGenerator.java62
-rw-r--r--src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorage.java4
3 files changed, 45 insertions, 25 deletions
diff --git a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCRepository.java b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCRepository.java
index 6849ca8..cd539f6 100644
--- a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCRepository.java
+++ b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCRepository.java
@@ -164,7 +164,7 @@ class JDBCRepository extends AbstractRepository<JDBCTransaction>
private final Log mLog = LogFactory.getLog(getClass());
- final boolean mIsMaster;
+ private final boolean mIsMaster;
final Iterable<TriggerFactory> mTriggerFactories;
private final AtomicReference<Repository> mRootRef;
private final String mDatabaseProductName;
@@ -699,7 +699,7 @@ class JDBCRepository extends AbstractRepository<JDBCTransaction>
}
}
- return new JDBCStorage<S>(this, info, autoVersioning, suppressReload);
+ return new JDBCStorage<S>(this, info, mIsMaster, autoVersioning, suppressReload);
}
@Override
diff --git a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorableGenerator.java b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorableGenerator.java
index 993b95c..8e6e468 100644
--- a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorableGenerator.java
+++ b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorableGenerator.java
@@ -90,18 +90,21 @@ class JDBCStorableGenerator<S extends Storable> {
}
static <S extends Storable> Class<? extends S> getGeneratedClass(JDBCStorableInfo<S> info,
+ boolean isMaster,
boolean autoVersioning,
boolean suppressReload)
throws SupportException
{
- Object key = KeyFactory.createKey(new Object[] {info, autoVersioning, suppressReload});
+ Object key = KeyFactory.createKey(new Object[] {
+ info, isMaster, autoVersioning, suppressReload});
synchronized (cCache) {
Class<? extends S> generatedClass = (Class<? extends S>) cCache.get(key);
if (generatedClass != null) {
return generatedClass;
}
- generatedClass = new JDBCStorableGenerator<S>(info, autoVersioning, suppressReload)
+ generatedClass = new JDBCStorableGenerator<S>
+ (info, isMaster, autoVersioning, suppressReload)
.generateAndInjectClass();
cCache.put(key, generatedClass);
return generatedClass;
@@ -110,7 +113,13 @@ class JDBCStorableGenerator<S extends Storable> {
private final Class<S> mStorableType;
private final JDBCStorableInfo<S> mInfo;
- private final boolean mAutoVersioning;
+
+ private static enum Versioning {
+ NONE, EXTERNAL, AUTO
+ }
+
+ private final Versioning mVersioning;
+
private final boolean mSuppressReload;
private final Map<String, ? extends JDBCStorableProperty<S>> mAllProperties;
@@ -119,22 +128,31 @@ class JDBCStorableGenerator<S extends Storable> {
private final ClassFile mClassFile;
private JDBCStorableGenerator(JDBCStorableInfo<S> info,
- boolean autoVersioning, boolean suppressReload)
+ boolean isMaster, boolean autoVersioning, boolean suppressReload)
throws SupportException
{
mStorableType = info.getStorableType();
mInfo = info;
- mAutoVersioning = autoVersioning;
mAllProperties = mInfo.getAllProperties();
EnumSet<MasterFeature> features = EnumSet
- .of(MasterFeature.INSERT_SEQUENCES,
- MasterFeature.INSERT_CHECK_REQUIRED, // Must use @Automatic to override.
- MasterFeature.INSERT_TXN, // Required because of reload after insert.
+ .of(MasterFeature.INSERT_TXN, // Required because of reload after insert.
MasterFeature.UPDATE_TXN); // Required because of reload after update.
- if (info.getVersionProperty() != null && info.getVersionProperty().isDerived()) {
- features.add(MasterFeature.VERSIONING);
+ if (!isMaster) {
+ mVersioning = Versioning.NONE;
+ } else {
+ features.add(MasterFeature.INSERT_SEQUENCES);
+ // Must use @Automatic to override.
+ features.add(MasterFeature.INSERT_CHECK_REQUIRED);
+
+ if (info.getVersionProperty() != null && info.getVersionProperty().isDerived()) {
+ features.add(MasterFeature.VERSIONING);
+ // Say none because master storable takes care of it.
+ mVersioning = Versioning.NONE;
+ } else {
+ mVersioning = autoVersioning ? Versioning.AUTO : Versioning.EXTERNAL;
+ }
}
if (suppressReload) {
@@ -155,7 +173,7 @@ class JDBCStorableGenerator<S extends Storable> {
suppressReload = false;
break honorSuppression;
}
- if (prop.isVersion() && !mAutoVersioning) {
+ if (prop.isVersion() && mVersioning == Versioning.EXTERNAL) {
// Always need to reload for version.
suppressReload = false;
break honorSuppression;
@@ -706,7 +724,7 @@ class JDBCStorableGenerator<S extends Storable> {
}
Label setNormally = b.createLabel();
- if (property.isVersion() && mAutoVersioning) {
+ if (property.isVersion() && mVersioning == Versioning.AUTO) {
// Automatically supply initial value unless manually supplied.
branchIfDirty(b, propNumber, setNormally, true);
setPreparedStatementValue
@@ -835,14 +853,14 @@ class JDBCStorableGenerator<S extends Storable> {
propNumber++;
if (property.isSelectable() && !property.isPrimaryKeyMember()) {
- if (property.isVersion() && !mAutoVersioning) {
+ if (property.isVersion() && mVersioning == Versioning.EXTERNAL) {
// Assume database trigger manages version.
continue;
}
Label isNotDirty = null;
- if (!property.isVersion()) {
- // Version must always be updated, but all other
+ if (!property.isVersion() || mVersioning != Versioning.AUTO) {
+ // Auto version must always be updated, but all other
// properties are updated only if dirty.
isNotDirty = b.createLabel();
branchIfDirty(b, propNumber, isNotDirty, false);
@@ -873,7 +891,7 @@ class JDBCStorableGenerator<S extends Storable> {
JDBCStorableProperty<S> versionProperty = mInfo.getVersionProperty();
if (versionProperty != null) {
- if (!versionProperty.isSelectable()) {
+ if (!versionProperty.isSelectable() || mVersioning == Versioning.NONE) {
versionProperty = null;
} else {
// Include version property in WHERE clause to support optimistic locking.
@@ -990,14 +1008,14 @@ class JDBCStorableGenerator<S extends Storable> {
propNumber++;
if (property.isSelectable() && !property.isPrimaryKeyMember()) {
- if (property.isVersion() && !mAutoVersioning) {
+ if (property.isVersion() && mVersioning == Versioning.EXTERNAL) {
// Assume database trigger manages version.
continue;
}
Label isNotDirty = null;
- if (!property.isVersion()) {
- // Version must always be updated, but all other
+ if (!property.isVersion() || mVersioning != Versioning.AUTO) {
+ // Auto version must always be updated, but all other
// properties are updated only if dirty.
isNotDirty = b.createLabel();
branchIfDirty(b, propNumber, isNotDirty, false);
@@ -1005,8 +1023,10 @@ class JDBCStorableGenerator<S extends Storable> {
b.loadLocal(psVar);
b.loadLocal(indexVar);
+ int mode = (property.isVersion() && mVersioning == Versioning.AUTO) ?
+ INCREMENT_VERSION : NORMAL;
setPreparedStatementValue
- (b, property, property.isVersion() ? INCREMENT_VERSION : NORMAL,
+ (b, property, mode,
null, lobArrayVar, lobIndexMap.get(property));
b.integerIncrement(indexVar, 1);
@@ -1196,7 +1216,7 @@ class JDBCStorableGenerator<S extends Storable> {
* Returns true if property value is always part of insert statement.
*/
private boolean isAlwaysInserted(JDBCStorableProperty<?> property) {
- return property.isVersion() ? mAutoVersioning : !property.isAutomatic();
+ return property.isVersion() ? (mVersioning == Versioning.AUTO) : !property.isAutomatic();
}
/**
diff --git a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorage.java b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorage.java
index dd81f90..cc9bef9 100644
--- a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorage.java
+++ b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorage.java
@@ -89,7 +89,7 @@ class JDBCStorage<S extends Storable> extends StandardQueryFactory<S>
final TriggerManager<S> mTriggerManager;
JDBCStorage(JDBCRepository repository, JDBCStorableInfo<S> info,
- boolean autoVersioning, boolean suppressReload)
+ boolean isMaster, boolean autoVersioning, boolean suppressReload)
throws SupportException, RepositoryException
{
super(info.getStorableType());
@@ -98,7 +98,7 @@ class JDBCStorage<S extends Storable> extends StandardQueryFactory<S>
mInfo = info;
Class<? extends S> generatedStorableClass = JDBCStorableGenerator
- .getGeneratedClass(info, autoVersioning, suppressReload);
+ .getGeneratedClass(info, isMaster, autoVersioning, suppressReload);
mInstanceFactory = QuickConstructorGenerator
.getInstance(generatedStorableClass, InstanceFactory.class);