Java 类org.hibernate.ogm.model.key.spi.EntityKey 实例源码

项目:hibernate-ogm-redis    文件:RedisHashDialect.java   
@Override
public Tuple getTuple(EntityKey key, OperationContext operationContext) {
    String entityIdString = entityId( key );
    if ( !connection.exists( entityIdString ) ) {
        return null;
    }

    Map<String, String> objects;
    if ( operationContext.getTupleTypeContext().getSelectableColumns().isEmpty() ) {
        objects = connection.hgetall( entityIdString );
    }
    else {
        List<String> hmget = connection.hmget( entityIdString, getFields( operationContext.getTupleTypeContext() ) );
        objects = toEntity( operationContext.getTupleTypeContext(), hmget );
    }

    return createTuple( objects );
}
项目:hibernate-ogm-redis    文件:RedisTestHelper.java   
private Map<String, Object> extractFromJsonDialect(
        EntityKey key,
        RedisJsonDialect gridDialect
) {

    Entity entity = gridDialect.getEntityStorageStrategy().getEntity(
            gridDialect.entityId( key )
    );

    if ( entity == null ) {
        return null;
    }

    for ( int i = 0; i < key.getColumnNames().length; i++ ) {
        entity.set( key.getColumnNames()[i], key.getColumnValues()[i] );
    }
    return new HashMap<>( entity.getProperties() );
}
项目:hibernate-ogm-redis    文件:RedisTestHelper.java   
private Map<String, Object> extractFromHashDialect(
        SessionFactory sessionFactory,
        EntityKey key,
        RedisHashDialect gridDialect) {

    RedisClusterCommands<String, String> connection = getConnection( sessionFactory );

    String entityId = gridDialect.entityId( key );

    if ( !connection.exists( entityId ) ) {
        return null;
    }

    Map<String, String> hgetall = connection.hgetall( entityId );

    Map<String, Object> result = new HashMap<>();
    result.putAll( hgetall );

    for ( int i = 0; i < key.getColumnNames().length; i++ ) {
        result.put( key.getColumnNames()[i], key.getColumnValues()[i] );
    }

    return result;
}
项目:hibernate-ogm-ignite    文件:IgniteDatastoreProvider.java   
/**
 * Converting entity key to cache key
 *
 * @param key entity key
 * @return string key
 */
public Object createKeyObject(EntityKey key) {
    Object result = null;
    if ( key.getColumnValues().length == 1 ) {
        IgniteCache<Object, BinaryObject> entityCache = getEntityCache( key.getMetadata() );
        CacheConfiguration cacheConfig = entityCache.getConfiguration( CacheConfiguration.class );
        result = toValidKeyObject( key.getColumnValues()[0], cacheConfig.getKeyType() );
    }
    else {
        BinaryObjectBuilder builder = createBinaryObjectBuilder( findKeyType( key.getMetadata() ) );
        for ( int i = 0; i < key.getColumnNames().length; i++ ) {
            builder.setField( StringHelper.stringAfterPoint( key.getColumnNames()[i] ), key.getColumnValues()[i] );
        }
        result = builder.build();
    }
    return result;
}
项目:hibernate-ogm-ignite    文件:IgniteTestHelper.java   
@Override
public Map<String, Object> extractEntityTuple(Session session, EntityKey key) {
    SessionFactoryImplementor sessionFactory = (SessionFactoryImplementor) session.getSessionFactory();
    IgniteCache<Object, BinaryObject> cache = getEntityCache( sessionFactory, key.getMetadata() );
    Object cacheKey = getProvider( sessionFactory ).createKeyObject( key );

    Map<String, Object> result = new HashMap<>();
    BinaryObject po = cache.get( cacheKey );

    TupleSnapshot snapshot = new IgniteTupleSnapshot( cacheKey, po, key.getMetadata() );
    for ( String fieldName : snapshot.getColumnNames() ) {
        result.put( fieldName, snapshot.get( fieldName ) );
    }

    return result;
}
项目:lightblue-hibernate-ogm    文件:LightblueDialect.java   
private ObjectNode fetchObject(EntityKey key, TupleContext tupleContext) {
    LightblueEntityMetadataId entityId = LightblueEntityMetadataId.extractEntityInfo(key.getMetadata());
    DataFindRequest request = new DataFindRequest(entityId.entityName, entityId.entityVersion);
    request.where(new ValueQuery("_id", ExpressionOperation.EQUALS, key.getColumnValues()[0].toString()));
    List<Projection> projections = new ArrayList<Projection>(Arrays.asList(projectionsFromColumns(tupleContext.getSelectableColumns())));
    projections.add(new FieldProjection("_id", true, true));
    request.select(projections);
    try {
        LightblueResponse response = provider.getLightblueClient().data(request);
        if (response.hasError()) {
            throw new RuntimeException("Error returned in response: " + response.getText());
        }
        return (ObjectNode) response.getJson().get("processed").get(0);
    } catch (LightblueException e) {
        throw new RuntimeException("Unable to communicate with lightblue.", e);
    }
}
项目:hibernate-ogm-redis    文件:RedisJsonDialect.java   
@Override
public Tuple getTuple(EntityKey key, OperationContext operationContext) {
    Entity entity = entityStorageStrategy.getEntity( entityId( key ) );

    if ( entity != null ) {
        return new Tuple( new RedisJsonTupleSnapshot( entity ), SnapshotType.UPDATE );
    }
    else if ( isInTheInsertionQueue( key, operationContext ) ) {
        return createTuple( key, operationContext );
    }
    else {
        return null;
    }
}
项目:hibernate-ogm-redis    文件:RedisJsonDialect.java   
private void storeEntity(EntityKey key, Entity entity, OptionsContext optionsContext) {
    String entityId = entityId( key );
    Long currentTtl = getObjectTTL( entityId, optionsContext );

    entityStorageStrategy.storeEntity( entityId, entity );

    setObjectTTL( entityId, currentTtl );
}
项目:hibernate-ogm-redis    文件:RedisHashDialect.java   
private void storeEntity(EntityKey key, HashEntity entity, OptionsContext optionsContext) {
    String entityId = entityId( key );

    if ( !entity.isEmpty() ) {
        Long currentTtl = getObjectTTL( entityId, optionsContext );
        connection.hmset( entityId, entity.getProperties() );
        setObjectTTL( entityId, currentTtl );
    }
}
项目:hibernate-ogm-redis    文件:RedisTestHelper.java   
@Override
public Map<String, Object> extractEntityTuple(Session session, EntityKey key) {
    RedisDatastoreProvider castProvider = getProvider( session.getSessionFactory() );
    AbstractRedisDialect gridDialect = getGridDialect( castProvider );

    if ( gridDialect instanceof RedisJsonDialect ) {
        return extractFromJsonDialect( key, (RedisJsonDialect) gridDialect );
    }

    if ( gridDialect instanceof RedisHashDialect ) {
        return extractFromHashDialect( session.getSessionFactory(), key, (RedisHashDialect) gridDialect );
    }

    throw new IllegalStateException( "Unsupported dialect " + gridDialect );
}
项目:hibernate-ogm-ignite    文件:IgniteDialect.java   
@Override
public Tuple getTuple(EntityKey key, OperationContext operationContext) {
    IgniteCache<Object, BinaryObject> entityCache = provider.getEntityCache( key.getMetadata() );
    if ( entityCache == null ) {
        throw log.cacheNotFound( key.getMetadata().getTable() );
    }
    Object id = provider.createKeyObject( key );
    BinaryObject po = entityCache.get( id );
    if ( po != null ) {
        return new Tuple( new IgniteTupleSnapshot( id, po, key.getMetadata() ), SnapshotType.UPDATE );
    }
    else {
        return null;
    }
}
项目:hibernate-ogm-ignite    文件:IgniteDialect.java   
@Override
public Tuple createTuple(EntityKey key, OperationContext operationContext) {
    IgniteCache<Object, BinaryObject> entityCache = provider.getEntityCache( key.getMetadata() );
    if ( entityCache == null ) {
        throw log.cacheNotFound( key.getMetadata().getTable() );
    }
    Object id = provider.createKeyObject( key );
    return new Tuple( new IgniteTupleSnapshot( id, null, key.getMetadata() ), SnapshotType.INSERT );
}
项目:hibernate-ogm-ignite    文件:IgniteDialect.java   
@Override
public void insertOrUpdateTuple(EntityKey key, TuplePointer tuplePointer, TupleContext tupleContext) throws TupleAlreadyExistsException {
    IgniteCache<Object, BinaryObject> entityCache = provider.getEntityCache( key.getMetadata() );
    Tuple tuple = tuplePointer.getTuple();

    Object keyObject = null;
    BinaryObjectBuilder builder = null;
    IgniteTupleSnapshot tupleSnapshot = (IgniteTupleSnapshot) tuple.getSnapshot();
    keyObject = tupleSnapshot.getCacheKey();
    if ( tuple.getSnapshotType() == SnapshotType.UPDATE ) {
        builder = provider.createBinaryObjectBuilder( tupleSnapshot.getCacheValue() );
    }
    else {
        builder = provider.createBinaryObjectBuilder( provider.getEntityTypeName( key.getMetadata().getTable() ) );
    }
    for ( String columnName : tuple.getColumnNames() ) {
        Object value = tuple.get( columnName );
        if ( value != null ) {
            builder.setField( StringHelper.realColumnName( columnName ), value );
        }
        else {
            builder.removeField( StringHelper.realColumnName( columnName ) );
        }
    }
    BinaryObject valueObject = builder.build();
    entityCache.put( keyObject, valueObject );
    tuplePointer.setTuple( new Tuple( new IgniteTupleSnapshot( keyObject, valueObject, key.getMetadata() ), SnapshotType.UPDATE ) );
}
项目:lightblue-hibernate-ogm    文件:LightblueDialect.java   
@Override
public Tuple getTuple(EntityKey key, TupleContext tupleContext) {
    ObjectNode object = fetchObject(key, tupleContext);
    if (object != null) {
        return new Tuple(new LightblueTupleSnapshot(object, key.getMetadata(), OperationType.UPDATE));
    }
    if (isInQueue(key, tupleContext)) {
        return createTuple(key, tupleContext);
    }
    return null;
}
项目:lightblue-hibernate-ogm    文件:LightblueDialect.java   
@Override
public void removeTuple(EntityKey key, TupleContext tupleContext) {
    LightblueEntityMetadataId entityId = LightblueEntityMetadataId.extractEntityInfo(key.getMetadata());
    DataDeleteRequest request = new DataDeleteRequest(entityId.entityName, entityId.entityVersion);
    request.where(new ValueQuery("_id", ExpressionOperation.EQUALS, key.getColumnValues()[0].toString()));
    try {
        LightblueResponse data = provider.getLightblueClient().data(request);
        System.out.println(data.getJson());
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
项目:hibernate-ogm-redis    文件:AbstractRedisDialect.java   
@Override
public void removeTuple(EntityKey key, TupleContext tupleContext) {
    remove( key );
}
项目:hibernate-ogm-redis    文件:AbstractRedisDialect.java   
protected void remove(EntityKey key) {
    connection.del( entityId( key ) );
}
项目:hibernate-ogm-redis    文件:RedisJsonDialect.java   
@Override
public Tuple createTuple(EntityKey key, OperationContext operationContext) {
    return new Tuple( new RedisJsonTupleSnapshot( new Entity() ), SnapshotType.INSERT );
}
项目:hibernate-ogm-redis    文件:RedisHashDialect.java   
@Override
public Tuple createTuple(EntityKey key, OperationContext operationContext) {
    return new Tuple( new RedisHashTupleSnapshot( new HashEntity( new HashMap<String, String>() ) ), SnapshotType.INSERT );
}
项目:hibernate-ogm-ignite    文件:IgniteDialect.java   
@Override
public void removeTuple(EntityKey key, TupleContext tupleContext) {
    IgniteCache<Object, BinaryObject> entityCache = provider.getEntityCache( key.getMetadata() );
    entityCache.remove( provider.createKeyObject( key ) );
}
项目:lightblue-hibernate-ogm    文件:LightblueDialect.java   
private boolean isInQueue(EntityKey key, TupleContext tupleContext) {
    return tupleContext.getOperationsQueue() != null && tupleContext.getOperationsQueue().contains(key);
}
项目:lightblue-hibernate-ogm    文件:LightblueDialect.java   
@Override
public Tuple createTuple(EntityKey key, TupleContext tupleContext) {
    return new Tuple(new LightblueTupleSnapshot(mapper.createObjectNode(), key.getMetadata(), OperationType.INSERT));
}