From 51bee836d498e1a842fbdabc5c99d05ab4d8a701 Mon Sep 17 00:00:00 2001 From: Robin Bygrave Date: Tue, 1 Dec 2015 10:19:36 +1300 Subject: [PATCH] #472 - DDL column ordering for @WhoCreated / @WhoModified. These columns should appear in the DDL with the @WhenCreated/@WhenModified columns. --- .../deploy/meta/DeployBeanProperty.java | 15 +++- .../java/com/avaje/tests/model/EWhoProps.java | 75 +---------------- .../com/avaje/tests/model/EWhoPropsSuper.java | 81 +++++++++++++++++++ 3 files changed, 94 insertions(+), 77 deletions(-) create mode 100644 src/test/java/com/avaje/tests/model/EWhoPropsSuper.java 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 7b856ac10..ce806d237 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 @@ -4,6 +4,8 @@ import com.avaje.ebean.annotation.CreatedTimestamp; import com.avaje.ebean.annotation.UpdatedTimestamp; import com.avaje.ebean.annotation.WhenCreated; import com.avaje.ebean.annotation.WhenModified; +import com.avaje.ebean.annotation.WhoCreated; +import com.avaje.ebean.annotation.WhoModified; import com.avaje.ebean.config.ScalarTypeConverter; import com.avaje.ebean.config.dbplatform.DbEncrypt; import com.avaje.ebean.config.dbplatform.DbEncryptFunction; @@ -215,9 +217,7 @@ public class DeployBeanProperty { return ID_ORDER; } else if (undirectionalShadow) { return UNIDIRECTIONAL_ORDER; - } else if (field.getAnnotation(WhenCreated.class) != null || field.getAnnotation(CreatedTimestamp.class) != null) { - return AUDITCOLUMN_ORDER; - } else if (field.getAnnotation(WhenModified.class) != null || field.getAnnotation(UpdatedTimestamp.class) != null) { + } else if (isAuditProperty()) { return AUDITCOLUMN_ORDER; } else if (field.getAnnotation(Version.class) != null) { return VERSIONCOLUMN_ORDER; @@ -225,6 +225,15 @@ public class DeployBeanProperty { return 0; } + private boolean isAuditProperty() { + return (field.getAnnotation(WhenCreated.class) != null + || field.getAnnotation(WhenModified.class) != null + || field.getAnnotation(WhoModified.class) != null + || field.getAnnotation(WhoCreated.class) != null + || field.getAnnotation(UpdatedTimestamp.class) != null + || field.getAnnotation(CreatedTimestamp.class) != null); + } + public String getFullBeanName() { return desc.getFullName() + "." + name; } diff --git a/src/test/java/com/avaje/tests/model/EWhoProps.java b/src/test/java/com/avaje/tests/model/EWhoProps.java index 5d9c2504d..b4c269b20 100644 --- a/src/test/java/com/avaje/tests/model/EWhoProps.java +++ b/src/test/java/com/avaje/tests/model/EWhoProps.java @@ -1,46 +1,12 @@ package com.avaje.tests.model; -import com.avaje.ebean.annotation.WhenCreated; -import com.avaje.ebean.annotation.WhenModified; -import com.avaje.ebean.annotation.WhoCreated; -import com.avaje.ebean.annotation.WhoModified; - import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Version; -import java.sql.Timestamp; @Entity -public class EWhoProps { - - @Id - Long id; +public class EWhoProps extends EWhoPropsSuper { String name; - @Version - Long version; - - @WhenCreated - Timestamp whenCreated; - - @WhenModified - Timestamp whenModified; - - @WhoCreated - String whoCreated; - - @WhoModified - String whoModified; - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - public String getName() { return name; } @@ -49,43 +15,4 @@ public class EWhoProps { this.name = name; } - public Long getVersion() { - return version; - } - - public void setVersion(Long version) { - this.version = version; - } - - public Timestamp getWhenCreated() { - return whenCreated; - } - - public void setWhenCreated(Timestamp whenCreated) { - this.whenCreated = whenCreated; - } - - public Timestamp getWhenModified() { - return whenModified; - } - - public void setWhenModified(Timestamp whenModified) { - this.whenModified = whenModified; - } - - public String getWhoCreated() { - return whoCreated; - } - - public void setWhoCreated(String whoCreated) { - this.whoCreated = whoCreated; - } - - public String getWhoModified() { - return whoModified; - } - - public void setWhoModified(String whoModified) { - this.whoModified = whoModified; - } } diff --git a/src/test/java/com/avaje/tests/model/EWhoPropsSuper.java b/src/test/java/com/avaje/tests/model/EWhoPropsSuper.java new file mode 100644 index 000000000..7b2e0c881 --- /dev/null +++ b/src/test/java/com/avaje/tests/model/EWhoPropsSuper.java @@ -0,0 +1,81 @@ +package com.avaje.tests.model; + +import com.avaje.ebean.annotation.WhenCreated; +import com.avaje.ebean.annotation.WhenModified; +import com.avaje.ebean.annotation.WhoCreated; +import com.avaje.ebean.annotation.WhoModified; + +import javax.persistence.Id; +import javax.persistence.MappedSuperclass; +import javax.persistence.Version; +import java.sql.Timestamp; + +@MappedSuperclass +public class EWhoPropsSuper { + + @Id + Long id; + + @Version + Long version; + + @WhenCreated + Timestamp whenCreated; + + @WhenModified + Timestamp whenModified; + + @WhoCreated + String whoCreated; + + @WhoModified + String whoModified; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Long getVersion() { + return version; + } + + public void setVersion(Long version) { + this.version = version; + } + + public Timestamp getWhenCreated() { + return whenCreated; + } + + public void setWhenCreated(Timestamp whenCreated) { + this.whenCreated = whenCreated; + } + + public Timestamp getWhenModified() { + return whenModified; + } + + public void setWhenModified(Timestamp whenModified) { + this.whenModified = whenModified; + } + + public String getWhoCreated() { + return whoCreated; + } + + public void setWhoCreated(String whoCreated) { + this.whoCreated = whoCreated; + } + + public String getWhoModified() { + return whoModified; + } + + public void setWhoModified(String whoModified) { + this.whoModified = whoModified; + } +}