mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#390 - ChangeLog - Add inheritance hierarchy check for @ChangeLog
This commit is contained in:
+15
-1
@@ -30,7 +30,7 @@ public class DefaultChangeLogRegister implements ChangeLogRegister {
|
||||
@Override
|
||||
public ChangeLogFilter getChangeFilter(Class<?> beanType) {
|
||||
|
||||
ChangeLog changeLog = beanType.getAnnotation(ChangeLog.class);
|
||||
ChangeLog changeLog = getChangeLog(beanType);
|
||||
if (changeLog == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -48,6 +48,20 @@ public class DefaultChangeLogRegister implements ChangeLogRegister {
|
||||
return new UpdateFilter(insertModeInclude(changeLog.inserts()), updateProps);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find and return the ChangeLog annotation in the inheritance hierarchy.
|
||||
*/
|
||||
private ChangeLog getChangeLog(Class<?> beanType) {
|
||||
ChangeLog changeLog = beanType.getAnnotation(ChangeLog.class);
|
||||
if (changeLog != null) {
|
||||
return changeLog;
|
||||
}
|
||||
if (Object.class.equals(beanType.getSuperclass())) {
|
||||
return null;
|
||||
}
|
||||
return getChangeLog(beanType.getSuperclass());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if inserts should be included in the change log.
|
||||
*/
|
||||
|
||||
+12
@@ -2,6 +2,7 @@ package com.avaje.ebeaninternal.server.changelog;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.event.changelog.ChangeLogFilter;
|
||||
import com.avaje.tests.inheritance.model.ProductConfiguration;
|
||||
import com.avaje.tests.model.basic.Address;
|
||||
import com.avaje.tests.model.basic.Contact;
|
||||
import com.avaje.tests.model.basic.Country;
|
||||
@@ -10,6 +11,7 @@ import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@@ -62,4 +64,14 @@ public class DefaultChangeLogRegisterTest extends BaseTestCase {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_inheritance() {
|
||||
|
||||
DefaultChangeLogRegister register = new DefaultChangeLogRegister(true);
|
||||
ChangeLogFilter changeFilter = register.getChangeFilter(ProductConfiguration.class);
|
||||
assertNotNull(changeFilter);
|
||||
DefaultChangeLogRegister.BasicFilter basicFilter = (DefaultChangeLogRegister.BasicFilter)changeFilter;
|
||||
assertTrue(basicFilter.includeInserts);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.avaje.tests.inheritance.model;
|
||||
|
||||
import com.avaje.ebean.annotation.ChangeLog;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.DiscriminatorColumn;
|
||||
import javax.persistence.DiscriminatorType;
|
||||
@@ -9,6 +11,7 @@ import javax.persistence.Inheritance;
|
||||
import javax.persistence.InheritanceType;
|
||||
import javax.persistence.ManyToOne;
|
||||
|
||||
@ChangeLog
|
||||
@Entity
|
||||
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
|
||||
@DiscriminatorColumn(name="type", discriminatorType=DiscriminatorType.STRING)
|
||||
|
||||
Reference in New Issue
Block a user