com.flipkart.hbaseobjectmapper.Records Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hbase-object-mapper Show documentation
Show all versions of hbase-object-mapper Show documentation
HBase ORM is a light-weight, thread-safe and performant library that enables:
[1] object-oriented access of HBase rows (Data Access Object) with minimal code and good testability
[2] reading from and/or writing to HBase tables in Hadoop MapReduce jobs
package com.flipkart.hbaseobjectmapper;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.*;
import java.io.*;
import java.util.Iterator;
/**
* This class is the return type of all 'records' methods of {@link AbstractHBDAO} class, which enable you to iterate over large number of records (e.g. {@link AbstractHBDAO#records(Serializable, Serializable) AbstractHBDAO.records(R, R)})
*
* Users of this library are not expected to instantiate this class on their own.
*
* Note: This class is not thread-safe. If you intend to scan records across multiple threads, keep different filter criteria for each thread.
*
* @param record type
*/
@SuppressWarnings("rawtypes")
public class Records implements Closeable, Iterable {
private final HBObjectMapper hbObjectMapper;
private final Class clazz;
private final Table table;
private final ResultScanner scanner;
Records(Connection connection, HBObjectMapper hbObjectMapper, Class clazz, TableName tableName, Scan scan) throws IOException {
this.hbObjectMapper = hbObjectMapper;
this.clazz = clazz;
this.table = connection.getTable(tableName);
this.scanner = table.getScanner(scan);
}
@Override
public void close() throws IOException {
scanner.close();
table.close();
}
@SuppressWarnings("NullableProblems")
@Override
public Iterator iterator() {
return new RecordsIterator<>(hbObjectMapper, clazz, scanner.iterator());
}
}