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

项目:hibernate-ogm-redis    文件:RedisJsonDialect.java   
@Override
public ClosableIterator<Tuple> get(TransactionContext transactionContext) {
    return new RedisJsonTupleIterator( cursor, storageStrategy, prefix, entityKeyMetadata );
}
项目:hibernate-ogm-redis    文件:RedisHashDialect.java   
@Override
public ClosableIterator<Tuple> get(TransactionContext transactionContext) {
    return new RedisHashTupleIterator( cursor, connection, prefix, entityKeyMetadata );
}
项目:hibernate-ogm-redis    文件:RedisDialectClusterForEachTest.java   
@Test
public void testScan() throws Exception {

    AbstractRedisDialect dialect = RedisTestHelper.getDialect( getProvider() );
    assumeTrue( dialect.isClusterMode() );

    // pre-computed key file.
    URL resource = Resources.getResource( "redis-cluster-slothashes.txt" );
    List<String> lines = Resources.readLines( resource, StandardCharsets.ISO_8859_1 );

    OgmSession session = openSession();
    session.getTransaction().begin();

    // given
    int availableKeys = 0;
    for ( String line : lines ) {

        if ( line.startsWith( "#" ) || line.trim().isEmpty() ) {
            continue;
        }

        String key = line.substring( 0, line.indexOf( ' ' ) ).trim();

        Band record = new Band( key, key );
        session.persist( record );
        availableKeys++;
    }
    session.getTransaction().commit();

    final AtomicInteger counter = new AtomicInteger();

    dialect.forEachTuple( new ModelConsumer() {
        @Override
        public void consume(TuplesSupplier supplier) {
            try ( ClosableIterator<Tuple> closableIterator = supplier.get( null ) ) {
                while ( closableIterator.hasNext() ) {
                    counter.incrementAndGet();
                }
            }
        }
    }, null, new DefaultEntityKeyMetadata( "Band", new String[] {"id"} ) );

    assertEquals( availableKeys, counter.get() );
}
项目:lightblue-hibernate-ogm    文件:LightblueDialect.java   
@Override
public ClosableIterator<Tuple> executeBackendQuery(BackendQuery<String> query, QueryParameters queryParameters) {
    final String queryString = query.getQuery();
    String entityName = queryParameters.getNamedParameters().get("entityName").getValue().toString();
    String entityVersion = queryParameters.getNamedParameters().get("entityVersion").getValue().toString();
    DataFindRequest request = new DataFindRequest(entityName, entityVersion);
    request.select(new FieldProjection("*", true, true)); // FIXME dummy projection for broken client
    request.where(new Query() {

        @Override
        public String toJson() {
            return queryString;
        }
    });
    JsonNode jsonNode;
    try {
        jsonNode = provider.getLightblueClient().data(request).getJson().get("processed");
        List<Tuple> tuples = new ArrayList<Tuple>(jsonNode.size());
        for (int i = 0; i < jsonNode.size(); i++) {
            tuples.add(tupleFromNode((ObjectNode) jsonNode.get(i), entityName, entityVersion));
        }
        final Iterator<Tuple> iter = tuples.iterator();
        return new ClosableIterator<Tuple>() {

            @Override
            public Tuple next() {
                return iter.next();
            }

            @Override
            public boolean hasNext() {
                return iter.hasNext();
            }

            @Override
            public void close() {
                // NO-OP
            }

            @Override
            public void remove() {
                // TODO Auto-generated method stub

            }
        };
    } catch (LightblueException e) {
        throw new RuntimeException("Error while communicating with lightblue.", e);
    }
}