Ignore collection changes if no revision on collection change is set
This commit is contained in:
parent
fd54b2df56
commit
e831e29435
|
@ -257,7 +257,9 @@ public class AuditEventListener implements PostInsertEventListener, PostUpdateEv
|
||||||
private void onCollectionAction(AbstractCollectionEvent event, PersistentCollection newColl, Serializable oldColl,
|
private void onCollectionAction(AbstractCollectionEvent event, PersistentCollection newColl, Serializable oldColl,
|
||||||
CollectionEntry collectionEntry) {
|
CollectionEntry collectionEntry) {
|
||||||
String entityName = event.getAffectedOwnerEntityName();
|
String entityName = event.getAffectedOwnerEntityName();
|
||||||
|
if (! verCfg.getGlobalCfg().isGenerateRevisionsForCollections()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (verCfg.getEntCfg().isVersioned(entityName)) {
|
if (verCfg.getEntCfg().isVersioned(entityName)) {
|
||||||
AuditProcess auditProcess = verCfg.getSyncManager().get(event.getSession());
|
AuditProcess auditProcess = verCfg.getSyncManager().get(event.getSession());
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
package org.hibernate.envers.test.integration.collection.norevision;
|
||||||
|
|
||||||
|
import org.hibernate.MappingException;
|
||||||
|
import org.testng.annotations.BeforeMethod;
|
||||||
|
|
||||||
|
import java.net.URISyntaxException;
|
||||||
|
|
||||||
|
public class CollectionChangRevisionTest extends CollectionChangeNoRevisionTest {
|
||||||
|
|
||||||
|
protected static final int PERSON_COUNT_NEW_REVISION_ON_COLLECTION = 2;
|
||||||
|
protected static final String NEW_REVISION_ON_COLLECTION = "true";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void initMappings() throws MappingException, URISyntaxException {
|
||||||
|
super.initMappings();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int getExpectedPersonRevisionCount() {
|
||||||
|
return PERSON_COUNT_NEW_REVISION_ON_COLLECTION;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getCollectionChangeValue() {
|
||||||
|
return NEW_REVISION_ON_COLLECTION;
|
||||||
|
}
|
||||||
|
}
|
|
@ -13,16 +13,26 @@ import org.testng.annotations.Test;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class CollectionChangeNoRevisionTest extends AbstractSessionTest {
|
public class CollectionChangeNoRevisionTest extends AbstractSessionTest {
|
||||||
|
|
||||||
private Integer personId;
|
protected static final int EXPECTED_PERSON_REVISION_COUNT = 1;
|
||||||
|
protected static final int EXPECTED_NAME_REVISION_COUNT = 1;
|
||||||
|
protected static final String CREATE_REVISION_ON_COLLECTION_CHANGE = "false";
|
||||||
|
protected Integer personId;
|
||||||
|
protected List<Integer> namesId = new ArrayList<Integer>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void initMappings() throws MappingException, URISyntaxException {
|
protected void initMappings() throws MappingException, URISyntaxException {
|
||||||
URL url = Thread.currentThread().getContextClassLoader().getResource("mappings/norevision/mappings.hbm.xml");
|
URL url = Thread.currentThread().getContextClassLoader().getResource("mappings/norevision/mappings.hbm.xml");
|
||||||
config.addFile(new File(url.toURI()));
|
config.addFile(new File(url.toURI()));
|
||||||
config.setProperty("org.hibernate.envers.revision_on_collection_change", "false");
|
config.setProperty("org.hibernate.envers.revision_on_collection_change", getCollectionChangeValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String getCollectionChangeValue() {
|
||||||
|
return CREATE_REVISION_ON_COLLECTION_CHANGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@BeforeMethod(firstTimeOnly = true)
|
@BeforeMethod(firstTimeOnly = true)
|
||||||
|
@ -36,7 +46,7 @@ public class CollectionChangeNoRevisionTest extends AbstractSessionTest {
|
||||||
getSession().saveOrUpdate(p);
|
getSession().saveOrUpdate(p);
|
||||||
transaction.commit();
|
transaction.commit();
|
||||||
personId = p.getId();
|
personId = p.getId();
|
||||||
System.err.print(p);
|
namesId.add(n.getId());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,10 +59,18 @@ public class CollectionChangeNoRevisionTest extends AbstractSessionTest {
|
||||||
Transaction transaction = getSession().beginTransaction();
|
Transaction transaction = getSession().beginTransaction();
|
||||||
getSession().saveOrUpdate(p);
|
getSession().saveOrUpdate(p);
|
||||||
transaction.commit();
|
transaction.commit();
|
||||||
int size = getAuditReader().getRevisions(Person.class, personId).size();
|
namesId.add(n2.getId());
|
||||||
System.out.println(size);
|
int sizePerson = getAuditReader().getRevisions(Person.class, personId).size();
|
||||||
Assert.assertEquals(config.getProperty("org.hibernate.envers.revision_on_collection_change"), "false");
|
Assert.assertEquals(config.getProperty("org.hibernate.envers.revision_on_collection_change"), getCollectionChangeValue());
|
||||||
Assert.assertEquals(size, 1);
|
Assert.assertEquals(sizePerson, getExpectedPersonRevisionCount());
|
||||||
|
for (Integer id : namesId) {
|
||||||
|
int sizeName = getAuditReader().getRevisions(Name.class, id).size();
|
||||||
|
Assert.assertEquals(sizeName, EXPECTED_NAME_REVISION_COUNT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected int getExpectedPersonRevisionCount() {
|
||||||
|
return EXPECTED_PERSON_REVISION_COUNT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,6 @@
|
||||||
</id>
|
</id>
|
||||||
<property name="name"/>
|
<property name="name"/>
|
||||||
<many-to-one name="person" class="org.hibernate.envers.test.integration.collection.norevision.Person"
|
<many-to-one name="person" class="org.hibernate.envers.test.integration.collection.norevision.Person"
|
||||||
column="Person_Id" cascade="save-update"/>
|
column="Person_Id" cascade="save-update" update="false" insert="false"/>
|
||||||
</class>
|
</class>
|
||||||
</hibernate-mapping>
|
</hibernate-mapping>
|
|
@ -6,6 +6,7 @@
|
||||||
<package name="org.hibernate.envers.test.integration.cache" />
|
<package name="org.hibernate.envers.test.integration.cache" />
|
||||||
<package name="org.hibernate.envers.test.integration.collection" />
|
<package name="org.hibernate.envers.test.integration.collection" />
|
||||||
<package name="org.hibernate.envers.test.integration.collection.mapkey" />
|
<package name="org.hibernate.envers.test.integration.collection.mapkey" />
|
||||||
|
<package name="org.hibernate.envers.test.integration.collection.norevision" />
|
||||||
<package name="org.hibernate.envers.test.integration.components" />
|
<package name="org.hibernate.envers.test.integration.components" />
|
||||||
<package name="org.hibernate.envers.test.integration.components.relations" />
|
<package name="org.hibernate.envers.test.integration.components.relations" />
|
||||||
<package name="org.hibernate.envers.test.integration.customtype" />
|
<package name="org.hibernate.envers.test.integration.customtype" />
|
||||||
|
|
Loading…
Reference in New Issue