Merge branch '3.6' of http://github.com/hernanch/hibernate-core into hernanch-3.6
This commit is contained in:
commit
b274c7218b
|
@ -3,6 +3,7 @@ package org.hibernate.envers.configuration.metadata.reader;
|
|||
/**
|
||||
* Implementations hold other audited properties.
|
||||
* @author Adam Warski (adam at warski dot org)
|
||||
* @author Hern&aacut;n Chanfreau
|
||||
*/
|
||||
public interface AuditedPropertiesHolder {
|
||||
/**
|
||||
|
@ -17,4 +18,16 @@ public interface AuditedPropertiesHolder {
|
|||
* @return Auditing data for the property.
|
||||
*/
|
||||
PropertyAuditingData getPropertyAuditingData(String propertyName);
|
||||
|
||||
|
||||
/**
|
||||
* @return true if the holder contains any audited property
|
||||
*/
|
||||
boolean isEmpty();
|
||||
|
||||
/**
|
||||
* @return true if the holder contains the given audited property
|
||||
*/
|
||||
boolean contains(String propertyName);
|
||||
|
||||
}
|
||||
|
|
|
@ -30,9 +30,10 @@ import org.hibernate.MappingException;
|
|||
* filling all the auditing data.
|
||||
* @author Adam Warski (adam at warski dot org)
|
||||
* @author Erik-Berndt Scheper
|
||||
* @author Hern&aacut;n Chanfreau
|
||||
*/
|
||||
public class AuditedPropertiesReader {
|
||||
private final ModificationStore defaultStore;
|
||||
protected final ModificationStore defaultStore;
|
||||
private final PersistentPropertiesSource persistentPropertiesSource;
|
||||
private final AuditedPropertiesHolder auditedPropertiesHolder;
|
||||
private final GlobalConfiguration globalCfg;
|
||||
|
@ -68,7 +69,7 @@ public class AuditedPropertiesReader {
|
|||
}
|
||||
|
||||
private void readPersistentPropertiesAccess() {
|
||||
Iterator propertyIter = persistentPropertiesSource.getPropertyIterator();
|
||||
Iterator<Property> propertyIter = persistentPropertiesSource.getPropertyIterator();
|
||||
while (propertyIter.hasNext()) {
|
||||
Property property = (Property) propertyIter.next();
|
||||
if ("field".equals(property.getPropertyAccessorName())) {
|
||||
|
@ -80,49 +81,84 @@ public class AuditedPropertiesReader {
|
|||
}
|
||||
|
||||
private void addPropertiesFromClass(XClass clazz) {
|
||||
XClass superclazz = clazz.getSuperclass();
|
||||
if (!clazz.isInterface() && !"java.lang.Object".equals(superclazz.getName())) {
|
||||
addPropertiesFromClass(superclazz);
|
||||
}
|
||||
Audited allClassAudited = clazz.getAnnotation(Audited.class);
|
||||
//look in the class
|
||||
addFromProperties(clazz.getDeclaredProperties("field"), "field", fieldAccessedPersistentProperties, allClassAudited);
|
||||
addFromProperties(clazz.getDeclaredProperties("property"), "property", propertyAccessedPersistentProperties, allClassAudited);
|
||||
|
||||
addFromProperties(clazz.getDeclaredProperties("field"), "field", fieldAccessedPersistentProperties);
|
||||
addFromProperties(clazz.getDeclaredProperties("property"), "property", propertyAccessedPersistentProperties);
|
||||
if(allClassAudited != null || !auditedPropertiesHolder.isEmpty()) {
|
||||
XClass superclazz = clazz.getSuperclass();
|
||||
if (!clazz.isInterface() && !"java.lang.Object".equals(superclazz.getName())) {
|
||||
addPropertiesFromClassRec(superclazz);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addFromProperties(Iterable<XProperty> properties, String accessType, Set<String> persistentProperties) {
|
||||
private void addPropertiesFromClassRec(XClass clazz) {
|
||||
|
||||
Audited allClassAudited = clazz.getAnnotation(Audited.class);
|
||||
|
||||
XClass superclazz = clazz.getSuperclass();
|
||||
if (!clazz.isInterface() && !"java.lang.Object".equals(superclazz.getName())) {
|
||||
addPropertiesFromClassRec(superclazz);
|
||||
}
|
||||
|
||||
addFromProperties(clazz.getDeclaredProperties("field"), "field", fieldAccessedPersistentProperties, allClassAudited);
|
||||
addFromProperties(clazz.getDeclaredProperties("property"), "property", propertyAccessedPersistentProperties, allClassAudited);
|
||||
}
|
||||
|
||||
private void addFromProperties(Iterable<XProperty> properties, String accessType, Set<String> persistentProperties, Audited allClassAudited) {
|
||||
for (XProperty property : properties) {
|
||||
// If this is not a persistent property, with the same access type as currently checked,
|
||||
// it's not audited as well.
|
||||
if (persistentProperties.contains(property.getName())) {
|
||||
// If the property was already defined by the subclass, is ignored by superclasses
|
||||
if ((persistentProperties.contains(property.getName()) && (!auditedPropertiesHolder
|
||||
.contains(property.getName())))) {
|
||||
Value propertyValue = persistentPropertiesSource.getProperty(property.getName()).getValue();
|
||||
|
||||
PropertyAuditingData propertyData;
|
||||
boolean isAudited;
|
||||
if (propertyValue instanceof Component) {
|
||||
ComponentAuditingData componentData = new ComponentAuditingData();
|
||||
isAudited = fillPropertyData(property, componentData, accessType);
|
||||
|
||||
PersistentPropertiesSource componentPropertiesSource = new ComponentPropertiesSource(
|
||||
(Component) propertyValue);
|
||||
new AuditedPropertiesReader(ModificationStore.FULL, componentPropertiesSource, componentData,
|
||||
globalCfg, reflectionManager,
|
||||
propertyNamePrefix + MappingTools.createComponentPrefix(property.getName()))
|
||||
.read();
|
||||
|
||||
propertyData = componentData;
|
||||
this.addFromComponentProperty(property, accessType, (Component)propertyValue, allClassAudited);
|
||||
} else {
|
||||
propertyData = new PropertyAuditingData();
|
||||
isAudited = fillPropertyData(property, propertyData, accessType);
|
||||
}
|
||||
|
||||
if (isAudited) {
|
||||
// Now we know that the property is audited
|
||||
auditedPropertiesHolder.addPropertyAuditingData(property.getName(), propertyData);
|
||||
this.addFromNotComponentProperty(property, accessType, allClassAudited);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addFromComponentProperty(XProperty property,
|
||||
String accessType, Component propertyValue, Audited allClassAudited) {
|
||||
|
||||
ComponentAuditingData componentData = new ComponentAuditingData();
|
||||
boolean isAudited = fillPropertyData(property, componentData, accessType,
|
||||
allClassAudited);
|
||||
|
||||
PersistentPropertiesSource componentPropertiesSource = new ComponentPropertiesSource(
|
||||
(Component) propertyValue);
|
||||
|
||||
ComponentAuditedPropertiesReader audPropReader = new ComponentAuditedPropertiesReader(
|
||||
ModificationStore.FULL, componentPropertiesSource,
|
||||
componentData, globalCfg, reflectionManager, propertyNamePrefix
|
||||
+ MappingTools
|
||||
.createComponentPrefix(property.getName()));
|
||||
audPropReader.read();
|
||||
|
||||
if (isAudited) {
|
||||
// Now we know that the property is audited
|
||||
auditedPropertiesHolder.addPropertyAuditingData(property.getName(),
|
||||
componentData);
|
||||
}
|
||||
}
|
||||
|
||||
private void addFromNotComponentProperty(XProperty property, String accessType, Audited allClassAudited){
|
||||
PropertyAuditingData propertyData = new PropertyAuditingData();
|
||||
boolean isAudited = fillPropertyData(property, propertyData, accessType, allClassAudited);
|
||||
|
||||
if (isAudited) {
|
||||
// Now we know that the property is audited
|
||||
auditedPropertiesHolder.addPropertyAuditingData(property.getName(), propertyData);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks if a property is audited and if yes, fills all of its data.
|
||||
* @param property Property to check.
|
||||
|
@ -131,7 +167,7 @@ public class AuditedPropertiesReader {
|
|||
* @return False if this property is not audited.
|
||||
*/
|
||||
private boolean fillPropertyData(XProperty property, PropertyAuditingData propertyData,
|
||||
String accessType) {
|
||||
String accessType, Audited allClassAudited) {
|
||||
|
||||
// check if a property is declared as not audited to exclude it
|
||||
// useful if a class is audited but some properties should be excluded
|
||||
|
@ -149,19 +185,12 @@ public class AuditedPropertiesReader {
|
|||
}
|
||||
}
|
||||
|
||||
// Checking if this property is explicitly audited or if all properties are.
|
||||
Audited aud = property.getAnnotation(Audited.class);
|
||||
if (aud != null) {
|
||||
propertyData.setStore(aud.modStore());
|
||||
propertyData.setRelationTargetAuditMode(aud.targetAuditMode());
|
||||
} else {
|
||||
if (defaultStore != null) {
|
||||
propertyData.setStore(defaultStore);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!this.checkAudited(property, propertyData, allClassAudited)){
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
propertyData.setName(propertyNamePrefix + property.getName());
|
||||
propertyData.setBeanName(property.getName());
|
||||
propertyData.setAccessType(accessType);
|
||||
|
@ -177,6 +206,21 @@ public class AuditedPropertiesReader {
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
protected boolean checkAudited(XProperty property,
|
||||
PropertyAuditingData propertyData, Audited allClassAudited) {
|
||||
// Checking if this property is explicitly audited or if all properties are.
|
||||
Audited aud = (property.isAnnotationPresent(Audited.class)) ? (property.getAnnotation(Audited.class)) : allClassAudited;
|
||||
//Audited aud = property.getAnnotation(Audited.class);
|
||||
if (aud != null) {
|
||||
propertyData.setStore(aud.modStore());
|
||||
propertyData.setRelationTargetAuditMode(aud.targetAuditMode());
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void setPropertyAuditMappedBy(XProperty property, PropertyAuditingData propertyData) {
|
||||
AuditMappedBy auditMappedBy = property.getAnnotation(AuditMappedBy.class);
|
||||
if (auditMappedBy != null) {
|
||||
|
|
|
@ -31,6 +31,7 @@ import static org.hibernate.envers.tools.Tools.*;
|
|||
/**
|
||||
* @author Adam Warski (adam at warski dot org)
|
||||
* @author Sebastian Komander
|
||||
* @author Hern&aacut;n Chanfreau
|
||||
*/
|
||||
public class ClassAuditingData implements AuditedPropertiesHolder {
|
||||
private final Map<String, PropertyAuditingData> properties;
|
||||
|
@ -49,6 +50,10 @@ public class ClassAuditingData implements AuditedPropertiesHolder {
|
|||
secondaryTableDictionary = newHashMap();
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return properties.isEmpty();
|
||||
}
|
||||
|
||||
public void addPropertyAuditingData(String propertyName, PropertyAuditingData auditingData) {
|
||||
properties.put(propertyName, auditingData);
|
||||
}
|
||||
|
@ -80,4 +85,8 @@ public class ClassAuditingData implements AuditedPropertiesHolder {
|
|||
public boolean isAudited() {
|
||||
return defaultAudited || properties.size() > 0;
|
||||
}
|
||||
|
||||
public boolean contains(String propertyName) {
|
||||
return properties.containsKey(propertyName);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
package org.hibernate.envers.configuration.metadata.reader;
|
||||
|
||||
import org.hibernate.annotations.common.reflection.ReflectionManager;
|
||||
import org.hibernate.annotations.common.reflection.XProperty;
|
||||
import org.hibernate.envers.Audited;
|
||||
import org.hibernate.envers.ModificationStore;
|
||||
import org.hibernate.envers.configuration.GlobalConfiguration;
|
||||
|
||||
/**
|
||||
* Reads the audited properties for components.
|
||||
*
|
||||
* @author Hern&aacut;n Chanfreau
|
||||
*
|
||||
*/
|
||||
public class ComponentAuditedPropertiesReader extends AuditedPropertiesReader {
|
||||
|
||||
public ComponentAuditedPropertiesReader(ModificationStore defaultStore,
|
||||
PersistentPropertiesSource persistentPropertiesSource,
|
||||
AuditedPropertiesHolder auditedPropertiesHolder,
|
||||
GlobalConfiguration globalCfg, ReflectionManager reflectionManager,
|
||||
String propertyNamePrefix) {
|
||||
super(defaultStore, persistentPropertiesSource, auditedPropertiesHolder,
|
||||
globalCfg, reflectionManager, propertyNamePrefix);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean checkAudited(XProperty property,
|
||||
PropertyAuditingData propertyData, Audited allClassAudited) {
|
||||
// Checking if this property is explicitly audited or if all properties are.
|
||||
Audited aud = property.getAnnotation(Audited.class);
|
||||
if (aud != null) {
|
||||
propertyData.setStore(aud.modStore());
|
||||
propertyData.setRelationTargetAuditMode(aud.targetAuditMode());
|
||||
} else {
|
||||
propertyData.setStore(ModificationStore.FULL);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -31,6 +31,7 @@ import java.util.Map;
|
|||
/**
|
||||
* Audit mapping meta-data for component.
|
||||
* @author Adam Warski (adam at warski dot org)
|
||||
* @author Hern&aacut;n Chanfreau
|
||||
*/
|
||||
public class ComponentAuditingData extends PropertyAuditingData implements AuditedPropertiesHolder {
|
||||
private final Map<String, PropertyAuditingData> properties;
|
||||
|
@ -39,6 +40,10 @@ public class ComponentAuditingData extends PropertyAuditingData implements Audit
|
|||
this.properties = newHashMap();
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return properties.isEmpty();
|
||||
}
|
||||
|
||||
public void addPropertyAuditingData(String propertyName, PropertyAuditingData auditingData) {
|
||||
properties.put(propertyName, auditingData);
|
||||
}
|
||||
|
@ -46,4 +51,8 @@ public class ComponentAuditingData extends PropertyAuditingData implements Audit
|
|||
public PropertyAuditingData getPropertyAuditingData(String propertyName) {
|
||||
return properties.get(propertyName);
|
||||
}
|
||||
|
||||
public boolean contains(String propertyName) {
|
||||
return properties.containsKey(propertyName);
|
||||
}
|
||||
}
|
|
@ -1,75 +0,0 @@
|
|||
/*
|
||||
* 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.superclass;
|
||||
|
||||
import java.util.Arrays;
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
import org.hibernate.envers.test.AbstractEntityTest;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import org.hibernate.ejb.Ejb3Configuration;
|
||||
|
||||
/**
|
||||
* @author Adam Warski (adam at warski dot org)
|
||||
*/
|
||||
public class MappedSubclassing extends AbstractEntityTest {
|
||||
private Integer id1;
|
||||
|
||||
public void configure(Ejb3Configuration cfg) {
|
||||
cfg.addAnnotatedClass(SubclassEntity.class);
|
||||
}
|
||||
|
||||
@BeforeClass(dependsOnMethods = "init")
|
||||
public void initData() {
|
||||
// Revision 1
|
||||
EntityManager em = getEntityManager();
|
||||
em.getTransaction().begin();
|
||||
SubclassEntity se1 = new SubclassEntity("x");
|
||||
em.persist(se1);
|
||||
id1 = se1.getId();
|
||||
em.getTransaction().commit();
|
||||
|
||||
// Revision 2
|
||||
em.getTransaction().begin();
|
||||
se1 = em.find(SubclassEntity.class, id1);
|
||||
se1.setStr("y");
|
||||
em.getTransaction().commit();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRevisionsCounts() {
|
||||
assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(SubclassEntity.class, id1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHistoryOfId1() {
|
||||
SubclassEntity ver1 = new SubclassEntity(id1, "x");
|
||||
SubclassEntity ver2 = new SubclassEntity(id1, "y");
|
||||
|
||||
assert getAuditReader().find(SubclassEntity.class, id1, 1).equals(ver1);
|
||||
assert getAuditReader().find(SubclassEntity.class, id1, 2).equals(ver2);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
* 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.superclass.auditAtMethodSuperclassLevel;
|
||||
|
||||
import javax.persistence.MappedSuperclass;
|
||||
|
||||
import org.hibernate.envers.Audited;
|
||||
|
||||
/**
|
||||
* @author Adam Warski (adam at warski dot org)
|
||||
*
|
||||
* @author Hern&aacut;n Chanfreau
|
||||
*/
|
||||
@MappedSuperclass
|
||||
public class AuditedMethodMappedSuperclass {
|
||||
|
||||
@Audited
|
||||
private String str;
|
||||
|
||||
private String otherStr;
|
||||
|
||||
public AuditedMethodMappedSuperclass() {
|
||||
}
|
||||
|
||||
public AuditedMethodMappedSuperclass(String str, String otherStr) {
|
||||
this.str = str;
|
||||
this.otherStr = otherStr;
|
||||
}
|
||||
|
||||
public String getStr() {
|
||||
return str;
|
||||
}
|
||||
|
||||
public void setStr(String str) {
|
||||
this.str = str;
|
||||
}
|
||||
|
||||
public String getOtherStr() {
|
||||
return otherStr;
|
||||
}
|
||||
|
||||
public void setOtherStr(String otherStr) {
|
||||
this.otherStr = otherStr;
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (this == o)
|
||||
return true;
|
||||
if (!(o instanceof AuditedMethodMappedSuperclass))
|
||||
return false;
|
||||
|
||||
AuditedMethodMappedSuperclass that = (AuditedMethodMappedSuperclass) o;
|
||||
|
||||
if (str != null ? !str.equals(that.str) : that.str != null)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return (str != null ? str.hashCode() : 0);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,96 @@
|
|||
/*
|
||||
* 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.superclass.auditAtMethodSuperclassLevel;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
|
||||
|
||||
/**
|
||||
* @author Adam Warski (adam at warski dot org)
|
||||
*
|
||||
* @author Hernán Chanfreau
|
||||
*
|
||||
*/
|
||||
@Entity
|
||||
public class NotAuditedSubclassEntity extends AuditedMethodMappedSuperclass {
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Integer id;
|
||||
|
||||
private String notAuditedStr;
|
||||
|
||||
public NotAuditedSubclassEntity() {
|
||||
}
|
||||
|
||||
public NotAuditedSubclassEntity(Integer id, String str, String otherStr, String notAuditedStr) {
|
||||
super(str, otherStr);
|
||||
this.notAuditedStr = notAuditedStr;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public NotAuditedSubclassEntity(String str, String otherStr, String notAuditedStr) {
|
||||
super(str, otherStr);
|
||||
this.notAuditedStr = notAuditedStr;
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getNotAuditedStr() {
|
||||
return notAuditedStr;
|
||||
}
|
||||
|
||||
public void setNotAuditedStr(String notAuditedStr) {
|
||||
this.notAuditedStr = notAuditedStr;
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (this == o)
|
||||
return true;
|
||||
if (!(o instanceof NotAuditedSubclassEntity))
|
||||
return false;
|
||||
if (!super.equals(o))
|
||||
return false;
|
||||
|
||||
NotAuditedSubclassEntity that = (NotAuditedSubclassEntity) o;
|
||||
|
||||
if (id != null ? !id.equals(that.id) : that.id != null)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
int result = super.hashCode();
|
||||
result = 31 * result + (id != null ? id.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
* 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.superclass.auditAtMethodSuperclassLevel.auditAllSubclass;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
|
||||
import org.hibernate.envers.Audited;
|
||||
import org.hibernate.envers.test.integration.superclass.auditAtMethodSuperclassLevel.AuditedMethodMappedSuperclass;
|
||||
|
||||
/**
|
||||
* @author Adam Warski (adam at warski dot org)
|
||||
* @author Hern&aacut;n Chanfreau
|
||||
*/
|
||||
@Entity
|
||||
@Audited
|
||||
public class AuditedAllSubclassEntity extends AuditedMethodMappedSuperclass {
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Integer id;
|
||||
|
||||
private String subAuditedStr;
|
||||
|
||||
|
||||
public AuditedAllSubclassEntity() {
|
||||
}
|
||||
|
||||
public AuditedAllSubclassEntity(Integer id, String str, String otherString, String subAuditedStr) {
|
||||
super(str, otherString);
|
||||
this.subAuditedStr = subAuditedStr;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public AuditedAllSubclassEntity(String str, String otherString, String subAuditedStr ) {
|
||||
super(str, otherString);
|
||||
this.subAuditedStr = subAuditedStr;
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getSubAuditedStr() {
|
||||
return subAuditedStr;
|
||||
}
|
||||
|
||||
public void setSubAuditedStr(String subAuditedStr) {
|
||||
this.subAuditedStr = subAuditedStr;
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof AuditedAllSubclassEntity)) return false;
|
||||
if (!super.equals(o)) return false;
|
||||
|
||||
AuditedAllSubclassEntity that = (AuditedAllSubclassEntity) o;
|
||||
|
||||
if (id != null ? !id.equals(that.id) : that.id != null) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
int result = super.hashCode();
|
||||
result = 31 * result + (id != null ? id.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,121 @@
|
|||
/*
|
||||
* 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.superclass.auditAtMethodSuperclassLevel.auditAllSubclass;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
import org.hibernate.ejb.Ejb3Configuration;
|
||||
import org.hibernate.envers.exception.NotAuditedException;
|
||||
import org.hibernate.envers.test.AbstractEntityTest;
|
||||
import org.hibernate.envers.test.integration.superclass.auditAtMethodSuperclassLevel.AuditedMethodMappedSuperclass;
|
||||
import org.hibernate.envers.test.integration.superclass.auditAtMethodSuperclassLevel.NotAuditedSubclassEntity;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* @author Adam Warski (adam at warski dot org)
|
||||
*
|
||||
* @author Hern&aacut;n Chanfreau
|
||||
*
|
||||
*/
|
||||
public class MappedSubclassingAllAuditedTest extends AbstractEntityTest {
|
||||
private Integer id2_1;
|
||||
private Integer id1_1;
|
||||
|
||||
public void configure(Ejb3Configuration cfg) {
|
||||
cfg.addAnnotatedClass(AuditedMethodMappedSuperclass.class);
|
||||
cfg.addAnnotatedClass(AuditedAllSubclassEntity.class);
|
||||
cfg.addAnnotatedClass(NotAuditedSubclassEntity.class);
|
||||
}
|
||||
|
||||
@BeforeClass(dependsOnMethods = "init")
|
||||
public void initData() {
|
||||
// Revision 1
|
||||
EntityManager em = getEntityManager();
|
||||
em.getTransaction().begin();
|
||||
NotAuditedSubclassEntity nas = new NotAuditedSubclassEntity("nae","super str","not audited str");
|
||||
em.persist(nas);
|
||||
AuditedAllSubclassEntity ae = new AuditedAllSubclassEntity("ae", "super str", "audited str");
|
||||
em.persist(ae);
|
||||
id1_1 = ae.getId();
|
||||
id2_1 = nas.getId();
|
||||
em.getTransaction().commit();
|
||||
|
||||
// Revision 2
|
||||
em.getTransaction().begin();
|
||||
ae = em.find(AuditedAllSubclassEntity.class, id1_1);
|
||||
ae.setStr("ae new");
|
||||
ae.setSubAuditedStr("audited str new");
|
||||
nas = em.find(NotAuditedSubclassEntity.class, id2_1);
|
||||
nas.setStr("nae new");
|
||||
nas.setNotAuditedStr("not aud str new");
|
||||
em.getTransaction().commit();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRevisionsCountsForAudited() {
|
||||
assert Arrays.asList(1, 2).equals(
|
||||
getAuditReader().getRevisions(AuditedAllSubclassEntity.class, id1_1));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions={ NotAuditedException.class })
|
||||
public void testRevisionsCountsForNotAudited() {
|
||||
try {
|
||||
getAuditReader().getRevisions(NotAuditedSubclassEntity.class, id2_1);
|
||||
assert(false);
|
||||
} catch (NotAuditedException nae) {
|
||||
throw nae;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testHistoryOfAudited() {
|
||||
AuditedAllSubclassEntity ver1 = new AuditedAllSubclassEntity(id1_1, "ae", "super str", "audited str");
|
||||
AuditedAllSubclassEntity ver2 = new AuditedAllSubclassEntity(id1_1, "ae new", "super str", "audited str new");
|
||||
|
||||
AuditedAllSubclassEntity rev1 = getAuditReader().find(AuditedAllSubclassEntity.class, id1_1, 1);
|
||||
AuditedAllSubclassEntity rev2 = getAuditReader().find(AuditedAllSubclassEntity.class, id1_1, 2);
|
||||
|
||||
//this property is not audited on superclass
|
||||
assert(rev1.getOtherStr() == null);
|
||||
assert(rev2.getOtherStr() == null);
|
||||
|
||||
assert rev1.equals(ver1);
|
||||
assert rev2.equals(ver2);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions={ NotAuditedException.class })
|
||||
public void testHistoryOfNotAudited() {
|
||||
try {
|
||||
getAuditReader().find(NotAuditedSubclassEntity.class, id2_1, 1);
|
||||
assert(false);
|
||||
} catch (NotAuditedException nae) {
|
||||
throw nae;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
* 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.superclass.auditAtMethodSuperclassLevel.auditMethodSubclass;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
|
||||
import org.hibernate.envers.Audited;
|
||||
import org.hibernate.envers.test.integration.superclass.auditAtMethodSuperclassLevel.AuditedMethodMappedSuperclass;
|
||||
|
||||
/**
|
||||
* @author Adam Warski (adam at warski dot org)
|
||||
* @author Hern&aacut;n Chanfreau
|
||||
*/
|
||||
@Entity
|
||||
public class AuditedMethodSubclassEntity extends AuditedMethodMappedSuperclass {
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Integer id;
|
||||
|
||||
@Audited
|
||||
private String subAuditedStr;
|
||||
|
||||
|
||||
public AuditedMethodSubclassEntity() {
|
||||
}
|
||||
|
||||
public AuditedMethodSubclassEntity(Integer id, String str, String otherString, String subAuditedStr) {
|
||||
super(str, otherString);
|
||||
this.subAuditedStr = subAuditedStr;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public AuditedMethodSubclassEntity(String str, String otherString, String subAuditedStr ) {
|
||||
super(str, otherString);
|
||||
this.subAuditedStr = subAuditedStr;
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getSubAuditedStr() {
|
||||
return subAuditedStr;
|
||||
}
|
||||
|
||||
public void setSubAuditedStr(String subAuditedStr) {
|
||||
this.subAuditedStr = subAuditedStr;
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof AuditedMethodSubclassEntity)) return false;
|
||||
if (!super.equals(o)) return false;
|
||||
|
||||
AuditedMethodSubclassEntity that = (AuditedMethodSubclassEntity) o;
|
||||
|
||||
if (id != null ? !id.equals(that.id) : that.id != null) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
int result = super.hashCode();
|
||||
result = 31 * result + (id != null ? id.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,121 @@
|
|||
/*
|
||||
* 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.superclass.auditAtMethodSuperclassLevel.auditMethodSubclass;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
import org.hibernate.ejb.Ejb3Configuration;
|
||||
import org.hibernate.envers.exception.NotAuditedException;
|
||||
import org.hibernate.envers.test.AbstractEntityTest;
|
||||
import org.hibernate.envers.test.integration.superclass.auditAtMethodSuperclassLevel.AuditedMethodMappedSuperclass;
|
||||
import org.hibernate.envers.test.integration.superclass.auditAtMethodSuperclassLevel.NotAuditedSubclassEntity;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* @author Adam Warski (adam at warski dot org)
|
||||
*
|
||||
* @author Hern&aacut;n Chanfreau
|
||||
*
|
||||
*/
|
||||
public class MappedSubclassingMethodAuditedTest extends AbstractEntityTest {
|
||||
private Integer id2_1;
|
||||
private Integer id1_1;
|
||||
|
||||
public void configure(Ejb3Configuration cfg) {
|
||||
cfg.addAnnotatedClass(AuditedMethodMappedSuperclass.class);
|
||||
cfg.addAnnotatedClass(AuditedMethodSubclassEntity.class);
|
||||
cfg.addAnnotatedClass(NotAuditedSubclassEntity.class);
|
||||
}
|
||||
|
||||
@BeforeClass(dependsOnMethods = "init")
|
||||
public void initData() {
|
||||
// Revision 1
|
||||
EntityManager em = getEntityManager();
|
||||
em.getTransaction().begin();
|
||||
NotAuditedSubclassEntity nas = new NotAuditedSubclassEntity("nae","super str","not audited str");
|
||||
em.persist(nas);
|
||||
AuditedMethodSubclassEntity ae = new AuditedMethodSubclassEntity("ae", "super str", "audited str");
|
||||
em.persist(ae);
|
||||
id1_1 = ae.getId();
|
||||
id2_1 = nas.getId();
|
||||
em.getTransaction().commit();
|
||||
|
||||
// Revision 2
|
||||
em.getTransaction().begin();
|
||||
ae = em.find(AuditedMethodSubclassEntity.class, id1_1);
|
||||
ae.setStr("ae new");
|
||||
ae.setSubAuditedStr("audited str new");
|
||||
nas = em.find(NotAuditedSubclassEntity.class, id2_1);
|
||||
nas.setStr("nae new");
|
||||
nas.setNotAuditedStr("not aud str new");
|
||||
em.getTransaction().commit();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRevisionsCountsForAudited() {
|
||||
assert Arrays.asList(1, 2).equals(
|
||||
getAuditReader().getRevisions(AuditedMethodSubclassEntity.class, id1_1));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions={ NotAuditedException.class })
|
||||
public void testRevisionsCountsForNotAudited() {
|
||||
try {
|
||||
getAuditReader().getRevisions(NotAuditedSubclassEntity.class, id2_1);
|
||||
assert(false);
|
||||
} catch (NotAuditedException nae) {
|
||||
throw nae;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testHistoryOfAudited() {
|
||||
AuditedMethodSubclassEntity ver1 = new AuditedMethodSubclassEntity(id1_1, "ae", "super str", "audited str");
|
||||
AuditedMethodSubclassEntity ver2 = new AuditedMethodSubclassEntity(id1_1, "ae new", "super str", "audited str new");
|
||||
|
||||
AuditedMethodSubclassEntity rev1 = getAuditReader().find(AuditedMethodSubclassEntity.class, id1_1, 1);
|
||||
AuditedMethodSubclassEntity rev2 = getAuditReader().find(AuditedMethodSubclassEntity.class, id1_1, 2);
|
||||
|
||||
//this property is not audited on superclass
|
||||
assert(rev1.getOtherStr() == null);
|
||||
assert(rev2.getOtherStr() == null);
|
||||
|
||||
assert rev1.equals(ver1);
|
||||
assert rev2.equals(ver2);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions={ NotAuditedException.class })
|
||||
public void testHistoryOfNotAudited() {
|
||||
try {
|
||||
getAuditReader().find(NotAuditedSubclassEntity.class, id2_1, 1);
|
||||
assert(false);
|
||||
} catch (NotAuditedException nae) {
|
||||
throw nae;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -21,7 +21,7 @@
|
|||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.envers.test.integration.superclass;
|
||||
package org.hibernate.envers.test.integration.superclass.auditedAtSuperclassLevel;
|
||||
|
||||
import javax.persistence.MappedSuperclass;
|
||||
|
||||
|
@ -29,39 +29,56 @@ import org.hibernate.envers.Audited;
|
|||
|
||||
/**
|
||||
* @author Adam Warski (adam at warski dot org)
|
||||
*
|
||||
* @author Hern&aacut;n Chanfreau
|
||||
*/
|
||||
@MappedSuperclass
|
||||
public class SuperclassOfEntity {
|
||||
@Audited
|
||||
private String str;
|
||||
@Audited
|
||||
public class AuditedAllMappedSuperclass {
|
||||
|
||||
public SuperclassOfEntity() {
|
||||
}
|
||||
private String str;
|
||||
|
||||
public SuperclassOfEntity(String str) {
|
||||
this.str = str;
|
||||
}
|
||||
private String otherStr;
|
||||
|
||||
public String getStr() {
|
||||
return str;
|
||||
}
|
||||
public AuditedAllMappedSuperclass() {
|
||||
}
|
||||
|
||||
public void setStr(String str) {
|
||||
this.str = str;
|
||||
}
|
||||
public AuditedAllMappedSuperclass(String str, String otherStr) {
|
||||
this.str = str;
|
||||
this.otherStr = otherStr;
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof SuperclassOfEntity)) return false;
|
||||
public String getStr() {
|
||||
return str;
|
||||
}
|
||||
|
||||
SuperclassOfEntity that = (SuperclassOfEntity) o;
|
||||
public void setStr(String str) {
|
||||
this.str = str;
|
||||
}
|
||||
|
||||
if (str != null ? !str.equals(that.str) : that.str != null) return false;
|
||||
public String getOtherStr() {
|
||||
return otherStr;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
public void setOtherStr(String otherStr) {
|
||||
this.otherStr = otherStr;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return (str != null ? str.hashCode() : 0);
|
||||
}
|
||||
public boolean equals(Object o) {
|
||||
if (this == o)
|
||||
return true;
|
||||
if (!(o instanceof AuditedAllMappedSuperclass))
|
||||
return false;
|
||||
|
||||
AuditedAllMappedSuperclass that = (AuditedAllMappedSuperclass) o;
|
||||
|
||||
if (str != null ? !str.equals(that.str) : that.str != null)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return (str != null ? str.hashCode() : 0);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,96 @@
|
|||
/*
|
||||
* 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.superclass.auditedAtSuperclassLevel;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
|
||||
|
||||
/**
|
||||
* @author Adam Warski (adam at warski dot org)
|
||||
*
|
||||
* @author Hernán Chanfreau
|
||||
*
|
||||
*/
|
||||
@Entity
|
||||
public class NotAuditedSubclassEntity extends AuditedAllMappedSuperclass {
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Integer id;
|
||||
|
||||
private String notAuditedStr;
|
||||
|
||||
public NotAuditedSubclassEntity() {
|
||||
}
|
||||
|
||||
public NotAuditedSubclassEntity(Integer id, String str, String otherStr, String notAuditedStr) {
|
||||
super(str, otherStr);
|
||||
this.notAuditedStr = notAuditedStr;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public NotAuditedSubclassEntity(String str, String otherStr, String notAuditedStr) {
|
||||
super(str, otherStr);
|
||||
this.notAuditedStr = notAuditedStr;
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getNotAuditedStr() {
|
||||
return notAuditedStr;
|
||||
}
|
||||
|
||||
public void setNotAuditedStr(String notAuditedStr) {
|
||||
this.notAuditedStr = notAuditedStr;
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (this == o)
|
||||
return true;
|
||||
if (!(o instanceof NotAuditedSubclassEntity))
|
||||
return false;
|
||||
if (!super.equals(o))
|
||||
return false;
|
||||
|
||||
NotAuditedSubclassEntity that = (NotAuditedSubclassEntity) o;
|
||||
|
||||
if (id != null ? !id.equals(that.id) : that.id != null)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
int result = super.hashCode();
|
||||
result = 31 * result + (id != null ? id.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -21,31 +21,41 @@
|
|||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.envers.test.integration.superclass;
|
||||
package org.hibernate.envers.test.integration.superclass.auditedAtSuperclassLevel.auditAllSubclass;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
|
||||
import org.hibernate.envers.Audited;
|
||||
import org.hibernate.envers.test.integration.superclass.auditedAtSuperclassLevel.AuditedAllMappedSuperclass;
|
||||
|
||||
/**
|
||||
* @author Adam Warski (adam at warski dot org)
|
||||
* @author Hern&aacut;n Chanfreau
|
||||
*/
|
||||
@Entity
|
||||
public class SubclassEntity extends SuperclassOfEntity {
|
||||
@Audited
|
||||
public class AuditedAllSubclassEntity extends AuditedAllMappedSuperclass {
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Integer id;
|
||||
|
||||
public SubclassEntity() {
|
||||
private String subAuditedStr;
|
||||
|
||||
|
||||
public AuditedAllSubclassEntity() {
|
||||
}
|
||||
|
||||
public SubclassEntity(Integer id, String str) {
|
||||
super(str);
|
||||
public AuditedAllSubclassEntity(Integer id, String str, String otherString, String subAuditedStr) {
|
||||
super(str, otherString);
|
||||
this.subAuditedStr = subAuditedStr;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public SubclassEntity(String str) {
|
||||
super(str);
|
||||
public AuditedAllSubclassEntity(String str, String otherString, String subAuditedStr ) {
|
||||
super(str, otherString);
|
||||
this.subAuditedStr = subAuditedStr;
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
|
@ -56,12 +66,20 @@ public class SubclassEntity extends SuperclassOfEntity {
|
|||
this.id = id;
|
||||
}
|
||||
|
||||
public String getSubAuditedStr() {
|
||||
return subAuditedStr;
|
||||
}
|
||||
|
||||
public void setSubAuditedStr(String subAuditedStr) {
|
||||
this.subAuditedStr = subAuditedStr;
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof SubclassEntity)) return false;
|
||||
if (!(o instanceof AuditedAllSubclassEntity)) return false;
|
||||
if (!super.equals(o)) return false;
|
||||
|
||||
SubclassEntity that = (SubclassEntity) o;
|
||||
AuditedAllSubclassEntity that = (AuditedAllSubclassEntity) o;
|
||||
|
||||
if (id != null ? !id.equals(that.id) : that.id != null) return false;
|
||||
|
|
@ -0,0 +1,120 @@
|
|||
/*
|
||||
* 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.superclass.auditedAtSuperclassLevel.auditAllSubclass;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
import org.hibernate.ejb.Ejb3Configuration;
|
||||
import org.hibernate.envers.exception.NotAuditedException;
|
||||
import org.hibernate.envers.test.AbstractEntityTest;
|
||||
import org.hibernate.envers.test.integration.superclass.auditedAtSuperclassLevel.AuditedAllMappedSuperclass;
|
||||
import org.hibernate.envers.test.integration.superclass.auditedAtSuperclassLevel.NotAuditedSubclassEntity;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* @author Adam Warski (adam at warski dot org)
|
||||
*
|
||||
* @author Hern&aacut;n Chanfreau
|
||||
*
|
||||
*/
|
||||
public class MappedSubclassingAllAuditedTest extends AbstractEntityTest {
|
||||
private Integer id2_1;
|
||||
private Integer id1_1;
|
||||
|
||||
public void configure(Ejb3Configuration cfg) {
|
||||
cfg.addAnnotatedClass(AuditedAllMappedSuperclass.class);
|
||||
cfg.addAnnotatedClass(AuditedAllSubclassEntity.class);
|
||||
cfg.addAnnotatedClass(NotAuditedSubclassEntity.class);
|
||||
}
|
||||
|
||||
@BeforeClass(dependsOnMethods = "init")
|
||||
public void initData() {
|
||||
// Revision 1
|
||||
EntityManager em = getEntityManager();
|
||||
em.getTransaction().begin();
|
||||
NotAuditedSubclassEntity nas = new NotAuditedSubclassEntity("nae","super str","not audited str");
|
||||
em.persist(nas);
|
||||
AuditedAllSubclassEntity ae = new AuditedAllSubclassEntity("ae", "super str", "audited str");
|
||||
em.persist(ae);
|
||||
id1_1 = ae.getId();
|
||||
id2_1 = nas.getId();
|
||||
em.getTransaction().commit();
|
||||
|
||||
// Revision 2
|
||||
em.getTransaction().begin();
|
||||
ae = em.find(AuditedAllSubclassEntity.class, id1_1);
|
||||
ae.setStr("ae new");
|
||||
ae.setSubAuditedStr("audited str new");
|
||||
nas = em.find(NotAuditedSubclassEntity.class, id2_1);
|
||||
nas.setStr("nae new");
|
||||
nas.setNotAuditedStr("not aud str new");
|
||||
em.getTransaction().commit();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRevisionsCountsForAudited() {
|
||||
assert Arrays.asList(1, 2).equals(
|
||||
getAuditReader().getRevisions(AuditedAllSubclassEntity.class, id1_1));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions={ NotAuditedException.class })
|
||||
public void testRevisionsCountsForNotAudited() {
|
||||
try {
|
||||
getAuditReader().getRevisions(NotAuditedSubclassEntity.class, id2_1);
|
||||
assert(false);
|
||||
} catch (NotAuditedException nae) {
|
||||
throw nae;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testHistoryOfAudited() {
|
||||
AuditedAllSubclassEntity ver1 = new AuditedAllSubclassEntity(id1_1, "ae", "super str", "audited str");
|
||||
AuditedAllSubclassEntity ver2 = new AuditedAllSubclassEntity(id1_1, "ae new", "super str", "audited str new");
|
||||
|
||||
AuditedAllSubclassEntity rev1 = getAuditReader().find(AuditedAllSubclassEntity.class, id1_1, 1);
|
||||
AuditedAllSubclassEntity rev2 = getAuditReader().find(AuditedAllSubclassEntity.class, id1_1, 2);
|
||||
|
||||
assert(rev1.getOtherStr() != null);
|
||||
assert(rev2.getOtherStr() != null);
|
||||
|
||||
assert rev1.equals(ver1);
|
||||
assert rev2.equals(ver2);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions={ NotAuditedException.class })
|
||||
public void testHistoryOfNotAudited() {
|
||||
try {
|
||||
getAuditReader().find(NotAuditedSubclassEntity.class, id2_1, 1);
|
||||
assert(false);
|
||||
} catch (NotAuditedException nae) {
|
||||
throw nae;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
* 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.superclass.auditedAtSuperclassLevel.auditMethodSubclass;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
|
||||
import org.hibernate.envers.Audited;
|
||||
import org.hibernate.envers.test.integration.superclass.auditedAtSuperclassLevel.AuditedAllMappedSuperclass;
|
||||
|
||||
/**
|
||||
* @author Adam Warski (adam at warski dot org)
|
||||
* @author Hern&aacut;n Chanfreau
|
||||
*/
|
||||
@Entity
|
||||
public class AuditedMethodSubclassEntity extends AuditedAllMappedSuperclass {
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Integer id;
|
||||
|
||||
@Audited
|
||||
private String subAuditedStr;
|
||||
|
||||
|
||||
public AuditedMethodSubclassEntity() {
|
||||
}
|
||||
|
||||
public AuditedMethodSubclassEntity(Integer id, String str, String otherString, String subAuditedStr) {
|
||||
super(str, otherString);
|
||||
this.subAuditedStr = subAuditedStr;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public AuditedMethodSubclassEntity(String str, String otherString, String subAuditedStr ) {
|
||||
super(str, otherString);
|
||||
this.subAuditedStr = subAuditedStr;
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getSubAuditedStr() {
|
||||
return subAuditedStr;
|
||||
}
|
||||
|
||||
public void setSubAuditedStr(String subAuditedStr) {
|
||||
this.subAuditedStr = subAuditedStr;
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof AuditedMethodSubclassEntity)) return false;
|
||||
if (!super.equals(o)) return false;
|
||||
|
||||
AuditedMethodSubclassEntity that = (AuditedMethodSubclassEntity) o;
|
||||
|
||||
if (id != null ? !id.equals(that.id) : that.id != null) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
int result = super.hashCode();
|
||||
result = 31 * result + (id != null ? id.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,120 @@
|
|||
/*
|
||||
* 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.superclass.auditedAtSuperclassLevel.auditMethodSubclass;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
import org.hibernate.ejb.Ejb3Configuration;
|
||||
import org.hibernate.envers.exception.NotAuditedException;
|
||||
import org.hibernate.envers.test.AbstractEntityTest;
|
||||
import org.hibernate.envers.test.integration.superclass.auditedAtSuperclassLevel.AuditedAllMappedSuperclass;
|
||||
import org.hibernate.envers.test.integration.superclass.auditedAtSuperclassLevel.NotAuditedSubclassEntity;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* @author Adam Warski (adam at warski dot org)
|
||||
*
|
||||
* @author Hern&aacut;n Chanfreau
|
||||
*
|
||||
*/
|
||||
public class MappedSubclassingMethodAuditedTest extends AbstractEntityTest {
|
||||
private Integer id2_1;
|
||||
private Integer id1_1;
|
||||
|
||||
public void configure(Ejb3Configuration cfg) {
|
||||
cfg.addAnnotatedClass(AuditedAllMappedSuperclass.class);
|
||||
cfg.addAnnotatedClass(AuditedMethodSubclassEntity.class);
|
||||
cfg.addAnnotatedClass(NotAuditedSubclassEntity.class);
|
||||
}
|
||||
|
||||
@BeforeClass(dependsOnMethods = "init")
|
||||
public void initData() {
|
||||
// Revision 1
|
||||
EntityManager em = getEntityManager();
|
||||
em.getTransaction().begin();
|
||||
NotAuditedSubclassEntity nas = new NotAuditedSubclassEntity("nae","super str","not audited str");
|
||||
em.persist(nas);
|
||||
AuditedMethodSubclassEntity ae = new AuditedMethodSubclassEntity("ae", "super str", "audited str");
|
||||
em.persist(ae);
|
||||
id1_1 = ae.getId();
|
||||
id2_1 = nas.getId();
|
||||
em.getTransaction().commit();
|
||||
|
||||
// Revision 2
|
||||
em.getTransaction().begin();
|
||||
ae = em.find(AuditedMethodSubclassEntity.class, id1_1);
|
||||
ae.setStr("ae new");
|
||||
ae.setSubAuditedStr("audited str new");
|
||||
nas = em.find(NotAuditedSubclassEntity.class, id2_1);
|
||||
nas.setStr("nae new");
|
||||
nas.setNotAuditedStr("not aud str new");
|
||||
em.getTransaction().commit();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRevisionsCountsForAudited() {
|
||||
assert Arrays.asList(1, 2).equals(
|
||||
getAuditReader().getRevisions(AuditedMethodSubclassEntity.class, id1_1));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions={ NotAuditedException.class })
|
||||
public void testRevisionsCountsForNotAudited() {
|
||||
try {
|
||||
getAuditReader().getRevisions(NotAuditedSubclassEntity.class, id2_1);
|
||||
assert(false);
|
||||
} catch (NotAuditedException nae) {
|
||||
throw nae;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testHistoryOfAudited() {
|
||||
AuditedMethodSubclassEntity ver1 = new AuditedMethodSubclassEntity(id1_1, "ae", "super str", "audited str");
|
||||
AuditedMethodSubclassEntity ver2 = new AuditedMethodSubclassEntity(id1_1, "ae new", "super str", "audited str new");
|
||||
|
||||
AuditedMethodSubclassEntity rev1 = getAuditReader().find(AuditedMethodSubclassEntity.class, id1_1, 1);
|
||||
AuditedMethodSubclassEntity rev2 = getAuditReader().find(AuditedMethodSubclassEntity.class, id1_1, 2);
|
||||
|
||||
assert(rev1.getOtherStr() != null);
|
||||
assert(rev2.getOtherStr() != null);
|
||||
|
||||
assert rev1.equals(ver1);
|
||||
assert rev2.equals(ver2);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions={ NotAuditedException.class })
|
||||
public void testHistoryOfNotAudited() {
|
||||
try {
|
||||
getAuditReader().find(NotAuditedSubclassEntity.class, id2_1, 1);
|
||||
assert(false);
|
||||
} catch (NotAuditedException nae) {
|
||||
throw nae;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -69,7 +69,12 @@
|
|||
<package name="org.hibernate.envers.test.integration.secondary.ids" />
|
||||
<package name="org.hibernate.envers.test.integration.serialization" />
|
||||
<package name="org.hibernate.envers.test.integration.strategy" />
|
||||
<package name="org.hibernate.envers.test.integration.superclass" />
|
||||
|
||||
<package name="org.hibernate.envers.test.integration.superclass.auditAtMethodSuperclassLevel" />
|
||||
<package name="org.hibernate.envers.test.integration.superclass.auditAtMethodSuperclassLevel.auditAllSubclass" />
|
||||
<package name="org.hibernate.envers.test.integration.superclass.auditedAtSuperclassLevel.auditAllSubclass" />
|
||||
<package name="org.hibernate.envers.test.integration.superclass.auditedAtSuperclassLevel.auditMethodSubclass" />
|
||||
|
||||
<package name="org.hibernate.envers.test.integration.entityNames.auditedEntity" />
|
||||
<package name="org.hibernate.envers.test.integration.entityNames.manyToManyAudited" />
|
||||
<package name="org.hibernate.envers.test.integration.entityNames.oneToManyAudited" />
|
||||
|
|
Loading…
Reference in New Issue