/** * Retrieve entity that contains the association, do not enhance with entity key */ protected TuplePointer getEmbeddingEntityTuplePointer(AssociationKey key, AssociationContext associationContext) { TuplePointer tuplePointer = associationContext.getEntityTuplePointer(); if ( tuplePointer.getTuple() == null ) { tuplePointer.setTuple( getTuple( key.getEntityKey(), associationContext ) ); } return tuplePointer; }
@Override public org.hibernate.ogm.model.spi.Association getAssociation(AssociationKey key, AssociationContext associationContext) { RedisAssociation redisAssociation = null; if ( isStoredInEntityStructure( key.getMetadata(), associationContext.getAssociationTypeContext() ) ) { TuplePointer tuplePointer = getEmbeddingEntityTuplePointer( key, associationContext ); if ( tuplePointer == null ) { // The entity associated with this association has already been removed // see ManyToOneTest#testRemovalOfTransientEntityWithAssociation return null; } Entity owningEntity = getEntityFromTuple( tuplePointer.getTuple() ); if ( owningEntity != null && DotPatternMapHelpers.hasField( owningEntity.getPropertiesAsHierarchy(), key.getMetadata().getCollectionRole() ) ) { redisAssociation = RedisAssociation.fromEmbeddedAssociation( tuplePointer, key.getMetadata() ); } } else { Association association = getAssociation( key ); if ( association != null ) { redisAssociation = RedisAssociation.fromAssociationDocument( association ); } } return redisAssociation != null ? new org.hibernate.ogm.model.spi.Association( new RedisAssociationSnapshot( redisAssociation, key ) ) : null; }
@Override public org.hibernate.ogm.model.spi.Association createAssociation( AssociationKey key, AssociationContext associationContext) { RedisAssociation redisAssociation; if ( isStoredInEntityStructure( key.getMetadata(), associationContext.getAssociationTypeContext() ) ) { TuplePointer tuplePointer = getEmbeddingEntityTuplePointer( key, associationContext ); Entity owningEntity = getEntityFromTuple( tuplePointer.getTuple() ); if ( owningEntity == null ) { owningEntity = new Entity(); storeEntity( key.getEntityKey(), owningEntity, associationContext.getAssociationTypeContext().getHostingEntityOptionsContext() ); tuplePointer.setTuple( new Tuple( new RedisJsonTupleSnapshot( owningEntity ), SnapshotType.UPDATE ) ); } redisAssociation = RedisAssociation.fromEmbeddedAssociation( tuplePointer, key.getMetadata() ); } else { redisAssociation = RedisAssociation.fromAssociationDocument( new Association() ); } org.hibernate.ogm.model.spi.Association association = new org.hibernate.ogm.model.spi.Association( new RedisAssociationSnapshot( redisAssociation, key ) ); // in the case of an association stored in the entity structure, we might end up with rows present in the current snapshot of the entity // while we want an empty association here. So, in this case, we clear the snapshot to be sure the association created is empty. if ( !association.isEmpty() ) { association.clear(); } return association; }
@Override public Association getAssociation( AssociationKey key, AssociationContext associationContext) { RedisAssociation redisAssociation = null; if ( isStoredInEntityStructure( key.getMetadata(), associationContext.getAssociationTypeContext() ) ) { TuplePointer tuplePointer = getEmbeddingEntityTuplePointer( key, associationContext ); if ( tuplePointer == null ) { // The entity associated with this association has already been removed // see ManyToOneTest#testRemovalOfTransientEntityWithAssociation return null; } HashEntity owningEntity = getEntityFromTuple( tuplePointer.getTuple() ); if ( owningEntity != null && owningEntity.has( key.getMetadata().getCollectionRole() ) ) { redisAssociation = RedisAssociation.fromHashEmbeddedAssociation( tuplePointer, key.getMetadata() ); } } else { org.hibernate.ogm.datastore.redis.dialect.value.Association association = getAssociation( key ); if ( association == null ) { return null; } redisAssociation = RedisAssociation.fromAssociationDocument( association ); } return redisAssociation != null ? new org.hibernate.ogm.model.spi.Association( new RedisAssociationSnapshot( redisAssociation, key ) ) : null; }
@Override public Association createAssociation( AssociationKey key, AssociationContext associationContext) { RedisAssociation redisAssociation; if ( isStoredInEntityStructure( key.getMetadata(), associationContext.getAssociationTypeContext() ) ) { TuplePointer tuplePointer = getEmbeddingEntityTuplePointer( key, associationContext ); HashEntity owningEntity = getEntityFromTuple( tuplePointer.getTuple() ); if ( owningEntity == null ) { owningEntity = new HashEntity( new HashMap<String, String>() ); storeEntity( key.getEntityKey(), owningEntity, associationContext.getAssociationTypeContext().getHostingEntityOptionsContext() ); tuplePointer.setTuple( new Tuple( new RedisHashTupleSnapshot( owningEntity ), SnapshotType.UPDATE ) ); } redisAssociation = RedisAssociation.fromHashEmbeddedAssociation( tuplePointer, key.getMetadata() ); } else { redisAssociation = RedisAssociation.fromAssociationDocument( new org.hibernate.ogm.datastore.redis.dialect.value.Association() ); } return new org.hibernate.ogm.model.spi.Association( new RedisAssociationSnapshot( redisAssociation, key ) ); }
@Override public Association createAssociation(AssociationKey key, AssociationContext associationContext) { if ( key.getMetadata().getAssociationKind() == AssociationKind.ASSOCIATION ) { return new Association( new IgniteAssociationSnapshot( key ) ); } else if ( key.getMetadata().getAssociationKind() == AssociationKind.EMBEDDED_COLLECTION ) { return new Association( new IgniteEmbeddedAssociationSnapshot( key, associationContext.getEntityTuplePointer().getTuple() ) ); } else { throw new UnsupportedOperationException( "Unknown association kind " + key.getMetadata().getAssociationKind() ); } }
@Override public Association getAssociation(AssociationKey key, AssociationContext associationContext) { throw new UnsupportedOperationException("not yet supported"); }
@Override public Association createAssociation(AssociationKey key, AssociationContext associationContext) { throw new UnsupportedOperationException("not yet supported"); }
@Override public void insertOrUpdateAssociation(AssociationKey key, Association association, AssociationContext associationContext) { throw new UnsupportedOperationException("not yet supported"); }
@Override public void removeAssociation(AssociationKey key, AssociationContext associationContext) { throw new UnsupportedOperationException("not yet supported"); }