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,9 +119,10 @@ public class AuditedPropertiesReader {
// First reading the access types for the persistent properties.
readPersistentPropertiesAccess();
if (persistentPropertiesSource instanceof DynamicComponentSource) {
addPropertiesFromDynamicComponent((DynamicComponentSource) persistentPropertiesSource);
} else {
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();
@ -304,33 +317,44 @@ public class AuditedPropertiesReader {
}
private void addPropertiesFromDynamicComponent(DynamicComponentSource dynamicComponentSource) {
Audited audited = computeAuditConfiguration(dynamicComponentSource.getXClass());
if(!fieldAccessedPersistentProperties.isEmpty()) {
Audited audited = computeAuditConfiguration( dynamicComponentSource.getXClass() );
if ( !fieldAccessedPersistentProperties.isEmpty() ) {
//TODO ŁŻ hmm... for sure ?
throw new MappingException("Dynamic component cannot have field accessed persistent properties");
throw new MappingException( "Dynamic component cannot have field accessed persistent properties" );
}
for (String property : propertyAccessedPersistentProperties) {
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);
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 if (propertiesGroupMapping.containsKey(property)) {
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)) {
final String embeddedName = propertiesGroupMapping.get( property );
if ( !auditedPropertiesHolder.contains( embeddedName ) ) {
// Manage properties mapped within <properties> tag.
final Value propertyValue = persistentPropertiesSource.getProperty(embeddedName).getValue();
final Value propertyValue = persistentPropertiesSource.getProperty( embeddedName ).getValue();
this.addFromPropertiesGroup(
embeddedName,
new DynamicProperty(dynamicComponentSource, property), accessType,
new DynamicProperty( dynamicComponentSource, property ), accessType,
(Component) propertyValue,
audited
);
@ -440,13 +464,14 @@ public class AuditedPropertiesReader {
Component propertyValue,
Audited allClassAudited) {
final ComponentAuditingData componentData = new ComponentAuditingData();
final boolean isAudited = fillPropertyData(property, componentData, accessType, allClassAudited);
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);
if ( propertyValue.isDynamic() ) {
componentPropertiesSource = new DynamicComponentSource( reflectionManager, propertyValue, property );
}
else {
componentPropertiesSource = new ComponentPropertiesSource( reflectionManager, propertyValue );
}
final ComponentAuditedPropertiesReader audPropReader = new ComponentAuditedPropertiesReader(
@ -455,13 +480,13 @@ public class AuditedPropertiesReader {
componentData,
globalCfg,
reflectionManager,
propertyNamePrefix + MappingTools.createComponentPrefix(property.getName())
propertyNamePrefix + MappingTools.createComponentPrefix( property.getName() )
);
audPropReader.read();
if (isAudited) {
if ( isAudited ) {
// Now we know that the property is audited
auditedPropertiesHolder.addPropertyAuditingData(property.getName(), componentData);
auditedPropertiesHolder.addPropertyAuditingData( property.getName(), componentData );
}
}
@ -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
@ -720,7 +745,7 @@ public class AuditedPropertiesReader {
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();
}
@ -749,7 +774,7 @@ public class AuditedPropertiesReader {
private XProperty baseProperty;
public DynamicComponentSource(ReflectionManager reflectionManager, Component component, XProperty baseProperty) {
super(reflectionManager.toXClass(Map.class), component);
super( reflectionManager.toXClass( Map.class ), component );
this.baseProperty = baseProperty;
}
}

View File

@ -1,13 +1,14 @@
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 {

View File

@ -51,10 +51,11 @@ public class ComponentPropertyMapper implements PropertyMapper, CompositeMapperB
public ComponentPropertyMapper(PropertyData propertyData, Class componentClass) {
this.propertyData = propertyData;
//ŁŻ this could be done better
if (Map.class.equals(componentClass)) {
this.delegate = new MultiDynamicComponentMapper(propertyData);
if ( Map.class.equals( componentClass ) ) {
this.delegate = new MultiDynamicComponentMapper( propertyData );
this.componentClass = HashMap.class;
} else {
}
else {
this.delegate = new MultiPropertyMapper();
this.componentClass = componentClass;
}
@ -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,10 +9,9 @@ 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 {
@ -28,21 +29,21 @@ public class MultiDynamicComponentMapper extends MultiPropertyMapper {
Object newObj,
Object oldObj) {
boolean ret = false;
for (PropertyData propertyData : properties.keySet()) {
if (newObj == null && oldObj == null) {
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);
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;
}
private Object getValue(Object newObj, PropertyData propertyData) {
return ((Map) newObj).get(propertyData.getBeanName());
return ( (Map) newObj ).get( propertyData.getBeanName() );
}
@Override
@ -53,15 +54,15 @@ public class MultiDynamicComponentMapper extends MultiPropertyMapper {
Object[] newState,
Object[] oldState) {
boolean ret = false;
for (int i = 0; i < propertyNames.length; i++) {
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);
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 );
}
}
@ -74,13 +75,13 @@ public class MultiDynamicComponentMapper extends MultiPropertyMapper {
Map<String, Object> data,
Object newObj,
Object oldObj) {
for (PropertyData propertyData : properties.keySet()) {
if (newObj == null && oldObj == null) {
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);
Object newValue = newObj == null ? null : getValue( newObj, propertyData );
Object oldValue = oldObj == null ? null : getValue( oldObj, propertyData );
properties.get( propertyData ).mapModifiedFlagsToMapFromEntity( session, data, newValue, oldValue );
}
}
@ -88,15 +89,23 @@ public class MultiDynamicComponentMapper extends MultiPropertyMapper {
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);
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("_", "");
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;

View File

@ -1,10 +1,10 @@
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 {
@ -12,7 +12,7 @@ public class AdvancedEntity {
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;
@ -40,15 +40,24 @@ public class AdvancedEntity {
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof AdvancedEntity)) return false;
if ( this == o ) {
return true;
}
if ( !( o instanceof AdvancedEntity ) ) {
return false;
}
AdvancedEntity that = (AdvancedEntity) o;
if (dynamicConfiguration != null ? !dynamicConfiguration.equals(that.dynamicConfiguration) : that.dynamicConfiguration != null)
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 ( 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;
}
@ -56,8 +65,8 @@ public class AdvancedEntity {
@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);
result = 31 * result + ( note != null ? note.hashCode() : 0 );
result = 31 * result + ( dynamicConfiguration != null ? dynamicConfiguration.hashCode() : 0 );
return result;
}

View File

@ -1,11 +1,11 @@
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;
@ -26,7 +26,7 @@ public class AuditedDynamicComponentEntity implements Serializable {
if ( this == o ) {
return true;
}
if ( !(o instanceof AuditedDynamicComponentEntity) ) {
if ( !( o instanceof AuditedDynamicComponentEntity ) ) {
return false;
}
@ -47,9 +47,9 @@ public class AuditedDynamicComponentEntity 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

@ -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)
@ -29,7 +30,7 @@ public class AuditedDynamicComponentTest extends BaseEnversFunctionalTestCase {
@Override
protected String[] getMappings() {
return new String[]{"mappings/dynamicComponents/mapAudited.hbm.xml"};
return new String[] { "mappings/dynamicComponents/mapAudited.hbm.xml" };
}
//@Test
@ -38,25 +39,27 @@ public class AuditedDynamicComponentTest extends BaseEnversFunctionalTestCase {
final URL hbm = Thread.currentThread().getContextClassLoader().getResource(
"mappings/dynamicComponents/mapAudited.hbm.xml"
);
config.addFile(new File(hbm.toURI()));
config.addFile( new File( hbm.toURI() ) );
final String auditStrategy = getAuditStrategy();
if (!StringTools.isEmpty(auditStrategy)) {
config.setProperty(EnversSettings.AUDIT_STRATEGY, auditStrategy);
if ( !StringTools.isEmpty( auditStrategy ) ) {
config.setProperty( EnversSettings.AUDIT_STRATEGY, auditStrategy );
}
final ServiceRegistry serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry(config.getProperties());
final ServiceRegistry serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( config.getProperties() );
try {
config.buildSessionFactory(serviceRegistry);
Assert.fail("MappingException expected");
} catch (MappingException e) {
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);
}
finally {
ServiceRegistryBuilder.destroy( serviceRegistry );
}
}
@ -65,58 +68,58 @@ public class AuditedDynamicComponentTest extends BaseEnversFunctionalTestCase {
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.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);
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);
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);
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);
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 = (AuditedDynamicComponentEntity) session.load( AuditedDynamicComponentEntity.class, entity.getId() );
entity.getCustomFields().clear();
session.update(entity);
session.update( entity );
session.getTransaction().commit();
// Revision 7
session.getTransaction().begin();
entity = (AuditedDynamicComponentEntity) session.load(AuditedDynamicComponentEntity.class, entity.getId());
session.delete(entity);
entity = (AuditedDynamicComponentEntity) session.load( AuditedDynamicComponentEntity.class, entity.getId() );
session.delete( entity );
session.getTransaction().commit();
session.close();
@ -125,107 +128,107 @@ public class AuditedDynamicComponentTest extends BaseEnversFunctionalTestCase {
@Test
public void testRevisionsCounts() {
Assert.assertEquals(
Arrays.asList(2, 3, 4, 5, 6, 7),
getAuditReader().getRevisions(AuditedDynamicComponentEntity.class, 1L)
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 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);
Assert.assertEquals( entity, ver2 );
// Revision 3
SimpleEntity simpleEntity2 = new SimpleEntity(2L, "Not so simple entity");
entity.getCustomFields().put("prop3", simpleEntity2);
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);
Assert.assertEquals( entity, ver3 );
// Revision 4
entity.getCustomFields().put("prop1", 2);
entity.getCustomFields().put("prop4", false);
entity.getCustomFields().put( "prop1", 2 );
entity.getCustomFields().put( "prop4", false );
AuditedDynamicComponentEntity ver4 = getAuditReader().find(
AuditedDynamicComponentEntity.class,
entity.getId(),
4
);
Assert.assertEquals(entity, ver4);
Assert.assertEquals( entity, ver4 );
// Revision 5
entity.getCustomFields().put("prop2", null);
entity.getCustomFields().put( "prop2", null );
AuditedDynamicComponentEntity ver5 = getAuditReader().find(
AuditedDynamicComponentEntity.class,
entity.getId(),
5
);
Assert.assertEquals(entity, ver5);
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);
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);
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);
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))
.forEntitiesAtRevision( AuditedDynamicComponentEntity.class, 2 )
.add( AuditEntity.property( "customFields_prop1" ).le( 20 ) )
.getResultList();
//then
Assert.assertEquals(entity, resultList.get(0));
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")))
.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);
.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())
.forEntitiesAtRevision( AuditedDynamicComponentEntity.class, 5 )
.add( AuditEntity.property( "customFields_prop2" ).isNull() )
.getResultList();
//then
Assert.assertEquals(entity, resultList.get(0));
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

@ -21,12 +21,18 @@ public class InternalComponent {
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof InternalComponent)) return false;
if ( this == o ) {
return true;
}
if ( !( o instanceof InternalComponent ) ) {
return false;
}
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;
}

View File

@ -34,13 +34,21 @@ public class ManyToManyEntity {
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof ManyToManyEntity)) return false;
if ( this == o ) {
return true;
}
if ( !( o instanceof ManyToManyEntity ) ) {
return false;
}
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;
}
@ -48,7 +56,7 @@ public class ManyToManyEntity {
@Override
public int hashCode() {
int result = id != null ? id.hashCode() : 0;
result = 31 * result + (note != null ? note.hashCode() : 0);
result = 31 * result + ( note != null ? note.hashCode() : 0 );
return result;
}

View File

@ -34,13 +34,21 @@ public class ManyToOneEntity {
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof ManyToOneEntity)) return false;
if ( this == o ) {
return true;
}
if ( !( o instanceof ManyToOneEntity ) ) {
return false;
}
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;
}
@ -48,7 +56,7 @@ public class ManyToOneEntity {
@Override
public int hashCode() {
int result = id != null ? id.hashCode() : 0;
result = 31 * result + (note != null ? note.hashCode() : 0);
result = 31 * result + ( note != null ? note.hashCode() : 0 );
return result;
}

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

@ -34,13 +34,21 @@ public class OneToOneEntity {
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof OneToOneEntity)) return false;
if ( this == o ) {
return true;
}
if ( !( o instanceof OneToOneEntity ) ) {
return false;
}
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;
}
@ -48,7 +56,7 @@ public class OneToOneEntity {
@Override
public int hashCode() {
int result = id != null ? id.hashCode() : 0;
result = 31 * result + (note != null ? note.hashCode() : 0);
result = 31 * result + ( note != null ? note.hashCode() : 0 );
return result;
}

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

@ -36,14 +36,21 @@ public class SimpleEntity {
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof SimpleEntity)) return false;
if ( this == o ) {
return true;
}
if ( !( o instanceof SimpleEntity ) ) {
return false;
}
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)
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;
}
@ -51,7 +58,7 @@ public class SimpleEntity {
@Override
public int hashCode() {
int result = id != null ? id.hashCode() : 0;
result = 31 * result + (simpleProperty != null ? simpleProperty.hashCode() : 0);
result = 31 * result + ( simpleProperty != null ? simpleProperty.hashCode() : 0 );
return result;
}