summaryrefslogtreecommitdiff
path: root/src/main/java/com/amazon/carbonado/info
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/amazon/carbonado/info')
-rw-r--r--src/main/java/com/amazon/carbonado/info/ChainedProperty.java25
-rw-r--r--src/main/java/com/amazon/carbonado/info/StorableIntrospector.java29
-rw-r--r--src/main/java/com/amazon/carbonado/info/StorableProperty.java9
3 files changed, 55 insertions, 8 deletions
diff --git a/src/main/java/com/amazon/carbonado/info/ChainedProperty.java b/src/main/java/com/amazon/carbonado/info/ChainedProperty.java
index 1c4022d..ab01c5f 100644
--- a/src/main/java/com/amazon/carbonado/info/ChainedProperty.java
+++ b/src/main/java/com/amazon/carbonado/info/ChainedProperty.java
@@ -165,6 +165,25 @@ public class ChainedProperty<S extends Storable> implements Appender {
}
/**
+ * Returns true if any property in the chain can be null.
+ *
+ * @see com.amazon.carbonado.Nullable
+ */
+ public boolean isNullable() {
+ if (mPrime.isNullable()) {
+ return true;
+ }
+ if (mChain != null) {
+ for (StorableProperty<?> prop : mChain) {
+ if (prop.isNullable()) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ /**
* Returns the last property in the chain, or the prime property if chain
* is empty.
*/
@@ -293,7 +312,8 @@ public class ChainedProperty<S extends Storable> implements Appender {
}
/**
- * Returns the chained property in a parseable form.
+ * Returns the chained property in a parseable form. The format is
+ * "name.subname.subsubname".
*/
@Override
public String toString() {
@@ -310,7 +330,8 @@ public class ChainedProperty<S extends Storable> implements Appender {
}
/**
- * Appends the chained property in a parseable form.
+ * Appends the chained property in a parseable form. The format is
+ * "name.subname.subsubname".
*/
public void appendTo(Appendable app) throws IOException {
app.append(mPrime.getName());
diff --git a/src/main/java/com/amazon/carbonado/info/StorableIntrospector.java b/src/main/java/com/amazon/carbonado/info/StorableIntrospector.java
index 8be3d02..c527371 100644
--- a/src/main/java/com/amazon/carbonado/info/StorableIntrospector.java
+++ b/src/main/java/com/amazon/carbonado/info/StorableIntrospector.java
@@ -49,6 +49,7 @@ import org.cojen.util.WeakIdentityMap;
import com.amazon.carbonado.Alias;
import com.amazon.carbonado.AlternateKeys;
import com.amazon.carbonado.Authoritative;
+import com.amazon.carbonado.Automatic;
import com.amazon.carbonado.FetchException;
import com.amazon.carbonado.Index;
import com.amazon.carbonado.Indexes;
@@ -696,6 +697,7 @@ public class StorableIntrospector {
Alias alias = null;
Version version = null;
Sequence sequence = null;
+ Automatic automatic = null;
Independent independent = null;
Join join = null;
@@ -714,6 +716,7 @@ public class StorableIntrospector {
alias = readMethod.getAnnotation(Alias.class);
version = readMethod.getAnnotation(Version.class);
sequence = readMethod.getAnnotation(Sequence.class);
+ automatic = readMethod.getAnnotation(Automatic.class);
independent = readMethod.getAnnotation(Independent.class);
join = readMethod.getAnnotation(Join.class);
}
@@ -745,6 +748,10 @@ public class StorableIntrospector {
errorMessages.add
("Sequence annotation not allowed on mutator: " + writeMethod);
}
+ if (writeMethod.getAnnotation(Automatic.class) != null) {
+ errorMessages.add
+ ("Automatic annotation not allowed on mutator: " + writeMethod);
+ }
if (writeMethod.getAnnotation(Independent.class) != null) {
errorMessages.add
("Independent annotation not allowed on mutator: " + writeMethod);
@@ -820,7 +827,7 @@ public class StorableIntrospector {
return new SimpleProperty<S>
(property, enclosing, nullable != null, pk, altKey,
aliases, constraints, adapters == null ? null : adapters[0],
- version != null, sequenceName, independent != null);
+ version != null, sequenceName, independent != null, automatic != null);
}
// Do additional work for join properties.
@@ -928,7 +935,8 @@ public class StorableIntrospector {
return new JoinProperty<S>
(property, enclosing, nullable != null, aliases,
constraints, adapters == null ? null : adapters[0],
- sequenceName, independent != null, joinedType, internal, external);
+ sequenceName, independent != null, automatic != null,
+ joinedType, internal, external);
}
private static StorablePropertyConstraint[] gatherConstraints
@@ -1379,12 +1387,15 @@ public class StorableIntrospector {
private final boolean mIsVersion;
private final String mSequence;
private final boolean mIndependent;
+ private final boolean mAutomatic;
SimpleProperty(BeanProperty property, Class<S> enclosing,
boolean nullable, boolean primaryKey, boolean alternateKey,
String[] aliases, StorablePropertyConstraint[] constraints,
StorablePropertyAdapter adapter,
- boolean isVersion, String sequence, boolean independent) {
+ boolean isVersion, String sequence,
+ boolean independent, boolean automatic)
+ {
mBeanProperty = property;
mEnclosingType = enclosing;
mNullable = property.getType().isPrimitive() ? false : nullable;
@@ -1396,6 +1407,7 @@ public class StorableIntrospector {
mIsVersion = isVersion;
mSequence = sequence;
mIndependent = independent;
+ mAutomatic = automatic;
}
public final String getName() {
@@ -1476,6 +1488,10 @@ public class StorableIntrospector {
return mSequence;
}
+ public final boolean isAutomatic() {
+ return mAutomatic;
+ }
+
public final boolean isIndependent() {
return mIndependent;
}
@@ -1601,11 +1617,12 @@ public class StorableIntrospector {
boolean nullable,
String[] aliases, StorablePropertyConstraint[] constraints,
StorablePropertyAdapter adapter,
- String sequence, boolean independent,
+ String sequence, boolean independent, boolean automatic,
Class<? extends Storable> joinedType,
- String[] internal, String[] external) {
+ String[] internal, String[] external)
+ {
super(property, enclosing, nullable, false, false,
- aliases, constraints, adapter, false, sequence, independent);
+ aliases, constraints, adapter, false, sequence, independent, automatic);
mJoinedType = joinedType;
int length = internal.length;
diff --git a/src/main/java/com/amazon/carbonado/info/StorableProperty.java b/src/main/java/com/amazon/carbonado/info/StorableProperty.java
index c9cc8e1..ce374ac 100644
--- a/src/main/java/com/amazon/carbonado/info/StorableProperty.java
+++ b/src/main/java/com/amazon/carbonado/info/StorableProperty.java
@@ -184,10 +184,19 @@ public interface StorableProperty<S extends Storable> extends Appender {
/**
* Returns the property's sequence name, or null if none.
+ *
+ * @see com.amazon.carbonado.Sequence
*/
String getSequenceName();
/**
+ * Returns true of this property is given an automatic value upon insert.
+ *
+ * @see com.amazon.carbonado.Automatic
+ */
+ boolean isAutomatic();
+
+ /**
* Returns true if this property is the designated version number for the
* Storable.
*