mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-18 14:58:47 +00:00
#390 - ChangeLog - Add ServerConfig.isChangeLogIncludeInserts() and ChangeLogInsertMode enum with associated changes
This commit is contained in:
1 parent
16d5e04809
commit
f3e66c459a
8 files changed
+111
-18
No files matched your search
@@ -13,10 +13,13 @@ import java.lang.annotation.Target;
|
||||
public @interface ChangeLog {
|
||||
|
||||
/**
|
||||
* Set this to true to exclude inserts on the associated bean type
|
||||
* from being included in the change log.
|
||||
* Specify if inserts should be explicitly Included or Excluded.
|
||||
* <p>
|
||||
* If not defined explicitly then the server default behaviour defined
|
||||
* on ServerConfig is used.
|
||||
* </p>
|
||||
*/
|
||||
boolean excludeInserts() default false;
|
||||
ChangeLogInsertMode inserts() default ChangeLogInsertMode.DEFAULT;
|
||||
|
||||
/**
|
||||
* When specified only include update requests that have at least one
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.avaje.ebean.annotation;
|
||||
|
||||
/**
|
||||
* The mode used to determine if inserts should be included or not for a given bean type.
|
||||
*/
|
||||
public enum ChangeLogInsertMode {
|
||||
|
||||
/**
|
||||
* Use the default behaviour as defined on ServerConfig.
|
||||
*/
|
||||
DEFAULT,
|
||||
|
||||
/**
|
||||
* Include inserts in the change log.
|
||||
*/
|
||||
INCLUDE,
|
||||
|
||||
/**
|
||||
* Exclude inserts in the change log.
|
||||
*/
|
||||
EXCLUDE
|
||||
}
|
||||
@@ -288,6 +288,11 @@ public class ServerConfig {
|
||||
private List<ServerConfigStartup> configStartupListeners = new ArrayList<ServerConfigStartup>();
|
||||
private List<TransactionEventListener> transactionEventListeners = new ArrayList<TransactionEventListener>();
|
||||
|
||||
/**
|
||||
* By default inserts are included in the change log.
|
||||
*/
|
||||
private boolean changeLogIncludeInserts = true;
|
||||
|
||||
private ChangeLogPrepare changeLogPrepare;
|
||||
|
||||
private ChangeLogListener changeLogListener;
|
||||
@@ -706,6 +711,20 @@ public class ServerConfig {
|
||||
this.changeLogRegister = changeLogRegister;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if inserts should be included in the change log by default.
|
||||
*/
|
||||
public boolean isChangeLogIncludeInserts() {
|
||||
return changeLogIncludeInserts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set if inserts should be included in the change log by default.
|
||||
*/
|
||||
public void setChangeLogIncludeInserts(boolean changeLogIncludeInserts) {
|
||||
this.changeLogIncludeInserts = changeLogIncludeInserts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the DB migration configuration.
|
||||
*/
|
||||
@@ -2054,6 +2073,7 @@ public class ServerConfig {
|
||||
|
||||
persistenceContextScope = PersistenceContextScope.valueOf(p.get("persistenceContextScope", "TRANSACTION"));
|
||||
|
||||
changeLogIncludeInserts = p.getBoolean("changeLogIncludeInserts", changeLogIncludeInserts);
|
||||
expressionEqualsWithNullAsNoop = p.getBoolean("expressionEqualsWithNullAsNoop", expressionEqualsWithNullAsNoop);
|
||||
diffFlatMode = p.getBoolean("diffFlatMode", diffFlatMode);
|
||||
asOfViewSuffix = p.get("asOfViewSuffix", asOfViewSuffix);
|
||||
|
||||
+22
-2
@@ -1,6 +1,7 @@
|
||||
package com.avaje.ebeaninternal.server.changelog;
|
||||
|
||||
import com.avaje.ebean.annotation.ChangeLog;
|
||||
import com.avaje.ebean.annotation.ChangeLogInsertMode;
|
||||
import com.avaje.ebean.event.BeanPersistRequest;
|
||||
import com.avaje.ebean.event.changelog.ChangeLogFilter;
|
||||
import com.avaje.ebean.event.changelog.ChangeLogRegister;
|
||||
@@ -17,6 +18,14 @@ public class DefaultChangeLogRegister implements ChangeLogRegister {
|
||||
|
||||
private static final BasicFilter EXCLUDE_INSERTS = new BasicFilter(false);
|
||||
|
||||
private final boolean defaultInsertsInclude;
|
||||
|
||||
/**
|
||||
* Create with the default insertsIncluded from ServerConfig.
|
||||
*/
|
||||
public DefaultChangeLogRegister(boolean defaultInsertsInclude) {
|
||||
this.defaultInsertsInclude = defaultInsertsInclude;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChangeLogFilter getChangeFilter(Class<?> beanType) {
|
||||
@@ -28,7 +37,7 @@ public class DefaultChangeLogRegister implements ChangeLogRegister {
|
||||
|
||||
String[] updatesThatInclude = changeLog.updatesThatInclude();
|
||||
if (updatesThatInclude.length == 0) {
|
||||
return changeLog.excludeInserts() ? EXCLUDE_INSERTS : INCLUDE_INSERTS;
|
||||
return insertModeInclude(changeLog.inserts()) ? INCLUDE_INSERTS : EXCLUDE_INSERTS;
|
||||
}
|
||||
|
||||
Set<String> updateProps = new HashSet<String>();
|
||||
@@ -36,7 +45,18 @@ public class DefaultChangeLogRegister implements ChangeLogRegister {
|
||||
updateProps.add(updatesThatInclude[i]);
|
||||
}
|
||||
|
||||
return new UpdateFilter(!changeLog.excludeInserts(), updateProps);
|
||||
return new UpdateFilter(insertModeInclude(changeLog.inserts()), updateProps);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if inserts should be included in the change log.
|
||||
*/
|
||||
private boolean insertModeInclude(ChangeLogInsertMode inserts) {
|
||||
if (inserts == ChangeLogInsertMode.DEFAULT) {
|
||||
// return the default as per the ServerConfig
|
||||
return defaultInsertsInclude;
|
||||
}
|
||||
return ChangeLogInsertMode.INCLUDE == inserts;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -180,7 +180,8 @@ public class InternalConfiguration {
|
||||
* Return the ChangeLogRegister to use with a default implementation if none defined.
|
||||
*/
|
||||
public ChangeLogRegister changeLogRegister(ChangeLogRegister register) {
|
||||
return plugin((register != null) ? register : new DefaultChangeLogRegister());
|
||||
boolean includeInserts = serverConfig.isChangeLogIncludeInserts();
|
||||
return plugin((register != null) ? register : new DefaultChangeLogRegister(includeInserts));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user