From 2121b331c71f884ed667aa66e4c1cfbdf05019f6 Mon Sep 17 00:00:00 2001 From: Emmanuel Bernard Date: Wed, 10 Dec 2014 13:26:59 +0100 Subject: [PATCH] OGM-678 Remove AssociationOperationType.PUT_NULL operation It was never used and is quite doubtful it would be necessary. I added a Contracts.assertNotNull on association.put to prevent setting the value to null. --- .../hibernate/ogm/datastore/map/impl/MapHelpers.java | 1 - .../java/org/hibernate/ogm/model/spi/Association.java | 11 ++++++----- .../ogm/model/spi/AssociationOperationType.java | 5 ++++- .../ogm/datastore/ehcache/EhcacheDialect.java | 1 - .../hibernate/ogm/datastore/neo4j/Neo4jDialect.java | 1 - 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/core/src/main/java/org/hibernate/ogm/datastore/map/impl/MapHelpers.java b/core/src/main/java/org/hibernate/ogm/datastore/map/impl/MapHelpers.java index 3be7099a0c..acad0684aa 100644 --- a/core/src/main/java/org/hibernate/ogm/datastore/map/impl/MapHelpers.java +++ b/core/src/main/java/org/hibernate/ogm/datastore/map/impl/MapHelpers.java @@ -69,7 +69,6 @@ public static void updateAssociation(Association association) { case PUT: underlyingMap.put( action.getKey(), MapHelpers.associationRowToMap( action.getValue() ) ); break; - case PUT_NULL: case REMOVE: underlyingMap.remove( action.getKey() ); break; diff --git a/core/src/main/java/org/hibernate/ogm/model/spi/Association.java b/core/src/main/java/org/hibernate/ogm/model/spi/Association.java index d0416975bf..182e3597b1 100644 --- a/core/src/main/java/org/hibernate/ogm/model/spi/Association.java +++ b/core/src/main/java/org/hibernate/ogm/model/spi/Association.java @@ -7,7 +7,6 @@ package org.hibernate.ogm.model.spi; import static org.hibernate.ogm.model.spi.AssociationOperationType.PUT; -import static org.hibernate.ogm.model.spi.AssociationOperationType.PUT_NULL; import static org.hibernate.ogm.model.spi.AssociationOperationType.REMOVE; import java.util.ArrayList; @@ -22,6 +21,7 @@ import org.hibernate.ogm.datastore.impl.EmptyAssociationSnapshot; import org.hibernate.ogm.dialect.spi.GridDialect; import org.hibernate.ogm.model.key.spi.RowKey; +import org.hibernate.ogm.util.impl.Contracts; import org.hibernate.ogm.util.impl.StringHelper; /** @@ -64,7 +64,7 @@ public Tuple get(RowKey key) { if ( result == null ) { return cleared ? null : snapshot.get( key ); } - else if ( result.getType() == PUT_NULL || result.getType() == REMOVE ) { + else if ( result.getType() == REMOVE ) { return null; } return result.getValue(); @@ -72,12 +72,15 @@ else if ( result.getType() == PUT_NULL || result.getType() == REMOVE ) { /** * Adds the given row to this association, using the given row key. + * The row must not be null, use the {@link #remove()} operation instead. * * @param key the key to store the row under * @param value the association row to store */ public void put(RowKey key, Tuple value) { - currentState.put( key, new AssociationOperation( key, value, value == null ? PUT_NULL : PUT ) ); + // instead of setting it to null, core must use remove + Contracts.assertNotNull( value, "association.put value" ); + currentState.put( key, new AssociationOperation( key, value, PUT ) ); } /** @@ -144,7 +147,6 @@ public int size() { for ( Map.Entry op : currentState.entrySet() ) { switch ( op.getValue().getType() ) { case PUT: - case PUT_NULL: if ( cleared || !snapshot.containsKey( op.getKey() ) ) { size++; } @@ -181,7 +183,6 @@ else if ( currentState.isEmpty() ) { for ( Map.Entry op : currentState.entrySet() ) { switch ( op.getValue().getType() ) { case PUT: - case PUT_NULL: keys.add( op.getKey() ); break; case REMOVE: diff --git a/core/src/main/java/org/hibernate/ogm/model/spi/AssociationOperationType.java b/core/src/main/java/org/hibernate/ogm/model/spi/AssociationOperationType.java index 9c6eae78f6..2d85e9a3e6 100644 --- a/core/src/main/java/org/hibernate/ogm/model/spi/AssociationOperationType.java +++ b/core/src/main/java/org/hibernate/ogm/model/spi/AssociationOperationType.java @@ -12,8 +12,11 @@ * @author Emmanuel Bernard <emmanuel@hibernate.org> */ public enum AssociationOperationType { + /** + * The PUT operation is never for a null value. + * Use REMOVE instead. + */ PUT, REMOVE, - PUT_NULL, CLEAR } diff --git a/ehcache/src/main/java/org/hibernate/ogm/datastore/ehcache/EhcacheDialect.java b/ehcache/src/main/java/org/hibernate/ogm/datastore/ehcache/EhcacheDialect.java index 82e8a25282..cf79361622 100644 --- a/ehcache/src/main/java/org/hibernate/ogm/datastore/ehcache/EhcacheDialect.java +++ b/ehcache/src/main/java/org/hibernate/ogm/datastore/ehcache/EhcacheDialect.java @@ -160,7 +160,6 @@ public void insertOrUpdateAssociation(AssociationKey key, Association associatio switch ( action.getType() ) { case CLEAR: associationRows.clear(); - case PUT_NULL: case PUT: associationRows.put( new SerializableRowKey( action.getKey() ), MapHelpers.associationRowToMap( action.getValue() ) ); break; diff --git a/neo4j/src/main/java/org/hibernate/ogm/datastore/neo4j/Neo4jDialect.java b/neo4j/src/main/java/org/hibernate/ogm/datastore/neo4j/Neo4jDialect.java index 9fcfc7ea37..c66b7bd232 100644 --- a/neo4j/src/main/java/org/hibernate/ogm/datastore/neo4j/Neo4jDialect.java +++ b/neo4j/src/main/java/org/hibernate/ogm/datastore/neo4j/Neo4jDialect.java @@ -353,7 +353,6 @@ private void applyAssociationOperation(Association association, AssociationKey k case PUT: putAssociationOperation( association, key, operation, associationContext.getAssociationTypeContext().getAssociatedEntityKeyMetadata() ); break; - case PUT_NULL: case REMOVE: removeAssociationOperation( association, key, operation, associationContext.getAssociationTypeContext().getAssociatedEntityKeyMetadata() ); break;