HHH-8505: Reformating to hibernate code style

This commit is contained in:
zuchos 2013-09-30 19:37:25 +02:00 committed by adamw
parent 631616ec74
commit 03449c1d37
17 changed files with 868 additions and 775 deletions

View File

@ -23,12 +23,31 @@
*/
package org.hibernate.envers.configuration.internal.metadata.reader;
import java.lang.annotation.Annotation;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.persistence.JoinColumn;
import javax.persistence.MapKey;
import javax.persistence.OneToMany;
import javax.persistence.Version;
import org.hibernate.MappingException;
import org.hibernate.annotations.common.reflection.ReflectionManager;
import org.hibernate.annotations.common.reflection.XClass;
import org.hibernate.annotations.common.reflection.XProperty;
import org.hibernate.cfg.AccessType;
import org.hibernate.envers.*;
import org.hibernate.envers.AuditJoinTable;
import org.hibernate.envers.AuditMappedBy;
import org.hibernate.envers.AuditOverride;
import org.hibernate.envers.AuditOverrides;
import org.hibernate.envers.Audited;
import org.hibernate.envers.ModificationStore;
import org.hibernate.envers.NotAudited;
import org.hibernate.envers.RelationTargetAuditMode;
import org.hibernate.envers.configuration.internal.GlobalConfiguration;
import org.hibernate.envers.configuration.internal.metadata.MetadataTools;
import org.hibernate.envers.internal.tools.MappingTools;
@ -38,13 +57,6 @@ import org.hibernate.mapping.Component;
import org.hibernate.mapping.Property;
import org.hibernate.mapping.Value;
import javax.persistence.JoinColumn;
import javax.persistence.MapKey;
import javax.persistence.OneToMany;
import javax.persistence.Version;
import java.lang.annotation.Annotation;
import java.util.*;
import static org.hibernate.envers.internal.tools.Tools.newHashMap;
import static org.hibernate.envers.internal.tools.Tools.newHashSet;
@ -107,18 +119,19 @@ public class AuditedPropertiesReader {
// First reading the access types for the persistent properties.
readPersistentPropertiesAccess();
if (persistentPropertiesSource instanceof DynamicComponentSource) {
addPropertiesFromDynamicComponent((DynamicComponentSource) persistentPropertiesSource);
} else {
// Retrieve classes and properties that are explicitly marked for auditing process by any superclass
// of currently mapped entity or itself.
final XClass clazz = persistentPropertiesSource.getXClass();
readAuditOverrides( clazz );
if ( persistentPropertiesSource instanceof DynamicComponentSource ) {
addPropertiesFromDynamicComponent( (DynamicComponentSource) persistentPropertiesSource );
}
else {
// Retrieve classes and properties that are explicitly marked for auditing process by any superclass
// of currently mapped entity or itself.
final XClass clazz = persistentPropertiesSource.getXClass();
readAuditOverrides( clazz );
// Adding all properties from the given class.
addPropertiesFromClass( clazz );
}
}
// Adding all properties from the given class.
addPropertiesFromClass( clazz );
}
}
/**
* Recursively constructs sets of audited and not audited properties and classes which behavior has been overridden
@ -139,7 +152,7 @@ public class AuditedPropertiesReader {
}
}
}
/* TODO: Code to remove with @Audited.auditParents - finish. */
/* TODO: Code to remove with @Audited.auditParents - finish. */
final List<AuditOverride> auditOverrides = computeAuditOverrides( clazz );
for ( AuditOverride auditOverride : auditOverrides ) {
if ( auditOverride.forClass() != void.class ) {
@ -303,41 +316,52 @@ public class AuditedPropertiesReader {
return allClassAudited;
}
private void addPropertiesFromDynamicComponent(DynamicComponentSource dynamicComponentSource) {
Audited audited = computeAuditConfiguration(dynamicComponentSource.getXClass());
if(!fieldAccessedPersistentProperties.isEmpty()) {
//TODO ŁŻ hmm... for sure ?
throw new MappingException("Dynamic component cannot have field accessed persistent properties");
}
for (String property : propertyAccessedPersistentProperties) {
// If this is not a persistent property, with the same access type as currently checked,
// it's not audited as well.
// If the property was already defined by the subclass, is ignored by superclasses
String accessType = AccessType.PROPERTY.getType();
if (!auditedPropertiesHolder.contains(property)) {
final Value propertyValue = persistentPropertiesSource.getProperty(property).getValue();
if (propertyValue instanceof Component) {
this.addFromComponentProperty(new DynamicProperty(dynamicComponentSource, property), accessType, (Component) propertyValue, audited);
} else {
this.addFromNotComponentProperty(new DynamicProperty(dynamicComponentSource, property), accessType, audited);
}
} else if (propertiesGroupMapping.containsKey(property)) {
//todo ŁŻ - I'm not sure is that the case that we should handle for dynamic component.
// Retrieve embedded component name based on class field.
final String embeddedName = propertiesGroupMapping.get(property);
if (!auditedPropertiesHolder.contains(embeddedName)) {
// Manage properties mapped within <properties> tag.
final Value propertyValue = persistentPropertiesSource.getProperty(embeddedName).getValue();
this.addFromPropertiesGroup(
embeddedName,
new DynamicProperty(dynamicComponentSource, property), accessType,
(Component) propertyValue,
audited
);
}
}
}
}
private void addPropertiesFromDynamicComponent(DynamicComponentSource dynamicComponentSource) {
Audited audited = computeAuditConfiguration( dynamicComponentSource.getXClass() );
if ( !fieldAccessedPersistentProperties.isEmpty() ) {
//TODO ŁŻ hmm... for sure ?
throw new MappingException( "Dynamic component cannot have field accessed persistent properties" );
}
for ( String property : propertyAccessedPersistentProperties ) {
// If this is not a persistent property, with the same access type as currently checked,
// it's not audited as well.
// If the property was already defined by the subclass, is ignored by superclasses
String accessType = AccessType.PROPERTY.getType();
if ( !auditedPropertiesHolder.contains( property ) ) {
final Value propertyValue = persistentPropertiesSource.getProperty( property ).getValue();
if ( propertyValue instanceof Component ) {
this.addFromComponentProperty(
new DynamicProperty( dynamicComponentSource, property ),
accessType,
(Component) propertyValue,
audited
);
}
else {
this.addFromNotComponentProperty(
new DynamicProperty( dynamicComponentSource, property ),
accessType,
audited
);
}
}
else if ( propertiesGroupMapping.containsKey( property ) ) {
//todo ŁŻ - I'm not sure is that the case that we should handle for dynamic component.
// Retrieve embedded component name based on class field.
final String embeddedName = propertiesGroupMapping.get( property );
if ( !auditedPropertiesHolder.contains( embeddedName ) ) {
// Manage properties mapped within <properties> tag.
final Value propertyValue = persistentPropertiesSource.getProperty( embeddedName ).getValue();
this.addFromPropertiesGroup(
embeddedName,
new DynamicProperty( dynamicComponentSource, property ), accessType,
(Component) propertyValue,
audited
);
}
}
}
}
/**
* Recursively adds all audited properties of entity class and its superclasses.
@ -347,7 +371,7 @@ public class AuditedPropertiesReader {
private void addPropertiesFromClass(XClass clazz) {
final Audited allClassAudited = computeAuditConfiguration( clazz );
//look in the class
//look in the class
addFromProperties(
clazz.getDeclaredProperties( "field" ),
"field",
@ -434,36 +458,37 @@ public class AuditedPropertiesReader {
}
}
private void addFromComponentProperty(
XProperty property,
String accessType,
Component propertyValue,
Audited allClassAudited) {
final ComponentAuditingData componentData = new ComponentAuditingData();
final boolean isAudited = fillPropertyData(property, componentData, accessType, allClassAudited);
private void addFromComponentProperty(
XProperty property,
String accessType,
Component propertyValue,
Audited allClassAudited) {
final ComponentAuditingData componentData = new ComponentAuditingData();
final boolean isAudited = fillPropertyData( property, componentData, accessType, allClassAudited );
final PersistentPropertiesSource componentPropertiesSource;
if (propertyValue.isDynamic()) {
componentPropertiesSource = new DynamicComponentSource(reflectionManager, propertyValue, property);
} else {
componentPropertiesSource = new ComponentPropertiesSource(reflectionManager, propertyValue);
}
final PersistentPropertiesSource componentPropertiesSource;
if ( propertyValue.isDynamic() ) {
componentPropertiesSource = new DynamicComponentSource( reflectionManager, propertyValue, property );
}
else {
componentPropertiesSource = new ComponentPropertiesSource( reflectionManager, propertyValue );
}
final ComponentAuditedPropertiesReader audPropReader = new ComponentAuditedPropertiesReader(
ModificationStore.FULL,
componentPropertiesSource,
componentData,
globalCfg,
reflectionManager,
propertyNamePrefix + MappingTools.createComponentPrefix(property.getName())
);
audPropReader.read();
final 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);
}
}
if ( isAudited ) {
// Now we know that the property is audited
auditedPropertiesHolder.addPropertyAuditingData( property.getName(), componentData );
}
}
private void addFromNotComponentProperty(XProperty property, String accessType, Audited allClassAudited) {
final PropertyAuditingData propertyData = new PropertyAuditingData();
@ -494,8 +519,8 @@ public class AuditedPropertiesReader {
// check if a property is declared as not audited to exclude it
// useful if a class is audited but some properties should be excluded
final NotAudited unVer = property.getAnnotation( NotAudited.class );
if ( (unVer != null
&& !overriddenAuditedProperties.contains( property ))
if ( ( unVer != null
&& !overriddenAuditedProperties.contains( property ) )
|| overriddenNotAuditedProperties.contains( property ) ) {
return false;
}
@ -544,7 +569,7 @@ public class AuditedPropertiesReader {
XProperty property,
PropertyAuditingData propertyData, Audited allClassAudited) {
// Checking if this property is explicitly audited or if all properties are.
Audited aud = (property.isAnnotationPresent( Audited.class ))
Audited aud = ( property.isAnnotationPresent( Audited.class ) )
? property.getAnnotation( Audited.class )
: allClassAudited;
if ( aud == null
@ -711,16 +736,16 @@ public class AuditedPropertiesReader {
private final XClass xclass;
private final Component component;
protected ComponentPropertiesSource(XClass xClazz, Component component) {
this.xclass = xClazz;
this.component = component;
}
protected ComponentPropertiesSource(XClass xClazz, Component component) {
this.xclass = xClazz;
this.component = component;
}
public ComponentPropertiesSource(ReflectionManager reflectionManager, Component component) {
try {
this.xclass = reflectionManager.classForName( component.getComponentClassName(), this.getClass() );
}
catch (ClassNotFoundException e) {
catch ( ClassNotFoundException e ) {
throw new MappingException( e );
}
@ -728,7 +753,7 @@ public class AuditedPropertiesReader {
}
@Override
@SuppressWarnings({"unchecked"})
@SuppressWarnings({ "unchecked" })
public Iterator<Property> getPropertyIterator() {
return component.getPropertyIterator();
}
@ -744,14 +769,14 @@ public class AuditedPropertiesReader {
}
}
public static class DynamicComponentSource extends ComponentPropertiesSource {
public static class DynamicComponentSource extends ComponentPropertiesSource {
private XProperty baseProperty;
private XProperty baseProperty;
public DynamicComponentSource(ReflectionManager reflectionManager, Component component, XProperty baseProperty) {
super(reflectionManager.toXClass(Map.class), component);
this.baseProperty = baseProperty;
}
}
public DynamicComponentSource(ReflectionManager reflectionManager, Component component, XProperty baseProperty) {
super( reflectionManager.toXClass( Map.class ), component );
this.baseProperty = baseProperty;
}
}
}

View File

@ -1,101 +1,102 @@
package org.hibernate.envers.configuration.internal.metadata.reader;
import org.hibernate.annotations.common.reflection.XClass;
import org.hibernate.annotations.common.reflection.XProperty;
import java.lang.annotation.Annotation;
import java.util.Collection;
import org.hibernate.annotations.common.reflection.XClass;
import org.hibernate.annotations.common.reflection.XProperty;
/**
* This class prenteds to be property but in fact it represents entry in the map (for dynamic component)
*
* @author Lukasz Zuchowski (author at zuchos dot com)
*/
public class DynamicProperty implements XProperty {
private AuditedPropertiesReader.DynamicComponentSource source;
private String propertyName;
private AuditedPropertiesReader.DynamicComponentSource source;
private String propertyName;
public DynamicProperty(AuditedPropertiesReader.DynamicComponentSource source, String propertyName) {
this.source = source;
this.propertyName = propertyName;
}
public DynamicProperty(AuditedPropertiesReader.DynamicComponentSource source, String propertyName) {
this.source = source;
this.propertyName = propertyName;
}
@Override
public XClass getDeclaringClass() {
return source.getXClass();
}
@Override
public XClass getDeclaringClass() {
return source.getXClass();
}
@Override
public String getName() {
return propertyName;
}
@Override
public String getName() {
return propertyName;
}
@Override
public boolean isCollection() {
return false;
}
@Override
public boolean isCollection() {
return false;
}
@Override
public boolean isArray() {
return false;
}
@Override
public boolean isArray() {
return false;
}
@Override
public Class<? extends Collection> getCollectionClass() {
return null;
}
@Override
public Class<? extends Collection> getCollectionClass() {
return null;
}
@Override
public XClass getType() {
return source.getXClass();
}
@Override
public XClass getType() {
return source.getXClass();
}
@Override
public XClass getElementClass() {
return null;
}
@Override
public XClass getElementClass() {
return null;
}
@Override
public XClass getClassOrElementClass() {
return null;
}
@Override
public XClass getClassOrElementClass() {
return null;
}
@Override
public XClass getMapKey() {
return null;
}
@Override
public XClass getMapKey() {
return null;
}
@Override
public int getModifiers() {
return 0;
}
@Override
public int getModifiers() {
return 0;
}
@Override
public void setAccessible(boolean accessible) {
}
@Override
public void setAccessible(boolean accessible) {
}
@Override
public Object invoke(Object target, Object... parameters) {
return null;
}
@Override
public Object invoke(Object target, Object... parameters) {
return null;
}
@Override
public boolean isTypeResolved() {
return false;
}
@Override
public boolean isTypeResolved() {
return false;
}
@Override
public <T extends Annotation> T getAnnotation(Class<T> annotationType) {
return null;
}
@Override
public <T extends Annotation> T getAnnotation(Class<T> annotationType) {
return null;
}
@Override
public <T extends Annotation> boolean isAnnotationPresent(Class<T> annotationType) {
return false;
}
@Override
public <T extends Annotation> boolean isAnnotationPresent(Class<T> annotationType) {
return false;
}
@Override
public Annotation[] getAnnotations() {
return new Annotation[0];
}
@Override
public Annotation[] getAnnotations() {
return new Annotation[0];
}
}

View File

@ -48,17 +48,18 @@ public class ComponentPropertyMapper implements PropertyMapper, CompositeMapperB
private final MultiPropertyMapper delegate;
private final Class componentClass;
public ComponentPropertyMapper(PropertyData propertyData, Class componentClass) {
this.propertyData = propertyData;
//ŁŻ this could be done better
if (Map.class.equals(componentClass)) {
this.delegate = new MultiDynamicComponentMapper(propertyData);
this.componentClass = HashMap.class;
} else {
this.delegate = new MultiPropertyMapper();
this.componentClass = componentClass;
}
}
public ComponentPropertyMapper(PropertyData propertyData, Class componentClass) {
this.propertyData = propertyData;
//ŁŻ this could be done better
if ( Map.class.equals( componentClass ) ) {
this.delegate = new MultiDynamicComponentMapper( propertyData );
this.componentClass = HashMap.class;
}
else {
this.delegate = new MultiPropertyMapper();
this.componentClass = componentClass;
}
}
@Override
public void add(PropertyData propertyData) {
@ -139,7 +140,7 @@ public class ComponentPropertyMapper implements PropertyMapper, CompositeMapperB
if ( data.get(
property.getKey()
.getName()
) != null || !(property.getValue() instanceof SinglePropertyMapper) ) {
) != null || !( property.getValue() instanceof SinglePropertyMapper ) ) {
allNullAndSingle = false;
break;
}
@ -156,7 +157,7 @@ public class ComponentPropertyMapper implements PropertyMapper, CompositeMapperB
setter.set( obj, subObj, null );
delegate.mapToEntityFromMap( verCfg, subObj, data, primaryKey, versionsReader, revision );
}
catch (Exception e) {
catch ( Exception e ) {
throw new AuditException( e );
}
}

View File

@ -1,5 +1,7 @@
package org.hibernate.envers.internal.entities.mapper;
import java.util.Map;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.envers.configuration.spi.AuditConfiguration;
import org.hibernate.envers.internal.entities.PropertyData;
@ -7,96 +9,103 @@ import org.hibernate.envers.internal.reader.AuditReaderImplementor;
import org.hibernate.envers.internal.tools.MapProxyTool;
import org.hibernate.envers.internal.tools.StringTools;
import java.util.Map;
/**
* Multi mapper for dynamic components (it knows that component is a map, not a class)
*
* @author Lukasz Zuchowski (author at zuchos dot com)
*/
public class MultiDynamicComponentMapper extends MultiPropertyMapper {
private PropertyData dynamicComponentData;
private PropertyData dynamicComponentData;
public MultiDynamicComponentMapper(PropertyData dynamicComponentData) {
this.dynamicComponentData = dynamicComponentData;
}
public MultiDynamicComponentMapper(PropertyData dynamicComponentData) {
this.dynamicComponentData = dynamicComponentData;
}
@Override
public boolean mapToMapFromEntity(
SessionImplementor session,
Map<String, Object> data,
Object newObj,
Object oldObj) {
boolean ret = false;
for (PropertyData propertyData : properties.keySet()) {
if (newObj == null && oldObj == null) {
return false;
}
Object newValue = newObj == null ? null : getValue(newObj, propertyData);
Object oldValue = oldObj == null ? null : getValue(oldObj, propertyData);
@Override
public boolean mapToMapFromEntity(
SessionImplementor session,
Map<String, Object> data,
Object newObj,
Object oldObj) {
boolean ret = false;
for ( PropertyData propertyData : properties.keySet() ) {
if ( newObj == null && oldObj == null ) {
return false;
}
Object newValue = newObj == null ? null : getValue( newObj, propertyData );
Object oldValue = oldObj == null ? null : getValue( oldObj, propertyData );
ret |= properties.get(propertyData).mapToMapFromEntity(session, data, newValue, oldValue);
}
ret |= properties.get( propertyData ).mapToMapFromEntity( session, data, newValue, oldValue );
}
return ret;
}
return ret;
}
private Object getValue(Object newObj, PropertyData propertyData) {
return ((Map) newObj).get(propertyData.getBeanName());
}
private Object getValue(Object newObj, PropertyData propertyData) {
return ( (Map) newObj ).get( propertyData.getBeanName() );
}
@Override
public boolean map(
SessionImplementor session,
Map<String, Object> data,
String[] propertyNames,
Object[] newState,
Object[] oldState) {
boolean ret = false;
for (int i = 0; i < propertyNames.length; i++) {
final String propertyName = propertyNames[i];
Map<String, PropertyData> propertyDatas = getPropertyDatas();
if (propertyDatas.containsKey(propertyName)) {
final PropertyMapper propertyMapper = properties.get(propertyDatas.get(propertyName));
final Object newObj = getAtIndexOrNull(newState, i);
final Object oldObj = getAtIndexOrNull(oldState, i);
ret |= propertyMapper.mapToMapFromEntity(session, data, newObj, oldObj);
propertyMapper.mapModifiedFlagsToMapFromEntity(session, data, newObj, oldObj);
}
}
@Override
public boolean map(
SessionImplementor session,
Map<String, Object> data,
String[] propertyNames,
Object[] newState,
Object[] oldState) {
boolean ret = false;
for ( int i = 0; i < propertyNames.length; i++ ) {
final String propertyName = propertyNames[i];
Map<String, PropertyData> propertyDatas = getPropertyDatas();
if ( propertyDatas.containsKey( propertyName ) ) {
final PropertyMapper propertyMapper = properties.get( propertyDatas.get( propertyName ) );
final Object newObj = getAtIndexOrNull( newState, i );
final Object oldObj = getAtIndexOrNull( oldState, i );
ret |= propertyMapper.mapToMapFromEntity( session, data, newObj, oldObj );
propertyMapper.mapModifiedFlagsToMapFromEntity( session, data, newObj, oldObj );
}
}
return ret;
}
return ret;
}
@Override
public void mapModifiedFlagsToMapFromEntity(
SessionImplementor session,
Map<String, Object> data,
Object newObj,
Object oldObj) {
for (PropertyData propertyData : properties.keySet()) {
if (newObj == null && oldObj == null) {
return;
}
Object newValue = newObj == null ? null : getValue(newObj, propertyData);
Object oldValue = oldObj == null ? null : getValue(oldObj, propertyData);
properties.get(propertyData).mapModifiedFlagsToMapFromEntity(session, data, newValue, oldValue);
}
}
@Override
public void mapModifiedFlagsToMapFromEntity(
SessionImplementor session,
Map<String, Object> data,
Object newObj,
Object oldObj) {
for ( PropertyData propertyData : properties.keySet() ) {
if ( newObj == null && oldObj == null ) {
return;
}
Object newValue = newObj == null ? null : getValue( newObj, propertyData );
Object oldValue = oldObj == null ? null : getValue( oldObj, propertyData );
properties.get( propertyData ).mapModifiedFlagsToMapFromEntity( session, data, newValue, oldValue );
}
}
@Override
public void mapToEntityFromMap(
AuditConfiguration verCfg, Object obj, Map data, Object primaryKey,
AuditReaderImplementor versionsReader, Number revision) {
Object mapProxy = MapProxyTool.newInstanceOfBeanProxyForMap(generateClassName(data, dynamicComponentData.getBeanName()), (Map) obj, properties.keySet(), verCfg.getClassLoaderService());
for (PropertyData propertyData : properties.keySet()) {
PropertyMapper mapper = properties.get(propertyData);
mapper.mapToEntityFromMap(verCfg, mapProxy, data, primaryKey, versionsReader, revision);
}
}
@Override
public void mapToEntityFromMap(
AuditConfiguration verCfg, Object obj, Map data, Object primaryKey,
AuditReaderImplementor versionsReader, Number revision) {
Object mapProxy = MapProxyTool.newInstanceOfBeanProxyForMap(
generateClassName(
data,
dynamicComponentData.getBeanName()
), (Map) obj, properties.keySet(), verCfg.getClassLoaderService()
);
for ( PropertyData propertyData : properties.keySet() ) {
PropertyMapper mapper = properties.get( propertyData );
mapper.mapToEntityFromMap( verCfg, mapProxy, data, primaryKey, versionsReader, revision );
}
}
private String generateClassName(Map data, String dynamicComponentPropertyName) {
return (data.get("$type$") + StringTools.capitalizeFirst(dynamicComponentPropertyName)).replaceAll("_", "");
}
private String generateClassName(Map data, String dynamicComponentPropertyName) {
return ( data.get( "$type$" ) + StringTools.capitalizeFirst( dynamicComponentPropertyName ) ).replaceAll(
"_",
""
);
}
}

View File

@ -67,7 +67,10 @@ public class MultiPropertyMapper implements ExtendedPropertyMapper {
return (CompositeMapperBuilder) properties.get( propertyData );
}
final ComponentPropertyMapper componentMapperBuilder = new ComponentPropertyMapper(propertyData, componentClass);
final ComponentPropertyMapper componentMapperBuilder = new ComponentPropertyMapper(
propertyData,
componentClass
);
addComposite( propertyData, componentMapperBuilder );
return componentMapperBuilder;
@ -225,7 +228,7 @@ public class MultiPropertyMapper implements ExtendedPropertyMapper {
return properties;
}
public Map<String, PropertyData> getPropertyDatas() {
return propertyDatas;
}
public Map<String, PropertyData> getPropertyDatas() {
return propertyDatas;
}
}

View File

@ -1,72 +1,81 @@
package org.hibernate.envers.test.integration.components.dynamic;
import org.hibernate.envers.Audited;
import java.util.HashMap;
import java.util.Map;
import org.hibernate.envers.Audited;
@Audited
public class AdvancedEntity {
private Long id;
private Long id;
private String note;
private String note;
private Map<String,Object> dynamicConfiguration = new HashMap<String, Object>();
private Map<String, Object> dynamicConfiguration = new HashMap<String, Object>();
public Long getId() {
return id;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public void setId(Long id) {
this.id = id;
}
public String getNote() {
return note;
}
public String getNote() {
return note;
}
public void setNote(String note) {
this.note = note;
}
public void setNote(String note) {
this.note = note;
}
public Map<String, Object> getDynamicConfiguration() {
return dynamicConfiguration;
}
public Map<String, Object> getDynamicConfiguration() {
return dynamicConfiguration;
}
public void setDynamicConfiguration(Map<String, Object> dynamicConfiguration) {
this.dynamicConfiguration = dynamicConfiguration;
}
public void setDynamicConfiguration(Map<String, Object> dynamicConfiguration) {
this.dynamicConfiguration = dynamicConfiguration;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof AdvancedEntity)) return false;
@Override
public boolean equals(Object o) {
if ( this == o ) {
return true;
}
if ( !( o instanceof AdvancedEntity ) ) {
return false;
}
AdvancedEntity that = (AdvancedEntity) o;
AdvancedEntity that = (AdvancedEntity) o;
if (dynamicConfiguration != null ? !dynamicConfiguration.equals(that.dynamicConfiguration) : that.dynamicConfiguration != null)
return false;
if (id != null ? !id.equals(that.id) : that.id != null) return false;
if (note != null ? !note.equals(that.note) : that.note != null) return false;
if ( dynamicConfiguration != null ? !dynamicConfiguration.equals( that.dynamicConfiguration ) : that.dynamicConfiguration != null ) {
return false;
}
if ( id != null ? !id.equals( that.id ) : that.id != null ) {
return false;
}
if ( note != null ? !note.equals( that.note ) : that.note != null ) {
return false;
}
return true;
}
return true;
}
@Override
public int hashCode() {
int result = id != null ? id.hashCode() : 0;
result = 31 * result + (note != null ? note.hashCode() : 0);
result = 31 * result + (dynamicConfiguration != null ? dynamicConfiguration.hashCode() : 0);
return result;
}
@Override
public int hashCode() {
int result = id != null ? id.hashCode() : 0;
result = 31 * result + ( note != null ? note.hashCode() : 0 );
result = 31 * result + ( dynamicConfiguration != null ? dynamicConfiguration.hashCode() : 0 );
return result;
}
@Override
public String toString() {
return "AdvancedEntity{" +
"id=" + id +
", note='" + note + '\'' +
", dynamicConfiguration=" + dynamicConfiguration +
'}';
}
@Override
public String toString() {
return "AdvancedEntity{" +
"id=" + id +
", note='" + note + '\'' +
", dynamicConfiguration=" + dynamicConfiguration +
'}';
}
}

View File

@ -1,93 +1,93 @@
package org.hibernate.envers.test.integration.components.dynamic;
import org.hibernate.envers.Audited;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import org.hibernate.envers.Audited;
@Audited
public class AuditedDynamicComponentEntity implements Serializable {
private long id;
private String note;
private Map<String, Object> customFields = new HashMap<String, Object>();
private SimpleEntity simpleEntity;
private long id;
private String note;
private Map<String, Object> customFields = new HashMap<String, Object>();
private SimpleEntity simpleEntity;
public AuditedDynamicComponentEntity() {
}
public AuditedDynamicComponentEntity() {
}
public AuditedDynamicComponentEntity(long id, String note) {
this.id = id;
this.note = note;
}
public AuditedDynamicComponentEntity(long id, String note) {
this.id = id;
this.note = note;
}
@Override
public boolean equals(Object o) {
if ( this == o ) {
return true;
}
if ( !(o instanceof AuditedDynamicComponentEntity) ) {
return false;
}
@Override
public boolean equals(Object o) {
if ( this == o ) {
return true;
}
if ( !( o instanceof AuditedDynamicComponentEntity ) ) {
return false;
}
AuditedDynamicComponentEntity that = (AuditedDynamicComponentEntity) o;
AuditedDynamicComponentEntity that = (AuditedDynamicComponentEntity) o;
if ( id != that.id ) {
return false;
}
if ( customFields != null ? !customFields.equals( that.customFields ) : that.customFields != null ) {
return false;
}
if ( note != null ? !note.equals( that.note ) : that.note != null ) {
return false;
}
if ( id != that.id ) {
return false;
}
if ( customFields != null ? !customFields.equals( that.customFields ) : that.customFields != null ) {
return false;
}
if ( note != null ? !note.equals( that.note ) : that.note != null ) {
return false;
}
return true;
}
return true;
}
@Override
public int hashCode() {
int result = (int) (id ^ (id >>> 32));
result = 31 * result + (note != null ? note.hashCode() : 0);
result = 31 * result + (customFields != null ? customFields.hashCode() : 0);
return result;
}
@Override
public int hashCode() {
int result = (int) ( id ^ ( id >>> 32 ) );
result = 31 * result + ( note != null ? note.hashCode() : 0 );
result = 31 * result + ( customFields != null ? customFields.hashCode() : 0 );
return result;
}
@Override
public String toString() {
return "AuditedDynamicMapComponent(id = " + id + ", note = " + note + ", customFields = " + customFields + ")";
}
@Override
public String toString() {
return "AuditedDynamicMapComponent(id = " + id + ", note = " + note + ", customFields = " + customFields + ")";
}
public long getId() {
return id;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public void setId(long id) {
this.id = id;
}
public String getNote() {
return note;
}
public String getNote() {
return note;
}
public void setNote(String note) {
this.note = note;
}
public void setNote(String note) {
this.note = note;
}
public Map<String, Object> getCustomFields() {
return customFields;
}
public Map<String, Object> getCustomFields() {
return customFields;
}
public void setCustomFields(Map<String, Object> customFields) {
this.customFields = customFields;
}
public void setCustomFields(Map<String, Object> customFields) {
this.customFields = customFields;
}
public SimpleEntity getSimpleEntity() {
return simpleEntity;
}
public SimpleEntity getSimpleEntity() {
return simpleEntity;
}
public void setSimpleEntity(SimpleEntity simpleEntity) {
this.simpleEntity = simpleEntity;
}
public void setSimpleEntity(SimpleEntity simpleEntity) {
this.simpleEntity = simpleEntity;
}
}

View File

@ -1,6 +1,14 @@
package org.hibernate.envers.test.integration.components.dynamic;
import java.io.File;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Arrays;
import java.util.List;
import junit.framework.Assert;
import org.junit.Test;
import org.hibernate.MappingException;
import org.hibernate.Session;
import org.hibernate.cfg.Configuration;
@ -12,13 +20,6 @@ import org.hibernate.envers.test.Priority;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.testing.ServiceRegistryBuilder;
import org.hibernate.testing.TestForIssue;
import org.junit.Test;
import java.io.File;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Arrays;
import java.util.List;
/**
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
@ -27,205 +28,207 @@ import java.util.List;
@TestForIssue(jiraKey = "HHH-8049")
public class AuditedDynamicComponentTest extends BaseEnversFunctionalTestCase {
@Override
protected String[] getMappings() {
return new String[]{"mappings/dynamicComponents/mapAudited.hbm.xml"};
}
@Override
protected String[] getMappings() {
return new String[] { "mappings/dynamicComponents/mapAudited.hbm.xml" };
}
//@Test
public void testAuditedDynamicComponentFailure() throws URISyntaxException {
final Configuration config = new Configuration();
final URL hbm = Thread.currentThread().getContextClassLoader().getResource(
"mappings/dynamicComponents/mapAudited.hbm.xml"
);
config.addFile(new File(hbm.toURI()));
//@Test
public void testAuditedDynamicComponentFailure() throws URISyntaxException {
final Configuration config = new Configuration();
final URL hbm = Thread.currentThread().getContextClassLoader().getResource(
"mappings/dynamicComponents/mapAudited.hbm.xml"
);
config.addFile( new File( hbm.toURI() ) );
final String auditStrategy = getAuditStrategy();
if (!StringTools.isEmpty(auditStrategy)) {
config.setProperty(EnversSettings.AUDIT_STRATEGY, auditStrategy);
}
final String auditStrategy = getAuditStrategy();
if ( !StringTools.isEmpty( auditStrategy ) ) {
config.setProperty( EnversSettings.AUDIT_STRATEGY, auditStrategy );
}
final ServiceRegistry serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry(config.getProperties());
try {
config.buildSessionFactory(serviceRegistry);
Assert.fail("MappingException expected");
} catch (MappingException e) {
Assert.assertEquals(
"Audited dynamic-component properties are not supported. Consider applying @NotAudited annotation to "
+ AuditedDynamicComponentEntity.class.getName() + "#customFields.",
e.getMessage()
);
} finally {
ServiceRegistryBuilder.destroy(serviceRegistry);
}
}
final ServiceRegistry serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( config.getProperties() );
try {
config.buildSessionFactory( serviceRegistry );
Assert.fail( "MappingException expected" );
}
catch ( MappingException e ) {
Assert.assertEquals(
"Audited dynamic-component properties are not supported. Consider applying @NotAudited annotation to "
+ AuditedDynamicComponentEntity.class.getName() + "#customFields.",
e.getMessage()
);
}
finally {
ServiceRegistryBuilder.destroy( serviceRegistry );
}
}
@Test
@Priority(10)
public void initData() {
Session session = openSession();
@Test
@Priority(10)
public void initData() {
Session session = openSession();
SimpleEntity simpleEntity = new SimpleEntity(1L, "Very simple entity");
SimpleEntity simpleEntity = new SimpleEntity( 1L, "Very simple entity" );
// Revision 1
session.getTransaction().begin();
session.save(simpleEntity);
session.getTransaction().commit();
// Revision 1
session.getTransaction().begin();
session.save( simpleEntity );
session.getTransaction().commit();
// Revision 2
session.getTransaction().begin();
AuditedDynamicComponentEntity entity = new AuditedDynamicComponentEntity(1L, "static field value");
entity.getCustomFields().put("prop1", 13);
entity.getCustomFields().put("prop2", 0.1f);
entity.getCustomFields().put("prop3", simpleEntity);
entity.getCustomFields().put("prop4", true);
session.save(entity);
session.getTransaction().commit();
// Revision 2
session.getTransaction().begin();
AuditedDynamicComponentEntity entity = new AuditedDynamicComponentEntity( 1L, "static field value" );
entity.getCustomFields().put( "prop1", 13 );
entity.getCustomFields().put( "prop2", 0.1f );
entity.getCustomFields().put( "prop3", simpleEntity );
entity.getCustomFields().put( "prop4", true );
session.save( entity );
session.getTransaction().commit();
// revision 3
session.getTransaction().begin();
SimpleEntity simpleEntity2 = new SimpleEntity(2L, "Not so simple entity");
session.save(simpleEntity2);
entity = (AuditedDynamicComponentEntity) session.get(AuditedDynamicComponentEntity.class, entity.getId());
entity.getCustomFields().put("prop3", simpleEntity2);
session.update(entity);
session.getTransaction().commit();
// revision 3
session.getTransaction().begin();
SimpleEntity simpleEntity2 = new SimpleEntity( 2L, "Not so simple entity" );
session.save( simpleEntity2 );
entity = (AuditedDynamicComponentEntity) session.get( AuditedDynamicComponentEntity.class, entity.getId() );
entity.getCustomFields().put( "prop3", simpleEntity2 );
session.update( entity );
session.getTransaction().commit();
// Revision 4
session.getTransaction().begin();
entity = (AuditedDynamicComponentEntity) session.get(AuditedDynamicComponentEntity.class, entity.getId());
entity.getCustomFields().put("prop1", 2);
entity.getCustomFields().put("prop4", false);
session.update(entity);
session.getTransaction().commit();
// Revision 4
session.getTransaction().begin();
entity = (AuditedDynamicComponentEntity) session.get( AuditedDynamicComponentEntity.class, entity.getId() );
entity.getCustomFields().put( "prop1", 2 );
entity.getCustomFields().put( "prop4", false );
session.update( entity );
session.getTransaction().commit();
// Revision 5
session.getTransaction().begin();
entity = (AuditedDynamicComponentEntity) session.load(AuditedDynamicComponentEntity.class, entity.getId());
entity.getCustomFields().remove("prop2");
session.update(entity);
session.getTransaction().commit();
// Revision 5
session.getTransaction().begin();
entity = (AuditedDynamicComponentEntity) session.load( AuditedDynamicComponentEntity.class, entity.getId() );
entity.getCustomFields().remove( "prop2" );
session.update( entity );
session.getTransaction().commit();
// Revision 6
session.getTransaction().begin();
entity = (AuditedDynamicComponentEntity) session.load(AuditedDynamicComponentEntity.class, entity.getId());
entity.getCustomFields().clear();
session.update(entity);
session.getTransaction().commit();
// Revision 6
session.getTransaction().begin();
entity = (AuditedDynamicComponentEntity) session.load( AuditedDynamicComponentEntity.class, entity.getId() );
entity.getCustomFields().clear();
session.update( entity );
session.getTransaction().commit();
// Revision 7
session.getTransaction().begin();
entity = (AuditedDynamicComponentEntity) session.load(AuditedDynamicComponentEntity.class, entity.getId());
session.delete(entity);
session.getTransaction().commit();
// Revision 7
session.getTransaction().begin();
entity = (AuditedDynamicComponentEntity) session.load( AuditedDynamicComponentEntity.class, entity.getId() );
session.delete( entity );
session.getTransaction().commit();
session.close();
}
session.close();
}
@Test
public void testRevisionsCounts() {
Assert.assertEquals(
Arrays.asList(2, 3, 4, 5, 6, 7),
getAuditReader().getRevisions(AuditedDynamicComponentEntity.class, 1L)
);
}
@Test
public void testRevisionsCounts() {
Assert.assertEquals(
Arrays.asList( 2, 3, 4, 5, 6, 7 ),
getAuditReader().getRevisions( AuditedDynamicComponentEntity.class, 1L )
);
}
@Test
public void testHistoryOfId1() {
// Revision 2
AuditedDynamicComponentEntity entity = new AuditedDynamicComponentEntity(1L, "static field value");
entity.getCustomFields().put("prop1", 13);
entity.getCustomFields().put("prop2", 0.1f);
entity.getCustomFields().put("prop3", new SimpleEntity(1L, "Very simple entity"));
entity.getCustomFields().put("prop4", true);
AuditedDynamicComponentEntity ver2 = getAuditReader().find(
AuditedDynamicComponentEntity.class,
entity.getId(),
2
);
Assert.assertEquals(entity, ver2);
@Test
public void testHistoryOfId1() {
// Revision 2
AuditedDynamicComponentEntity entity = new AuditedDynamicComponentEntity( 1L, "static field value" );
entity.getCustomFields().put( "prop1", 13 );
entity.getCustomFields().put( "prop2", 0.1f );
entity.getCustomFields().put( "prop3", new SimpleEntity( 1L, "Very simple entity" ) );
entity.getCustomFields().put( "prop4", true );
AuditedDynamicComponentEntity ver2 = getAuditReader().find(
AuditedDynamicComponentEntity.class,
entity.getId(),
2
);
Assert.assertEquals( entity, ver2 );
// Revision 3
SimpleEntity simpleEntity2 = new SimpleEntity(2L, "Not so simple entity");
entity.getCustomFields().put("prop3", simpleEntity2);
AuditedDynamicComponentEntity ver3 = getAuditReader().find(
AuditedDynamicComponentEntity.class,
entity.getId(),
3
);
Assert.assertEquals(entity, ver3);
// Revision 3
SimpleEntity simpleEntity2 = new SimpleEntity( 2L, "Not so simple entity" );
entity.getCustomFields().put( "prop3", simpleEntity2 );
AuditedDynamicComponentEntity ver3 = getAuditReader().find(
AuditedDynamicComponentEntity.class,
entity.getId(),
3
);
Assert.assertEquals( entity, ver3 );
// Revision 4
entity.getCustomFields().put("prop1", 2);
entity.getCustomFields().put("prop4", false);
AuditedDynamicComponentEntity ver4 = getAuditReader().find(
AuditedDynamicComponentEntity.class,
entity.getId(),
4
);
Assert.assertEquals(entity, ver4);
// Revision 4
entity.getCustomFields().put( "prop1", 2 );
entity.getCustomFields().put( "prop4", false );
AuditedDynamicComponentEntity ver4 = getAuditReader().find(
AuditedDynamicComponentEntity.class,
entity.getId(),
4
);
Assert.assertEquals( entity, ver4 );
// Revision 5
entity.getCustomFields().put("prop2", null);
AuditedDynamicComponentEntity ver5 = getAuditReader().find(
AuditedDynamicComponentEntity.class,
entity.getId(),
5
);
Assert.assertEquals(entity, ver5);
// Revision 5
entity.getCustomFields().put( "prop2", null );
AuditedDynamicComponentEntity ver5 = getAuditReader().find(
AuditedDynamicComponentEntity.class,
entity.getId(),
5
);
Assert.assertEquals( entity, ver5 );
// Revision 5
entity.getCustomFields().put("prop1", null);
entity.getCustomFields().put("prop2", null);
entity.getCustomFields().put("prop3", null);
entity.getCustomFields().put("prop4", null);
AuditedDynamicComponentEntity ver6 = getAuditReader().find(
AuditedDynamicComponentEntity.class,
entity.getId(),
6
);
Assert.assertEquals(entity, ver6);
}
// Revision 5
entity.getCustomFields().put( "prop1", null );
entity.getCustomFields().put( "prop2", null );
entity.getCustomFields().put( "prop3", null );
entity.getCustomFields().put( "prop4", null );
AuditedDynamicComponentEntity ver6 = getAuditReader().find(
AuditedDynamicComponentEntity.class,
entity.getId(),
6
);
Assert.assertEquals( entity, ver6 );
}
@Test
public void testOfQueryOnDynamicComponent() {
//given (and result of initData()
AuditedDynamicComponentEntity entity = new AuditedDynamicComponentEntity(1L, "static field value");
entity.getCustomFields().put("prop1", 13);
entity.getCustomFields().put("prop2", 0.1f);
entity.getCustomFields().put("prop3", new SimpleEntity(1L, "Very simple entity"));
entity.getCustomFields().put("prop4", true);
@Test
public void testOfQueryOnDynamicComponent() {
//given (and result of initData()
AuditedDynamicComponentEntity entity = new AuditedDynamicComponentEntity( 1L, "static field value" );
entity.getCustomFields().put( "prop1", 13 );
entity.getCustomFields().put( "prop2", 0.1f );
entity.getCustomFields().put( "prop3", new SimpleEntity( 1L, "Very simple entity" ) );
entity.getCustomFields().put( "prop4", true );
//when
List resultList = getAuditReader().createQuery()
.forEntitiesAtRevision(AuditedDynamicComponentEntity.class, 2)
.add(AuditEntity.property("customFields_prop1").le(20))
.getResultList();
//when
List resultList = getAuditReader().createQuery()
.forEntitiesAtRevision( AuditedDynamicComponentEntity.class, 2 )
.add( AuditEntity.property( "customFields_prop1" ).le( 20 ) )
.getResultList();
//then
Assert.assertEquals(entity, resultList.get(0));
//then
Assert.assertEquals( entity, resultList.get( 0 ) );
//when
resultList = getAuditReader().createQuery()
.forEntitiesAtRevision(AuditedDynamicComponentEntity.class, 2)
.add(AuditEntity.property("customFields_prop3").eq(new SimpleEntity(1L, "Very simple entity")))
.getResultList();
//when
resultList = getAuditReader().createQuery()
.forEntitiesAtRevision( AuditedDynamicComponentEntity.class, 2 )
.add( AuditEntity.property( "customFields_prop3" ).eq( new SimpleEntity( 1L, "Very simple entity" ) ) )
.getResultList();
//then
entity = (AuditedDynamicComponentEntity) getAuditReader().createQuery()
.forEntitiesAtRevision(AuditedDynamicComponentEntity.class, 4)
.getResultList().get(0);
entity.getCustomFields().put("prop2", null);
//then
entity = (AuditedDynamicComponentEntity) getAuditReader().createQuery()
.forEntitiesAtRevision( AuditedDynamicComponentEntity.class, 4 )
.getResultList().get( 0 );
entity.getCustomFields().put( "prop2", null );
resultList = getAuditReader().createQuery()
.forEntitiesAtRevision(AuditedDynamicComponentEntity.class, 5)
.add(AuditEntity.property("customFields_prop2").isNull())
.getResultList();
resultList = getAuditReader().createQuery()
.forEntitiesAtRevision( AuditedDynamicComponentEntity.class, 5 )
.add( AuditEntity.property( "customFields_prop2" ).isNull() )
.getResultList();
//then
Assert.assertEquals(entity, resultList.get(0));
}
//then
Assert.assertEquals( entity, resultList.get( 0 ) );
}
}

View File

@ -298,7 +298,10 @@ public class AuditedDynamicComponentsAdvancedCasesTest extends BaseEnversFunctio
Assert.fail();
}
catch ( AuditException e ) {
Assert.assertEquals( "This type of relation (org.hibernate.envers.test.integration.components.dynamic.AdvancedEntity.dynamicConfiguration_internalMapWithEntities) isn't supported and can't be used in queries." , e.getMessage());
Assert.assertEquals(
"This type of relation (org.hibernate.envers.test.integration.components.dynamic.AdvancedEntity.dynamicConfiguration_internalMapWithEntities) isn't supported and can't be used in queries.",
e.getMessage()
);
}
catch ( Exception e ) {
Assert.fail();

View File

@ -2,44 +2,50 @@ package org.hibernate.envers.test.integration.components.dynamic;
public class InternalComponent {
private String property;
private String property;
public InternalComponent() {
}
public InternalComponent() {
}
public InternalComponent(String property) {
this.property = property;
}
public InternalComponent(String property) {
this.property = property;
}
public String getProperty() {
return property;
}
public String getProperty() {
return property;
}
public void setProperty(String property) {
this.property = property;
}
public void setProperty(String property) {
this.property = property;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof InternalComponent)) return false;
@Override
public boolean equals(Object o) {
if ( this == o ) {
return true;
}
if ( !( o instanceof InternalComponent ) ) {
return false;
}
InternalComponent that = (InternalComponent) o;
InternalComponent that = (InternalComponent) o;
if (property != null ? !property.equals(that.property) : that.property != null) return false;
if ( property != null ? !property.equals( that.property ) : that.property != null ) {
return false;
}
return true;
}
return true;
}
@Override
public int hashCode() {
return property != null ? property.hashCode() : 0;
}
@Override
public int hashCode() {
return property != null ? property.hashCode() : 0;
}
@Override
public String toString() {
return "InternalComponent{" +
"property='" + property + '\'' +
'}';
}
@Override
public String toString() {
return "InternalComponent{" +
"property='" + property + '\'' +
'}';
}
}

View File

@ -5,58 +5,66 @@ import org.hibernate.envers.Audited;
@Audited
public class ManyToManyEntity {
private Long id;
private String note;
private Long id;
private String note;
public ManyToManyEntity() {
}
public ManyToManyEntity() {
}
public ManyToManyEntity(Long id, String note) {
this.id = id;
this.note = note;
}
public ManyToManyEntity(Long id, String note) {
this.id = id;
this.note = note;
}
public Long getId() {
return id;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public void setId(Long id) {
this.id = id;
}
public String getNote() {
return note;
}
public String getNote() {
return note;
}
public void setNote(String note) {
this.note = note;
}
public void setNote(String note) {
this.note = note;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof ManyToManyEntity)) return false;
@Override
public boolean equals(Object o) {
if ( this == o ) {
return true;
}
if ( !( o instanceof ManyToManyEntity ) ) {
return false;
}
ManyToManyEntity that = (ManyToManyEntity) o;
ManyToManyEntity that = (ManyToManyEntity) o;
if (id != null ? !id.equals(that.id) : that.id != null) return false;
if (note != null ? !note.equals(that.note) : that.note != null) return false;
if ( id != null ? !id.equals( that.id ) : that.id != null ) {
return false;
}
if ( note != null ? !note.equals( that.note ) : that.note != null ) {
return false;
}
return true;
}
return true;
}
@Override
public int hashCode() {
int result = id != null ? id.hashCode() : 0;
result = 31 * result + (note != null ? note.hashCode() : 0);
return result;
}
@Override
public int hashCode() {
int result = id != null ? id.hashCode() : 0;
result = 31 * result + ( note != null ? note.hashCode() : 0 );
return result;
}
@Override
public String toString() {
return "ManyToManyEntity{" +
"id=" + id +
", note='" + note + '\'' +
'}';
}
@Override
public String toString() {
return "ManyToManyEntity{" +
"id=" + id +
", note='" + note + '\'' +
'}';
}
}

View File

@ -5,58 +5,66 @@ import org.hibernate.envers.Audited;
@Audited
public class ManyToOneEntity {
private Long id;
private String note;
private Long id;
private String note;
public ManyToOneEntity() {
}
public ManyToOneEntity() {
}
public ManyToOneEntity(Long id, String note) {
this.id = id;
this.note = note;
}
public ManyToOneEntity(Long id, String note) {
this.id = id;
this.note = note;
}
public Long getId() {
return id;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public void setId(Long id) {
this.id = id;
}
public String getNote() {
return note;
}
public String getNote() {
return note;
}
public void setNote(String note) {
this.note = note;
}
public void setNote(String note) {
this.note = note;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof ManyToOneEntity)) return false;
@Override
public boolean equals(Object o) {
if ( this == o ) {
return true;
}
if ( !( o instanceof ManyToOneEntity ) ) {
return false;
}
ManyToOneEntity that = (ManyToOneEntity) o;
ManyToOneEntity that = (ManyToOneEntity) o;
if (id != null ? !id.equals(that.id) : that.id != null) return false;
if (note != null ? !note.equals(that.note) : that.note != null) return false;
if ( id != null ? !id.equals( that.id ) : that.id != null ) {
return false;
}
if ( note != null ? !note.equals( that.note ) : that.note != null ) {
return false;
}
return true;
}
return true;
}
@Override
public int hashCode() {
int result = id != null ? id.hashCode() : 0;
result = 31 * result + (note != null ? note.hashCode() : 0);
return result;
}
@Override
public int hashCode() {
int result = id != null ? id.hashCode() : 0;
result = 31 * result + ( note != null ? note.hashCode() : 0 );
return result;
}
@Override
public String toString() {
return "ManyToOneEntity{" +
"id=" + id +
", note='" + note + '\'' +
'}';
}
@Override
public String toString() {
return "ManyToOneEntity{" +
"id=" + id +
", note='" + note + '\'' +
'}';
}
}

View File

@ -2,13 +2,12 @@ package org.hibernate.envers.test.integration.components.dynamic;
import java.util.Arrays;
import junit.framework.Assert;
import org.junit.Test;
import org.hibernate.Session;
import org.hibernate.envers.test.BaseEnversFunctionalTestCase;
import org.hibernate.envers.test.Priority;
import org.junit.Test;
import junit.framework.Assert;
import org.hibernate.testing.TestForIssue;
/**
@ -18,7 +17,7 @@ import org.hibernate.testing.TestForIssue;
public class NotAuditedDynamicComponentTest extends BaseEnversFunctionalTestCase {
@Override
protected String[] getMappings() {
return new String[] {"mappings/dynamicComponents/mapNotAudited.hbm.xml"};
return new String[] { "mappings/dynamicComponents/mapNotAudited.hbm.xml" };
}
@Test

View File

@ -29,7 +29,7 @@ public class NotAuditedDynamicMapComponent implements Serializable {
if ( this == o ) {
return true;
}
if ( !(o instanceof NotAuditedDynamicMapComponent) ) {
if ( !( o instanceof NotAuditedDynamicMapComponent ) ) {
return false;
}
@ -50,9 +50,9 @@ public class NotAuditedDynamicMapComponent implements Serializable {
@Override
public int hashCode() {
int result = (int) (id ^ (id >>> 32));
result = 31 * result + (note != null ? note.hashCode() : 0);
result = 31 * result + (customFields != null ? customFields.hashCode() : 0);
int result = (int) ( id ^ ( id >>> 32 ) );
result = 31 * result + ( note != null ? note.hashCode() : 0 );
result = 31 * result + ( customFields != null ? customFields.hashCode() : 0 );
return result;
}

View File

@ -5,58 +5,66 @@ import org.hibernate.envers.Audited;
@Audited
public class OneToOneEntity {
private Long id;
private String note;
private Long id;
private String note;
public OneToOneEntity() {
}
public OneToOneEntity() {
}
public OneToOneEntity(Long id, String note) {
this.id = id;
this.note = note;
}
public OneToOneEntity(Long id, String note) {
this.id = id;
this.note = note;
}
public Long getId() {
return id;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public void setId(Long id) {
this.id = id;
}
public String getNote() {
return note;
}
public String getNote() {
return note;
}
public void setNote(String note) {
this.note = note;
}
public void setNote(String note) {
this.note = note;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof OneToOneEntity)) return false;
@Override
public boolean equals(Object o) {
if ( this == o ) {
return true;
}
if ( !( o instanceof OneToOneEntity ) ) {
return false;
}
OneToOneEntity that = (OneToOneEntity) o;
OneToOneEntity that = (OneToOneEntity) o;
if (id != null ? !id.equals(that.id) : that.id != null) return false;
if (note != null ? !note.equals(that.note) : that.note != null) return false;
if ( id != null ? !id.equals( that.id ) : that.id != null ) {
return false;
}
if ( note != null ? !note.equals( that.note ) : that.note != null ) {
return false;
}
return true;
}
return true;
}
@Override
public int hashCode() {
int result = id != null ? id.hashCode() : 0;
result = 31 * result + (note != null ? note.hashCode() : 0);
return result;
}
@Override
public int hashCode() {
int result = id != null ? id.hashCode() : 0;
result = 31 * result + ( note != null ? note.hashCode() : 0 );
return result;
}
@Override
public String toString() {
return "OneToOneEntity{" +
"id=" + id +
", note='" + note + '\'' +
'}';
}
@Override
public String toString() {
return "OneToOneEntity{" +
"id=" + id +
", note='" + note + '\'' +
'}';
}
}

View File

@ -111,7 +111,10 @@ public class SanityCheckTest extends BaseEnversFunctionalTestCase {
Assert.fail();
}
catch ( AuditException e ) {
Assert.assertEquals( "This type of relation (org.hibernate.envers.test.integration.components.dynamic.PlainEntity.component_manyToManyList) isn't supported and can't be used in queries." , e.getMessage());
Assert.assertEquals(
"This type of relation (org.hibernate.envers.test.integration.components.dynamic.PlainEntity.component_manyToManyList) isn't supported and can't be used in queries.",
e.getMessage()
);
}
catch ( Exception e ) {
Assert.fail();

View File

@ -5,69 +5,76 @@ import org.hibernate.envers.Audited;
@Audited
public class SimpleEntity {
private Long id;
private String simpleProperty;
private Long id;
private String simpleProperty;
private AdvancedEntity parent;
private AdvancedEntity parent;
public SimpleEntity() {
}
public SimpleEntity() {
}
public SimpleEntity(Long id, String simpleProperty) {
this.id = id;
this.simpleProperty = simpleProperty;
}
public SimpleEntity(Long id, String simpleProperty) {
this.id = id;
this.simpleProperty = simpleProperty;
}
public Long getId() {
return id;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public void setId(Long id) {
this.id = id;
}
public String getSimpleProperty() {
return simpleProperty;
}
public String getSimpleProperty() {
return simpleProperty;
}
public void setSimpleProperty(String simpleProperty) {
this.simpleProperty = simpleProperty;
}
public void setSimpleProperty(String simpleProperty) {
this.simpleProperty = simpleProperty;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof SimpleEntity)) return false;
@Override
public boolean equals(Object o) {
if ( this == o ) {
return true;
}
if ( !( o instanceof SimpleEntity ) ) {
return false;
}
SimpleEntity that = (SimpleEntity) o;
SimpleEntity that = (SimpleEntity) o;
if (id != null ? !id.equals(that.id) : that.id != null) return false;
if (simpleProperty != null ? !simpleProperty.equals(that.simpleProperty) : that.simpleProperty != null)
return false;
if ( id != null ? !id.equals( that.id ) : that.id != null ) {
return false;
}
if ( simpleProperty != null ? !simpleProperty.equals( that.simpleProperty ) : that.simpleProperty != null ) {
return false;
}
return true;
}
return true;
}
@Override
public int hashCode() {
int result = id != null ? id.hashCode() : 0;
result = 31 * result + (simpleProperty != null ? simpleProperty.hashCode() : 0);
return result;
}
@Override
public int hashCode() {
int result = id != null ? id.hashCode() : 0;
result = 31 * result + ( simpleProperty != null ? simpleProperty.hashCode() : 0 );
return result;
}
@Override
public String toString() {
return "SimpleEntity{" +
"id=" + id +
", simpleProperty='" + simpleProperty + '\'' +
'}';
}
@Override
public String toString() {
return "SimpleEntity{" +
"id=" + id +
", simpleProperty='" + simpleProperty + '\'' +
'}';
}
public AdvancedEntity getParent() {
return parent;
}
public AdvancedEntity getParent() {
return parent;
}
public void setParent(AdvancedEntity parent) {
this.parent = parent;
}
public void setParent(AdvancedEntity parent) {
this.parent = parent;
}
}