Moved Test logic to separate classes
Added new test cases Merge logic for CollectionChangeWorkUnits
This commit is contained in:
parent
313bb01c50
commit
d7904dbf0d
|
@ -75,7 +75,7 @@ public class AddWorkUnit extends AbstractAuditWorkUnit implements AuditWorkUnit
|
||||||
}
|
}
|
||||||
|
|
||||||
public AuditWorkUnit merge(CollectionChangeWorkUnit second) {
|
public AuditWorkUnit merge(CollectionChangeWorkUnit second) {
|
||||||
second.addCollectionModifiedData(data);
|
second.mergeCollectionModifiedData(data);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,6 @@ import org.hibernate.Hibernate;
|
||||||
import org.hibernate.engine.spi.SessionImplementor;
|
import org.hibernate.engine.spi.SessionImplementor;
|
||||||
import org.hibernate.envers.RevisionType;
|
import org.hibernate.envers.RevisionType;
|
||||||
import org.hibernate.envers.configuration.AuditConfiguration;
|
import org.hibernate.envers.configuration.AuditConfiguration;
|
||||||
import org.hibernate.envers.configuration.metadata.MetadataTools;
|
|
||||||
import org.hibernate.proxy.HibernateProxy;
|
import org.hibernate.proxy.HibernateProxy;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
@ -59,12 +58,14 @@ public class CollectionChangeWorkUnit extends AbstractAuditWorkUnit implements A
|
||||||
public Map<String, Object> generateData(Object revisionData) {
|
public Map<String, Object> generateData(Object revisionData) {
|
||||||
fillDataWithId(data, revisionData);
|
fillDataWithId(data, revisionData);
|
||||||
resolveProxyIfNeeded();
|
resolveProxyIfNeeded();
|
||||||
|
Map<String, Object> preGenerateData = new HashMap<String, Object>(data);
|
||||||
verCfg.getEntCfg().get(getEntityName()).getPropertyMapper()
|
verCfg.getEntCfg().get(getEntityName()).getPropertyMapper()
|
||||||
.mapToMapFromEntity(sessionImplementor, data, entity, null);
|
.mapToMapFromEntity(sessionImplementor, data, entity, null);
|
||||||
verCfg.getEntCfg().get(getEntityName()).getPropertyMapper()
|
verCfg.getEntCfg().get(getEntityName()).getPropertyMapper()
|
||||||
.mapModifiedFlagsToMapFromEntity(sessionImplementor, data, entity, entity);
|
.mapModifiedFlagsToMapFromEntity(sessionImplementor, data, entity, entity);
|
||||||
verCfg.getEntCfg().get(getEntityName()).getPropertyMapper()
|
verCfg.getEntCfg().get(getEntityName()).getPropertyMapper()
|
||||||
.mapModifiedFlagsToMapForCollectionChange(collectionPropertyName, data);
|
.mapModifiedFlagsToMapForCollectionChange(collectionPropertyName, data);
|
||||||
|
data.putAll(preGenerateData);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,19 +77,10 @@ public class CollectionChangeWorkUnit extends AbstractAuditWorkUnit implements A
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addCollectionModifiedData(Map<String, Object> data) {
|
public void mergeCollectionModifiedData(Map<String, Object> data) {
|
||||||
String modifiedFlagForCollection = getModifiedFlagPropertyNameForCollection();
|
verCfg.getEntCfg().get(getEntityName()).getPropertyMapper()
|
||||||
if(data.containsKey(modifiedFlagForCollection)) {
|
.mapModifiedFlagsToMapForCollectionChange(
|
||||||
data.put(modifiedFlagForCollection, true);
|
collectionPropertyName, data);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getModifiedFlagPropertyNameForCollection() {
|
|
||||||
int dotIdx = collectionPropertyName.indexOf('.');
|
|
||||||
if (dotIdx != -1) { // in component
|
|
||||||
return MetadataTools.getModifiedFlagPropertyName(collectionPropertyName.substring(0, dotIdx));
|
|
||||||
}
|
|
||||||
return MetadataTools.getModifiedFlagPropertyName(collectionPropertyName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public AuditWorkUnit merge(AddWorkUnit second) {
|
public AuditWorkUnit merge(AddWorkUnit second) {
|
||||||
|
@ -104,6 +96,7 @@ public class CollectionChangeWorkUnit extends AbstractAuditWorkUnit implements A
|
||||||
}
|
}
|
||||||
|
|
||||||
public AuditWorkUnit merge(CollectionChangeWorkUnit second) {
|
public AuditWorkUnit merge(CollectionChangeWorkUnit second) {
|
||||||
|
second.mergeCollectionModifiedData(data);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,6 @@ import org.hibernate.ejb.Ejb3Configuration;
|
||||||
import org.hibernate.ejb.EntityManagerFactoryImpl;
|
import org.hibernate.ejb.EntityManagerFactoryImpl;
|
||||||
import org.hibernate.envers.AuditReader;
|
import org.hibernate.envers.AuditReader;
|
||||||
import org.hibernate.envers.AuditReaderFactory;
|
import org.hibernate.envers.AuditReaderFactory;
|
||||||
import org.hibernate.envers.configuration.GlobalConfiguration;
|
|
||||||
import org.hibernate.envers.event.EnversIntegrator;
|
import org.hibernate.envers.event.EnversIntegrator;
|
||||||
import org.hibernate.internal.SessionFactoryImpl;
|
import org.hibernate.internal.SessionFactoryImpl;
|
||||||
import org.hibernate.service.BootstrapServiceRegistryBuilder;
|
import org.hibernate.service.BootstrapServiceRegistryBuilder;
|
||||||
|
@ -101,9 +100,6 @@ public abstract class AbstractEntityTest extends AbstractEnversTest {
|
||||||
configurationProperties.setProperty("org.hibernate.envers.audit_strategy", auditStrategy);
|
configurationProperties.setProperty("org.hibernate.envers.audit_strategy", auditStrategy);
|
||||||
}
|
}
|
||||||
|
|
||||||
configurationProperties.setProperty(GlobalConfiguration.OVERRIDE_USING_MODIFIED_FLAG_PROPERTY, "true");
|
|
||||||
configurationProperties.setProperty(GlobalConfiguration.USING_MODIFIED_FLAG_PROPERTY, "true");
|
|
||||||
|
|
||||||
addConfigurationProperties(configurationProperties);
|
addConfigurationProperties(configurationProperties);
|
||||||
|
|
||||||
cfg = new Ejb3Configuration();
|
cfg = new Ejb3Configuration();
|
||||||
|
|
|
@ -6,7 +6,6 @@ import org.hibernate.SessionFactory;
|
||||||
import org.hibernate.cfg.Configuration;
|
import org.hibernate.cfg.Configuration;
|
||||||
import org.hibernate.envers.AuditReader;
|
import org.hibernate.envers.AuditReader;
|
||||||
import org.hibernate.envers.AuditReaderFactory;
|
import org.hibernate.envers.AuditReaderFactory;
|
||||||
import org.hibernate.envers.configuration.GlobalConfiguration;
|
|
||||||
import org.hibernate.service.ServiceRegistry;
|
import org.hibernate.service.ServiceRegistry;
|
||||||
import org.hibernate.testing.AfterClassOnce;
|
import org.hibernate.testing.AfterClassOnce;
|
||||||
import org.hibernate.testing.BeforeClassOnce;
|
import org.hibernate.testing.BeforeClassOnce;
|
||||||
|
@ -41,8 +40,7 @@ public abstract class AbstractOneSessionTest extends AbstractEnversTest {
|
||||||
if (auditStrategy != null && !"".equals(auditStrategy)) {
|
if (auditStrategy != null && !"".equals(auditStrategy)) {
|
||||||
config.setProperty("org.hibernate.envers.audit_strategy", auditStrategy);
|
config.setProperty("org.hibernate.envers.audit_strategy", auditStrategy);
|
||||||
}
|
}
|
||||||
config.setProperty(GlobalConfiguration.OVERRIDE_USING_MODIFIED_FLAG_PROPERTY, "true");
|
addProperties(config);
|
||||||
config.setProperty(GlobalConfiguration.USING_MODIFIED_FLAG_PROPERTY, "true");
|
|
||||||
|
|
||||||
this.initMappings();
|
this.initMappings();
|
||||||
|
|
||||||
|
@ -52,6 +50,8 @@ public abstract class AbstractOneSessionTest extends AbstractEnversTest {
|
||||||
|
|
||||||
protected abstract void initMappings() throws MappingException, URISyntaxException ;
|
protected abstract void initMappings() throws MappingException, URISyntaxException ;
|
||||||
|
|
||||||
|
protected void addProperties(Configuration configuration) {}
|
||||||
|
|
||||||
protected String getHibernateConfigurationFileName(){
|
protected String getHibernateConfigurationFileName(){
|
||||||
return "hibernate.test.session-cfg.xml";
|
return "hibernate.test.session-cfg.xml";
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,6 @@ import org.hibernate.SessionFactory;
|
||||||
import org.hibernate.cfg.Configuration;
|
import org.hibernate.cfg.Configuration;
|
||||||
import org.hibernate.envers.AuditReader;
|
import org.hibernate.envers.AuditReader;
|
||||||
import org.hibernate.envers.AuditReaderFactory;
|
import org.hibernate.envers.AuditReaderFactory;
|
||||||
import org.hibernate.envers.configuration.GlobalConfiguration;
|
|
||||||
import org.hibernate.service.ServiceRegistry;
|
import org.hibernate.service.ServiceRegistry;
|
||||||
import org.hibernate.testing.AfterClassOnce;
|
import org.hibernate.testing.AfterClassOnce;
|
||||||
import org.hibernate.testing.BeforeClassOnce;
|
import org.hibernate.testing.BeforeClassOnce;
|
||||||
|
@ -42,8 +41,6 @@ public abstract class AbstractSessionTest extends AbstractEnversTest {
|
||||||
if (auditStrategy != null && !"".equals(auditStrategy)) {
|
if (auditStrategy != null && !"".equals(auditStrategy)) {
|
||||||
config.setProperty("org.hibernate.envers.audit_strategy", auditStrategy);
|
config.setProperty("org.hibernate.envers.audit_strategy", auditStrategy);
|
||||||
}
|
}
|
||||||
config.setProperty(GlobalConfiguration.OVERRIDE_USING_MODIFIED_FLAG_PROPERTY, "true");
|
|
||||||
config.setProperty(GlobalConfiguration.USING_MODIFIED_FLAG_PROPERTY, "true");
|
|
||||||
|
|
||||||
this.initMappings();
|
this.initMappings();
|
||||||
|
|
||||||
|
|
|
@ -25,17 +25,12 @@ package org.hibernate.envers.test.integration.auditReader;
|
||||||
|
|
||||||
import org.hibernate.ejb.Ejb3Configuration;
|
import org.hibernate.ejb.Ejb3Configuration;
|
||||||
import org.hibernate.envers.exception.NotAuditedException;
|
import org.hibernate.envers.exception.NotAuditedException;
|
||||||
import org.hibernate.envers.query.AuditEntity;
|
|
||||||
import org.hibernate.envers.test.AbstractEntityTest;
|
import org.hibernate.envers.test.AbstractEntityTest;
|
||||||
import org.hibernate.envers.test.Priority;
|
import org.hibernate.envers.test.Priority;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static junit.framework.Assert.assertEquals;
|
|
||||||
import static junit.framework.Assert.assertTrue;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A test which checks the correct behavior of AuditReader.isEntityClassAudited(Class entityClass).
|
* A test which checks the correct behavior of AuditReader.isEntityClassAudited(Class entityClass).
|
||||||
|
@ -76,19 +71,6 @@ public class AuditReaderAPITest extends AbstractEntityTest {
|
||||||
assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(AuditedTestEntity.class, 1));
|
assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(AuditedTestEntity.class, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testHasChangedHasNotChangedCriteria() throws Exception {
|
|
||||||
List list = getAuditReader().createQuery().forRevisionsOfEntity(AuditedTestEntity.class, true, true).
|
|
||||||
add(AuditEntity.property("str1").hasChanged()).getResultList();
|
|
||||||
assertEquals(2, list.size());
|
|
||||||
assertEquals("str1", ((AuditedTestEntity) list.get(0)).getStr1());
|
|
||||||
assertEquals("str2", ((AuditedTestEntity) list.get(1)).getStr1());
|
|
||||||
|
|
||||||
list = getAuditReader().createQuery().forRevisionsOfEntity(AuditedTestEntity.class, true, true).
|
|
||||||
add(AuditEntity.property("str1").hasNotChanged()).getResultList();
|
|
||||||
assertTrue(list.isEmpty());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsEntityClassAuditedForNotAuditedEntity() {
|
public void testIsEntityClassAuditedForNotAuditedEntity() {
|
||||||
|
|
||||||
|
|
|
@ -24,17 +24,12 @@
|
||||||
package org.hibernate.envers.test.integration.basic;
|
package org.hibernate.envers.test.integration.basic;
|
||||||
|
|
||||||
import org.hibernate.ejb.Ejb3Configuration;
|
import org.hibernate.ejb.Ejb3Configuration;
|
||||||
import org.hibernate.envers.query.AuditEntity;
|
|
||||||
import org.hibernate.envers.test.AbstractEntityTest;
|
import org.hibernate.envers.test.AbstractEntityTest;
|
||||||
import org.hibernate.envers.test.Priority;
|
import org.hibernate.envers.test.Priority;
|
||||||
import org.hibernate.envers.test.tools.TestTools;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static junit.framework.Assert.assertEquals;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Adam Warski (adam at warski dot org)
|
* @author Adam Warski (adam at warski dot org)
|
||||||
|
@ -105,42 +100,4 @@ public class NullProperties extends AbstractEntityTest {
|
||||||
assert getAuditReader().find(BasicTestEntity1.class, id2, 4).equals(ver2);
|
assert getAuditReader().find(BasicTestEntity1.class, id2, 4).equals(ver2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testHasChanged() throws Exception {
|
|
||||||
List list = getAuditReader().createQuery().forRevisionsOfEntity(BasicTestEntity1.class, false, true)
|
|
||||||
.add(AuditEntity.property("str1").hasChanged())
|
|
||||||
.add(AuditEntity.id().eq(id1))
|
|
||||||
.getResultList();
|
|
||||||
assertEquals(2, list.size());
|
|
||||||
assertEquals(TestTools.makeList(1, 3), extractRevisionNumbers(list));
|
|
||||||
|
|
||||||
list = getAuditReader().createQuery().forRevisionsOfEntity(BasicTestEntity1.class, false, true)
|
|
||||||
.add(AuditEntity.property("long1").hasChanged())
|
|
||||||
.add(AuditEntity.id().eq(id1))
|
|
||||||
.getResultList();
|
|
||||||
assertEquals(1, list.size());
|
|
||||||
assertEquals(TestTools.makeList(1), extractRevisionNumbers(list));
|
|
||||||
|
|
||||||
list = getAuditReader().createQuery().forRevisionsOfEntity(BasicTestEntity1.class, false, true)
|
|
||||||
.add(AuditEntity.property("str1").hasChanged())
|
|
||||||
.add(AuditEntity.id().eq(id2))
|
|
||||||
.getResultList();
|
|
||||||
// str1 property was null before insert and after insert so in a way it didn't change - is it a good way to go?
|
|
||||||
assertEquals(1, list.size());
|
|
||||||
assertEquals(TestTools.makeList(4), extractRevisionNumbers(list));
|
|
||||||
|
|
||||||
list = getAuditReader().createQuery().forRevisionsOfEntity(BasicTestEntity1.class, false, true)
|
|
||||||
.add(AuditEntity.property("long1").hasChanged())
|
|
||||||
.add(AuditEntity.id().eq(id2))
|
|
||||||
.getResultList();
|
|
||||||
assertEquals(1, list.size());
|
|
||||||
assertEquals(TestTools.makeList(2), extractRevisionNumbers(list));
|
|
||||||
|
|
||||||
list = getAuditReader().createQuery().forRevisionsOfEntity(BasicTestEntity1.class, false, true)
|
|
||||||
.add(AuditEntity.property("str1").hasChanged())
|
|
||||||
.add(AuditEntity.property("long1").hasChanged())
|
|
||||||
.getResultList();
|
|
||||||
assertEquals(1, list.size());
|
|
||||||
assertEquals(TestTools.makeList(1), extractRevisionNumbers(list));
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -23,9 +23,7 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.envers.test.integration.basic;
|
package org.hibernate.envers.test.integration.basic;
|
||||||
|
|
||||||
import org.hibernate.QueryException;
|
|
||||||
import org.hibernate.ejb.Ejb3Configuration;
|
import org.hibernate.ejb.Ejb3Configuration;
|
||||||
import org.hibernate.envers.query.AuditEntity;
|
|
||||||
import org.hibernate.envers.test.AbstractEntityTest;
|
import org.hibernate.envers.test.AbstractEntityTest;
|
||||||
import org.hibernate.envers.test.Priority;
|
import org.hibernate.envers.test.Priority;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -84,11 +82,4 @@ public class UnversionedPropertiesChange extends AbstractEntityTest {
|
||||||
assert getAuditReader().find(BasicTestEntity2.class, id1, 1).equals(ver1);
|
assert getAuditReader().find(BasicTestEntity2.class, id1, 1).equals(ver1);
|
||||||
assert getAuditReader().find(BasicTestEntity2.class, id1, 2).equals(ver2);
|
assert getAuditReader().find(BasicTestEntity2.class, id1, 2).equals(ver2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = QueryException.class)
|
|
||||||
public void testExceptionOnHasChangedQuery() throws Exception {
|
|
||||||
getAuditReader().createQuery().forRevisionsOfEntity(BasicTestEntity2.class, true, false)
|
|
||||||
.add(AuditEntity.property("str2").hasChanged())
|
|
||||||
.getResultList();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,6 @@
|
||||||
package org.hibernate.envers.test.integration.collection;
|
package org.hibernate.envers.test.integration.collection;
|
||||||
|
|
||||||
import org.hibernate.ejb.Ejb3Configuration;
|
import org.hibernate.ejb.Ejb3Configuration;
|
||||||
import org.hibernate.envers.query.AuditEntity;
|
|
||||||
import org.hibernate.envers.test.AbstractEntityTest;
|
import org.hibernate.envers.test.AbstractEntityTest;
|
||||||
import org.hibernate.envers.test.Priority;
|
import org.hibernate.envers.test.Priority;
|
||||||
import org.hibernate.envers.test.entities.collection.EnumSetEntity;
|
import org.hibernate.envers.test.entities.collection.EnumSetEntity;
|
||||||
|
@ -35,9 +34,6 @@ import org.junit.Test;
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static junit.framework.Assert.assertEquals;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Adam Warski (adam at warski dot org)
|
* @author Adam Warski (adam at warski dot org)
|
||||||
|
@ -111,29 +107,4 @@ public class EnumSet extends AbstractEntityTest {
|
||||||
assert rev3.getEnums2().equals(TestTools.makeSet(E2.A));
|
assert rev3.getEnums2().equals(TestTools.makeSet(E2.A));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testHasChanged() throws Exception {
|
|
||||||
List list = getAuditReader().createQuery().forRevisionsOfEntity(EnumSetEntity.class, false, false)
|
|
||||||
.add(AuditEntity.property("enums1").hasChanged())
|
|
||||||
.getResultList();
|
|
||||||
assertEquals(3, list.size());
|
|
||||||
assertEquals(TestTools.makeList(1, 2, 3), extractRevisionNumbers(list));
|
|
||||||
|
|
||||||
list = getAuditReader().createQuery().forRevisionsOfEntity(EnumSetEntity.class, false, false)
|
|
||||||
.add(AuditEntity.property("enums2").hasChanged())
|
|
||||||
.getResultList();
|
|
||||||
assertEquals(1, list.size());
|
|
||||||
assertEquals(TestTools.makeList(1), extractRevisionNumbers(list));
|
|
||||||
|
|
||||||
list = getAuditReader().createQuery().forRevisionsOfEntity(EnumSetEntity.class, false, false)
|
|
||||||
.add(AuditEntity.property("enums1").hasNotChanged())
|
|
||||||
.getResultList();
|
|
||||||
assertEquals(0, list.size());
|
|
||||||
|
|
||||||
list = getAuditReader().createQuery().forRevisionsOfEntity(EnumSetEntity.class, false, false)
|
|
||||||
.add(AuditEntity.property("enums2").hasNotChanged())
|
|
||||||
.getResultList();
|
|
||||||
assertEquals(2, list.size());
|
|
||||||
assertEquals(TestTools.makeList(2, 3), extractRevisionNumbers(list));
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -24,7 +24,6 @@
|
||||||
package org.hibernate.envers.test.integration.collection;
|
package org.hibernate.envers.test.integration.collection;
|
||||||
|
|
||||||
import org.hibernate.ejb.Ejb3Configuration;
|
import org.hibernate.ejb.Ejb3Configuration;
|
||||||
import org.hibernate.envers.query.AuditEntity;
|
|
||||||
import org.hibernate.envers.test.AbstractEntityTest;
|
import org.hibernate.envers.test.AbstractEntityTest;
|
||||||
import org.hibernate.envers.test.Priority;
|
import org.hibernate.envers.test.Priority;
|
||||||
import org.hibernate.envers.test.entities.collection.StringMapEntity;
|
import org.hibernate.envers.test.entities.collection.StringMapEntity;
|
||||||
|
@ -34,9 +33,6 @@ import org.junit.Test;
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static junit.framework.Assert.assertEquals;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Adam Warski (adam at warski dot org)
|
* @author Adam Warski (adam at warski dot org)
|
||||||
|
@ -138,32 +134,4 @@ public class StringMap extends AbstractEntityTest {
|
||||||
assert rev4.getStrings().equals(TestTools.makeMap("1", "b"));
|
assert rev4.getStrings().equals(TestTools.makeMap("1", "b"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testHasChanged() throws Exception {
|
|
||||||
List list = getAuditReader().createQuery().forRevisionsOfEntity(StringMapEntity.class, false, false)
|
|
||||||
.add(AuditEntity.id().eq(sme1_id))
|
|
||||||
.add(AuditEntity.property("strings").hasChanged())
|
|
||||||
.getResultList();
|
|
||||||
assertEquals(3, list.size());
|
|
||||||
assertEquals(TestTools.makeList(1, 2, 3), extractRevisionNumbers(list));
|
|
||||||
|
|
||||||
list = getAuditReader().createQuery().forRevisionsOfEntity(StringMapEntity.class, false, false)
|
|
||||||
.add(AuditEntity.id().eq(sme2_id))
|
|
||||||
.add(AuditEntity.property("strings").hasChanged())
|
|
||||||
.getResultList();
|
|
||||||
assertEquals(2, list.size());
|
|
||||||
assertEquals(TestTools.makeList(1, 3), extractRevisionNumbers(list));
|
|
||||||
|
|
||||||
list = getAuditReader().createQuery().forRevisionsOfEntity(StringMapEntity.class, false, false)
|
|
||||||
.add(AuditEntity.id().eq(sme1_id))
|
|
||||||
.add(AuditEntity.property("strings").hasNotChanged())
|
|
||||||
.getResultList();
|
|
||||||
assertEquals(0, list.size());
|
|
||||||
|
|
||||||
list = getAuditReader().createQuery().forRevisionsOfEntity(StringMapEntity.class, false, false)
|
|
||||||
.add(AuditEntity.id().eq(sme2_id))
|
|
||||||
.add(AuditEntity.property("strings").hasNotChanged())
|
|
||||||
.getResultList();
|
|
||||||
assertEquals(0, list.size()); // in rev 2 there was no version generated for sme2_id
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -24,7 +24,6 @@
|
||||||
package org.hibernate.envers.test.integration.collection;
|
package org.hibernate.envers.test.integration.collection;
|
||||||
|
|
||||||
import org.hibernate.ejb.Ejb3Configuration;
|
import org.hibernate.ejb.Ejb3Configuration;
|
||||||
import org.hibernate.envers.query.AuditEntity;
|
|
||||||
import org.hibernate.envers.test.AbstractEntityTest;
|
import org.hibernate.envers.test.AbstractEntityTest;
|
||||||
import org.hibernate.envers.test.Priority;
|
import org.hibernate.envers.test.Priority;
|
||||||
import org.hibernate.envers.test.entities.collection.StringSetEntity;
|
import org.hibernate.envers.test.entities.collection.StringSetEntity;
|
||||||
|
@ -34,9 +33,6 @@ import org.junit.Test;
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static junit.framework.Assert.assertEquals;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Adam Warski (adam at warski dot org)
|
* @author Adam Warski (adam at warski dot org)
|
||||||
|
@ -126,32 +122,4 @@ public class StringSet extends AbstractEntityTest {
|
||||||
assert rev3.getStrings().equals(TestTools.makeSet("sse2_string2"));
|
assert rev3.getStrings().equals(TestTools.makeSet("sse2_string2"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testHasChanged() throws Exception {
|
|
||||||
List list = getAuditReader().createQuery().forRevisionsOfEntity(StringSetEntity.class, false, false)
|
|
||||||
.add(AuditEntity.id().eq(sse1_id))
|
|
||||||
.add(AuditEntity.property("strings").hasChanged())
|
|
||||||
.getResultList();
|
|
||||||
assertEquals(2, list.size());
|
|
||||||
assertEquals(TestTools.makeList(1, 2), extractRevisionNumbers(list));
|
|
||||||
|
|
||||||
list = getAuditReader().createQuery().forRevisionsOfEntity(StringSetEntity.class, false, false)
|
|
||||||
.add(AuditEntity.id().eq(sse2_id))
|
|
||||||
.add(AuditEntity.property("strings").hasChanged())
|
|
||||||
.getResultList();
|
|
||||||
assertEquals(2, list.size());
|
|
||||||
assertEquals(TestTools.makeList(1, 3), extractRevisionNumbers(list));
|
|
||||||
|
|
||||||
list = getAuditReader().createQuery().forRevisionsOfEntity(StringSetEntity.class, false, false)
|
|
||||||
.add(AuditEntity.id().eq(sse1_id))
|
|
||||||
.add(AuditEntity.property("strings").hasNotChanged())
|
|
||||||
.getResultList();
|
|
||||||
assertEquals(0, list.size());
|
|
||||||
|
|
||||||
list = getAuditReader().createQuery().forRevisionsOfEntity(StringSetEntity.class, false, false)
|
|
||||||
.add(AuditEntity.id().eq(sse2_id))
|
|
||||||
.add(AuditEntity.property("strings").hasNotChanged())
|
|
||||||
.getResultList();
|
|
||||||
assertEquals(0, list.size());
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -24,7 +24,6 @@
|
||||||
package org.hibernate.envers.test.integration.collection.mapkey;
|
package org.hibernate.envers.test.integration.collection.mapkey;
|
||||||
|
|
||||||
import org.hibernate.ejb.Ejb3Configuration;
|
import org.hibernate.ejb.Ejb3Configuration;
|
||||||
import org.hibernate.envers.query.AuditEntity;
|
|
||||||
import org.hibernate.envers.test.AbstractEntityTest;
|
import org.hibernate.envers.test.AbstractEntityTest;
|
||||||
import org.hibernate.envers.test.Priority;
|
import org.hibernate.envers.test.Priority;
|
||||||
import org.hibernate.envers.test.entities.components.Component1;
|
import org.hibernate.envers.test.entities.components.Component1;
|
||||||
|
@ -35,9 +34,6 @@ import org.junit.Test;
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static junit.framework.Assert.assertEquals;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Adam Warski (adam at warski dot org)
|
* @author Adam Warski (adam at warski dot org)
|
||||||
|
@ -113,20 +109,4 @@ public class ComponentMapKey extends AbstractEntityTest {
|
||||||
assert rev1.getIdmap().equals(TestTools.makeMap(cte1.getComp1(), cte1));
|
assert rev1.getIdmap().equals(TestTools.makeMap(cte1.getComp1(), cte1));
|
||||||
assert rev2.getIdmap().equals(TestTools.makeMap(cte1.getComp1(), cte1, cte2.getComp1(), cte2));
|
assert rev2.getIdmap().equals(TestTools.makeMap(cte1.getComp1(), cte1, cte2.getComp1(), cte2));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testHasChanged() throws Exception {
|
|
||||||
List list = getAuditReader().createQuery().forRevisionsOfEntity(ComponentMapKeyEntity.class, false, false)
|
|
||||||
.add(AuditEntity.id().eq(cmke_id))
|
|
||||||
.add(AuditEntity.property("idmap").hasChanged())
|
|
||||||
.getResultList();
|
|
||||||
assertEquals(2, list.size());
|
|
||||||
assertEquals(TestTools.makeList(1, 2), extractRevisionNumbers(list));
|
|
||||||
|
|
||||||
list = getAuditReader().createQuery().forRevisionsOfEntity(ComponentMapKeyEntity.class, false, false)
|
|
||||||
.add(AuditEntity.id().eq(cmke_id))
|
|
||||||
.add(AuditEntity.property("idmap").hasNotChanged())
|
|
||||||
.getResultList();
|
|
||||||
assertEquals(0, list.size());
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -24,7 +24,6 @@
|
||||||
package org.hibernate.envers.test.integration.collection.mapkey;
|
package org.hibernate.envers.test.integration.collection.mapkey;
|
||||||
|
|
||||||
import org.hibernate.ejb.Ejb3Configuration;
|
import org.hibernate.ejb.Ejb3Configuration;
|
||||||
import org.hibernate.envers.query.AuditEntity;
|
|
||||||
import org.hibernate.envers.test.AbstractEntityTest;
|
import org.hibernate.envers.test.AbstractEntityTest;
|
||||||
import org.hibernate.envers.test.Priority;
|
import org.hibernate.envers.test.Priority;
|
||||||
import org.hibernate.envers.test.entities.StrTestEntity;
|
import org.hibernate.envers.test.entities.StrTestEntity;
|
||||||
|
@ -33,9 +32,6 @@ import org.junit.Test;
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static junit.framework.Assert.assertEquals;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Adam Warski (adam at warski dot org)
|
* @author Adam Warski (adam at warski dot org)
|
||||||
|
@ -108,19 +104,4 @@ public class IdMapKey extends AbstractEntityTest {
|
||||||
assert rev2.getIdmap().equals(TestTools.makeMap(ste1.getId(), ste1, ste2.getId(), ste2));
|
assert rev2.getIdmap().equals(TestTools.makeMap(ste1.getId(), ste1, ste2.getId(), ste2));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testHasChanged() throws Exception {
|
|
||||||
List list = getAuditReader().createQuery().forRevisionsOfEntity(IdMapKeyEntity.class, false, false)
|
|
||||||
.add(AuditEntity.id().eq(imke_id))
|
|
||||||
.add(AuditEntity.property("idmap").hasChanged())
|
|
||||||
.getResultList();
|
|
||||||
assertEquals(2, list.size());
|
|
||||||
assertEquals(TestTools.makeList(1, 2), extractRevisionNumbers(list));
|
|
||||||
|
|
||||||
list = getAuditReader().createQuery().forRevisionsOfEntity(IdMapKeyEntity.class, false, false)
|
|
||||||
.add(AuditEntity.id().eq(imke_id))
|
|
||||||
.add(AuditEntity.property("idmap").hasNotChanged())
|
|
||||||
.getResultList();
|
|
||||||
assertEquals(0, list.size());
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -23,22 +23,16 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.envers.test.integration.components;
|
package org.hibernate.envers.test.integration.components;
|
||||||
|
|
||||||
import org.hibernate.QueryException;
|
|
||||||
import org.hibernate.ejb.Ejb3Configuration;
|
import org.hibernate.ejb.Ejb3Configuration;
|
||||||
import org.hibernate.envers.query.AuditEntity;
|
|
||||||
import org.hibernate.envers.test.AbstractEntityTest;
|
import org.hibernate.envers.test.AbstractEntityTest;
|
||||||
import org.hibernate.envers.test.Priority;
|
import org.hibernate.envers.test.Priority;
|
||||||
import org.hibernate.envers.test.entities.components.Component1;
|
import org.hibernate.envers.test.entities.components.Component1;
|
||||||
import org.hibernate.envers.test.entities.components.Component2;
|
import org.hibernate.envers.test.entities.components.Component2;
|
||||||
import org.hibernate.envers.test.entities.components.ComponentTestEntity;
|
import org.hibernate.envers.test.entities.components.ComponentTestEntity;
|
||||||
import org.hibernate.envers.test.tools.TestTools;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static junit.framework.Assert.assertEquals;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Adam Warski (adam at warski dot org)
|
* @author Adam Warski (adam at warski dot org)
|
||||||
|
@ -179,75 +173,4 @@ public class Components extends AbstractEntityTest {
|
||||||
assert getAuditReader().find(ComponentTestEntity.class, id4, 4).equals(ver3);
|
assert getAuditReader().find(ComponentTestEntity.class, id4, 4).equals(ver3);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = QueryException.class)
|
|
||||||
public void testHasChangedNotAudited() throws Exception {
|
|
||||||
getAuditReader().createQuery().forRevisionsOfEntity(ComponentTestEntity.class, false, false)
|
|
||||||
.add(AuditEntity.property("comp2").hasChanged())
|
|
||||||
.getResultList();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testHasChangedId1() throws Exception {
|
|
||||||
List list = getAuditReader().createQuery().forRevisionsOfEntity(ComponentTestEntity.class, false, false)
|
|
||||||
.add(AuditEntity.id().eq(id1))
|
|
||||||
.add(AuditEntity.property("comp1").hasChanged())
|
|
||||||
.getResultList();
|
|
||||||
assertEquals(2, list.size());
|
|
||||||
assertEquals(TestTools.makeList(1, 2), extractRevisionNumbers(list));
|
|
||||||
|
|
||||||
list = getAuditReader().createQuery().forRevisionsOfEntity(ComponentTestEntity.class, false, false)
|
|
||||||
.add(AuditEntity.id().eq(id1))
|
|
||||||
.add(AuditEntity.property("comp1").hasNotChanged())
|
|
||||||
.getResultList();
|
|
||||||
assertEquals(0, list.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testHasChangedId2() throws Exception {
|
|
||||||
List list = getAuditReader().createQuery().forRevisionsOfEntity(ComponentTestEntity.class, false, true)
|
|
||||||
.add(AuditEntity.id().eq(id2))
|
|
||||||
.add(AuditEntity.property("comp1").hasChanged())
|
|
||||||
.getResultList();
|
|
||||||
assertEquals(3, list.size());
|
|
||||||
assertEquals(TestTools.makeList(1, 2, 4), extractRevisionNumbers(list));
|
|
||||||
|
|
||||||
list = getAuditReader().createQuery().forRevisionsOfEntity(ComponentTestEntity.class, false, true)
|
|
||||||
.add(AuditEntity.id().eq(id2))
|
|
||||||
.add(AuditEntity.property("comp1").hasNotChanged())
|
|
||||||
.getResultList();
|
|
||||||
assertEquals(0, list.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testHasChangedId3() throws Exception {
|
|
||||||
List list = getAuditReader().createQuery().forRevisionsOfEntity(ComponentTestEntity.class, false, true)
|
|
||||||
.add(AuditEntity.id().eq(id3))
|
|
||||||
.add(AuditEntity.property("comp1").hasChanged())
|
|
||||||
.getResultList();
|
|
||||||
assertEquals(2, list.size());
|
|
||||||
assertEquals(TestTools.makeList(1, 3), extractRevisionNumbers(list));
|
|
||||||
|
|
||||||
list = getAuditReader().createQuery().forRevisionsOfEntity(ComponentTestEntity.class, false, true)
|
|
||||||
.add(AuditEntity.id().eq(id3))
|
|
||||||
.add(AuditEntity.property("comp1").hasNotChanged())
|
|
||||||
.getResultList();
|
|
||||||
assertEquals(0, list.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testHasChangedId4() throws Exception {
|
|
||||||
List list = getAuditReader().createQuery().forRevisionsOfEntity(ComponentTestEntity.class, false, true)
|
|
||||||
.add(AuditEntity.id().eq(id4))
|
|
||||||
.add(AuditEntity.property("comp1").hasChanged())
|
|
||||||
.getResultList();
|
|
||||||
assertEquals(2, list.size());
|
|
||||||
assertEquals(TestTools.makeList(2, 3), extractRevisionNumbers(list));
|
|
||||||
|
|
||||||
list = getAuditReader().createQuery().forRevisionsOfEntity(ComponentTestEntity.class, false, true)
|
|
||||||
.add(AuditEntity.id().eq(id4))
|
|
||||||
.add(AuditEntity.property("comp1").hasNotChanged())
|
|
||||||
.getResultList();
|
|
||||||
assertEquals(1, list.size());
|
|
||||||
assertEquals(TestTools.makeList(1), extractRevisionNumbers(list));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,20 +24,17 @@
|
||||||
package org.hibernate.envers.test.integration.components.relations;
|
package org.hibernate.envers.test.integration.components.relations;
|
||||||
|
|
||||||
import org.hibernate.ejb.Ejb3Configuration;
|
import org.hibernate.ejb.Ejb3Configuration;
|
||||||
import org.hibernate.envers.query.AuditEntity;
|
|
||||||
import org.hibernate.envers.test.AbstractEntityTest;
|
import org.hibernate.envers.test.AbstractEntityTest;
|
||||||
import org.hibernate.envers.test.Priority;
|
import org.hibernate.envers.test.Priority;
|
||||||
import org.hibernate.envers.test.entities.StrTestEntity;
|
import org.hibernate.envers.test.entities.StrTestEntity;
|
||||||
import org.hibernate.envers.test.entities.components.relations.ManyToOneComponent;
|
import org.hibernate.envers.test.entities.components.relations
|
||||||
import org.hibernate.envers.test.entities.components.relations.ManyToOneComponentTestEntity;
|
.ManyToOneComponent;
|
||||||
import org.hibernate.envers.test.tools.TestTools;
|
import org.hibernate.envers.test.entities.components.relations
|
||||||
|
.ManyToOneComponentTestEntity;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static junit.framework.Assert.assertEquals;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Adam Warski (adam at warski dot org)
|
* @author Adam Warski (adam at warski dot org)
|
||||||
|
@ -112,20 +109,4 @@ public class ManyToOneInComponent extends AbstractEntityTest {
|
||||||
assert getAuditReader().find(ManyToOneComponentTestEntity.class, mtocte_id1, 3).equals(ver3);
|
assert getAuditReader().find(ManyToOneComponentTestEntity.class, mtocte_id1, 3).equals(ver3);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testHasChangedId1() throws Exception {
|
|
||||||
List list = getAuditReader().createQuery().forRevisionsOfEntity(ManyToOneComponentTestEntity.class, false, false)
|
|
||||||
.add(AuditEntity.id().eq(mtocte_id1))
|
|
||||||
.add(AuditEntity.property("comp1").hasChanged())
|
|
||||||
.getResultList();
|
|
||||||
assertEquals(2, list.size());
|
|
||||||
assertEquals(TestTools.makeList(2, 3), extractRevisionNumbers(list));
|
|
||||||
|
|
||||||
list = getAuditReader().createQuery().forRevisionsOfEntity(ManyToOneComponentTestEntity.class, false, false)
|
|
||||||
.add(AuditEntity.id().eq(mtocte_id1))
|
|
||||||
.add(AuditEntity.property("comp1").hasNotChanged())
|
|
||||||
.getResultList();
|
|
||||||
assertEquals(0, list.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,20 +24,17 @@
|
||||||
package org.hibernate.envers.test.integration.components.relations;
|
package org.hibernate.envers.test.integration.components.relations;
|
||||||
|
|
||||||
import org.hibernate.ejb.Ejb3Configuration;
|
import org.hibernate.ejb.Ejb3Configuration;
|
||||||
import org.hibernate.envers.query.AuditEntity;
|
|
||||||
import org.hibernate.envers.test.AbstractEntityTest;
|
import org.hibernate.envers.test.AbstractEntityTest;
|
||||||
import org.hibernate.envers.test.Priority;
|
import org.hibernate.envers.test.Priority;
|
||||||
import org.hibernate.envers.test.entities.UnversionedStrTestEntity;
|
import org.hibernate.envers.test.entities.UnversionedStrTestEntity;
|
||||||
import org.hibernate.envers.test.entities.components.relations.NotAuditedManyToOneComponent;
|
import org.hibernate.envers.test.entities.components.relations
|
||||||
import org.hibernate.envers.test.entities.components.relations.NotAuditedManyToOneComponentTestEntity;
|
.NotAuditedManyToOneComponent;
|
||||||
import org.hibernate.envers.test.tools.TestTools;
|
import org.hibernate.envers.test.entities.components.relations
|
||||||
|
.NotAuditedManyToOneComponentTestEntity;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static junit.framework.Assert.assertEquals;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Adam Warski (adam at warski dot org)
|
* @author Adam Warski (adam at warski dot org)
|
||||||
|
@ -116,19 +113,4 @@ public class NotAuditedManyToOneInComponent extends AbstractEntityTest {
|
||||||
assert getAuditReader().find(NotAuditedManyToOneComponentTestEntity.class, mtocte_id1, 2).equals(ver2);
|
assert getAuditReader().find(NotAuditedManyToOneComponentTestEntity.class, mtocte_id1, 2).equals(ver2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testHasChangedId1() throws Exception {
|
|
||||||
List list = getAuditReader().createQuery().forRevisionsOfEntity(NotAuditedManyToOneComponentTestEntity.class, false, false)
|
|
||||||
.add(AuditEntity.id().eq(mtocte_id1))
|
|
||||||
.add(AuditEntity.property("comp1").hasChanged())
|
|
||||||
.getResultList();
|
|
||||||
assertEquals(2, list.size());
|
|
||||||
assertEquals(TestTools.makeList(1, 2), extractRevisionNumbers(list));
|
|
||||||
|
|
||||||
list = getAuditReader().createQuery().forRevisionsOfEntity(NotAuditedManyToOneComponentTestEntity.class, false, false)
|
|
||||||
.add(AuditEntity.id().eq(mtocte_id1))
|
|
||||||
.add(AuditEntity.property("comp1").hasNotChanged())
|
|
||||||
.getResultList();
|
|
||||||
assertEquals(0, list.size());
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -24,20 +24,17 @@
|
||||||
package org.hibernate.envers.test.integration.components.relations;
|
package org.hibernate.envers.test.integration.components.relations;
|
||||||
|
|
||||||
import org.hibernate.ejb.Ejb3Configuration;
|
import org.hibernate.ejb.Ejb3Configuration;
|
||||||
import org.hibernate.envers.query.AuditEntity;
|
|
||||||
import org.hibernate.envers.test.AbstractEntityTest;
|
import org.hibernate.envers.test.AbstractEntityTest;
|
||||||
import org.hibernate.envers.test.Priority;
|
import org.hibernate.envers.test.Priority;
|
||||||
import org.hibernate.envers.test.entities.StrTestEntity;
|
import org.hibernate.envers.test.entities.StrTestEntity;
|
||||||
import org.hibernate.envers.test.entities.components.relations.OneToManyComponent;
|
import org.hibernate.envers.test.entities.components.relations
|
||||||
import org.hibernate.envers.test.entities.components.relations.OneToManyComponentTestEntity;
|
.OneToManyComponent;
|
||||||
import org.hibernate.envers.test.tools.TestTools;
|
import org.hibernate.envers.test.entities.components.relations
|
||||||
|
.OneToManyComponentTestEntity;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static junit.framework.Assert.assertEquals;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Adam Warski (adam at warski dot org)
|
* @author Adam Warski (adam at warski dot org)
|
||||||
|
@ -116,19 +113,4 @@ public class OneToManyInComponent extends AbstractEntityTest {
|
||||||
assert getAuditReader().find(OneToManyComponentTestEntity.class, otmcte_id1, 3).equals(ver3);
|
assert getAuditReader().find(OneToManyComponentTestEntity.class, otmcte_id1, 3).equals(ver3);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testHasChangedId1() throws Exception {
|
|
||||||
List list = getAuditReader().createQuery().forRevisionsOfEntity(OneToManyComponentTestEntity.class, false, false)
|
|
||||||
.add(AuditEntity.id().eq(otmcte_id1))
|
|
||||||
.add(AuditEntity.property("comp1").hasChanged())
|
|
||||||
.getResultList();
|
|
||||||
assertEquals(2, list.size());
|
|
||||||
assertEquals(TestTools.makeList(2, 3), extractRevisionNumbers(list));
|
|
||||||
|
|
||||||
list = getAuditReader().createQuery().forRevisionsOfEntity(OneToManyComponentTestEntity.class, false, false)
|
|
||||||
.add(AuditEntity.id().eq(otmcte_id1))
|
|
||||||
.add(AuditEntity.property("comp1").hasNotChanged())
|
|
||||||
.getResultList();
|
|
||||||
assertEquals(0, list.size());
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -24,19 +24,14 @@
|
||||||
package org.hibernate.envers.test.integration.customtype;
|
package org.hibernate.envers.test.integration.customtype;
|
||||||
|
|
||||||
import org.hibernate.ejb.Ejb3Configuration;
|
import org.hibernate.ejb.Ejb3Configuration;
|
||||||
import org.hibernate.envers.query.AuditEntity;
|
|
||||||
import org.hibernate.envers.test.AbstractEntityTest;
|
import org.hibernate.envers.test.AbstractEntityTest;
|
||||||
import org.hibernate.envers.test.Priority;
|
import org.hibernate.envers.test.Priority;
|
||||||
import org.hibernate.envers.test.entities.customtype.Component;
|
import org.hibernate.envers.test.entities.customtype.Component;
|
||||||
import org.hibernate.envers.test.entities.customtype.CompositeCustomTypeEntity;
|
import org.hibernate.envers.test.entities.customtype.CompositeCustomTypeEntity;
|
||||||
import org.hibernate.envers.test.tools.TestTools;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static junit.framework.Assert.assertEquals;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Adam Warski (adam at warski dot org)
|
* @author Adam Warski (adam at warski dot org)
|
||||||
|
@ -103,19 +98,4 @@ public class CompositeCustom extends AbstractEntityTest {
|
||||||
assert rev3.getComponent().equals(new Component("c", 3));
|
assert rev3.getComponent().equals(new Component("c", 3));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testHasChanged() throws Exception {
|
|
||||||
List list = getAuditReader().createQuery().forRevisionsOfEntity(CompositeCustomTypeEntity.class, false, false)
|
|
||||||
.add(AuditEntity.id().eq(ccte_id))
|
|
||||||
.add(AuditEntity.property("component").hasChanged())
|
|
||||||
.getResultList();
|
|
||||||
assertEquals(3, list.size());
|
|
||||||
assertEquals(TestTools.makeList(1, 2, 3), extractRevisionNumbers(list));
|
|
||||||
|
|
||||||
list = getAuditReader().createQuery().forRevisionsOfEntity(CompositeCustomTypeEntity.class, false, false)
|
|
||||||
.add(AuditEntity.id().eq(ccte_id))
|
|
||||||
.add(AuditEntity.property("component").hasNotChanged())
|
|
||||||
.getResultList();
|
|
||||||
assertEquals(0, list.size());
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -1,10 +1,8 @@
|
||||||
package org.hibernate.envers.test.integration.entityNames.manyToManyAudited;
|
package org.hibernate.envers.test.integration.entityNames.manyToManyAudited;
|
||||||
|
|
||||||
import org.hibernate.MappingException;
|
import org.hibernate.MappingException;
|
||||||
import org.hibernate.envers.query.AuditEntity;
|
|
||||||
import org.hibernate.envers.test.AbstractOneSessionTest;
|
import org.hibernate.envers.test.AbstractOneSessionTest;
|
||||||
import org.hibernate.envers.test.Priority;
|
import org.hibernate.envers.test.Priority;
|
||||||
import org.hibernate.envers.test.tools.TestTools;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -13,8 +11,6 @@ import java.net.URL;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static junit.framework.Assert.assertEquals;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Hernán Chanfreau
|
* @author Hernán Chanfreau
|
||||||
*
|
*
|
||||||
|
@ -134,52 +130,4 @@ public class ReadEntityWithAuditedManyToManyTest extends AbstractOneSessionTest{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testHasChangedPerson1() throws Exception {
|
|
||||||
List list = getAuditReader().createQuery().forRevisionsOfEntity(Person.class, "Personaje", false, false)
|
|
||||||
.add(AuditEntity.id().eq(id_pers1))
|
|
||||||
.add(AuditEntity.property("cars").hasChanged())
|
|
||||||
.getResultList();
|
|
||||||
assertEquals(1, list.size());
|
|
||||||
assertEquals(TestTools.makeList(1), extractRevisionNumbers(list));
|
|
||||||
|
|
||||||
list = getAuditReader().createQuery().forRevisionsOfEntity(Person.class, "Personaje", false, false)
|
|
||||||
.add(AuditEntity.id().eq(id_pers1))
|
|
||||||
.add(AuditEntity.property("cars").hasNotChanged())
|
|
||||||
.getResultList();
|
|
||||||
assertEquals(1, list.size());
|
|
||||||
assertEquals(TestTools.makeList(2), extractRevisionNumbers(list));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testHasChangedPerson2() throws Exception {
|
|
||||||
List list = getAuditReader().createQuery().forRevisionsOfEntity(Person.class, "Personaje", false, false)
|
|
||||||
.add(AuditEntity.id().eq(id_pers2))
|
|
||||||
.add(AuditEntity.property("cars").hasChanged())
|
|
||||||
.getResultList();
|
|
||||||
assertEquals(2, list.size());
|
|
||||||
assertEquals(TestTools.makeList(1, 2), extractRevisionNumbers(list));
|
|
||||||
|
|
||||||
list = getAuditReader().createQuery().forRevisionsOfEntity(Person.class, "Personaje", false, false)
|
|
||||||
.add(AuditEntity.id().eq(id_pers2))
|
|
||||||
.add(AuditEntity.property("cars").hasNotChanged())
|
|
||||||
.getResultList();
|
|
||||||
assertEquals(0, list.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testHasChangedCar1() throws Exception {
|
|
||||||
List list = getAuditReader().createQuery().forRevisionsOfEntity(Car.class, false, false)
|
|
||||||
.add(AuditEntity.id().eq(id_car1))
|
|
||||||
.add(AuditEntity.property("owners").hasChanged())
|
|
||||||
.getResultList();
|
|
||||||
assertEquals(1, list.size());
|
|
||||||
assertEquals(TestTools.makeList(1), extractRevisionNumbers(list));
|
|
||||||
|
|
||||||
list = getAuditReader().createQuery().forRevisionsOfEntity(Car.class, false, false)
|
|
||||||
.add(AuditEntity.id().eq(id_car1))
|
|
||||||
.add(AuditEntity.property("owners").hasNotChanged())
|
|
||||||
.getResultList();
|
|
||||||
assertEquals(0, list.size());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
package org.hibernate.envers.test.integration.entityNames.singleAssociatedAudited;
|
package org.hibernate.envers.test.integration.entityNames.singleAssociatedAudited;
|
||||||
|
|
||||||
|
|
||||||
import org.hibernate.MappingException;
|
import org.hibernate.MappingException;
|
||||||
import org.hibernate.envers.query.AuditEntity;
|
|
||||||
import org.hibernate.envers.test.AbstractOneSessionTest;
|
import org.hibernate.envers.test.AbstractOneSessionTest;
|
||||||
import org.hibernate.envers.test.Priority;
|
import org.hibernate.envers.test.Priority;
|
||||||
import org.hibernate.envers.test.tools.TestTools;
|
|
||||||
import org.hibernate.testing.TestForIssue;
|
import org.hibernate.testing.TestForIssue;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -12,9 +11,6 @@ import org.junit.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.List;
|
|
||||||
|
|
||||||
import static junit.framework.Assert.assertEquals;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
|
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
|
||||||
|
@ -67,14 +63,4 @@ public class SingleDomainObjectToMultipleTablesTest extends AbstractOneSessionTe
|
||||||
Assert.assertEquals(1, carVer1.getNumber());
|
Assert.assertEquals(1, carVer1.getNumber());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testHasChangedCar1() throws Exception {
|
|
||||||
List list = getAuditReader().createQuery().forRevisionsOfEntity(Car.class, false, false)
|
|
||||||
.add(AuditEntity.id().eq(carId))
|
|
||||||
.add(AuditEntity.property("owner").hasChanged())
|
|
||||||
.add(AuditEntity.property("driver").hasChanged())
|
|
||||||
.getResultList();
|
|
||||||
assertEquals(1, list.size());
|
|
||||||
assertEquals(TestTools.makeList(1), extractRevisionNumbers(list));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,17 +25,12 @@
|
||||||
package org.hibernate.envers.test.integration.inheritance.joined;
|
package org.hibernate.envers.test.integration.inheritance.joined;
|
||||||
|
|
||||||
import org.hibernate.ejb.Ejb3Configuration;
|
import org.hibernate.ejb.Ejb3Configuration;
|
||||||
import org.hibernate.envers.query.AuditEntity;
|
|
||||||
import org.hibernate.envers.test.AbstractEntityTest;
|
import org.hibernate.envers.test.AbstractEntityTest;
|
||||||
import org.hibernate.envers.test.Priority;
|
import org.hibernate.envers.test.Priority;
|
||||||
import org.hibernate.envers.test.tools.TestTools;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static junit.framework.Assert.assertEquals;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Adam Warski (adam at warski dot org)
|
* @author Adam Warski (adam at warski dot org)
|
||||||
|
@ -97,48 +92,4 @@ public class ChildAuditing extends AbstractEntityTest {
|
||||||
.equals(childVer1);
|
.equals(childVer1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testChildHasChanged() throws Exception {
|
|
||||||
List list = getAuditReader().createQuery().forRevisionsOfEntity(ChildEntity.class, false, false)
|
|
||||||
.add(AuditEntity.id().eq(id1))
|
|
||||||
.add(AuditEntity.property("data").hasChanged())
|
|
||||||
.getResultList();
|
|
||||||
assertEquals(2, list.size());
|
|
||||||
assertEquals(TestTools.makeList(1, 2), extractRevisionNumbers(list));
|
|
||||||
|
|
||||||
list = getAuditReader().createQuery().forRevisionsOfEntity(ChildEntity.class, false, false)
|
|
||||||
.add(AuditEntity.id().eq(id1))
|
|
||||||
.add(AuditEntity.property("number").hasChanged())
|
|
||||||
.getResultList();
|
|
||||||
assertEquals(2, list.size());
|
|
||||||
assertEquals(TestTools.makeList(1, 2), extractRevisionNumbers(list));
|
|
||||||
|
|
||||||
list = getAuditReader().createQuery().forRevisionsOfEntity(ChildEntity.class, false, false)
|
|
||||||
.add(AuditEntity.id().eq(id1))
|
|
||||||
.add(AuditEntity.property("data").hasNotChanged())
|
|
||||||
.getResultList();
|
|
||||||
assertEquals(0, list.size());
|
|
||||||
|
|
||||||
list = getAuditReader().createQuery().forRevisionsOfEntity(ChildEntity.class, false, false)
|
|
||||||
.add(AuditEntity.id().eq(id1))
|
|
||||||
.add(AuditEntity.property("number").hasNotChanged())
|
|
||||||
.getResultList();
|
|
||||||
assertEquals(0, list.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testParentHasChanged() throws Exception {
|
|
||||||
List list = getAuditReader().createQuery().forRevisionsOfEntity(ParentEntity.class, false, false)
|
|
||||||
.add(AuditEntity.id().eq(id1))
|
|
||||||
.add(AuditEntity.property("data").hasChanged())
|
|
||||||
.getResultList();
|
|
||||||
assertEquals(2, list.size());
|
|
||||||
assertEquals(TestTools.makeList(1, 2), extractRevisionNumbers(list));
|
|
||||||
|
|
||||||
list = getAuditReader().createQuery().forRevisionsOfEntity(ParentEntity.class, false, false)
|
|
||||||
.add(AuditEntity.id().eq(id1))
|
|
||||||
.add(AuditEntity.property("data").hasNotChanged())
|
|
||||||
.getResultList();
|
|
||||||
assertEquals(0, list.size());
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -25,7 +25,6 @@
|
||||||
package org.hibernate.envers.test.integration.inheritance.joined.childrelation;
|
package org.hibernate.envers.test.integration.inheritance.joined.childrelation;
|
||||||
|
|
||||||
import org.hibernate.ejb.Ejb3Configuration;
|
import org.hibernate.ejb.Ejb3Configuration;
|
||||||
import org.hibernate.envers.query.AuditEntity;
|
|
||||||
import org.hibernate.envers.test.AbstractEntityTest;
|
import org.hibernate.envers.test.AbstractEntityTest;
|
||||||
import org.hibernate.envers.test.Priority;
|
import org.hibernate.envers.test.Priority;
|
||||||
import org.hibernate.envers.test.tools.TestTools;
|
import org.hibernate.envers.test.tools.TestTools;
|
||||||
|
@ -33,9 +32,6 @@ import org.junit.Test;
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static junit.framework.Assert.assertEquals;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Adam Warski (adam at warski dot org)
|
* @author Adam Warski (adam at warski dot org)
|
||||||
|
@ -126,28 +122,4 @@ public class ChildReferencing extends AbstractEntityTest {
|
||||||
new ReferencedEntity(re_id2));
|
new ReferencedEntity(re_id2));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testReferencedEntityHasChanged() throws Exception {
|
|
||||||
List list = getAuditReader().createQuery().forRevisionsOfEntity(ReferencedEntity.class, false, false)
|
|
||||||
.add(AuditEntity.id().eq(re_id1))
|
|
||||||
.add(AuditEntity.property("referencing").hasChanged())
|
|
||||||
.getResultList();
|
|
||||||
assertEquals(2, list.size());
|
|
||||||
assertEquals(TestTools.makeList(2, 3), extractRevisionNumbers(list));
|
|
||||||
|
|
||||||
list = getAuditReader().createQuery().forRevisionsOfEntity(ReferencedEntity.class, false, false)
|
|
||||||
.add(AuditEntity.id().eq(re_id1))
|
|
||||||
.add(AuditEntity.property("referencing").hasNotChanged())
|
|
||||||
.getResultList();
|
|
||||||
assertEquals(1, list.size()); // initially referencing collection is null
|
|
||||||
assertEquals(TestTools.makeList(1), extractRevisionNumbers(list));
|
|
||||||
|
|
||||||
list = getAuditReader().createQuery().forRevisionsOfEntity(ReferencedEntity.class, false, false)
|
|
||||||
.add(AuditEntity.id().eq(re_id2))
|
|
||||||
.add(AuditEntity.property("referencing").hasChanged())
|
|
||||||
.getResultList();
|
|
||||||
assertEquals(1, list.size());
|
|
||||||
assertEquals(TestTools.makeList(3), extractRevisionNumbers(list));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -24,8 +24,8 @@
|
||||||
|
|
||||||
package org.hibernate.envers.test.integration.inheritance.joined.notownedrelation;
|
package org.hibernate.envers.test.integration.inheritance.joined.notownedrelation;
|
||||||
|
|
||||||
|
|
||||||
import org.hibernate.ejb.Ejb3Configuration;
|
import org.hibernate.ejb.Ejb3Configuration;
|
||||||
import org.hibernate.envers.query.AuditEntity;
|
|
||||||
import org.hibernate.envers.test.AbstractEntityTest;
|
import org.hibernate.envers.test.AbstractEntityTest;
|
||||||
import org.hibernate.envers.test.Priority;
|
import org.hibernate.envers.test.Priority;
|
||||||
import org.hibernate.envers.test.tools.TestTools;
|
import org.hibernate.envers.test.tools.TestTools;
|
||||||
|
@ -33,9 +33,6 @@ import org.junit.Test;
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static junit.framework.Assert.assertEquals;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Adam Warski (adam at warski dot org)
|
* @author Adam Warski (adam at warski dot org)
|
||||||
|
@ -117,27 +114,4 @@ public class NotOwnedBidirectional extends AbstractEntityTest {
|
||||||
TestTools.makeSet(new Address(a1_id, "a1"), new Address(a2_id, "a2")));
|
TestTools.makeSet(new Address(a1_id, "a1"), new Address(a2_id, "a2")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testReferencedEntityHasChanged() throws Exception {
|
|
||||||
List list = getAuditReader().createQuery().forRevisionsOfEntity(PersonalContact.class, false, false)
|
|
||||||
.add(AuditEntity.id().eq(pc_id))
|
|
||||||
.add(AuditEntity.property("addresses").hasChanged())
|
|
||||||
.getResultList();
|
|
||||||
assertEquals(2, list.size());
|
|
||||||
assertEquals(TestTools.makeList(1, 2), extractRevisionNumbers(list));
|
|
||||||
|
|
||||||
list = getAuditReader().createQuery().forRevisionsOfEntity(Address.class, false, false)
|
|
||||||
.add(AuditEntity.id().eq(a1_id))
|
|
||||||
.add(AuditEntity.property("contact").hasChanged())
|
|
||||||
.getResultList();
|
|
||||||
assertEquals(1, list.size());
|
|
||||||
assertEquals(TestTools.makeList(1), extractRevisionNumbers(list));
|
|
||||||
|
|
||||||
list = getAuditReader().createQuery().forRevisionsOfEntity(Address.class, false, false)
|
|
||||||
.add(AuditEntity.id().eq(a2_id))
|
|
||||||
.add(AuditEntity.property("contact").hasChanged())
|
|
||||||
.getResultList();
|
|
||||||
assertEquals(1, list.size());
|
|
||||||
assertEquals(TestTools.makeList(2), extractRevisionNumbers(list));
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -0,0 +1,107 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Middleware LLC.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.hibernate.envers.test.integration.modifiedflags;
|
||||||
|
|
||||||
|
import org.hibernate.envers.configuration.GlobalConfiguration;
|
||||||
|
import org.hibernate.envers.query.AuditEntity;
|
||||||
|
import org.hibernate.envers.query.AuditQuery;
|
||||||
|
import org.hibernate.envers.test.AbstractEntityTest;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base test for modified flags feature
|
||||||
|
*
|
||||||
|
* @author Michal Skowronek (mskowr at o2 dot pl)
|
||||||
|
*/
|
||||||
|
public abstract class AbstractModifiedFlagsEntityTest extends AbstractEntityTest {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addConfigurationProperties(Properties configuration) {
|
||||||
|
super.addConfigurationProperties(configuration);
|
||||||
|
if (forceModifiedFlags()) {
|
||||||
|
configuration.setProperty(
|
||||||
|
GlobalConfiguration.OVERRIDE_USING_MODIFIED_FLAG_PROPERTY,
|
||||||
|
"true");
|
||||||
|
configuration
|
||||||
|
.setProperty(
|
||||||
|
GlobalConfiguration.USING_MODIFIED_FLAG_PROPERTY,
|
||||||
|
"true");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean forceModifiedFlags() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected List queryForPropertyHasChanged(Class<?> clazz, Object id,
|
||||||
|
String... propertyNames) {
|
||||||
|
AuditQuery query = createForRevisionsQuery(clazz, id, false);
|
||||||
|
addHasChangedProperties(query, propertyNames);
|
||||||
|
return query.getResultList();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected List queryForPropertyHasChangedWithDeleted(Class<?> clazz, Object id,
|
||||||
|
String... propertyNames) {
|
||||||
|
AuditQuery query = createForRevisionsQuery(clazz, id, true);
|
||||||
|
addHasChangedProperties(query, propertyNames);
|
||||||
|
return query.getResultList();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected List queryForPropertyHasNotChanged(Class<?> clazz, Object id,
|
||||||
|
String... propertyNames) {
|
||||||
|
AuditQuery query = createForRevisionsQuery(clazz, id, false);
|
||||||
|
addHasNotChangedProperties(query, propertyNames);
|
||||||
|
return query.getResultList();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected List queryForPropertyHasNotChangedWithDeleted(Class<?> clazz, Object id,
|
||||||
|
String... propertyNames) {
|
||||||
|
AuditQuery query = createForRevisionsQuery(clazz, id, true);
|
||||||
|
addHasNotChangedProperties(query, propertyNames);
|
||||||
|
return query.getResultList();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addHasChangedProperties(AuditQuery query,
|
||||||
|
String[] propertyNames) {
|
||||||
|
for (String propertyName : propertyNames) {
|
||||||
|
query.add(AuditEntity.property(propertyName).hasChanged());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addHasNotChangedProperties(AuditQuery query,
|
||||||
|
String[] propertyNames) {
|
||||||
|
for (String propertyName : propertyNames) {
|
||||||
|
query.add(AuditEntity.property(propertyName).hasNotChanged());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private AuditQuery createForRevisionsQuery(Class<?> clazz, Object id, boolean withDeleted) {
|
||||||
|
return getAuditReader().createQuery()
|
||||||
|
.forRevisionsOfEntity(clazz, false, withDeleted)
|
||||||
|
.add(AuditEntity.id().eq(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,56 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Middleware LLC.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.hibernate.envers.test.integration.modifiedflags;
|
||||||
|
|
||||||
|
import org.hibernate.cfg.Configuration;
|
||||||
|
import org.hibernate.envers.configuration.GlobalConfiguration;
|
||||||
|
import org.hibernate.envers.test.AbstractOneSessionTest;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base test for modified flags feature
|
||||||
|
*
|
||||||
|
* @author Michal Skowronek (mskowr at o2 dot pl)
|
||||||
|
*/
|
||||||
|
public abstract class AbstractModifiedFlagsOneSessionTest extends
|
||||||
|
AbstractOneSessionTest {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void addProperties(Configuration configuration) {
|
||||||
|
super.addProperties(configuration);
|
||||||
|
if (forceModifiedFlags()) {
|
||||||
|
configuration.setProperty(
|
||||||
|
GlobalConfiguration.OVERRIDE_USING_MODIFIED_FLAG_PROPERTY,
|
||||||
|
"true");
|
||||||
|
configuration
|
||||||
|
.setProperty(
|
||||||
|
GlobalConfiguration.USING_MODIFIED_FLAG_PROPERTY,
|
||||||
|
"true");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean forceModifiedFlags() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,85 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Middleware LLC.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.hibernate.envers.test.integration.modifiedflags;
|
||||||
|
|
||||||
|
import org.hibernate.ejb.Ejb3Configuration;
|
||||||
|
import org.hibernate.envers.query.AuditEntity;
|
||||||
|
import org.hibernate.envers.test.Priority;
|
||||||
|
import org.hibernate.envers.test.integration.auditReader.AuditedTestEntity;
|
||||||
|
import org.hibernate.envers.test.integration.auditReader.NotAuditedTestEntity;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static junit.framework.Assert.assertEquals;
|
||||||
|
import static junit.framework.Assert.assertTrue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A test which checks the correct behavior of AuditReader.isEntityClassAudited(Class entityClass).
|
||||||
|
*
|
||||||
|
* @author Hernan Chanfreau
|
||||||
|
* @author Michal Skowronek (mskowr at o2 dot pl)
|
||||||
|
*/
|
||||||
|
public class HasChangedAPITest extends AbstractModifiedFlagsEntityTest {
|
||||||
|
public void configure(Ejb3Configuration cfg) {
|
||||||
|
cfg.addAnnotatedClass(AuditedTestEntity.class);
|
||||||
|
cfg.addAnnotatedClass(NotAuditedTestEntity.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Priority(10)
|
||||||
|
public void initData() {
|
||||||
|
EntityManager em = getEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
|
AuditedTestEntity ent1 = new AuditedTestEntity(1, "str1");
|
||||||
|
NotAuditedTestEntity ent2 = new NotAuditedTestEntity(1, "str1");
|
||||||
|
|
||||||
|
em.persist(ent1);
|
||||||
|
em.persist(ent2);
|
||||||
|
em.getTransaction().commit();
|
||||||
|
|
||||||
|
em.getTransaction().begin();
|
||||||
|
|
||||||
|
ent1 = em.find(AuditedTestEntity.class, 1);
|
||||||
|
ent2 = em.find(NotAuditedTestEntity.class, 1);
|
||||||
|
ent1.setStr1("str2");
|
||||||
|
ent2.setStr1("str2");
|
||||||
|
em.getTransaction().commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHasChangedHasNotChangedCriteria() throws Exception {
|
||||||
|
List list = getAuditReader().createQuery().forRevisionsOfEntity(AuditedTestEntity.class, true, true).
|
||||||
|
add(AuditEntity.property("str1").hasChanged()).getResultList();
|
||||||
|
assertEquals(2, list.size());
|
||||||
|
assertEquals("str1", ((AuditedTestEntity) list.get(0)).getStr1());
|
||||||
|
assertEquals("str2", ((AuditedTestEntity) list.get(1)).getStr1());
|
||||||
|
|
||||||
|
list = getAuditReader().createQuery().forRevisionsOfEntity(AuditedTestEntity.class, true, true).
|
||||||
|
add(AuditEntity.property("str1").hasNotChanged()).getResultList();
|
||||||
|
assertTrue(list.isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,134 @@
|
||||||
|
package org.hibernate.envers.test.integration.modifiedflags;
|
||||||
|
|
||||||
|
import org.hibernate.MappingException;
|
||||||
|
import org.hibernate.envers.query.AuditEntity;
|
||||||
|
import org.hibernate.envers.test.Priority;
|
||||||
|
import org.hibernate.envers.test.integration.entityNames.manyToManyAudited.Car;
|
||||||
|
import org.hibernate.envers.test.integration.entityNames.manyToManyAudited
|
||||||
|
.Person;
|
||||||
|
import org.hibernate.envers.test.tools.TestTools;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static junit.framework.Assert.assertEquals;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Hernán Chanfreau
|
||||||
|
* @author Michal Skowronek (mskowr at o2 dot pl)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class HasChangedAuditedManyToManyTest extends AbstractModifiedFlagsOneSessionTest{
|
||||||
|
|
||||||
|
private long id_car1;
|
||||||
|
private long id_car2;
|
||||||
|
|
||||||
|
private long id_pers1;
|
||||||
|
private long id_pers2;
|
||||||
|
|
||||||
|
private Person person1;
|
||||||
|
private Car car1;
|
||||||
|
|
||||||
|
private Person person1_1;
|
||||||
|
private Car car1_2;
|
||||||
|
|
||||||
|
protected void initMappings() throws MappingException, URISyntaxException {
|
||||||
|
URL url = Thread.currentThread().getContextClassLoader().getResource("mappings/entityNames/manyToManyAudited/mappings.hbm.xml");
|
||||||
|
config.addFile(new File(url.toURI()));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Priority(10)
|
||||||
|
public void initData() {
|
||||||
|
|
||||||
|
initializeSession();
|
||||||
|
|
||||||
|
Person pers1 = new Person("Hernan", 28);
|
||||||
|
Person pers2 = new Person("Leandro", 29);
|
||||||
|
Person pers3 = new Person("Barba", 32);
|
||||||
|
Person pers4 = new Person("Camomo", 15);
|
||||||
|
|
||||||
|
//REV 1
|
||||||
|
getSession().getTransaction().begin();
|
||||||
|
List<Person > owners = new ArrayList<Person>();
|
||||||
|
owners.add(pers1);
|
||||||
|
owners.add(pers2);
|
||||||
|
owners.add(pers3);
|
||||||
|
Car car1 = new Car(5, owners);
|
||||||
|
|
||||||
|
getSession().persist(car1);
|
||||||
|
getSession().getTransaction().commit();
|
||||||
|
id_pers1 = pers1.getId();
|
||||||
|
id_car1 = car1.getId();
|
||||||
|
id_pers2 = pers2.getId();
|
||||||
|
|
||||||
|
owners = new ArrayList<Person>();
|
||||||
|
owners.add(pers2);
|
||||||
|
owners.add(pers3);
|
||||||
|
owners.add(pers4);
|
||||||
|
Car car2 = new Car(27, owners);
|
||||||
|
//REV 2
|
||||||
|
getSession().getTransaction().begin();
|
||||||
|
Person person1 = (Person)getSession().get("Personaje", id_pers1);
|
||||||
|
person1.setName("Hernan David");
|
||||||
|
person1.setAge(40);
|
||||||
|
getSession().persist(car1);
|
||||||
|
getSession().persist(car2);
|
||||||
|
getSession().getTransaction().commit();
|
||||||
|
id_car2 = car2.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHasChangedPerson1() throws Exception {
|
||||||
|
List list = getAuditReader().createQuery().forRevisionsOfEntity(Person.class, "Personaje", false, false)
|
||||||
|
.add(AuditEntity.id().eq(id_pers1))
|
||||||
|
.add(AuditEntity.property("cars").hasChanged())
|
||||||
|
.getResultList();
|
||||||
|
assertEquals(1, list.size());
|
||||||
|
assertEquals(TestTools.makeList(1), extractRevisionNumbers(list));
|
||||||
|
|
||||||
|
list = getAuditReader().createQuery().forRevisionsOfEntity(Person.class, "Personaje", false, false)
|
||||||
|
.add(AuditEntity.id().eq(id_pers1))
|
||||||
|
.add(AuditEntity.property("cars").hasNotChanged())
|
||||||
|
.getResultList();
|
||||||
|
assertEquals(1, list.size());
|
||||||
|
assertEquals(TestTools.makeList(2), extractRevisionNumbers(list));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHasChangedPerson2() throws Exception {
|
||||||
|
List list = getAuditReader().createQuery().forRevisionsOfEntity(Person.class, "Personaje", false, false)
|
||||||
|
.add(AuditEntity.id().eq(id_pers2))
|
||||||
|
.add(AuditEntity.property("cars").hasChanged())
|
||||||
|
.getResultList();
|
||||||
|
assertEquals(2, list.size());
|
||||||
|
assertEquals(TestTools.makeList(1, 2), extractRevisionNumbers(list));
|
||||||
|
|
||||||
|
list = getAuditReader().createQuery().forRevisionsOfEntity(Person.class, "Personaje", false, false)
|
||||||
|
.add(AuditEntity.id().eq(id_pers2))
|
||||||
|
.add(AuditEntity.property("cars").hasNotChanged())
|
||||||
|
.getResultList();
|
||||||
|
assertEquals(0, list.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHasChangedCar1() throws Exception {
|
||||||
|
List list = getAuditReader().createQuery().forRevisionsOfEntity(Car.class, false, false)
|
||||||
|
.add(AuditEntity.id().eq(id_car1))
|
||||||
|
.add(AuditEntity.property("owners").hasChanged())
|
||||||
|
.getResultList();
|
||||||
|
assertEquals(1, list.size());
|
||||||
|
assertEquals(TestTools.makeList(1), extractRevisionNumbers(list));
|
||||||
|
|
||||||
|
list = getAuditReader().createQuery().forRevisionsOfEntity(Car.class, false, false)
|
||||||
|
.add(AuditEntity.id().eq(id_car1))
|
||||||
|
.add(AuditEntity.property("owners").hasNotChanged())
|
||||||
|
.getResultList();
|
||||||
|
assertEquals(0, list.size());
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,131 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Middleware LLC.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.hibernate.envers.test.integration.modifiedflags;
|
||||||
|
|
||||||
|
import org.hibernate.ejb.Ejb3Configuration;
|
||||||
|
import org.hibernate.envers.test.Priority;
|
||||||
|
import org.hibernate.envers.test.integration.onetoone.bidirectional
|
||||||
|
.BiRefEdEntity;
|
||||||
|
import org.hibernate.envers.test.integration.onetoone.bidirectional
|
||||||
|
.BiRefIngEntity;
|
||||||
|
import org.hibernate.envers.test.tools.TestTools;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static junit.framework.Assert.assertEquals;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Adam Warski (adam at warski dot org)
|
||||||
|
* @author Michal Skowronek (mskowr at o2 dot pl)
|
||||||
|
*/
|
||||||
|
public class HasChangedBidirectional2 extends AbstractModifiedFlagsEntityTest {
|
||||||
|
private Integer ed1_id;
|
||||||
|
private Integer ed2_id;
|
||||||
|
|
||||||
|
private Integer ing1_id;
|
||||||
|
private Integer ing2_id;
|
||||||
|
|
||||||
|
public void configure(Ejb3Configuration cfg) {
|
||||||
|
cfg.addAnnotatedClass(BiRefEdEntity.class);
|
||||||
|
cfg.addAnnotatedClass(BiRefIngEntity.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Priority(10)
|
||||||
|
public void initData() {
|
||||||
|
BiRefEdEntity ed1 = new BiRefEdEntity(1, "data_ed_1");
|
||||||
|
BiRefEdEntity ed2 = new BiRefEdEntity(2, "data_ed_2");
|
||||||
|
|
||||||
|
BiRefIngEntity ing1 = new BiRefIngEntity(3, "data_ing_1");
|
||||||
|
BiRefIngEntity ing2 = new BiRefIngEntity(4, "data_ing_2");
|
||||||
|
|
||||||
|
// Revision 1
|
||||||
|
EntityManager em = getEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
|
|
||||||
|
em.persist(ed1);
|
||||||
|
em.persist(ed2);
|
||||||
|
|
||||||
|
em.getTransaction().commit();
|
||||||
|
|
||||||
|
// Revision 2
|
||||||
|
em.getTransaction().begin();
|
||||||
|
|
||||||
|
ed1 = em.find(BiRefEdEntity.class, ed1.getId());
|
||||||
|
|
||||||
|
ing1.setReference(ed1);
|
||||||
|
|
||||||
|
em.persist(ing1);
|
||||||
|
em.persist(ing2);
|
||||||
|
|
||||||
|
em.getTransaction().commit();
|
||||||
|
|
||||||
|
// Revision 3
|
||||||
|
em.getTransaction().begin();
|
||||||
|
|
||||||
|
ed1 = em.find(BiRefEdEntity.class, ed1.getId());
|
||||||
|
ing1 = em.find(BiRefIngEntity.class, ing1.getId());
|
||||||
|
ing2 = em.find(BiRefIngEntity.class, ing2.getId());
|
||||||
|
|
||||||
|
ing1.setReference(null);
|
||||||
|
ing2.setReference(ed1);
|
||||||
|
|
||||||
|
em.getTransaction().commit();
|
||||||
|
|
||||||
|
// Revision 4
|
||||||
|
em.getTransaction().begin();
|
||||||
|
|
||||||
|
ed2 = em.find(BiRefEdEntity.class, ed2.getId());
|
||||||
|
ing1 = em.find(BiRefIngEntity.class, ing1.getId());
|
||||||
|
ing2 = em.find(BiRefIngEntity.class, ing2.getId());
|
||||||
|
|
||||||
|
ing1.setReference(ed2);
|
||||||
|
ing2.setReference(null);
|
||||||
|
|
||||||
|
em.getTransaction().commit();
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
ed1_id = ed1.getId();
|
||||||
|
ed2_id = ed2.getId();
|
||||||
|
|
||||||
|
ing1_id = ing1.getId();
|
||||||
|
ing2_id = ing2.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHasChanged() throws Exception {
|
||||||
|
List list = queryForPropertyHasChanged(BiRefEdEntity.class, ed1_id,
|
||||||
|
"referencing");
|
||||||
|
assertEquals(3, list.size());
|
||||||
|
assertEquals(TestTools.makeList(2, 3, 4), extractRevisionNumbers(list));
|
||||||
|
|
||||||
|
list = queryForPropertyHasChanged(BiRefEdEntity.class, ed2_id,
|
||||||
|
"referencing");
|
||||||
|
assertEquals(1, list.size());
|
||||||
|
assertEquals(TestTools.makeList(4), extractRevisionNumbers(list));
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,98 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Middleware LLC.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.hibernate.envers.test.integration.modifiedflags;
|
||||||
|
|
||||||
|
import org.hibernate.ejb.Ejb3Configuration;
|
||||||
|
import org.hibernate.envers.test.Priority;
|
||||||
|
import org.hibernate.envers.test.integration.inheritance.joined.ChildEntity;
|
||||||
|
import org.hibernate.envers.test.integration.inheritance.joined.ParentEntity;
|
||||||
|
import org.hibernate.envers.test.tools.TestTools;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static junit.framework.Assert.assertEquals;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Adam Warski (adam at warski dot org)
|
||||||
|
* @author Michal Skowronek (mskowr at o2 dot pl)
|
||||||
|
*/
|
||||||
|
public class HasChangedChildAuditing extends AbstractModifiedFlagsEntityTest {
|
||||||
|
private Integer id1;
|
||||||
|
|
||||||
|
public void configure(Ejb3Configuration cfg) {
|
||||||
|
cfg.addAnnotatedClass(ChildEntity.class);
|
||||||
|
cfg.addAnnotatedClass(ParentEntity.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Priority(10)
|
||||||
|
public void initData() {
|
||||||
|
EntityManager em = getEntityManager();
|
||||||
|
|
||||||
|
id1 = 1;
|
||||||
|
|
||||||
|
// Rev 1
|
||||||
|
em.getTransaction().begin();
|
||||||
|
ChildEntity ce = new ChildEntity(id1, "x", 1l);
|
||||||
|
em.persist(ce);
|
||||||
|
em.getTransaction().commit();
|
||||||
|
|
||||||
|
// Rev 2
|
||||||
|
em.getTransaction().begin();
|
||||||
|
ce = em.find(ChildEntity.class, id1);
|
||||||
|
ce.setData("y");
|
||||||
|
ce.setNumber(2l);
|
||||||
|
em.getTransaction().commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testChildHasChanged() throws Exception {
|
||||||
|
List list = queryForPropertyHasChanged(ChildEntity.class, id1, "data");
|
||||||
|
assertEquals(2, list.size());
|
||||||
|
assertEquals(TestTools.makeList(1, 2), extractRevisionNumbers(list));
|
||||||
|
|
||||||
|
list = queryForPropertyHasChanged(ChildEntity.class, id1, "number");
|
||||||
|
assertEquals(2, list.size());
|
||||||
|
assertEquals(TestTools.makeList(1, 2), extractRevisionNumbers(list));
|
||||||
|
|
||||||
|
list = queryForPropertyHasNotChanged(ChildEntity.class, id1, "data");
|
||||||
|
assertEquals(0, list.size());
|
||||||
|
|
||||||
|
list = queryForPropertyHasNotChanged(ChildEntity.class, id1, "number");
|
||||||
|
assertEquals(0, list.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testParentHasChanged() throws Exception {
|
||||||
|
List list = queryForPropertyHasChanged(ParentEntity.class, id1, "data");
|
||||||
|
assertEquals(2, list.size());
|
||||||
|
assertEquals(TestTools.makeList(1, 2), extractRevisionNumbers(list));
|
||||||
|
|
||||||
|
list = queryForPropertyHasNotChanged(ParentEntity.class, id1, "data");
|
||||||
|
assertEquals(0, list.size());
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,116 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Middleware LLC.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.hibernate.envers.test.integration.modifiedflags;
|
||||||
|
|
||||||
|
import org.hibernate.ejb.Ejb3Configuration;
|
||||||
|
import org.hibernate.envers.test.Priority;
|
||||||
|
import org.hibernate.envers.test.integration.inheritance.joined.childrelation
|
||||||
|
.ChildIngEntity;
|
||||||
|
import org.hibernate.envers.test.integration.inheritance.joined.childrelation
|
||||||
|
.ParentNotIngEntity;
|
||||||
|
import org.hibernate.envers.test.integration.inheritance.joined.childrelation
|
||||||
|
.ReferencedEntity;
|
||||||
|
import org.hibernate.envers.test.tools.TestTools;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static junit.framework.Assert.assertEquals;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Adam Warski (adam at warski dot org)
|
||||||
|
* @author Michal Skowronek (mskowr at o2 dot pl)
|
||||||
|
*/
|
||||||
|
public class HasChangedChildReferencing extends AbstractModifiedFlagsEntityTest {
|
||||||
|
private Integer re_id1;
|
||||||
|
private Integer re_id2;
|
||||||
|
private Integer c_id;
|
||||||
|
|
||||||
|
public void configure(Ejb3Configuration cfg) {
|
||||||
|
cfg.addAnnotatedClass(ChildIngEntity.class);
|
||||||
|
cfg.addAnnotatedClass(ParentNotIngEntity.class);
|
||||||
|
cfg.addAnnotatedClass(ReferencedEntity.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Priority(10)
|
||||||
|
public void initData() {
|
||||||
|
EntityManager em = getEntityManager();
|
||||||
|
|
||||||
|
re_id1 = 1;
|
||||||
|
re_id2 = 10;
|
||||||
|
c_id = 100;
|
||||||
|
|
||||||
|
// Rev 1
|
||||||
|
em.getTransaction().begin();
|
||||||
|
|
||||||
|
ReferencedEntity re1 = new ReferencedEntity(re_id1);
|
||||||
|
em.persist(re1);
|
||||||
|
|
||||||
|
ReferencedEntity re2 = new ReferencedEntity(re_id2);
|
||||||
|
em.persist(re2);
|
||||||
|
|
||||||
|
em.getTransaction().commit();
|
||||||
|
|
||||||
|
// Rev 2
|
||||||
|
em.getTransaction().begin();
|
||||||
|
|
||||||
|
re1 = em.find(ReferencedEntity.class, re_id1);
|
||||||
|
|
||||||
|
ChildIngEntity cie = new ChildIngEntity(c_id, "y", 1l);
|
||||||
|
cie.setReferenced(re1);
|
||||||
|
em.persist(cie);
|
||||||
|
c_id = cie.getId();
|
||||||
|
|
||||||
|
em.getTransaction().commit();
|
||||||
|
|
||||||
|
// Rev 3
|
||||||
|
em.getTransaction().begin();
|
||||||
|
|
||||||
|
re2 = em.find(ReferencedEntity.class, re_id2);
|
||||||
|
cie = em.find(ChildIngEntity.class, c_id);
|
||||||
|
|
||||||
|
cie.setReferenced(re2);
|
||||||
|
|
||||||
|
em.getTransaction().commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testReferencedEntityHasChanged() throws Exception {
|
||||||
|
List list = queryForPropertyHasChanged(ReferencedEntity.class, re_id1, "referencing");
|
||||||
|
assertEquals(2, list.size());
|
||||||
|
assertEquals(TestTools.makeList(2, 3), extractRevisionNumbers(list));
|
||||||
|
|
||||||
|
list = queryForPropertyHasNotChanged(ReferencedEntity.class, re_id1, "referencing");
|
||||||
|
assertEquals(1, list.size()); // initially referencing collection is null
|
||||||
|
assertEquals(TestTools.makeList(1), extractRevisionNumbers(list));
|
||||||
|
|
||||||
|
list = queryForPropertyHasChanged(ReferencedEntity.class, re_id2, "referencing");
|
||||||
|
assertEquals(1, list.size());
|
||||||
|
assertEquals(TestTools.makeList(3), extractRevisionNumbers(list));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,125 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Middleware LLC.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.hibernate.envers.test.integration.modifiedflags;
|
||||||
|
|
||||||
|
import org.hibernate.ejb.Ejb3Configuration;
|
||||||
|
import org.hibernate.envers.test.Priority;
|
||||||
|
import org.hibernate.envers.test.entities.components.Component1;
|
||||||
|
import org.hibernate.envers.test.entities.components.Component2;
|
||||||
|
import org.hibernate.envers.test.entities.components.ComponentTestEntity;
|
||||||
|
import org.hibernate.envers.test.integration.collection.mapkey
|
||||||
|
.ComponentMapKeyEntity;
|
||||||
|
import org.hibernate.envers.test.tools.TestTools;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static junit.framework.Assert.assertEquals;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Adam Warski (adam at warski dot org)
|
||||||
|
* @author Michal Skowronek (mskowr at o2 dot pl)
|
||||||
|
*/
|
||||||
|
public class HasChangedComponentMapKey extends AbstractModifiedFlagsEntityTest {
|
||||||
|
private Integer cmke_id;
|
||||||
|
|
||||||
|
private Integer cte1_id;
|
||||||
|
private Integer cte2_id;
|
||||||
|
|
||||||
|
public void configure(Ejb3Configuration cfg) {
|
||||||
|
cfg.addAnnotatedClass(ComponentMapKeyEntity.class);
|
||||||
|
cfg.addAnnotatedClass(ComponentTestEntity.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Priority(10)
|
||||||
|
public void initData() {
|
||||||
|
EntityManager em = getEntityManager();
|
||||||
|
|
||||||
|
ComponentMapKeyEntity imke = new ComponentMapKeyEntity();
|
||||||
|
|
||||||
|
// Revision 1 (intialy 1 mapping)
|
||||||
|
em.getTransaction().begin();
|
||||||
|
|
||||||
|
ComponentTestEntity cte1 = new ComponentTestEntity(new Component1("x1", "y2"), new Component2("a1", "b2"));
|
||||||
|
ComponentTestEntity cte2 = new ComponentTestEntity(new Component1("x1", "y2"), new Component2("a1", "b2"));
|
||||||
|
|
||||||
|
em.persist(cte1);
|
||||||
|
em.persist(cte2);
|
||||||
|
|
||||||
|
imke.getIdmap().put(cte1.getComp1(), cte1);
|
||||||
|
|
||||||
|
em.persist(imke);
|
||||||
|
|
||||||
|
em.getTransaction().commit();
|
||||||
|
|
||||||
|
// Revision 2 (sse1: adding 1 mapping)
|
||||||
|
em.getTransaction().begin();
|
||||||
|
|
||||||
|
cte2 = em.find(ComponentTestEntity.class, cte2.getId());
|
||||||
|
imke = em.find(ComponentMapKeyEntity.class, imke.getId());
|
||||||
|
|
||||||
|
imke.getIdmap().put(cte2.getComp1(), cte2);
|
||||||
|
|
||||||
|
em.getTransaction().commit();
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
cmke_id = imke.getId();
|
||||||
|
|
||||||
|
cte1_id = cte1.getId();
|
||||||
|
cte2_id = cte2.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHasChangedMapEntity() throws Exception {
|
||||||
|
List list = queryForPropertyHasChanged(ComponentMapKeyEntity.class, cmke_id, "idmap");
|
||||||
|
assertEquals(2, list.size());
|
||||||
|
assertEquals(TestTools.makeList(1, 2), extractRevisionNumbers(list));
|
||||||
|
|
||||||
|
list = queryForPropertyHasNotChanged(ComponentMapKeyEntity.class,
|
||||||
|
cmke_id, "idmap");
|
||||||
|
assertEquals(0, list.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHasChangedComponentEntity() throws Exception {
|
||||||
|
List list = queryForPropertyHasChanged(ComponentTestEntity.class,
|
||||||
|
cte1_id, "comp1");
|
||||||
|
assertEquals(1, list.size());
|
||||||
|
assertEquals(TestTools.makeList(1), extractRevisionNumbers(list));
|
||||||
|
|
||||||
|
list = queryForPropertyHasNotChanged(ComponentTestEntity.class, cte1_id,
|
||||||
|
"comp1");
|
||||||
|
assertEquals(0, list.size());
|
||||||
|
|
||||||
|
list = queryForPropertyHasChanged(ComponentTestEntity.class, cte2_id, "comp1");
|
||||||
|
assertEquals(1, list.size());
|
||||||
|
assertEquals(TestTools.makeList(1), extractRevisionNumbers(list));
|
||||||
|
|
||||||
|
list = queryForPropertyHasNotChanged(ComponentTestEntity.class, cte2_id, "comp1");
|
||||||
|
assertEquals(0, list.size());
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,169 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Middleware LLC.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.hibernate.envers.test.integration.modifiedflags;
|
||||||
|
|
||||||
|
import org.hibernate.QueryException;
|
||||||
|
import org.hibernate.ejb.Ejb3Configuration;
|
||||||
|
import org.hibernate.envers.test.Priority;
|
||||||
|
import org.hibernate.envers.test.entities.components.Component1;
|
||||||
|
import org.hibernate.envers.test.entities.components.Component2;
|
||||||
|
import org.hibernate.envers.test.entities.components.ComponentTestEntity;
|
||||||
|
import org.hibernate.envers.test.tools.TestTools;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static junit.framework.Assert.assertEquals;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Adam Warski (adam at warski dot org)
|
||||||
|
* @author Michal Skowronek (mskowr at o2 dot pl)
|
||||||
|
*/
|
||||||
|
public class HasChangedComponents extends AbstractModifiedFlagsEntityTest {
|
||||||
|
private Integer id1;
|
||||||
|
private Integer id2;
|
||||||
|
private Integer id3;
|
||||||
|
private Integer id4;
|
||||||
|
|
||||||
|
public void configure(Ejb3Configuration cfg) {
|
||||||
|
cfg.addAnnotatedClass(ComponentTestEntity.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Priority(10)
|
||||||
|
public void initData() {
|
||||||
|
// Revision 1
|
||||||
|
EntityManager em = getEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
|
|
||||||
|
ComponentTestEntity cte1 = new ComponentTestEntity(new Component1("a", "b"), new Component2("x", "y"));
|
||||||
|
ComponentTestEntity cte2 = new ComponentTestEntity(new Component1("a2", "b2"), new Component2("x2", "y2"));
|
||||||
|
ComponentTestEntity cte3 = new ComponentTestEntity(new Component1("a3", "b3"), new Component2("x3", "y3"));
|
||||||
|
ComponentTestEntity cte4 = new ComponentTestEntity(null, null);
|
||||||
|
|
||||||
|
em.persist(cte1);
|
||||||
|
em.persist(cte2);
|
||||||
|
em.persist(cte3);
|
||||||
|
em.persist(cte4);
|
||||||
|
|
||||||
|
em.getTransaction().commit();
|
||||||
|
|
||||||
|
// Revision 2
|
||||||
|
em = getEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
|
|
||||||
|
cte1 = em.find(ComponentTestEntity.class, cte1.getId());
|
||||||
|
cte2 = em.find(ComponentTestEntity.class, cte2.getId());
|
||||||
|
cte3 = em.find(ComponentTestEntity.class, cte3.getId());
|
||||||
|
cte4 = em.find(ComponentTestEntity.class, cte4.getId());
|
||||||
|
|
||||||
|
cte1.setComp1(new Component1("a'", "b'"));
|
||||||
|
cte2.getComp1().setStr1("a2'");
|
||||||
|
cte3.getComp2().setStr6("y3'");
|
||||||
|
cte4.setComp1(new Component1());
|
||||||
|
cte4.getComp1().setStr1("n");
|
||||||
|
cte4.setComp2(new Component2());
|
||||||
|
cte4.getComp2().setStr5("m");
|
||||||
|
|
||||||
|
em.getTransaction().commit();
|
||||||
|
|
||||||
|
// Revision 3
|
||||||
|
em = getEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
|
|
||||||
|
cte1 = em.find(ComponentTestEntity.class, cte1.getId());
|
||||||
|
cte2 = em.find(ComponentTestEntity.class, cte2.getId());
|
||||||
|
cte3 = em.find(ComponentTestEntity.class, cte3.getId());
|
||||||
|
cte4 = em.find(ComponentTestEntity.class, cte4.getId());
|
||||||
|
|
||||||
|
cte1.setComp2(new Component2("x'", "y'"));
|
||||||
|
cte3.getComp1().setStr2("b3'");
|
||||||
|
cte4.setComp1(null);
|
||||||
|
cte4.setComp2(null);
|
||||||
|
|
||||||
|
em.getTransaction().commit();
|
||||||
|
|
||||||
|
// Revision 4
|
||||||
|
em = getEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
|
|
||||||
|
cte2 = em.find(ComponentTestEntity.class, cte2.getId());
|
||||||
|
|
||||||
|
em.remove(cte2);
|
||||||
|
|
||||||
|
em.getTransaction().commit();
|
||||||
|
|
||||||
|
id1 = cte1.getId();
|
||||||
|
id2 = cte2.getId();
|
||||||
|
id3 = cte3.getId();
|
||||||
|
id4 = cte4.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = QueryException.class)
|
||||||
|
public void testHasChangedNotAudited() throws Exception {
|
||||||
|
queryForPropertyHasChanged(ComponentTestEntity.class, id1, "comp2");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHasChangedId1() throws Exception {
|
||||||
|
List list = queryForPropertyHasChanged(ComponentTestEntity.class, id1, "comp1");
|
||||||
|
assertEquals(2, list.size());
|
||||||
|
assertEquals(TestTools.makeList(1, 2), extractRevisionNumbers(list));
|
||||||
|
|
||||||
|
list = queryForPropertyHasNotChanged(ComponentTestEntity.class, id1, "comp1");
|
||||||
|
assertEquals(0, list.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHasChangedId2() throws Exception {
|
||||||
|
List list = queryForPropertyHasChangedWithDeleted(ComponentTestEntity.class, id2, "comp1");
|
||||||
|
assertEquals(3, list.size());
|
||||||
|
assertEquals(TestTools.makeList(1, 2, 4), extractRevisionNumbers(list));
|
||||||
|
|
||||||
|
list = queryForPropertyHasNotChangedWithDeleted(ComponentTestEntity.class, id2, "comp1");
|
||||||
|
assertEquals(0, list.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHasChangedId3() throws Exception {
|
||||||
|
List list = queryForPropertyHasChangedWithDeleted(ComponentTestEntity.class, id3, "comp1");
|
||||||
|
assertEquals(2, list.size());
|
||||||
|
assertEquals(TestTools.makeList(1, 3), extractRevisionNumbers(list));
|
||||||
|
|
||||||
|
list = queryForPropertyHasNotChangedWithDeleted(ComponentTestEntity.class, id3, "comp1");
|
||||||
|
assertEquals(0, list.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHasChangedId4() throws Exception {
|
||||||
|
List list = queryForPropertyHasChangedWithDeleted(ComponentTestEntity.class, id4, "comp1");
|
||||||
|
assertEquals(2, list.size());
|
||||||
|
assertEquals(TestTools.makeList(2, 3), extractRevisionNumbers(list));
|
||||||
|
|
||||||
|
list = queryForPropertyHasNotChangedWithDeleted(ComponentTestEntity.class, id4, "comp1");
|
||||||
|
assertEquals(1, list.size());
|
||||||
|
assertEquals(TestTools.makeList(1), extractRevisionNumbers(list));
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,97 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Middleware LLC.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.hibernate.envers.test.integration.modifiedflags;
|
||||||
|
|
||||||
|
import org.hibernate.ejb.Ejb3Configuration;
|
||||||
|
import org.hibernate.envers.test.Priority;
|
||||||
|
import org.hibernate.envers.test.entities.customtype.Component;
|
||||||
|
import org.hibernate.envers.test.entities.customtype.CompositeCustomTypeEntity;
|
||||||
|
import org.hibernate.envers.test.tools.TestTools;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static junit.framework.Assert.assertEquals;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Adam Warski (adam at warski dot org)
|
||||||
|
* @author Michal Skowronek (mskowr at o2 dot pl)
|
||||||
|
*/
|
||||||
|
public class HasChangedCompositeCustom extends AbstractModifiedFlagsEntityTest {
|
||||||
|
private Integer ccte_id;
|
||||||
|
|
||||||
|
public void configure(Ejb3Configuration cfg) {
|
||||||
|
cfg.addAnnotatedClass(CompositeCustomTypeEntity.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Priority(10)
|
||||||
|
public void initData() {
|
||||||
|
EntityManager em = getEntityManager();
|
||||||
|
|
||||||
|
CompositeCustomTypeEntity ccte = new CompositeCustomTypeEntity();
|
||||||
|
|
||||||
|
// Revision 1 (persisting 1 entity)
|
||||||
|
em.getTransaction().begin();
|
||||||
|
|
||||||
|
ccte.setComponent(new Component("a", 1));
|
||||||
|
|
||||||
|
em.persist(ccte);
|
||||||
|
|
||||||
|
em.getTransaction().commit();
|
||||||
|
|
||||||
|
// Revision 2 (changing the component)
|
||||||
|
em.getTransaction().begin();
|
||||||
|
|
||||||
|
ccte = em.find(CompositeCustomTypeEntity.class, ccte.getId());
|
||||||
|
|
||||||
|
ccte.getComponent().setProp1("b");
|
||||||
|
|
||||||
|
em.getTransaction().commit();
|
||||||
|
|
||||||
|
// Revision 3 (replacing the component)
|
||||||
|
em.getTransaction().begin();
|
||||||
|
|
||||||
|
ccte = em.find(CompositeCustomTypeEntity.class, ccte.getId());
|
||||||
|
|
||||||
|
ccte.setComponent(new Component("c", 3));
|
||||||
|
|
||||||
|
em.getTransaction().commit();
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
ccte_id = ccte.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHasChanged() throws Exception {
|
||||||
|
List list = queryForPropertyHasChanged(CompositeCustomTypeEntity.class,ccte_id, "component");
|
||||||
|
assertEquals(3, list.size());
|
||||||
|
assertEquals(TestTools.makeList(1, 2, 3), extractRevisionNumbers(list));
|
||||||
|
|
||||||
|
list = queryForPropertyHasNotChanged(CompositeCustomTypeEntity.class,ccte_id, "component");
|
||||||
|
assertEquals(0, list.size());
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,262 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Middleware LLC.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.hibernate.envers.test.integration.modifiedflags;
|
||||||
|
|
||||||
|
import org.hibernate.ejb.Ejb3Configuration;
|
||||||
|
import org.hibernate.envers.test.Priority;
|
||||||
|
import org.hibernate.envers.test.entities.onetomany.detached
|
||||||
|
.DoubleListJoinColumnBidirectionalRefEdEntity1;
|
||||||
|
import org.hibernate.envers.test.entities.onetomany.detached
|
||||||
|
.DoubleListJoinColumnBidirectionalRefEdEntity2;
|
||||||
|
import org.hibernate.envers.test.entities.onetomany.detached
|
||||||
|
.DoubleListJoinColumnBidirectionalRefIngEntity;
|
||||||
|
import org.hibernate.envers.test.tools.TestTools;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static junit.framework.Assert.assertEquals;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test for a double "fake" bidirectional mapping where one side uses @OneToMany+@JoinColumn
|
||||||
|
* (and thus owns the relation), and the other uses a @ManyToOne(insertable=false, updatable=false).
|
||||||
|
* @author Adam Warski (adam at warski dot org)
|
||||||
|
* @author Michal Skowronek (mskowr at o2 dot pl)
|
||||||
|
*/
|
||||||
|
public class HasChangedDoubleJoinColumnBidirectionalList extends AbstractModifiedFlagsEntityTest {
|
||||||
|
private Integer ed1_1_id;
|
||||||
|
private Integer ed2_1_id;
|
||||||
|
private Integer ed1_2_id;
|
||||||
|
private Integer ed2_2_id;
|
||||||
|
|
||||||
|
private Integer ing1_id;
|
||||||
|
private Integer ing2_id;
|
||||||
|
|
||||||
|
public void configure(Ejb3Configuration cfg) {
|
||||||
|
cfg.addAnnotatedClass(DoubleListJoinColumnBidirectionalRefIngEntity.class);
|
||||||
|
cfg.addAnnotatedClass(DoubleListJoinColumnBidirectionalRefEdEntity1.class);
|
||||||
|
cfg.addAnnotatedClass(DoubleListJoinColumnBidirectionalRefEdEntity2.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Priority(10)
|
||||||
|
public void createData() {
|
||||||
|
EntityManager em = getEntityManager();
|
||||||
|
|
||||||
|
DoubleListJoinColumnBidirectionalRefEdEntity1 ed1_1 = new DoubleListJoinColumnBidirectionalRefEdEntity1("ed1_1", null);
|
||||||
|
DoubleListJoinColumnBidirectionalRefEdEntity1 ed1_2 = new DoubleListJoinColumnBidirectionalRefEdEntity1("ed1_2", null);
|
||||||
|
|
||||||
|
DoubleListJoinColumnBidirectionalRefEdEntity2 ed2_1 = new DoubleListJoinColumnBidirectionalRefEdEntity2("ed2_1", null);
|
||||||
|
DoubleListJoinColumnBidirectionalRefEdEntity2 ed2_2 = new DoubleListJoinColumnBidirectionalRefEdEntity2("ed2_2", null);
|
||||||
|
|
||||||
|
DoubleListJoinColumnBidirectionalRefIngEntity ing1 = new DoubleListJoinColumnBidirectionalRefIngEntity("coll1");
|
||||||
|
DoubleListJoinColumnBidirectionalRefIngEntity ing2 = new DoubleListJoinColumnBidirectionalRefIngEntity("coll2");
|
||||||
|
|
||||||
|
// Revision 1 (ing1: ed1_1, ed2_1, ing2: ed1_2, ed2_2)
|
||||||
|
em.getTransaction().begin();
|
||||||
|
|
||||||
|
ing1.getReferences1().add(ed1_1);
|
||||||
|
ing1.getReferences2().add(ed2_1);
|
||||||
|
|
||||||
|
ing2.getReferences1().add(ed1_2);
|
||||||
|
ing2.getReferences2().add(ed2_2);
|
||||||
|
|
||||||
|
em.persist(ed1_1);
|
||||||
|
em.persist(ed1_2);
|
||||||
|
em.persist(ed2_1);
|
||||||
|
em.persist(ed2_2);
|
||||||
|
em.persist(ing1);
|
||||||
|
em.persist(ing2);
|
||||||
|
|
||||||
|
em.getTransaction().commit();
|
||||||
|
|
||||||
|
// Revision 2 (ing1: ed1_1, ed1_2, ed2_1, ed2_2)
|
||||||
|
em.getTransaction().begin();
|
||||||
|
|
||||||
|
ing1 = em.find(DoubleListJoinColumnBidirectionalRefIngEntity.class, ing1.getId());
|
||||||
|
ing2 = em.find(DoubleListJoinColumnBidirectionalRefIngEntity.class, ing2.getId());
|
||||||
|
ed1_1 = em.find(DoubleListJoinColumnBidirectionalRefEdEntity1.class, ed1_1.getId());
|
||||||
|
ed1_2 = em.find(DoubleListJoinColumnBidirectionalRefEdEntity1.class, ed1_2.getId());
|
||||||
|
ed2_1 = em.find(DoubleListJoinColumnBidirectionalRefEdEntity2.class, ed2_1.getId());
|
||||||
|
ed2_2 = em.find(DoubleListJoinColumnBidirectionalRefEdEntity2.class, ed2_2.getId());
|
||||||
|
|
||||||
|
ing2.getReferences1().clear();
|
||||||
|
ing2.getReferences2().clear();
|
||||||
|
|
||||||
|
ing1.getReferences1().add(ed1_2);
|
||||||
|
ing1.getReferences2().add(ed2_2);
|
||||||
|
|
||||||
|
em.getTransaction().commit();
|
||||||
|
em.clear();
|
||||||
|
|
||||||
|
// Revision 3 (ing1: ed1_1, ed1_2, ed2_1, ed2_2)
|
||||||
|
em.getTransaction().begin();
|
||||||
|
|
||||||
|
ing1 = em.find(DoubleListJoinColumnBidirectionalRefIngEntity.class, ing1.getId());
|
||||||
|
ing2 = em.find(DoubleListJoinColumnBidirectionalRefIngEntity.class, ing2.getId());
|
||||||
|
ed1_1 = em.find(DoubleListJoinColumnBidirectionalRefEdEntity1.class, ed1_1.getId());
|
||||||
|
ed1_2 = em.find(DoubleListJoinColumnBidirectionalRefEdEntity1.class, ed1_2.getId());
|
||||||
|
ed2_1 = em.find(DoubleListJoinColumnBidirectionalRefEdEntity2.class, ed2_1.getId());
|
||||||
|
ed2_2 = em.find(DoubleListJoinColumnBidirectionalRefEdEntity2.class, ed2_2.getId());
|
||||||
|
|
||||||
|
ed1_1.setData("ed1_1 bis");
|
||||||
|
ed2_2.setData("ed2_2 bis");
|
||||||
|
|
||||||
|
em.getTransaction().commit();
|
||||||
|
em.clear();
|
||||||
|
|
||||||
|
// Revision 4 (ing1: ed2_2, ing2: ed2_1, ed1_1, ed1_2)
|
||||||
|
em.getTransaction().begin();
|
||||||
|
|
||||||
|
ing1 = em.find(DoubleListJoinColumnBidirectionalRefIngEntity.class, ing1.getId());
|
||||||
|
ing2 = em.find(DoubleListJoinColumnBidirectionalRefIngEntity.class, ing2.getId());
|
||||||
|
ed1_1 = em.find(DoubleListJoinColumnBidirectionalRefEdEntity1.class, ed1_1.getId());
|
||||||
|
ed1_2 = em.find(DoubleListJoinColumnBidirectionalRefEdEntity1.class, ed1_2.getId());
|
||||||
|
ed2_1 = em.find(DoubleListJoinColumnBidirectionalRefEdEntity2.class, ed2_1.getId());
|
||||||
|
ed2_2 = em.find(DoubleListJoinColumnBidirectionalRefEdEntity2.class, ed2_2.getId());
|
||||||
|
|
||||||
|
ing1.getReferences1().clear();
|
||||||
|
ing2.getReferences1().add(ed1_1);
|
||||||
|
ing2.getReferences1().add(ed1_2);
|
||||||
|
|
||||||
|
ing1.getReferences2().remove(ed2_1);
|
||||||
|
ing2.getReferences2().add(ed2_1);
|
||||||
|
|
||||||
|
em.getTransaction().commit();
|
||||||
|
em.clear();
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
ing1_id = ing1.getId();
|
||||||
|
ing2_id = ing2.getId();
|
||||||
|
|
||||||
|
ed1_1_id = ed1_1.getId();
|
||||||
|
ed1_2_id = ed1_2.getId();
|
||||||
|
ed2_1_id = ed2_1.getId();
|
||||||
|
ed2_2_id = ed2_2.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOwnerHasChanged() throws Exception {
|
||||||
|
List list = queryForPropertyHasChanged(
|
||||||
|
DoubleListJoinColumnBidirectionalRefEdEntity1.class, ed1_1_id,
|
||||||
|
"owner");
|
||||||
|
assertEquals(2, list.size());
|
||||||
|
assertEquals(TestTools.makeList(1, 4), extractRevisionNumbers(list));
|
||||||
|
|
||||||
|
list = queryForPropertyHasNotChanged(
|
||||||
|
DoubleListJoinColumnBidirectionalRefEdEntity1.class, ed1_1_id,
|
||||||
|
"owner");
|
||||||
|
assertEquals(1, list.size());
|
||||||
|
assertEquals(TestTools.makeList(3), extractRevisionNumbers(list));
|
||||||
|
|
||||||
|
list = queryForPropertyHasChanged(
|
||||||
|
DoubleListJoinColumnBidirectionalRefEdEntity1.class, ed1_2_id,
|
||||||
|
"owner");
|
||||||
|
assertEquals(3, list.size());
|
||||||
|
assertEquals(TestTools.makeList(1,2, 4), extractRevisionNumbers(list));
|
||||||
|
|
||||||
|
list = queryForPropertyHasNotChanged(
|
||||||
|
DoubleListJoinColumnBidirectionalRefEdEntity1.class, ed1_2_id,
|
||||||
|
"owner");
|
||||||
|
assertEquals(0, list.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOwnerSecEntityHasChanged() throws Exception {
|
||||||
|
List list = queryForPropertyHasChanged(
|
||||||
|
DoubleListJoinColumnBidirectionalRefEdEntity2.class, ed2_1_id,
|
||||||
|
"owner");
|
||||||
|
assertEquals(2, list.size());
|
||||||
|
assertEquals(TestTools.makeList(1, 4), extractRevisionNumbers(list));
|
||||||
|
|
||||||
|
list = queryForPropertyHasNotChanged(
|
||||||
|
DoubleListJoinColumnBidirectionalRefEdEntity2.class, ed2_1_id,
|
||||||
|
"owner");
|
||||||
|
assertEquals(0, list.size());
|
||||||
|
|
||||||
|
list = queryForPropertyHasChanged(
|
||||||
|
DoubleListJoinColumnBidirectionalRefEdEntity2.class, ed2_2_id,
|
||||||
|
"owner");
|
||||||
|
assertEquals(2, list.size());
|
||||||
|
assertEquals(TestTools.makeList(1, 2), extractRevisionNumbers(list));
|
||||||
|
|
||||||
|
list = queryForPropertyHasNotChanged(
|
||||||
|
DoubleListJoinColumnBidirectionalRefEdEntity2.class, ed2_2_id,
|
||||||
|
"owner");
|
||||||
|
assertEquals(1, list.size());
|
||||||
|
assertEquals(TestTools.makeList(3), extractRevisionNumbers(list));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testReferences1HasChanged() throws Exception {
|
||||||
|
List list = queryForPropertyHasChanged(
|
||||||
|
DoubleListJoinColumnBidirectionalRefIngEntity.class, ing1_id,
|
||||||
|
"references1");
|
||||||
|
assertEquals(3, list.size());
|
||||||
|
assertEquals(TestTools.makeList(1, 2, 4), extractRevisionNumbers(list));
|
||||||
|
|
||||||
|
list = queryForPropertyHasChanged(
|
||||||
|
DoubleListJoinColumnBidirectionalRefIngEntity.class, ing2_id,
|
||||||
|
"references1");
|
||||||
|
assertEquals(3, list.size());
|
||||||
|
assertEquals(TestTools.makeList(1, 2, 4), extractRevisionNumbers(list));
|
||||||
|
|
||||||
|
list = queryForPropertyHasNotChanged(
|
||||||
|
DoubleListJoinColumnBidirectionalRefIngEntity.class, ing1_id,
|
||||||
|
"references1");
|
||||||
|
assertEquals(0, list.size());
|
||||||
|
|
||||||
|
list = queryForPropertyHasNotChanged(
|
||||||
|
DoubleListJoinColumnBidirectionalRefIngEntity.class, ing2_id,
|
||||||
|
"references1");
|
||||||
|
assertEquals(0, list.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testReferences2HasChanged() throws Exception {
|
||||||
|
List list = queryForPropertyHasChanged(
|
||||||
|
DoubleListJoinColumnBidirectionalRefIngEntity.class, ing1_id,
|
||||||
|
"references2");
|
||||||
|
assertEquals(3, list.size());
|
||||||
|
assertEquals(TestTools.makeList(1, 2, 4), extractRevisionNumbers(list));
|
||||||
|
|
||||||
|
list = queryForPropertyHasChanged(
|
||||||
|
DoubleListJoinColumnBidirectionalRefIngEntity.class, ing2_id,
|
||||||
|
"references2");
|
||||||
|
assertEquals(3, list.size());
|
||||||
|
assertEquals(TestTools.makeList(1, 2, 4), extractRevisionNumbers(list));
|
||||||
|
|
||||||
|
list = queryForPropertyHasNotChanged(
|
||||||
|
DoubleListJoinColumnBidirectionalRefIngEntity.class, ing1_id,
|
||||||
|
"references2");
|
||||||
|
assertEquals(0, list.size());
|
||||||
|
|
||||||
|
list = queryForPropertyHasNotChanged(
|
||||||
|
DoubleListJoinColumnBidirectionalRefIngEntity.class, ing2_id,
|
||||||
|
"references2");
|
||||||
|
assertEquals(0, list.size());
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,113 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Middleware LLC.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.hibernate.envers.test.integration.modifiedflags;
|
||||||
|
|
||||||
|
import org.hibernate.ejb.Ejb3Configuration;
|
||||||
|
import org.hibernate.envers.test.Priority;
|
||||||
|
import org.hibernate.envers.test.entities.collection.EnumSetEntity;
|
||||||
|
import org.hibernate.envers.test.entities.collection.EnumSetEntity.E1;
|
||||||
|
import org.hibernate.envers.test.entities.collection.EnumSetEntity.E2;
|
||||||
|
import org.hibernate.envers.test.tools.TestTools;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static junit.framework.Assert.assertEquals;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Adam Warski (adam at warski dot org)
|
||||||
|
* @author Michal Skowronek (mskowr at o2 dot pl)
|
||||||
|
*/
|
||||||
|
public class HasChangedEnumSet extends AbstractModifiedFlagsEntityTest {
|
||||||
|
private Integer sse1_id;
|
||||||
|
|
||||||
|
public void configure(Ejb3Configuration cfg) {
|
||||||
|
cfg.addAnnotatedClass(EnumSetEntity.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Priority(10)
|
||||||
|
public void initData() {
|
||||||
|
EntityManager em = getEntityManager();
|
||||||
|
|
||||||
|
EnumSetEntity sse1 = new EnumSetEntity();
|
||||||
|
|
||||||
|
// Revision 1 (sse1: initialy 1 element)
|
||||||
|
em.getTransaction().begin();
|
||||||
|
|
||||||
|
sse1.getEnums1().add(E1.X);
|
||||||
|
sse1.getEnums2().add(E2.A);
|
||||||
|
|
||||||
|
em.persist(sse1);
|
||||||
|
|
||||||
|
em.getTransaction().commit();
|
||||||
|
|
||||||
|
// Revision 2 (sse1: adding 1 element/removing a non-existing element)
|
||||||
|
em.getTransaction().begin();
|
||||||
|
|
||||||
|
sse1 = em.find(EnumSetEntity.class, sse1.getId());
|
||||||
|
|
||||||
|
sse1.getEnums1().add(E1.Y);
|
||||||
|
sse1.getEnums2().remove(E2.B);
|
||||||
|
|
||||||
|
em.getTransaction().commit();
|
||||||
|
|
||||||
|
// Revision 3 (sse1: removing 1 element/adding an exisiting element)
|
||||||
|
em.getTransaction().begin();
|
||||||
|
|
||||||
|
sse1 = em.find(EnumSetEntity.class, sse1.getId());
|
||||||
|
|
||||||
|
sse1.getEnums1().remove(E1.X);
|
||||||
|
sse1.getEnums2().add(E2.A);
|
||||||
|
|
||||||
|
em.getTransaction().commit();
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
sse1_id = sse1.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHasChanged() throws Exception {
|
||||||
|
List list = queryForPropertyHasChanged(EnumSetEntity.class, sse1_id,
|
||||||
|
"enums1");
|
||||||
|
assertEquals(3, list.size());
|
||||||
|
assertEquals(TestTools.makeList(1, 2, 3), extractRevisionNumbers(list));
|
||||||
|
|
||||||
|
list = queryForPropertyHasChanged(EnumSetEntity.class, sse1_id,
|
||||||
|
"enums2");
|
||||||
|
assertEquals(1, list.size());
|
||||||
|
assertEquals(TestTools.makeList(1), extractRevisionNumbers(list));
|
||||||
|
|
||||||
|
list = queryForPropertyHasNotChanged(EnumSetEntity.class, sse1_id,
|
||||||
|
"enums1");
|
||||||
|
assertEquals(0, list.size());
|
||||||
|
|
||||||
|
list = queryForPropertyHasNotChanged(EnumSetEntity.class, sse1_id,
|
||||||
|
"enums2");
|
||||||
|
assertEquals(2, list.size());
|
||||||
|
assertEquals(TestTools.makeList(2, 3), extractRevisionNumbers(list));
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,274 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Middleware LLC.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.hibernate.envers.test.integration.modifiedflags;
|
||||||
|
|
||||||
|
import org.hibernate.QueryException;
|
||||||
|
import org.hibernate.ejb.Ejb3Configuration;
|
||||||
|
import org.hibernate.envers.test.Priority;
|
||||||
|
import org.hibernate.envers.test.entities.StrTestEntity;
|
||||||
|
import org.hibernate.envers.test.entities.components.Component1;
|
||||||
|
import org.hibernate.envers.test.entities.components.Component2;
|
||||||
|
import org.hibernate.envers.test.integration.modifiedflags.entities
|
||||||
|
.NotUsingModifiedFlagsEntity;
|
||||||
|
import org.hibernate.envers.test.integration.modifiedflags.entities.RefEntity;
|
||||||
|
import org.hibernate.envers.test.tools.TestTools;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static junit.framework.Assert.assertEquals;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Michal Skowronek (mskowr at o2 dot pl)
|
||||||
|
*/
|
||||||
|
public class HasChangedForDefaultNotUsing extends AbstractModifiedFlagsEntityTest {
|
||||||
|
private static final int entityId = 1;
|
||||||
|
private static final int refEntityId = 1;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean forceModifiedFlags() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void configure(Ejb3Configuration cfg) {
|
||||||
|
cfg.addAnnotatedClass(NotUsingModifiedFlagsEntity.class);
|
||||||
|
cfg.addAnnotatedClass(RefEntity.class);
|
||||||
|
cfg.addAnnotatedClass(StrTestEntity.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Priority(10)
|
||||||
|
public void initData() {
|
||||||
|
|
||||||
|
NotUsingModifiedFlagsEntity entity =
|
||||||
|
new NotUsingModifiedFlagsEntity(entityId);
|
||||||
|
|
||||||
|
// Revision 1
|
||||||
|
EntityManager em = getEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
|
|
||||||
|
em.persist(entity);
|
||||||
|
|
||||||
|
em.getTransaction().commit();
|
||||||
|
|
||||||
|
// Revision 2
|
||||||
|
em.getTransaction().begin();
|
||||||
|
|
||||||
|
entity.setData("data1");
|
||||||
|
entity = em.merge(entity);
|
||||||
|
|
||||||
|
em.getTransaction().commit();
|
||||||
|
|
||||||
|
// Revision 3
|
||||||
|
em.getTransaction().begin();
|
||||||
|
|
||||||
|
entity.setComp1(new Component1("str1", "str2"));
|
||||||
|
entity = em.merge(entity);
|
||||||
|
|
||||||
|
em.getTransaction().commit();
|
||||||
|
|
||||||
|
// Revision 4
|
||||||
|
em.getTransaction().begin();
|
||||||
|
|
||||||
|
entity.setComp2(new Component2("str1", "str2"));
|
||||||
|
entity = em.merge(entity);
|
||||||
|
|
||||||
|
em.getTransaction().commit();
|
||||||
|
|
||||||
|
// Revision 5
|
||||||
|
em.getTransaction().begin();
|
||||||
|
|
||||||
|
RefEntity refEntity = new RefEntity(refEntityId, "first");
|
||||||
|
refEntity.setReference(entity);
|
||||||
|
em.persist(refEntity);
|
||||||
|
|
||||||
|
em.getTransaction().commit();
|
||||||
|
|
||||||
|
// Revision 6
|
||||||
|
em.getTransaction().begin();
|
||||||
|
|
||||||
|
refEntity = em.find(RefEntity.class, refEntityId);
|
||||||
|
refEntity.setReference(null);
|
||||||
|
refEntity.setSecondReference(entity);
|
||||||
|
refEntity = em.merge(refEntity);
|
||||||
|
|
||||||
|
em.getTransaction().commit();
|
||||||
|
|
||||||
|
// Revision 7
|
||||||
|
em.getTransaction().begin();
|
||||||
|
|
||||||
|
entity.getStringSet().add("firstElement");
|
||||||
|
entity.getStringSet().add("secondElement");
|
||||||
|
entity = em.merge(entity);
|
||||||
|
|
||||||
|
em.getTransaction().commit();
|
||||||
|
|
||||||
|
// Revision 8
|
||||||
|
em.getTransaction().begin();
|
||||||
|
|
||||||
|
entity.getStringSet().remove("secondElement");
|
||||||
|
entity.getStringMap().put("someKey", "someValue");
|
||||||
|
entity = em.merge(entity);
|
||||||
|
|
||||||
|
em.getTransaction().commit();
|
||||||
|
|
||||||
|
// Revision 9 - main entity doesn't change
|
||||||
|
em.getTransaction().begin();
|
||||||
|
|
||||||
|
StrTestEntity strTestEntity = new StrTestEntity("first");
|
||||||
|
em.persist(strTestEntity);
|
||||||
|
|
||||||
|
em.getTransaction().commit();
|
||||||
|
|
||||||
|
// Revision 10
|
||||||
|
em.getTransaction().begin();
|
||||||
|
|
||||||
|
entity.getEntitiesSet().add(strTestEntity);
|
||||||
|
entity = em.merge(entity);
|
||||||
|
|
||||||
|
em.getTransaction().commit();
|
||||||
|
|
||||||
|
// Revision 11
|
||||||
|
em.getTransaction().begin();
|
||||||
|
|
||||||
|
entity.getEntitiesSet().remove(strTestEntity);
|
||||||
|
entity.getEntitiesMap().put("someKey", strTestEntity);
|
||||||
|
entity = em.merge(entity);
|
||||||
|
|
||||||
|
em.getTransaction().commit();
|
||||||
|
|
||||||
|
// Revision 12 - main entity doesn't change
|
||||||
|
em.getTransaction().begin();
|
||||||
|
|
||||||
|
strTestEntity.setStr("second");
|
||||||
|
strTestEntity = em.merge(strTestEntity);
|
||||||
|
|
||||||
|
em.getTransaction().commit();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRevisionsCounts() {
|
||||||
|
assertEquals(Arrays.asList((Number) 1, 2, 3, 4, 5, 6, 7, 8, 10, 11),
|
||||||
|
getAuditReader()
|
||||||
|
.getRevisions(NotUsingModifiedFlagsEntity.class,
|
||||||
|
entityId));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHasChangedData() throws Exception {
|
||||||
|
List list = queryForPropertyHasChanged(
|
||||||
|
NotUsingModifiedFlagsEntity.class,
|
||||||
|
entityId, "data");
|
||||||
|
assertEquals(1, list.size());
|
||||||
|
assertEquals(TestTools.makeList(2), extractRevisionNumbers(list));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHasChangedComp1() throws Exception {
|
||||||
|
List list = queryForPropertyHasChanged(
|
||||||
|
NotUsingModifiedFlagsEntity.class,
|
||||||
|
entityId, "comp1");
|
||||||
|
assertEquals(1, list.size());
|
||||||
|
assertEquals(TestTools.makeList(3), extractRevisionNumbers(list));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = QueryException.class)
|
||||||
|
public void testHasChangedComp2() throws Exception {
|
||||||
|
queryForPropertyHasChanged(NotUsingModifiedFlagsEntity.class,
|
||||||
|
entityId, "comp2");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHasChangedReferencing() throws Exception {
|
||||||
|
List list = queryForPropertyHasChanged(
|
||||||
|
NotUsingModifiedFlagsEntity.class,
|
||||||
|
entityId, "referencing");
|
||||||
|
assertEquals(2, list.size());
|
||||||
|
assertEquals(TestTools.makeList(5, 6), extractRevisionNumbers(list));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = QueryException.class)
|
||||||
|
public void testHasChangedReferencing2() throws Exception {
|
||||||
|
queryForPropertyHasChanged(NotUsingModifiedFlagsEntity.class,
|
||||||
|
entityId, "referencing2");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHasChangedStringSet() throws Exception {
|
||||||
|
List list = queryForPropertyHasChanged(
|
||||||
|
NotUsingModifiedFlagsEntity.class,
|
||||||
|
entityId, "stringSet");
|
||||||
|
assertEquals(3, list.size());
|
||||||
|
assertEquals(TestTools.makeList(1, 7, 8), extractRevisionNumbers(list));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHasChangedStringMap() throws Exception {
|
||||||
|
List list = queryForPropertyHasChanged(
|
||||||
|
NotUsingModifiedFlagsEntity.class,
|
||||||
|
entityId, "stringMap");
|
||||||
|
assertEquals(2, list.size());
|
||||||
|
assertEquals(TestTools.makeList(1, 8), extractRevisionNumbers(list));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHasChangedStringSetAndMap() throws Exception {
|
||||||
|
List list = queryForPropertyHasChanged(
|
||||||
|
NotUsingModifiedFlagsEntity.class,
|
||||||
|
entityId, "stringSet", "stringMap");
|
||||||
|
assertEquals(2, list.size());
|
||||||
|
assertEquals(TestTools.makeList(1, 8), extractRevisionNumbers(list));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHasChangedEntitiesSet() throws Exception {
|
||||||
|
List list = queryForPropertyHasChanged(
|
||||||
|
NotUsingModifiedFlagsEntity.class,
|
||||||
|
entityId, "entitiesSet");
|
||||||
|
assertEquals(3, list.size());
|
||||||
|
assertEquals(TestTools.makeList(1, 10, 11), extractRevisionNumbers(list));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHasChangedEntitiesMap() throws Exception {
|
||||||
|
List list = queryForPropertyHasChanged(
|
||||||
|
NotUsingModifiedFlagsEntity.class,
|
||||||
|
entityId, "entitiesMap");
|
||||||
|
assertEquals(2, list.size());
|
||||||
|
assertEquals(TestTools.makeList(1, 11), extractRevisionNumbers(list));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHasChangedEntitiesSetAndMap() throws Exception {
|
||||||
|
List list = queryForPropertyHasChanged(
|
||||||
|
NotUsingModifiedFlagsEntity.class,
|
||||||
|
entityId, "entitiesSet", "entitiesMap");
|
||||||
|
assertEquals(2, list.size());
|
||||||
|
assertEquals(TestTools.makeList(1, 11), extractRevisionNumbers(list));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,104 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Middleware LLC.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.hibernate.envers.test.integration.modifiedflags;
|
||||||
|
|
||||||
|
import org.hibernate.ejb.Ejb3Configuration;
|
||||||
|
import org.hibernate.envers.test.Priority;
|
||||||
|
import org.hibernate.envers.test.entities.StrTestEntity;
|
||||||
|
import org.hibernate.envers.test.integration.collection.mapkey.IdMapKeyEntity;
|
||||||
|
import org.hibernate.envers.test.tools.TestTools;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static junit.framework.Assert.assertEquals;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Adam Warski (adam at warski dot org)
|
||||||
|
* @author Michal Skowronek (mskowr at o2 dot pl)
|
||||||
|
*/
|
||||||
|
public class HasChangedIdMapKey extends AbstractModifiedFlagsEntityTest {
|
||||||
|
private Integer imke_id;
|
||||||
|
|
||||||
|
private Integer ste1_id;
|
||||||
|
private Integer ste2_id;
|
||||||
|
|
||||||
|
public void configure(Ejb3Configuration cfg) {
|
||||||
|
cfg.addAnnotatedClass(IdMapKeyEntity.class);
|
||||||
|
cfg.addAnnotatedClass(StrTestEntity.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Priority(10)
|
||||||
|
public void initData() {
|
||||||
|
EntityManager em = getEntityManager();
|
||||||
|
|
||||||
|
IdMapKeyEntity imke = new IdMapKeyEntity();
|
||||||
|
|
||||||
|
// Revision 1 (intialy 1 mapping)
|
||||||
|
em.getTransaction().begin();
|
||||||
|
|
||||||
|
StrTestEntity ste1 = new StrTestEntity("x");
|
||||||
|
StrTestEntity ste2 = new StrTestEntity("y");
|
||||||
|
|
||||||
|
em.persist(ste1);
|
||||||
|
em.persist(ste2);
|
||||||
|
|
||||||
|
imke.getIdmap().put(ste1.getId(), ste1);
|
||||||
|
|
||||||
|
em.persist(imke);
|
||||||
|
|
||||||
|
em.getTransaction().commit();
|
||||||
|
|
||||||
|
// Revision 2 (sse1: adding 1 mapping)
|
||||||
|
em.getTransaction().begin();
|
||||||
|
|
||||||
|
ste2 = em.find(StrTestEntity.class, ste2.getId());
|
||||||
|
imke = em.find(IdMapKeyEntity.class, imke.getId());
|
||||||
|
|
||||||
|
imke.getIdmap().put(ste2.getId(), ste2);
|
||||||
|
|
||||||
|
em.getTransaction().commit();
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
imke_id = imke.getId();
|
||||||
|
|
||||||
|
ste1_id = ste1.getId();
|
||||||
|
ste2_id = ste2.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHasChanged() throws Exception {
|
||||||
|
List list = queryForPropertyHasChanged(IdMapKeyEntity.class, imke_id,
|
||||||
|
"idmap");
|
||||||
|
assertEquals(2, list.size());
|
||||||
|
assertEquals(TestTools.makeList(1, 2), extractRevisionNumbers(list));
|
||||||
|
|
||||||
|
list = queryForPropertyHasNotChanged(IdMapKeyEntity.class, imke_id,
|
||||||
|
"idmap");
|
||||||
|
assertEquals(0, list.size());
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,109 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Middleware LLC.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.hibernate.envers.test.integration.modifiedflags;
|
||||||
|
|
||||||
|
import org.hibernate.ejb.Ejb3Configuration;
|
||||||
|
import org.hibernate.envers.test.Priority;
|
||||||
|
import org.hibernate.envers.test.entities.StrTestEntity;
|
||||||
|
import org.hibernate.envers.test.entities.components.relations
|
||||||
|
.ManyToOneComponent;
|
||||||
|
import org.hibernate.envers.test.entities.components.relations
|
||||||
|
.ManyToOneComponentTestEntity;
|
||||||
|
import org.hibernate.envers.test.tools.TestTools;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static junit.framework.Assert.assertEquals;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Adam Warski (adam at warski dot org)
|
||||||
|
* @author Michal Skowronek (mskowr at o2 dot pl)
|
||||||
|
*/
|
||||||
|
public class HasChangedManyToOneInComponent extends AbstractModifiedFlagsEntityTest {
|
||||||
|
private Integer mtocte_id1;
|
||||||
|
private Integer ste_id1;
|
||||||
|
private Integer ste_id2;
|
||||||
|
|
||||||
|
public void configure(Ejb3Configuration cfg) {
|
||||||
|
cfg.addAnnotatedClass(ManyToOneComponentTestEntity.class);
|
||||||
|
cfg.addAnnotatedClass(StrTestEntity.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Priority(10)
|
||||||
|
public void initData() {
|
||||||
|
// Revision 1
|
||||||
|
EntityManager em = getEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
|
|
||||||
|
StrTestEntity ste1 = new StrTestEntity();
|
||||||
|
ste1.setStr("str1");
|
||||||
|
|
||||||
|
StrTestEntity ste2 = new StrTestEntity();
|
||||||
|
ste2.setStr("str2");
|
||||||
|
|
||||||
|
em.persist(ste1);
|
||||||
|
em.persist(ste2);
|
||||||
|
|
||||||
|
em.getTransaction().commit();
|
||||||
|
|
||||||
|
// Revision 2
|
||||||
|
em = getEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
|
|
||||||
|
ManyToOneComponentTestEntity mtocte1 = new ManyToOneComponentTestEntity(new ManyToOneComponent(ste1, "data1"));
|
||||||
|
|
||||||
|
em.persist(mtocte1);
|
||||||
|
|
||||||
|
em.getTransaction().commit();
|
||||||
|
|
||||||
|
// Revision 3
|
||||||
|
em = getEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
|
|
||||||
|
mtocte1 = em.find(ManyToOneComponentTestEntity.class, mtocte1.getId());
|
||||||
|
mtocte1.getComp1().setEntity(ste2);
|
||||||
|
|
||||||
|
em.getTransaction().commit();
|
||||||
|
|
||||||
|
mtocte_id1 = mtocte1.getId();
|
||||||
|
ste_id1 = ste1.getId();
|
||||||
|
ste_id2 = ste2.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHasChangedId1() throws Exception {
|
||||||
|
List list = queryForPropertyHasChanged(ManyToOneComponentTestEntity.class,
|
||||||
|
mtocte_id1, "comp1");
|
||||||
|
assertEquals(2, list.size());
|
||||||
|
assertEquals(TestTools.makeList(2, 3), extractRevisionNumbers(list));
|
||||||
|
|
||||||
|
list = queryForPropertyHasNotChanged(ManyToOneComponentTestEntity.class,
|
||||||
|
mtocte_id1, "comp1");
|
||||||
|
assertEquals(0, list.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,116 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Middleware LLC.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.hibernate.envers.test.integration.modifiedflags;
|
||||||
|
|
||||||
|
import org.hibernate.ejb.Ejb3Configuration;
|
||||||
|
import org.hibernate.envers.test.Priority;
|
||||||
|
import org.hibernate.envers.test.entities.UnversionedStrTestEntity;
|
||||||
|
import org.hibernate.envers.test.entities.components.relations
|
||||||
|
.NotAuditedManyToOneComponent;
|
||||||
|
import org.hibernate.envers.test.entities.components.relations
|
||||||
|
.NotAuditedManyToOneComponentTestEntity;
|
||||||
|
import org.hibernate.envers.test.tools.TestTools;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static junit.framework.Assert.assertEquals;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Adam Warski (adam at warski dot org)
|
||||||
|
* @author Michal Skowronek (mskowr at o2 dot pl)
|
||||||
|
*/
|
||||||
|
public class HasChangedNotAuditedManyToOneInComponent extends AbstractModifiedFlagsEntityTest {
|
||||||
|
private Integer mtocte_id1;
|
||||||
|
|
||||||
|
public void configure(Ejb3Configuration cfg) {
|
||||||
|
cfg.addAnnotatedClass(NotAuditedManyToOneComponentTestEntity.class);
|
||||||
|
cfg.addAnnotatedClass(UnversionedStrTestEntity.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Priority(10)
|
||||||
|
public void initData() {
|
||||||
|
// No revision
|
||||||
|
EntityManager em = getEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
|
|
||||||
|
UnversionedStrTestEntity ste1 = new UnversionedStrTestEntity();
|
||||||
|
ste1.setStr("str1");
|
||||||
|
|
||||||
|
UnversionedStrTestEntity ste2 = new UnversionedStrTestEntity();
|
||||||
|
ste2.setStr("str2");
|
||||||
|
|
||||||
|
em.persist(ste1);
|
||||||
|
em.persist(ste2);
|
||||||
|
|
||||||
|
em.getTransaction().commit();
|
||||||
|
|
||||||
|
// Revision 1
|
||||||
|
em = getEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
|
|
||||||
|
NotAuditedManyToOneComponentTestEntity mtocte1 = new NotAuditedManyToOneComponentTestEntity(
|
||||||
|
new NotAuditedManyToOneComponent(ste1, "data1"));
|
||||||
|
|
||||||
|
em.persist(mtocte1);
|
||||||
|
|
||||||
|
em.getTransaction().commit();
|
||||||
|
|
||||||
|
// No revision
|
||||||
|
em = getEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
|
|
||||||
|
mtocte1 = em.find(NotAuditedManyToOneComponentTestEntity.class, mtocte1.getId());
|
||||||
|
mtocte1.getComp1().setEntity(ste2);
|
||||||
|
|
||||||
|
em.getTransaction().commit();
|
||||||
|
|
||||||
|
// Revision 2
|
||||||
|
em = getEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
|
|
||||||
|
mtocte1 = em.find(NotAuditedManyToOneComponentTestEntity.class, mtocte1.getId());
|
||||||
|
mtocte1.getComp1().setData("data2");
|
||||||
|
|
||||||
|
em.getTransaction().commit();
|
||||||
|
|
||||||
|
mtocte_id1 = mtocte1.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHasChangedId1() throws Exception {
|
||||||
|
List list = queryForPropertyHasChanged(
|
||||||
|
NotAuditedManyToOneComponentTestEntity.class, mtocte_id1,
|
||||||
|
"comp1");
|
||||||
|
assertEquals(2, list.size());
|
||||||
|
assertEquals(TestTools.makeList(1, 2), extractRevisionNumbers(list));
|
||||||
|
|
||||||
|
list = queryForPropertyHasNotChanged(
|
||||||
|
NotAuditedManyToOneComponentTestEntity.class, mtocte_id1,
|
||||||
|
"comp1");
|
||||||
|
assertEquals(0, list.size());
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,108 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Middleware LLC.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.hibernate.envers.test.integration.modifiedflags;
|
||||||
|
|
||||||
|
import org.hibernate.ejb.Ejb3Configuration;
|
||||||
|
import org.hibernate.envers.test.Priority;
|
||||||
|
import org.hibernate.envers.test.integration.inheritance.joined
|
||||||
|
.notownedrelation.Address;
|
||||||
|
import org.hibernate.envers.test.integration.inheritance.joined
|
||||||
|
.notownedrelation.Contact;
|
||||||
|
import org.hibernate.envers.test.integration.inheritance.joined
|
||||||
|
.notownedrelation.PersonalContact;
|
||||||
|
import org.hibernate.envers.test.tools.TestTools;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static junit.framework.Assert.assertEquals;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Adam Warski (adam at warski dot org)
|
||||||
|
* @author Michal Skowronek (mskowr at o2 dot pl)
|
||||||
|
*/
|
||||||
|
public class HasChangedNotOwnedBidirectional extends AbstractModifiedFlagsEntityTest {
|
||||||
|
private Long pc_id;
|
||||||
|
private Long a1_id;
|
||||||
|
private Long a2_id;
|
||||||
|
|
||||||
|
public void configure(Ejb3Configuration cfg) {
|
||||||
|
cfg.addAnnotatedClass(Address.class);
|
||||||
|
cfg.addAnnotatedClass(Contact.class);
|
||||||
|
cfg.addAnnotatedClass(PersonalContact.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Priority(10)
|
||||||
|
public void initData() {
|
||||||
|
EntityManager em = getEntityManager();
|
||||||
|
|
||||||
|
pc_id = 1l;
|
||||||
|
a1_id = 10l;
|
||||||
|
a2_id = 100l;
|
||||||
|
|
||||||
|
// Rev 1
|
||||||
|
em.getTransaction().begin();
|
||||||
|
|
||||||
|
PersonalContact pc = new PersonalContact(pc_id, "e", "f");
|
||||||
|
|
||||||
|
Address a1 = new Address(a1_id, "a1");
|
||||||
|
a1.setContact(pc);
|
||||||
|
|
||||||
|
em.persist(pc);
|
||||||
|
em.persist(a1);
|
||||||
|
|
||||||
|
em.getTransaction().commit();
|
||||||
|
|
||||||
|
// Rev 2
|
||||||
|
em.getTransaction().begin();
|
||||||
|
|
||||||
|
pc = em.find(PersonalContact.class, pc_id);
|
||||||
|
|
||||||
|
Address a2 = new Address(a2_id, "a2");
|
||||||
|
a2.setContact(pc);
|
||||||
|
|
||||||
|
em.persist(a2);
|
||||||
|
|
||||||
|
em.getTransaction().commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testReferencedEntityHasChanged() throws Exception {
|
||||||
|
List list = queryForPropertyHasChanged(PersonalContact.class, pc_id,
|
||||||
|
"addresses");
|
||||||
|
assertEquals(2, list.size());
|
||||||
|
assertEquals(TestTools.makeList(1, 2), extractRevisionNumbers(list));
|
||||||
|
|
||||||
|
list = queryForPropertyHasChanged(Address.class, a1_id, "contact");
|
||||||
|
assertEquals(1, list.size());
|
||||||
|
assertEquals(TestTools.makeList(1), extractRevisionNumbers(list));
|
||||||
|
|
||||||
|
list = queryForPropertyHasChanged(Address.class, a2_id, "contact");
|
||||||
|
assertEquals(1, list.size());
|
||||||
|
assertEquals(TestTools.makeList(2), extractRevisionNumbers(list));
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,109 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Middleware LLC.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.hibernate.envers.test.integration.modifiedflags;
|
||||||
|
|
||||||
|
import org.hibernate.ejb.Ejb3Configuration;
|
||||||
|
import org.hibernate.envers.query.AuditEntity;
|
||||||
|
import org.hibernate.envers.test.Priority;
|
||||||
|
import org.hibernate.envers.test.integration.basic.BasicTestEntity1;
|
||||||
|
import org.hibernate.envers.test.tools.TestTools;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static junit.framework.Assert.assertEquals;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Adam Warski (adam at warski dot org)
|
||||||
|
* @author Michal Skowronek (mskowr at o2 dot pl)
|
||||||
|
*/
|
||||||
|
public class HasChangedNullProperties extends AbstractModifiedFlagsEntityTest {
|
||||||
|
private Integer id1;
|
||||||
|
private Integer id2;
|
||||||
|
|
||||||
|
public void configure(Ejb3Configuration cfg) {
|
||||||
|
cfg.addAnnotatedClass(BasicTestEntity1.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Integer addNewEntity(String str, long lng) {
|
||||||
|
EntityManager em = getEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
|
BasicTestEntity1 bte1 = new BasicTestEntity1(str, lng);
|
||||||
|
em.persist(bte1);
|
||||||
|
em.getTransaction().commit();
|
||||||
|
|
||||||
|
return bte1.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void modifyEntity(Integer id, String str, long lng) {
|
||||||
|
EntityManager em = getEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
|
BasicTestEntity1 bte1 = em.find(BasicTestEntity1.class, id);
|
||||||
|
bte1.setLong1(lng);
|
||||||
|
bte1.setStr1(str);
|
||||||
|
em.getTransaction().commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Priority(10)
|
||||||
|
public void initData() {
|
||||||
|
id1 = addNewEntity("x", 1); // rev 1
|
||||||
|
id2 = addNewEntity(null, 20); // rev 2
|
||||||
|
|
||||||
|
modifyEntity(id1, null, 1); // rev 3
|
||||||
|
modifyEntity(id2, "y2", 20); // rev 4
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHasChanged() throws Exception {
|
||||||
|
List list = queryForPropertyHasChangedWithDeleted(BasicTestEntity1.class,
|
||||||
|
id1, "str1");
|
||||||
|
assertEquals(2, list.size());
|
||||||
|
assertEquals(TestTools.makeList(1, 3), extractRevisionNumbers(list));
|
||||||
|
|
||||||
|
list = queryForPropertyHasChangedWithDeleted(BasicTestEntity1.class,
|
||||||
|
id1, "long1");
|
||||||
|
assertEquals(1, list.size());
|
||||||
|
assertEquals(TestTools.makeList(1), extractRevisionNumbers(list));
|
||||||
|
|
||||||
|
list = queryForPropertyHasChangedWithDeleted(BasicTestEntity1.class,
|
||||||
|
id2, "str1");
|
||||||
|
// str1 property was null before insert and after insert so in a way it didn't change - is it a good way to go?
|
||||||
|
assertEquals(1, list.size());
|
||||||
|
assertEquals(TestTools.makeList(4), extractRevisionNumbers(list));
|
||||||
|
|
||||||
|
list = queryForPropertyHasChangedWithDeleted(BasicTestEntity1.class,
|
||||||
|
id2, "long1");
|
||||||
|
assertEquals(1, list.size());
|
||||||
|
assertEquals(TestTools.makeList(2), extractRevisionNumbers(list));
|
||||||
|
|
||||||
|
list = getAuditReader().createQuery().forRevisionsOfEntity(BasicTestEntity1.class, false, true)
|
||||||
|
.add(AuditEntity.property("str1").hasChanged())
|
||||||
|
.add(AuditEntity.property("long1").hasChanged())
|
||||||
|
.getResultList();
|
||||||
|
assertEquals(1, list.size());
|
||||||
|
assertEquals(TestTools.makeList(1), extractRevisionNumbers(list));
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,110 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Middleware LLC.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.hibernate.envers.test.integration.modifiedflags;
|
||||||
|
|
||||||
|
import org.hibernate.ejb.Ejb3Configuration;
|
||||||
|
import org.hibernate.envers.test.Priority;
|
||||||
|
import org.hibernate.envers.test.entities.StrTestEntity;
|
||||||
|
import org.hibernate.envers.test.entities.components.relations
|
||||||
|
.OneToManyComponent;
|
||||||
|
import org.hibernate.envers.test.entities.components.relations
|
||||||
|
.OneToManyComponentTestEntity;
|
||||||
|
import org.hibernate.envers.test.tools.TestTools;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static junit.framework.Assert.assertEquals;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Adam Warski (adam at warski dot org)
|
||||||
|
* @author Michal Skowronek (mskowr at o2 dot pl)
|
||||||
|
*/
|
||||||
|
public class HasChangedOneToManyInComponent extends AbstractModifiedFlagsEntityTest {
|
||||||
|
private Integer otmcte_id1;
|
||||||
|
private Integer ste_id1;
|
||||||
|
private Integer ste_id2;
|
||||||
|
|
||||||
|
public void configure(Ejb3Configuration cfg) {
|
||||||
|
cfg.addAnnotatedClass(OneToManyComponentTestEntity.class);
|
||||||
|
cfg.addAnnotatedClass(StrTestEntity.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Priority(10)
|
||||||
|
public void initData() {
|
||||||
|
// Revision 1
|
||||||
|
EntityManager em = getEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
|
|
||||||
|
StrTestEntity ste1 = new StrTestEntity();
|
||||||
|
ste1.setStr("str1");
|
||||||
|
|
||||||
|
StrTestEntity ste2 = new StrTestEntity();
|
||||||
|
ste2.setStr("str2");
|
||||||
|
|
||||||
|
em.persist(ste1);
|
||||||
|
em.persist(ste2);
|
||||||
|
|
||||||
|
em.getTransaction().commit();
|
||||||
|
|
||||||
|
// Revision 2
|
||||||
|
em = getEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
|
|
||||||
|
OneToManyComponentTestEntity otmcte1 = new OneToManyComponentTestEntity(new OneToManyComponent("data1"));
|
||||||
|
otmcte1.getComp1().getEntities().add(ste1);
|
||||||
|
|
||||||
|
em.persist(otmcte1);
|
||||||
|
|
||||||
|
em.getTransaction().commit();
|
||||||
|
|
||||||
|
// Revision 3
|
||||||
|
em = getEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
|
|
||||||
|
otmcte1 = em.find(OneToManyComponentTestEntity.class, otmcte1.getId());
|
||||||
|
otmcte1.getComp1().getEntities().add(ste2);
|
||||||
|
|
||||||
|
em.getTransaction().commit();
|
||||||
|
|
||||||
|
otmcte_id1 = otmcte1.getId();
|
||||||
|
ste_id1 = ste1.getId();
|
||||||
|
ste_id2 = ste2.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHasChangedId1() throws Exception {
|
||||||
|
List list =
|
||||||
|
queryForPropertyHasChanged(OneToManyComponentTestEntity.class,
|
||||||
|
otmcte_id1, "comp1");
|
||||||
|
assertEquals(2, list.size());
|
||||||
|
assertEquals(TestTools.makeList(2, 3), extractRevisionNumbers(list));
|
||||||
|
|
||||||
|
list = queryForPropertyHasNotChanged(OneToManyComponentTestEntity.class,
|
||||||
|
otmcte_id1, "comp1");
|
||||||
|
assertEquals(0, list.size());
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,126 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Middleware LLC.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.hibernate.envers.test.integration.modifiedflags;
|
||||||
|
|
||||||
|
import org.hibernate.ejb.Ejb3Configuration;
|
||||||
|
import org.hibernate.envers.test.Priority;
|
||||||
|
import org.hibernate.envers.test.entities.collection.StringMapEntity;
|
||||||
|
import org.hibernate.envers.test.tools.TestTools;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static junit.framework.Assert.assertEquals;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Adam Warski (adam at warski dot org)
|
||||||
|
* @author Michal Skowronek (mskowr at o2 dot pl)
|
||||||
|
*/
|
||||||
|
public class HasChangedStringMap extends AbstractModifiedFlagsEntityTest {
|
||||||
|
private Integer sme1_id;
|
||||||
|
private Integer sme2_id;
|
||||||
|
|
||||||
|
public void configure(Ejb3Configuration cfg) {
|
||||||
|
cfg.addAnnotatedClass(StringMapEntity.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Priority(10)
|
||||||
|
public void initData() {
|
||||||
|
EntityManager em = getEntityManager();
|
||||||
|
|
||||||
|
StringMapEntity sme1 = new StringMapEntity();
|
||||||
|
StringMapEntity sme2 = new StringMapEntity();
|
||||||
|
|
||||||
|
// Revision 1 (sme1: initialy empty, sme2: initialy 1 mapping)
|
||||||
|
em.getTransaction().begin();
|
||||||
|
|
||||||
|
sme2.getStrings().put("1", "a");
|
||||||
|
|
||||||
|
em.persist(sme1);
|
||||||
|
em.persist(sme2);
|
||||||
|
|
||||||
|
em.getTransaction().commit();
|
||||||
|
|
||||||
|
// Revision 2 (sme1: adding 2 mappings, sme2: no changes)
|
||||||
|
em.getTransaction().begin();
|
||||||
|
|
||||||
|
sme1 = em.find(StringMapEntity.class, sme1.getId());
|
||||||
|
sme2 = em.find(StringMapEntity.class, sme2.getId());
|
||||||
|
|
||||||
|
sme1.getStrings().put("1", "a");
|
||||||
|
sme1.getStrings().put("2", "b");
|
||||||
|
|
||||||
|
em.getTransaction().commit();
|
||||||
|
|
||||||
|
// Revision 3 (sme1: removing an existing mapping, sme2: replacing a value)
|
||||||
|
em.getTransaction().begin();
|
||||||
|
|
||||||
|
sme1 = em.find(StringMapEntity.class, sme1.getId());
|
||||||
|
sme2 = em.find(StringMapEntity.class, sme2.getId());
|
||||||
|
|
||||||
|
sme1.getStrings().remove("1");
|
||||||
|
sme2.getStrings().put("1", "b");
|
||||||
|
|
||||||
|
em.getTransaction().commit();
|
||||||
|
|
||||||
|
// No revision (sme1: removing a non-existing mapping, sme2: replacing with the same value)
|
||||||
|
em.getTransaction().begin();
|
||||||
|
|
||||||
|
sme1 = em.find(StringMapEntity.class, sme1.getId());
|
||||||
|
sme2 = em.find(StringMapEntity.class, sme2.getId());
|
||||||
|
|
||||||
|
sme1.getStrings().remove("3");
|
||||||
|
sme2.getStrings().put("1", "b");
|
||||||
|
|
||||||
|
em.getTransaction().commit();
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
sme1_id = sme1.getId();
|
||||||
|
sme2_id = sme2.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHasChanged() throws Exception {
|
||||||
|
List list = queryForPropertyHasChanged(StringMapEntity.class, sme1_id,
|
||||||
|
"strings");
|
||||||
|
assertEquals(3, list.size());
|
||||||
|
assertEquals(TestTools.makeList(1, 2, 3), extractRevisionNumbers(list));
|
||||||
|
|
||||||
|
list = queryForPropertyHasChanged(StringMapEntity.class, sme2_id,
|
||||||
|
"strings");
|
||||||
|
assertEquals(2, list.size());
|
||||||
|
assertEquals(TestTools.makeList(1, 3), extractRevisionNumbers(list));
|
||||||
|
|
||||||
|
list = queryForPropertyHasNotChanged(StringMapEntity.class, sme1_id,
|
||||||
|
"strings");
|
||||||
|
assertEquals(0, list.size());
|
||||||
|
|
||||||
|
list = queryForPropertyHasNotChanged(StringMapEntity.class, sme2_id,
|
||||||
|
"strings");
|
||||||
|
assertEquals(0, list.size()); // in rev 2 there was no version generated for sme2_id
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,118 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Middleware LLC.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.hibernate.envers.test.integration.modifiedflags;
|
||||||
|
|
||||||
|
import org.hibernate.ejb.Ejb3Configuration;
|
||||||
|
import org.hibernate.envers.test.Priority;
|
||||||
|
import org.hibernate.envers.test.entities.collection.StringSetEntity;
|
||||||
|
import org.hibernate.envers.test.tools.TestTools;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static junit.framework.Assert.assertEquals;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Adam Warski (adam at warski dot org)
|
||||||
|
* @author Michal Skowronek (mskowr at o2 dot pl)
|
||||||
|
*/
|
||||||
|
public class HasChangedStringSet extends AbstractModifiedFlagsEntityTest {
|
||||||
|
private Integer sse1_id;
|
||||||
|
private Integer sse2_id;
|
||||||
|
|
||||||
|
public void configure(Ejb3Configuration cfg) {
|
||||||
|
cfg.addAnnotatedClass(StringSetEntity.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Priority(10)
|
||||||
|
public void initData() {
|
||||||
|
EntityManager em = getEntityManager();
|
||||||
|
|
||||||
|
StringSetEntity sse1 = new StringSetEntity();
|
||||||
|
StringSetEntity sse2 = new StringSetEntity();
|
||||||
|
|
||||||
|
// Revision 1 (sse1: initialy empty, sse2: initialy 2 elements)
|
||||||
|
em.getTransaction().begin();
|
||||||
|
|
||||||
|
sse2.getStrings().add("sse2_string1");
|
||||||
|
sse2.getStrings().add("sse2_string2");
|
||||||
|
|
||||||
|
em.persist(sse1);
|
||||||
|
em.persist(sse2);
|
||||||
|
|
||||||
|
em.getTransaction().commit();
|
||||||
|
|
||||||
|
// Revision 2 (sse1: adding 2 elements, sse2: adding an existing element)
|
||||||
|
em.getTransaction().begin();
|
||||||
|
|
||||||
|
sse1 = em.find(StringSetEntity.class, sse1.getId());
|
||||||
|
sse2 = em.find(StringSetEntity.class, sse2.getId());
|
||||||
|
|
||||||
|
sse1.getStrings().add("sse1_string1");
|
||||||
|
sse1.getStrings().add("sse1_string2");
|
||||||
|
|
||||||
|
sse2.getStrings().add("sse2_string1");
|
||||||
|
|
||||||
|
em.getTransaction().commit();
|
||||||
|
|
||||||
|
// Revision 3 (sse1: removing a non-existing element, sse2: removing one element)
|
||||||
|
em.getTransaction().begin();
|
||||||
|
|
||||||
|
sse1 = em.find(StringSetEntity.class, sse1.getId());
|
||||||
|
sse2 = em.find(StringSetEntity.class, sse2.getId());
|
||||||
|
|
||||||
|
sse1.getStrings().remove("sse1_string3");
|
||||||
|
sse2.getStrings().remove("sse2_string1");
|
||||||
|
|
||||||
|
em.getTransaction().commit();
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
sse1_id = sse1.getId();
|
||||||
|
sse2_id = sse2.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHasChanged() throws Exception {
|
||||||
|
List list = queryForPropertyHasChanged(StringSetEntity.class, sse1_id,
|
||||||
|
"strings");
|
||||||
|
assertEquals(2, list.size());
|
||||||
|
assertEquals(TestTools.makeList(1, 2), extractRevisionNumbers(list));
|
||||||
|
|
||||||
|
list = queryForPropertyHasChanged(StringSetEntity.class, sse2_id,
|
||||||
|
"strings");
|
||||||
|
assertEquals(2, list.size());
|
||||||
|
assertEquals(TestTools.makeList(1, 3), extractRevisionNumbers(list));
|
||||||
|
|
||||||
|
list = queryForPropertyHasNotChanged(StringSetEntity.class, sse1_id,
|
||||||
|
"strings");
|
||||||
|
assertEquals(0, list.size());
|
||||||
|
|
||||||
|
list = queryForPropertyHasNotChanged(StringSetEntity.class, sse2_id,
|
||||||
|
"strings");
|
||||||
|
assertEquals(0, list.size());
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,90 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Middleware LLC.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.hibernate.envers.test.integration.modifiedflags;
|
||||||
|
|
||||||
|
import org.hibernate.QueryException;
|
||||||
|
import org.hibernate.ejb.Ejb3Configuration;
|
||||||
|
import org.hibernate.envers.test.Priority;
|
||||||
|
import org.hibernate.envers.test.integration.basic.BasicTestEntity2;
|
||||||
|
import org.hibernate.envers.test.tools.TestTools;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static junit.framework.Assert.assertEquals;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Adam Warski (adam at warski dot org)
|
||||||
|
* @author Michal Skowronek (mskowr at o2 dot pl)
|
||||||
|
*/
|
||||||
|
public class HasChangedUnversionedProperties extends AbstractModifiedFlagsEntityTest {
|
||||||
|
private Integer id1;
|
||||||
|
|
||||||
|
public void configure(Ejb3Configuration cfg) {
|
||||||
|
cfg.addAnnotatedClass(BasicTestEntity2.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Integer addNewEntity(String str1, String str2) {
|
||||||
|
EntityManager em = getEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
|
BasicTestEntity2 bte2 = new BasicTestEntity2(str1, str2);
|
||||||
|
em.persist(bte2);
|
||||||
|
em.getTransaction().commit();
|
||||||
|
|
||||||
|
return bte2.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void modifyEntity(Integer id, String str1, String str2) {
|
||||||
|
EntityManager em = getEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
|
BasicTestEntity2 bte2 = em.find(BasicTestEntity2.class, id);
|
||||||
|
bte2.setStr1(str1);
|
||||||
|
bte2.setStr2(str2);
|
||||||
|
em.getTransaction().commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Priority(10)
|
||||||
|
public void initData() {
|
||||||
|
id1 = addNewEntity("x", "a"); // rev 1
|
||||||
|
modifyEntity(id1, "x", "a"); // no rev
|
||||||
|
modifyEntity(id1, "y", "b"); // rev 2
|
||||||
|
modifyEntity(id1, "y", "c"); // no rev
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHasChangedQuery() throws Exception {
|
||||||
|
List list = queryForPropertyHasChanged(BasicTestEntity2.class,
|
||||||
|
id1, "str1");
|
||||||
|
assertEquals(2, list.size());
|
||||||
|
assertEquals(TestTools.makeList(1, 2), extractRevisionNumbers(list));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = QueryException.class)
|
||||||
|
public void testExceptionOnHasChangedQuery() throws Exception {
|
||||||
|
queryForPropertyHasChangedWithDeleted(BasicTestEntity2.class,
|
||||||
|
id1, "str2");
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,189 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Middleware LLC.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.hibernate.envers.test.integration.modifiedflags.entities;
|
||||||
|
|
||||||
|
import org.hibernate.envers.Audited;
|
||||||
|
import org.hibernate.envers.test.entities.StrTestEntity;
|
||||||
|
import org.hibernate.envers.test.entities.components.Component1;
|
||||||
|
import org.hibernate.envers.test.entities.components.Component2;
|
||||||
|
|
||||||
|
import javax.persistence.*;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Michal Skowronek (mskowr at o2 dot pl)
|
||||||
|
*/
|
||||||
|
@Entity
|
||||||
|
@Audited(usingModifiedFlag = false)
|
||||||
|
public class NotUsingModifiedFlagsEntity {
|
||||||
|
@Id
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
@Audited(usingModifiedFlag = true)
|
||||||
|
private String data;
|
||||||
|
|
||||||
|
@Audited(usingModifiedFlag = true)
|
||||||
|
@Embedded
|
||||||
|
private Component1 comp1;
|
||||||
|
|
||||||
|
@Audited(usingModifiedFlag = false)
|
||||||
|
@Embedded
|
||||||
|
private Component2 comp2;
|
||||||
|
|
||||||
|
@Audited(usingModifiedFlag = true)
|
||||||
|
@OneToOne(mappedBy="reference")
|
||||||
|
private RefEntity referencing;
|
||||||
|
|
||||||
|
@Audited(usingModifiedFlag = false)
|
||||||
|
@OneToOne(mappedBy="secondReference")
|
||||||
|
private RefEntity referencing2;
|
||||||
|
|
||||||
|
@Audited(usingModifiedFlag = true)
|
||||||
|
@ElementCollection
|
||||||
|
private Set<String> stringSet = new HashSet<String>();
|
||||||
|
|
||||||
|
@Audited(usingModifiedFlag = true)
|
||||||
|
@ManyToMany
|
||||||
|
@CollectionTable(name = "ENTITIESSET")
|
||||||
|
private Set<StrTestEntity> entitiesSet = new HashSet<StrTestEntity>();
|
||||||
|
|
||||||
|
@Audited(usingModifiedFlag = true)
|
||||||
|
@ElementCollection
|
||||||
|
private Map<String, String> stringMap = new HashMap<String, String>();
|
||||||
|
|
||||||
|
@Audited(usingModifiedFlag = true)
|
||||||
|
@ManyToMany
|
||||||
|
@CollectionTable(name = "ENTITIESMAP")
|
||||||
|
private Map<String, StrTestEntity> entitiesMap =
|
||||||
|
new HashMap<String, StrTestEntity>();
|
||||||
|
|
||||||
|
public NotUsingModifiedFlagsEntity() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public NotUsingModifiedFlagsEntity(Integer id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Integer id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getData() {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setData(String data) {
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RefEntity getReferencing() {
|
||||||
|
return referencing;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setReferencing(RefEntity referencing) {
|
||||||
|
this.referencing = referencing;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RefEntity getReferencing2() {
|
||||||
|
return referencing2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setReferencing2(RefEntity referencing) {
|
||||||
|
this.referencing2 = referencing;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Component1 getComp1() {
|
||||||
|
return comp1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setComp1(Component1 comp1) {
|
||||||
|
this.comp1 = comp1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Component2 getComp2() {
|
||||||
|
return comp2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setComp2(Component2 comp2) {
|
||||||
|
this.comp2 = comp2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<String> getStringSet() {
|
||||||
|
return stringSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStringSet(Set<String> stringSet) {
|
||||||
|
this.stringSet = stringSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<StrTestEntity> getEntitiesSet() {
|
||||||
|
return entitiesSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEntitiesSet(Set<StrTestEntity> entitiesSet) {
|
||||||
|
this.entitiesSet = entitiesSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, String> getStringMap() {
|
||||||
|
return stringMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStringMap(Map<String, String> stringMap) {
|
||||||
|
this.stringMap = stringMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, StrTestEntity> getEntitiesMap() {
|
||||||
|
return entitiesMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEntitiesMap(Map<String, StrTestEntity> entitiesMap) {
|
||||||
|
this.entitiesMap = entitiesMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (!(o instanceof NotUsingModifiedFlagsEntity)) return false;
|
||||||
|
|
||||||
|
NotUsingModifiedFlagsEntity that = (NotUsingModifiedFlagsEntity) o;
|
||||||
|
|
||||||
|
if (data != null ? !data.equals(that.data) : that.data != null) return false;
|
||||||
|
if (id != null ? !id.equals(that.id) : that.id != null) return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int hashCode() {
|
||||||
|
int result;
|
||||||
|
result = (id != null ? id.hashCode() : 0);
|
||||||
|
result = 31 * result + (data != null ? data.hashCode() : 0);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,107 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
||||||
|
* indicated by the @author tags or express copyright attribution
|
||||||
|
* statements applied by the authors. All third-party contributions are
|
||||||
|
* distributed under license by Red Hat Middleware LLC.
|
||||||
|
*
|
||||||
|
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||||
|
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||||
|
* Lesser General Public License, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this distribution; if not, write to:
|
||||||
|
* Free Software Foundation, Inc.
|
||||||
|
* 51 Franklin Street, Fifth Floor
|
||||||
|
* Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.hibernate.envers.test.integration.modifiedflags.entities;
|
||||||
|
|
||||||
|
import org.hibernate.envers.Audited;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.OneToOne;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Adam Warski (adam at warski dot org)
|
||||||
|
*/
|
||||||
|
@Entity
|
||||||
|
@Audited(usingModifiedFlag = true)
|
||||||
|
public class RefEntity {
|
||||||
|
@Id
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
private String data;
|
||||||
|
|
||||||
|
@OneToOne
|
||||||
|
private NotUsingModifiedFlagsEntity reference;
|
||||||
|
|
||||||
|
@OneToOne
|
||||||
|
private NotUsingModifiedFlagsEntity secondReference;
|
||||||
|
|
||||||
|
public RefEntity() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public RefEntity(Integer id, String data) {
|
||||||
|
this.id = id;
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Integer id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getData() {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setData(String data) {
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public NotUsingModifiedFlagsEntity getReference() {
|
||||||
|
return reference;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setReference(NotUsingModifiedFlagsEntity reference) {
|
||||||
|
this.reference = reference;
|
||||||
|
}
|
||||||
|
|
||||||
|
public NotUsingModifiedFlagsEntity getSecondReference() {
|
||||||
|
return secondReference;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSecondReference(NotUsingModifiedFlagsEntity reference) {
|
||||||
|
this.secondReference = reference;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (!(o instanceof RefEntity)) return false;
|
||||||
|
|
||||||
|
RefEntity that = (RefEntity) o;
|
||||||
|
|
||||||
|
if (data != null ? !data.equals(that.data) : that.data != null) return false;
|
||||||
|
if (id != null ? !id.equals(that.id) : that.id != null) return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int hashCode() {
|
||||||
|
int result;
|
||||||
|
result = (id != null ? id.hashCode() : 0);
|
||||||
|
result = 31 * result + (data != null ? data.hashCode() : 0);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
|
@ -300,5 +300,4 @@ public class DoubleJoinColumnBidirectionalList extends AbstractEntityTest {
|
||||||
assertEquals(rev4.getData(), "ed2_2 bis");
|
assertEquals(rev4.getData(), "ed2_2 bis");
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo write tests for haschanged
|
|
||||||
}
|
}
|
|
@ -24,17 +24,12 @@
|
||||||
package org.hibernate.envers.test.integration.onetoone.bidirectional;
|
package org.hibernate.envers.test.integration.onetoone.bidirectional;
|
||||||
|
|
||||||
import org.hibernate.ejb.Ejb3Configuration;
|
import org.hibernate.ejb.Ejb3Configuration;
|
||||||
import org.hibernate.envers.query.AuditEntity;
|
|
||||||
import org.hibernate.envers.test.AbstractEntityTest;
|
import org.hibernate.envers.test.AbstractEntityTest;
|
||||||
import org.hibernate.envers.test.Priority;
|
import org.hibernate.envers.test.Priority;
|
||||||
import org.hibernate.envers.test.tools.TestTools;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static junit.framework.Assert.assertEquals;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Adam Warski (adam at warski dot org)
|
* @author Adam Warski (adam at warski dot org)
|
||||||
|
@ -154,20 +149,4 @@ public class Bidirectional2 extends AbstractEntityTest {
|
||||||
assert rev4.getReferencing().equals(ing1);
|
assert rev4.getReferencing().equals(ing1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testHasChanged() throws Exception {
|
|
||||||
List list = getAuditReader().createQuery().forRevisionsOfEntity(BiRefEdEntity.class, false, false)
|
|
||||||
.add(AuditEntity.id().eq(ed1_id))
|
|
||||||
.add(AuditEntity.property("referencing").hasChanged())
|
|
||||||
.getResultList();
|
|
||||||
assertEquals(3, list.size());
|
|
||||||
assertEquals(TestTools.makeList(2, 3, 4), extractRevisionNumbers(list));
|
|
||||||
|
|
||||||
list = getAuditReader().createQuery().forRevisionsOfEntity(BiRefEdEntity.class, false, false)
|
|
||||||
.add(AuditEntity.id().eq(ed2_id))
|
|
||||||
.add(AuditEntity.property("referencing").hasChanged())
|
|
||||||
.getResultList();
|
|
||||||
assertEquals(1, list.size());
|
|
||||||
assertEquals(TestTools.makeList(4), extractRevisionNumbers(list));
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue