HHH-8171 - Cleanup
This commit is contained in:
parent
4796553a3f
commit
f2b9ab8278
|
@ -323,7 +323,7 @@
|
|||
SETORDINAL
|
||||
</entry>
|
||||
<entry>
|
||||
The name of the column used for storing the ordinal of the change in sets of embeddables.
|
||||
Name of column used for storing ordinal of the change in sets of embeddable elements.
|
||||
</entry>
|
||||
</row>
|
||||
</tbody>
|
||||
|
|
|
@ -101,7 +101,7 @@ public interface EnversSettings {
|
|||
public static final String AUDIT_STRATEGY_VALIDITY_REVEND_TIMESTAMP_FIELD_NAME = "org.hibernate.envers.audit_strategy_validity_revend_timestamp_field_name";
|
||||
|
||||
/**
|
||||
* The name of the column used for storing the ordinal of the change in sets of embeddables. Defaults to {@literal SETORDINAL}.
|
||||
* Name of column used for storing ordinal of the change in sets of embeddable elements. Defaults to {@literal SETORDINAL}.
|
||||
*/
|
||||
public static final String EMBEDDABLE_SET_ORDINAL_FIELD_NAME = "org.hibernate.envers.embeddable_set_ordinal_field_name";
|
||||
}
|
||||
|
|
|
@ -104,7 +104,8 @@ public class AuditEntitiesConfiguration {
|
|||
revisionPropBasePath = originalIdPropName + "." + revisionFieldName + ".";
|
||||
|
||||
embeddableSetOrdinalPropertyName = ConfigurationHelper.getString(
|
||||
EnversSettings.EMBEDDABLE_SET_ORDINAL_FIELD_NAME, properties, "SETORDINAL" );
|
||||
EnversSettings.EMBEDDABLE_SET_ORDINAL_FIELD_NAME, properties, "SETORDINAL"
|
||||
);
|
||||
}
|
||||
|
||||
public String getOriginalIdPropName() {
|
||||
|
|
|
@ -88,7 +88,6 @@ import org.hibernate.mapping.ManyToOne;
|
|||
import org.hibernate.mapping.OneToMany;
|
||||
import org.hibernate.mapping.PersistentClass;
|
||||
import org.hibernate.mapping.Property;
|
||||
import org.hibernate.mapping.SimpleValue;
|
||||
import org.hibernate.mapping.Table;
|
||||
import org.hibernate.mapping.Value;
|
||||
import org.hibernate.type.BagType;
|
||||
|
@ -507,20 +506,16 @@ public final class CollectionMetadataGenerator {
|
|||
);
|
||||
}
|
||||
|
||||
// Add an additional column holding a number to make each entry unique within the set,
|
||||
// since embeddable properties can be null
|
||||
if ( propertyValue.getCollectionType() instanceof SetType ) {
|
||||
final String auditedEmbeddableSetOrdinalPropertyName = mainGenerator.getVerEntCfg()
|
||||
.getEmbeddableSetOrdinalPropertyName();
|
||||
final String auditedEmbeddableSetOrdinalPropertyType = "integer";
|
||||
|
||||
final SimpleValue simpleValue = new SimpleValue( component.getMappings(), component.getTable() );
|
||||
simpleValue.setTypeName( auditedEmbeddableSetOrdinalPropertyType );
|
||||
|
||||
final Element idProperty = MetadataTools.addProperty( xmlMapping,
|
||||
auditedEmbeddableSetOrdinalPropertyName, auditedEmbeddableSetOrdinalPropertyType, true, true );
|
||||
MetadataTools.addColumn( idProperty, auditedEmbeddableSetOrdinalPropertyName, null, 0, 0, null, null,
|
||||
null, false );
|
||||
// Add an additional column holding a number to make each entry unique within the set.
|
||||
// Embeddable properties may contain null values, so cannot be stored within composite primary key.
|
||||
if ( propertyValue.isSet() ) {
|
||||
final String setOrdinalPropertyName = mainGenerator.getVerEntCfg().getEmbeddableSetOrdinalPropertyName();
|
||||
final Element ordinalProperty = MetadataTools.addProperty(
|
||||
xmlMapping, setOrdinalPropertyName, "integer", true, true
|
||||
);
|
||||
MetadataTools.addColumn(
|
||||
ordinalProperty, setOrdinalPropertyName, null, null, null, null, null, null, false
|
||||
);
|
||||
}
|
||||
|
||||
return new MiddleComponentData( componentMapper, 0 );
|
||||
|
|
|
@ -87,27 +87,16 @@ public abstract class AbstractCollectionMapper<T> implements PropertyMapper {
|
|||
protected abstract void mapToMapFromObject(SessionImplementor session, Map<String, Object> idData, Map<String, Object> data, Object changed);
|
||||
|
||||
/**
|
||||
* Creates a Map for the id.
|
||||
*
|
||||
* <p>
|
||||
* The ordinal parameter represents the iteration ordinal of the current element, used to add a synthetic id when
|
||||
* dealing with embeddables since embeddable fields can't be contained within the primary key since they might be
|
||||
* nullable.
|
||||
* </p>
|
||||
*
|
||||
* @param ordinal
|
||||
* The element iteration ordinal.
|
||||
*
|
||||
* @return A Map for holding the ID information.
|
||||
* Creates map for storing identifier data. Ordinal parameter guarantees uniqueness of primary key.
|
||||
* Composite primary key cannot contain embeddable properties since they might be nullable.
|
||||
* @param ordinal Iteration ordinal.
|
||||
* @return Map for holding identifier data.
|
||||
*/
|
||||
protected Map<String, Object> createIdMap(int ordinal) {
|
||||
final HashMap<String, Object> idMap = new HashMap<String, Object>();
|
||||
|
||||
final Map<String, Object> idMap = new HashMap<String, Object>();
|
||||
if ( ordinalInId ) {
|
||||
idMap.put( this.commonCollectionMapperData.getVerEntCfg().getEmbeddableSetOrdinalPropertyName(),
|
||||
Integer.valueOf( ordinal ) );
|
||||
idMap.put( commonCollectionMapperData.getVerEntCfg().getEmbeddableSetOrdinalPropertyName(), ordinal );
|
||||
}
|
||||
|
||||
return idMap;
|
||||
}
|
||||
|
||||
|
|
|
@ -41,8 +41,7 @@ public final class SortedSetCollectionMapper extends BasicCollectionMapper<Sorte
|
|||
Class<? extends SortedSet> collectionClass, Class<? extends SortedSet> proxyClass,
|
||||
MiddleComponentData elementComponentData, Comparator comparator, boolean ordinalInId,
|
||||
boolean revisionTypeInId) {
|
||||
super( commonCollectionMapperData, collectionClass, proxyClass, elementComponentData, ordinalInId,
|
||||
revisionTypeInId );
|
||||
super( commonCollectionMapperData, collectionClass, proxyClass, elementComponentData, ordinalInId, revisionTypeInId );
|
||||
this.comparator = comparator;
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
package org.hibernate.envers.test.integration.collection.embeddable;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
import org.junit.Test;
|
||||
|
@ -65,7 +64,7 @@ public class EmbeddableSet extends BaseEnversJPAFunctionalTestCase {
|
|||
|
||||
EmbeddableSetEntity ese1 = new EmbeddableSetEntity();
|
||||
|
||||
// Revision 1 (ese1: initially 2 elements)
|
||||
// Revision 1 (ese1: initially two elements)
|
||||
em.getTransaction().begin();
|
||||
ese1.getComponentSet().add( c3_1 );
|
||||
ese1.getComponentSet().add( c3_3 );
|
||||
|
@ -84,33 +83,33 @@ public class EmbeddableSet extends BaseEnversJPAFunctionalTestCase {
|
|||
ese1.getComponentSet().add( c3_2 );
|
||||
em.getTransaction().commit();
|
||||
|
||||
// Revision 3 (ese1: adding one existing element)
|
||||
// Revision (still 2) (ese1: adding one existing element)
|
||||
em.getTransaction().begin();
|
||||
ese1 = em.find( EmbeddableSetEntity.class, ese1.getId() );
|
||||
ese1.getComponentSet().add( c3_1 );
|
||||
em.getTransaction().commit();
|
||||
|
||||
// Revision 4 (ese1: removing one existing element)
|
||||
// Revision 3 (ese1: removing one existing element)
|
||||
em.getTransaction().begin();
|
||||
ese1 = em.find( EmbeddableSetEntity.class, ese1.getId() );
|
||||
ese1.getComponentSet().remove( c3_2 );
|
||||
em.getTransaction().commit();
|
||||
|
||||
// Revision 5 (ese1: adding two elements)
|
||||
// Revision 4 (ese1: adding two elements)
|
||||
em.getTransaction().begin();
|
||||
ese1 = em.find( EmbeddableSetEntity.class, ese1.getId() );
|
||||
ese1.getComponentSet().add( c3_2 );
|
||||
ese1.getComponentSet().add( c3_4 );
|
||||
em.getTransaction().commit();
|
||||
|
||||
// Revision 6 (ese1: removing two elements)
|
||||
// Revision 5 (ese1: removing two elements)
|
||||
em.getTransaction().begin();
|
||||
ese1 = em.find( EmbeddableSetEntity.class, ese1.getId() );
|
||||
ese1.getComponentSet().remove( c3_2 );
|
||||
ese1.getComponentSet().remove( c3_4 );
|
||||
em.getTransaction().commit();
|
||||
|
||||
// Revision 7 (ese1: removing and adding two elements)
|
||||
// Revision 6 (ese1: removing and adding two elements)
|
||||
em.getTransaction().begin();
|
||||
ese1 = em.find( EmbeddableSetEntity.class, ese1.getId() );
|
||||
ese1.getComponentSet().remove( c3_1 );
|
||||
|
@ -119,6 +118,12 @@ public class EmbeddableSet extends BaseEnversJPAFunctionalTestCase {
|
|||
ese1.getComponentSet().add( c3_4 );
|
||||
em.getTransaction().commit();
|
||||
|
||||
// Revision 7 (ese1: adding one element)
|
||||
em.getTransaction().begin();
|
||||
ese1 = em.find( EmbeddableSetEntity.class, ese1.getId() );
|
||||
ese1.getComponentSet().add( c3_1 );
|
||||
em.getTransaction().commit();
|
||||
|
||||
ese1_id = ese1.getId();
|
||||
|
||||
em.close();
|
||||
|
@ -126,7 +131,7 @@ public class EmbeddableSet extends BaseEnversJPAFunctionalTestCase {
|
|||
|
||||
@Test
|
||||
public void testRevisionsCounts() {
|
||||
assertEquals( Arrays.asList( 1, 2, 3, 4, 5, 6 ), getAuditReader().getRevisions( EmbeddableSetEntity.class, ese1_id ) );
|
||||
assertEquals( Arrays.asList( 1, 2, 3, 4, 5, 6, 7 ), getAuditReader().getRevisions( EmbeddableSetEntity.class, ese1_id ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -137,6 +142,7 @@ public class EmbeddableSet extends BaseEnversJPAFunctionalTestCase {
|
|||
EmbeddableSetEntity rev4 = getAuditReader().find( EmbeddableSetEntity.class, ese1_id, 4 );
|
||||
EmbeddableSetEntity rev5 = getAuditReader().find( EmbeddableSetEntity.class, ese1_id, 5 );
|
||||
EmbeddableSetEntity rev6 = getAuditReader().find( EmbeddableSetEntity.class, ese1_id, 6 );
|
||||
EmbeddableSetEntity rev7 = getAuditReader().find( EmbeddableSetEntity.class, ese1_id, 7 );
|
||||
|
||||
assertEquals( TestTools.makeSet( c3_1, c3_3 ), rev1.getComponentSet() );
|
||||
assertEquals( TestTools.makeSet( c3_1, c3_2, c3_3 ), rev2.getComponentSet() );
|
||||
|
@ -144,5 +150,6 @@ public class EmbeddableSet extends BaseEnversJPAFunctionalTestCase {
|
|||
assertEquals( TestTools.makeSet( c3_1, c3_2, c3_3, c3_4 ), rev4.getComponentSet() );
|
||||
assertEquals( TestTools.makeSet( c3_1, c3_3 ), rev5.getComponentSet() );
|
||||
assertEquals( TestTools.makeSet( c3_2, c3_4 ), rev6.getComponentSet() );
|
||||
assertEquals( TestTools.makeSet( c3_2, c3_4, c3_1 ), rev7.getComponentSet() );
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue