Skip to content

Commit

Permalink
OGM-1285 Some minor style fixes and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
gsmet committed Jul 7, 2017
1 parent 1f24c4c commit 5c80c66
Showing 1 changed file with 28 additions and 21 deletions.
Expand Up @@ -167,7 +167,7 @@ private static class OwningEntity {

private final EntityKey ownerEntityKey;

// A representation/ of the entity that we want to create or insert
// A representation of the entity that we want to create or insert
private Map<String, Object> owningEntity;

// If the entity already exists in the datastore or not
Expand Down Expand Up @@ -218,20 +218,20 @@ private void insertEntity(ProtoStreamMappingAdapter mapper, ProtostreamId idBuff
}

public void removeAssociation(RemoveAssociationOperation removeAssociationOperation) {
AssociationKey associationKey = removeAssociationOperation.getAssociationKey();
AssociationContext associationContext = removeAssociationOperation.getContext();
// N.B. 'key' might match multiple entries
if ( associationStoredWithinEntityEntry( associationKey, associationContext ) ) {
// The entity contains the association
if ( owningEntity == null ) {
TuplePointer entityTuplePointer = getEmbeddingEntityTuplePointer( provider, associationKey, associationContext );
applyOperations( entityTuplePointer.getTuple() );
}
}
else {
// The association is mapped with a bridge "table"
associationsToRemove.add( associationKey );
AssociationKey associationKey = removeAssociationOperation.getAssociationKey();
AssociationContext associationContext = removeAssociationOperation.getContext();
// N.B. 'key' might match multiple entries
if ( associationStoredWithinEntityEntry( associationKey, associationContext ) ) {
// The entity contains the association
if ( owningEntity == null ) {
TuplePointer entityTuplePointer = getEmbeddingEntityTuplePointer( provider, associationKey, associationContext );
applyOperations( entityTuplePointer.getTuple() );
}
}
else {
// The association is mapped with a bridge "table"
associationsToRemove.add( associationKey );
}
}

/**
Expand Down Expand Up @@ -292,14 +292,17 @@ public void removeTuple(EntityKey key, TupleContext tupleContext) {
}

private static String cacheName(EntityKey key) {
final String cacheName = key.getTable();
return cacheName;
return key.getTable();
}

private static String cacheName(AssociationKey key) {
return key.getTable();
}

private static String cacheName(EntityKeyMetadata keyMetadata) {
return keyMetadata.getTable();
}

@Override
public Association getAssociation(AssociationKey key, AssociationContext associationContext) {
Map<RowKey, Map<String, Object>> results = loadRowKeysByQuery( provider, key );
Expand All @@ -312,7 +315,7 @@ public Association getAssociation(AssociationKey key, AssociationContext associa
}

private static Map<RowKey, Map<String, Object>> loadRowKeysByQuery(InfinispanRemoteDatastoreProvider provider, AssociationKey key) {
final String cacheName = key.getTable();
final String cacheName = cacheName( key );
ProtostreamAssociationMappingAdapter mapper = provider.getCollectionsDataMapper( cacheName );
return mapper.withinCacheEncodingContext( c -> {
QueryFactory queryFactory = Search.getQueryFactory( c );
Expand Down Expand Up @@ -401,7 +404,7 @@ public Number nextValue(NextValueRequest request) {

@Override
public void forEachTuple(ModelConsumer consumer, TupleTypeContext tupleTypeContext, EntityKeyMetadata entityKeyMetadata) {
final String cacheName = entityKeyMetadata.getTable();
final String cacheName = cacheName( entityKeyMetadata );
ProtoStreamMappingAdapter mapper = provider.getDataMapperForCache( cacheName );

VersionedValue<ProtostreamPayload> v = mapper.withinCacheEncodingContext( c -> {
Expand Down Expand Up @@ -438,15 +441,15 @@ else if ( keys.length == 1 ) {
return Collections.singletonList( getTuple( keys[0], tupleContext ) );
}
else {
final String cacheName = keys[0].getTable();
final String cacheName = cacheName( keys[0] );
final ProtoStreamMappingAdapter mapper = provider.getDataMapperForCache( cacheName );
final Map<EntityKey,ProtostreamId> keyConversionMatch = new HashMap<>();
final Set<ProtostreamId> convertedKeys = new HashSet<>();
for ( EntityKey ek : keys ) {
if ( ek == null ) {
continue;
}
assert ek.getTable().equals( cacheName ) : "The javadoc comment promised batches would be loaded from the same table";
assert cacheName( ek ).equals( cacheName ) : "The javadoc comment promised batches would be loaded from the same table";
ProtostreamId idBuffer = mapper.createIdPayload( ek.getColumnNames(), ek.getColumnValues() );
keyConversionMatch.put( ek, idBuffer );
convertedKeys.add( idBuffer );
Expand Down Expand Up @@ -476,8 +479,12 @@ else if ( keys.length == 1 ) {
}

private static boolean associationStoredWithinEntityEntry(AssociationKey key, AssociationContext associationContext) {
final String cacheName = key.getTable();
final String cacheName = cacheName( key );
final String entityTableName = associationContext.getAssociationTypeContext().getAssociatedEntityKeyMetadata().getEntityKeyMetadata().getTable();

// in the case of embedded collections, the entityTableName and the cacheName are equal but they reference the name of a
// join table so the association is not stored in the entity entry.

return cacheName.equals( entityTableName ) && ! key.getMetadata().getAssociationKind().equals( AssociationKind.EMBEDDED_COLLECTION );
}

Expand Down

0 comments on commit 5c80c66

Please sign in to comment.