mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
FIX: Changelog-oldValue did not work for Json mutable properties
This commit is contained in:
@@ -16,10 +16,13 @@ import io.ebean.event.changelog.ChangeLogRegister;
|
||||
import io.ebean.event.changelog.ChangeSet;
|
||||
import io.ebean.event.changelog.ChangeType;
|
||||
import io.ebean.event.changelog.TxnState;
|
||||
import io.ebeantest.LoggedSql;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.tests.model.basic.EBasicChangeLog;
|
||||
import org.tests.model.json.PlainBean;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -130,7 +133,31 @@ public class TestChangeLog extends BaseTestCase {
|
||||
assertThat(change.getEvent()).isEqualTo(ChangeType.DELETE);
|
||||
assertThat(change.getData()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithJsonMutationDetection() {
|
||||
|
||||
EBasicChangeLog bean = new EBasicChangeLog();
|
||||
bean.setName(null);
|
||||
bean.setShortDescription("hello");
|
||||
PlainBean jsonBean = new PlainBean();
|
||||
bean.setPlainBean(jsonBean);
|
||||
jsonBean.setName("A");
|
||||
server.save(bean);
|
||||
|
||||
BeanChange change = firstChange();
|
||||
assertThat(change.getEvent()).isEqualTo(ChangeType.INSERT);
|
||||
|
||||
jsonBean.setName("B");
|
||||
LoggedSql.start();
|
||||
server.save(bean);
|
||||
assertThat(LoggedSql.stop()).isNotEmpty();
|
||||
|
||||
change = firstChange();
|
||||
assertThat(change.getEvent()).isEqualTo(ChangeType.UPDATE);
|
||||
assertThat(change.getData()).contains("\"plainBean\":{\"name\":\"B\"");
|
||||
assertThat(change.getOldData()).contains("\"plainBean\":{\"name\":\"A\"");
|
||||
}
|
||||
private Database createServer() {
|
||||
|
||||
DatabaseConfig config = new DatabaseConfig();
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.tests.model.basic;
|
||||
|
||||
import io.ebean.annotation.Cache;
|
||||
import io.ebean.annotation.ChangeLog;
|
||||
import io.ebean.annotation.DbJson;
|
||||
import io.ebean.annotation.ReadAudit;
|
||||
import io.ebean.annotation.WhenCreated;
|
||||
import io.ebean.annotation.WhenModified;
|
||||
@@ -12,11 +13,16 @@ import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Version;
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
import org.tests.model.json.PlainBean;
|
||||
|
||||
import static io.ebean.annotation.MutationDetection.SOURCE;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
|
||||
@Cache(enableQueryCache = true)
|
||||
@ReadAudit
|
||||
@ChangeLog(updatesThatInclude = {"name", "shortDescription"})
|
||||
@ChangeLog(updatesThatInclude = {"name", "shortDescription", "plainBean"})
|
||||
@Entity
|
||||
public class EBasicChangeLog {
|
||||
|
||||
@@ -46,6 +52,9 @@ public class EBasicChangeLog {
|
||||
|
||||
@Version
|
||||
Long version;
|
||||
|
||||
@DbJson(length = 500, mutationDetection = SOURCE) // such that we can rebuild old values
|
||||
PlainBean plainBean;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
@@ -118,4 +127,12 @@ public class EBasicChangeLog {
|
||||
public void setVersion(Long version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public PlainBean getPlainBean() {
|
||||
return plainBean;
|
||||
}
|
||||
|
||||
public void setPlainBean(PlainBean plainBean) {
|
||||
this.plainBean = plainBean;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user