diff --git a/src/main/java/com/avaje/ebean/annotation/DraftReset.java b/src/main/java/com/avaje/ebean/annotation/DraftReset.java new file mode 100644 index 000000000..6063cf081 --- /dev/null +++ b/src/main/java/com/avaje/ebean/annotation/DraftReset.java @@ -0,0 +1,19 @@ +package com.avaje.ebean.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Marks a property on a @Draftable bean that is set to null on the 'draft bean' on publish. + *
+ * This is expected to be put on properties that get 'reset' or 'cleared' after a publish. + * These properties might represent a publish comment or publish timestamp. + *
+ */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +public @interface DraftReset { + +} diff --git a/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanDescriptor.java b/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanDescriptor.java index 5076cc767..c54ee3868 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanDescriptor.java +++ b/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanDescriptor.java @@ -837,6 +837,13 @@ public class BeanDescriptor+ * This will recursive transfer values to all @DraftableElement properties. + *
+ */ public T publish(T draftBean, T liveBean) { if (liveBean == null) { diff --git a/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanProperty.java b/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanProperty.java index dbec4d4bf..d97f11480 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanProperty.java +++ b/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanProperty.java @@ -227,6 +227,8 @@ public class BeanProperty implements ElPropertyValue { final boolean draftDirty; + final boolean draftReset; + final boolean indexed; final String indexName; @@ -255,6 +257,7 @@ public class BeanProperty implements ElPropertyValue { this.excludedFromHistory = deploy.isExcludedFromHistory(); this.draftDirty = deploy.isDraftDirty(); this.draftOnly = deploy.isDraftOnly(); + this.draftReset = deploy.isDraftReset(); this.secondaryTable = deploy.isSecondaryTable(); if (secondaryTable) { @@ -341,6 +344,7 @@ public class BeanProperty implements ElPropertyValue { this.excludedFromHistory = source.excludedFromHistory; this.draftDirty = source.draftDirty; this.draftOnly = source.draftOnly; + this.draftReset = source.draftReset; this.fetchEager = source.fetchEager; this.unidirectionalShadow = source.unidirectionalShadow; this.discriminator = source.discriminator; @@ -1045,6 +1049,13 @@ public class BeanProperty implements ElPropertyValue { return draftDirty; } + /** + * Return true if this property is reset/cleared on publish (on the draft bean). + */ + public boolean isDraftReset() { + return draftReset; + } + /** * Return true if this property should be included in an Insert. */ diff --git a/src/main/java/com/avaje/ebeaninternal/server/deploy/meta/DeployBeanProperty.java b/src/main/java/com/avaje/ebeaninternal/server/deploy/meta/DeployBeanProperty.java index c87c35246..7b856ac10 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/deploy/meta/DeployBeanProperty.java +++ b/src/main/java/com/avaje/ebeaninternal/server/deploy/meta/DeployBeanProperty.java @@ -185,6 +185,7 @@ public class DeployBeanProperty { private boolean draftOnly; private boolean draftDirty; + private boolean draftReset; public DeployBeanProperty(DeployBeanDescriptor> desc, Class> propertyType, ScalarType> scalarType, ScalarTypeConverter, ?> typeConverter) { this.desc = desc; @@ -854,4 +855,12 @@ public class DeployBeanProperty { public boolean isDraftDirty() { return draftDirty; } + + public void setDraftReset() { + this.draftReset = true; + } + + public boolean isDraftReset() { + return draftReset; + } } diff --git a/src/main/java/com/avaje/ebeaninternal/server/deploy/parse/AnnotationFields.java b/src/main/java/com/avaje/ebeaninternal/server/deploy/parse/AnnotationFields.java index 85683bdb6..95b7cb3d8 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/deploy/parse/AnnotationFields.java +++ b/src/main/java/com/avaje/ebeaninternal/server/deploy/parse/AnnotationFields.java @@ -152,10 +152,12 @@ public class AnnotationFields extends AnnotationParser { if (get(prop, DraftOnly.class) != null) { prop.setDraftOnly(); } - if (get(prop, DraftDirty.class) != null) { prop.setDraftDirty(); } + if (get(prop, DraftReset.class) != null) { + prop.setDraftReset(); + } DbJson dbJson = get(prop, DbJson.class); if (dbJson != null) { diff --git a/src/main/java/com/avaje/ebeaninternal/server/persist/DefaultPersister.java b/src/main/java/com/avaje/ebeaninternal/server/persist/DefaultPersister.java index 884395cac..7cf75ff6e 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/persist/DefaultPersister.java +++ b/src/main/java/com/avaje/ebeaninternal/server/persist/DefaultPersister.java @@ -159,10 +159,7 @@ public final class DefaultPersister implements Persister { BeanManager