Skip to content

Commit

Permalink
OGM-678 Remove AssociationOperationType.PUT_NULL operation
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
emmanuelbernard authored and DavideD committed Dec 10, 2014
1 parent 23a7c8c commit 2121b33
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 9 deletions.
Expand Up @@ -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;
Expand Down
11 changes: 6 additions & 5 deletions core/src/main/java/org/hibernate/ogm/model/spi/Association.java
Expand Up @@ -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;
Expand All @@ -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;

/**
Expand Down Expand Up @@ -64,20 +64,23 @@ 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();
}

/**
* 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 ) );
}

/**
Expand Down Expand Up @@ -144,7 +147,6 @@ public int size() {
for ( Map.Entry<RowKey,AssociationOperation> op : currentState.entrySet() ) {
switch ( op.getValue().getType() ) {
case PUT:
case PUT_NULL:
if ( cleared || !snapshot.containsKey( op.getKey() ) ) {
size++;
}
Expand Down Expand Up @@ -181,7 +183,6 @@ else if ( currentState.isEmpty() ) {
for ( Map.Entry<RowKey,AssociationOperation> op : currentState.entrySet() ) {
switch ( op.getValue().getType() ) {
case PUT:
case PUT_NULL:
keys.add( op.getKey() );
break;
case REMOVE:
Expand Down
Expand Up @@ -12,8 +12,11 @@
* @author Emmanuel Bernard &lt;emmanuel@hibernate.org&gt;
*/
public enum AssociationOperationType {
/**
* The PUT operation is never for a null value.
* Use REMOVE instead.
*/
PUT,
REMOVE,
PUT_NULL,
CLEAR
}
Expand Up @@ -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;
Expand Down
Expand Up @@ -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;
Expand Down

0 comments on commit 2121b33

Please sign in to comment.