#347 - @History support with query.asOf(Timestamp)

This commit is contained in:
Robin Bygrave
2015-07-24 10:18:17 +12:00
parent 3cafb37a73
commit 82489636d5
37 changed files with 601 additions and 92 deletions
@@ -8,6 +8,7 @@ import javax.persistence.MapKey;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import com.avaje.ebean.annotation.HistoryExclude;
import com.avaje.ebean.annotation.PrivateOwned;
import com.avaje.ebean.annotation.Where;
import com.avaje.ebean.bean.BeanCollection.ModifyListenMode;
@@ -65,7 +66,11 @@ public class AnnotationAssocManys extends AnnotationParser {
readToMany(manyToMany, prop);
}
OrderBy orderBy = get(prop, OrderBy.class);
if (get(prop, HistoryExclude.class) != null) {
prop.setExcludedFromHistory(true);
}
OrderBy orderBy = get(prop, OrderBy.class);
if (orderBy != null) {
prop.setFetchOrderBy(orderBy.value());
}
@@ -10,6 +10,7 @@ import javax.persistence.UniqueConstraint;
import com.avaje.ebean.annotation.CacheStrategy;
import com.avaje.ebean.annotation.CacheTuning;
import com.avaje.ebean.annotation.EntityConcurrencyMode;
import com.avaje.ebean.annotation.History;
import com.avaje.ebean.annotation.NamedUpdate;
import com.avaje.ebean.annotation.NamedUpdates;
import com.avaje.ebean.annotation.UpdateMode;
@@ -26,8 +27,11 @@ import com.avaje.ebeaninternal.server.deploy.meta.DeployBeanProperty;
*/
public class AnnotationClass extends AnnotationParser {
public AnnotationClass(DeployBeanInfo<?> info) {
private final String asOfViewSuffix;
public AnnotationClass(DeployBeanInfo<?> info, String asOfViewSuffix) {
super(info);
this.asOfViewSuffix = asOfViewSuffix;
}
/**
@@ -48,7 +52,7 @@ public class AnnotationClass extends AnnotationParser {
// default the TableName using NamingConvention.
TableName tableName = namingConvention.getTableName(descriptor.getBeanType());
descriptor.setBaseTable(tableName);
descriptor.setBaseTable(tableName, asOfViewSuffix);
}
}
@@ -84,6 +88,11 @@ public class AnnotationClass extends AnnotationParser {
}
}
History history = cls.getAnnotation(History.class);
if (history != null) {
descriptor.setHistorySupport(true);
}
UpdateMode updateMode = cls.getAnnotation(UpdateMode.class);
if (updateMode != null) {
descriptor.setUpdateChangesOnly(updateMode.updateChangesOnly());
@@ -8,6 +8,7 @@ import com.avaje.ebean.annotation.EmbeddedColumns;
import com.avaje.ebean.annotation.Encrypted;
import com.avaje.ebean.annotation.Expose;
import com.avaje.ebean.annotation.Formula;
import com.avaje.ebean.annotation.HistoryExclude;
import com.avaje.ebean.annotation.Index;
import com.avaje.ebean.annotation.JsonIgnore;
import com.avaje.ebean.annotation.UpdatedTimestamp;
@@ -217,6 +218,10 @@ public class AnnotationFields extends AnnotationParser {
generatedPropFactory.setUpdateTimestamp(prop);
}
if (get(prop, HistoryExclude.class) != null) {
prop.setExcludedFromHistory(true);
}
if (validationAnnotations) {
NotNull notNull = get(prop, NotNull.class);
if (notNull != null && isNotNullOnAllValidationGroups(notNull.groups())) {
@@ -8,7 +8,17 @@ import com.avaje.ebeaninternal.server.deploy.BeanDescriptorManager;
*/
public class ReadAnnotations {
/**
/**
* Typically _with_history and when appended to the base table derives the name of
* the view that unions the base table with the history table to support asOf queries.
*/
private final String asOfViewSuffix;
public ReadAnnotations(String asOfViewSuffix) {
this.asOfViewSuffix = asOfViewSuffix;
}
/**
* Read the initial non-relationship annotations included Id and EmbeddedId.
* <p>
* We then have enough to create BeanTables which are used in readAssociations
@@ -18,7 +28,7 @@ public class ReadAnnotations {
public void readInitial(DeployBeanInfo<?> info, boolean eagerFetchLobs){
try {
new AnnotationClass(info).parse();
new AnnotationClass(info, asOfViewSuffix).parse();
new AnnotationFields(info, eagerFetchLobs).parse();
} catch (RuntimeException e){