From 4a0115c24f7eb72405ecdc2c2d4cc25af429e5e1 Mon Sep 17 00:00:00 2001 From: Tobias Holgers Date: Wed, 29 Apr 2009 00:48:35 +0000 Subject: Added @Derived(shouldCopy=true) to copy derived properties used as repository hints --- .../java/com/amazon/carbonado/info/StorableIntrospector.java | 11 +++++++++++ src/main/java/com/amazon/carbonado/info/StorableProperty.java | 10 ++++++++++ 2 files changed, 21 insertions(+) (limited to 'src/main/java/com/amazon/carbonado/info') diff --git a/src/main/java/com/amazon/carbonado/info/StorableIntrospector.java b/src/main/java/com/amazon/carbonado/info/StorableIntrospector.java index 835741b..06218a4 100644 --- a/src/main/java/com/amazon/carbonado/info/StorableIntrospector.java +++ b/src/main/java/com/amazon/carbonado/info/StorableIntrospector.java @@ -85,6 +85,7 @@ import com.amazon.carbonado.util.ThrowUnchecked; * * @author Brian S O'Neill * @author Fang Chen + * @author Tobias Holgers */ public class StorableIntrospector { // Weakly maps Class objects to softly referenced StorableInfo objects. @@ -1038,6 +1039,10 @@ public class StorableIntrospector { errorMessages.add("Derived properties cannot be abstract: " + propertyName); } + if (writeMethod == null && derived.shouldCopy()) { + errorMessages.add("Derived properties which should be copied " + + "must have a write method: " + propertyName); + } if (pk) { errorMessages.add("Derived properties cannot be a member of primary key: " + propertyName); @@ -1782,6 +1787,7 @@ public class StorableIntrospector { private final boolean mIndependent; private final boolean mAutomatic; private final boolean mIsDerived; + private final boolean mShouldCopyDerived; private final String mName; private final String mBeanName; @@ -1824,6 +1830,7 @@ public class StorableIntrospector { mIndependent = independent; mAutomatic = automatic; mIsDerived = derived != null; + mShouldCopyDerived = (mIsDerived ? derived.shouldCopy() : false); mDerived = derived; mBeanName = mBeanProperty.getName(); mName = name == null ? mBeanName : name; @@ -1962,6 +1969,10 @@ public class StorableIntrospector { return mDerivedTo.clone(); } + public final boolean shouldCopyDerived() { + return mShouldCopyDerived; + } + public boolean isJoin() { return false; } diff --git a/src/main/java/com/amazon/carbonado/info/StorableProperty.java b/src/main/java/com/amazon/carbonado/info/StorableProperty.java index 36491f8..aadc623 100644 --- a/src/main/java/com/amazon/carbonado/info/StorableProperty.java +++ b/src/main/java/com/amazon/carbonado/info/StorableProperty.java @@ -27,6 +27,7 @@ import com.amazon.carbonado.util.Appender; * Contains all the metadata describing a property of a specific {@link Storable} type. * * @author Brian S O'Neill + * @author Tobias Holgers * @see StorableIntrospector */ public interface StorableProperty extends Serializable, Appender { @@ -278,5 +279,14 @@ public interface StorableProperty extends Serializable, Appe */ ChainedProperty[] getDerivedToProperties(); + /** + * Returns true if this derived property should be included when copying a + * storable. Copying of a derived property uses the "get" and "set" methods + * and requires the "set" method to be defined. + * + * @since 1.2 + */ + boolean shouldCopyDerived(); + String toString(); } -- cgit v1.2.3