#374 - Add GeneratedWhenCreated and GeneratedWhenModified marker interfaces etc - used to find bean properties with those behaviours

This commit is contained in:
Robin Bygrave
2015-08-16 20:08:56 +12:00
parent f22563b36a
commit a15dd33380
11 changed files with 97 additions and 6 deletions
@@ -994,6 +994,32 @@ public class BeanDescriptor<T> implements MetaBeanInfo {
return deleteRecurseSkippable;
}
/**
* Find a property annotated with @WhenCreated or @CreatedTimestamp.
*/
public BeanProperty findWhenCreatedProperty() {
for (int i = 0; i < propertiesBaseScalar.length; i++) {
if (propertiesBaseScalar[i].isGeneratedWhenCreated()) {
return propertiesBaseScalar[i];
}
}
return null;
}
/**
* Find a property annotated with @WhenModified or @UpdatedTimestamp.
*/
public BeanProperty findWhenModifiedProperty() {
for (int i = 0; i < propertiesBaseScalar.length; i++) {
if (propertiesBaseScalar[i].isGeneratedWhenModified()) {
return propertiesBaseScalar[i];
}
}
return null;
}
/**
* Return the many property included in the query or null if one is not.
*/
@@ -7,6 +7,8 @@ import com.avaje.ebean.config.dbplatform.DbType;
import com.avaje.ebean.text.StringParser;
import com.avaje.ebeaninternal.server.core.InternString;
import com.avaje.ebeaninternal.server.deploy.generatedproperty.GeneratedProperty;
import com.avaje.ebeaninternal.server.deploy.generatedproperty.GeneratedWhenCreated;
import com.avaje.ebeaninternal.server.deploy.generatedproperty.GeneratedWhenModified;
import com.avaje.ebeaninternal.server.deploy.meta.DeployBeanProperty;
import com.avaje.ebeaninternal.server.el.ElPropertyChainBuilder;
import com.avaje.ebeaninternal.server.el.ElPropertyValue;
@@ -864,6 +866,20 @@ public class BeanProperty implements ElPropertyValue {
return isVersion() || (generatedProperty != null && generatedProperty.isDDLNotNullable());
}
/**
* Return true if this is a generated property mapping to @WhenCreated or @CreatedTimestamp.
*/
public boolean isGeneratedWhenCreated() {
return generatedProperty instanceof GeneratedWhenCreated;
}
/**
* Return true if this is a generated property mapping to @WhenModified or @UpdatedTimestamp.
*/
public boolean isGeneratedWhenModified() {
return generatedProperty instanceof GeneratedWhenModified;
}
/**
* Return true if the DB column should be unique.
*/
@@ -12,7 +12,7 @@ import java.time.ZonedDateTime;
*/
public class GeneratedInsertJavaTime {
public static abstract class Base implements GeneratedProperty {
public static abstract class Base implements GeneratedProperty, GeneratedWhenCreated {
@Override
public boolean includeInUpdate() {
@@ -11,7 +11,7 @@ import org.joda.time.DateTime;
*/
public class GeneratedInsertJodaTime {
public static abstract class Base implements GeneratedProperty {
public static abstract class Base implements GeneratedProperty, GeneratedWhenCreated {
@Override
public boolean includeInUpdate() {
@@ -8,7 +8,7 @@ import com.avaje.ebeaninternal.server.deploy.BeanProperty;
/**
* Used to generate a timestamp when a bean is inserted.
*/
public class GeneratedInsertTimestamp implements GeneratedProperty {
public class GeneratedInsertTimestamp implements GeneratedProperty, GeneratedWhenCreated {
/**
* Return the current time as a Timestamp.
@@ -12,7 +12,7 @@ import java.time.ZonedDateTime;
*/
public class GeneratedUpdateJavaTime {
public static abstract class Base implements GeneratedProperty {
public static abstract class Base implements GeneratedProperty, GeneratedWhenModified {
@Override
public boolean includeInUpdate() {
@@ -11,7 +11,7 @@ import org.joda.time.DateTime;
*/
public class GeneratedUpdateJodaTime {
public static abstract class Base implements GeneratedProperty {
public static abstract class Base implements GeneratedProperty, GeneratedWhenModified {
@Override
public boolean includeInUpdate() {
@@ -8,7 +8,7 @@ import com.avaje.ebeaninternal.server.deploy.BeanProperty;
/**
* Generate a Timestamp whenever the bean is inserted or updated.
*/
public class GeneratedUpdateTimestamp implements GeneratedProperty {
public class GeneratedUpdateTimestamp implements GeneratedProperty, GeneratedWhenModified {
/**
* Return now as a Timestamp.
@@ -0,0 +1,7 @@
package com.avaje.ebeaninternal.server.deploy.generatedproperty;
/**
* Marker interface for all implementations mapping to @WhenCreated or @CreatedTimestamp.
*/
public interface GeneratedWhenCreated {
}
@@ -0,0 +1,7 @@
package com.avaje.ebeaninternal.server.deploy.generatedproperty;
/**
* Marker interface for all implementations mapping to @WhenModified or @UpdatedTimestamp.
*/
public interface GeneratedWhenModified {
}