Java 类org.hibernate.ogm.dialect.spi.AssociationContext 实例源码

项目:hibernate-ogm-redis    文件:AbstractRedisDialect.java   
/**
 * 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;
}
项目:hibernate-ogm-redis    文件:RedisJsonDialect.java   
@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;
}
项目:hibernate-ogm-redis    文件:RedisJsonDialect.java   
@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;
}
项目:hibernate-ogm-redis    文件:RedisHashDialect.java   
@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;
}
项目:hibernate-ogm-redis    文件:RedisHashDialect.java   
@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
            )
    );
}
项目:hibernate-ogm-ignite    文件:IgniteDialect.java   
@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() );
    }
}
项目:lightblue-hibernate-ogm    文件:LightblueDialect.java   
@Override
public Association getAssociation(AssociationKey key, AssociationContext associationContext) {
    throw new UnsupportedOperationException("not yet supported");
}
项目:lightblue-hibernate-ogm    文件:LightblueDialect.java   
@Override
public Association createAssociation(AssociationKey key, AssociationContext associationContext) {
    throw new UnsupportedOperationException("not yet supported");
}
项目:lightblue-hibernate-ogm    文件:LightblueDialect.java   
@Override
public void insertOrUpdateAssociation(AssociationKey key, Association association, AssociationContext associationContext) {
    throw new UnsupportedOperationException("not yet supported");
}
项目:lightblue-hibernate-ogm    文件:LightblueDialect.java   
@Override
public void removeAssociation(AssociationKey key, AssociationContext associationContext) {
    throw new UnsupportedOperationException("not yet supported");
}