org.springframework.data.hadoop.hbase
Class HbaseTemplate

java.lang.Object
  extended by org.springframework.data.hadoop.hbase.HbaseTemplate
All Implemented Interfaces:
InitializingBean, HbaseOperations

public class HbaseTemplate
extends Object
implements InitializingBean, HbaseOperations

Central class for accessing the HBase API. Simplifies the use of HBase and helps to avoid common errors. It executes core HBase workflow, leaving application code to invoke actions and extract results.

Author:
Costin Leau

Constructor Summary
HbaseTemplate()
           
HbaseTemplate(Configuration configuration)
           
 
Method Summary
 void afterPropertiesSet()
           
 DataAccessException convertHbaseAccessException(Exception ex)
           
<T> T
execute(String tableName, TableCallback<T> action)
          Executes the given action against the specified table handling resource management.
<T> T
find(String tableName, Scan scan, ResultsExtractor<T> action)
          Scans the target table using the given Scan object.
<T> List<T>
find(String tableName, Scan scan, RowMapper<T> action)
          Scans the target table using the given Scan object.
<T> T
find(String tableName, String family, ResultsExtractor<T> action)
          Scans the target table, using the given family.
<T> List<T>
find(String tableName, String family, RowMapper<T> action)
          Scans the target table, using the given column family.
<T> T
find(String tableName, String family, String qualifier, ResultsExtractor<T> action)
          Scans the target table, using the given column family and qualifier.
<T> List<T>
find(String tableName, String family, String qualifier, RowMapper<T> action)
          Scans the target table, using the given column family.
<T> T
get(String tableName, String rowName, RowMapper<T> mapper)
          Gets an individual row from the given table.
<T> T
get(String tableName, String rowName, String familyName, RowMapper<T> mapper)
          Gets an individual row from the given table.
<T> T
get(String tableName, String rowName, String familyName, String qualifier, RowMapper<T> mapper)
          Gets an individual row from the given table.
 void setAutoFlush(boolean autoFlush)
          Sets the auto flush.
 void setConfiguration(Configuration configuration)
          Sets the configuration.
 void setEncoding(String encoding)
          Sets the encoding.
 void setTableFactory(HTableInterfaceFactory tableFactory)
          Sets the table factory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HbaseTemplate

public HbaseTemplate()

HbaseTemplate

public HbaseTemplate(Configuration configuration)
Method Detail

afterPropertiesSet

public void afterPropertiesSet()
Specified by:
afterPropertiesSet in interface InitializingBean

execute

public <T> T execute(String tableName,
                     TableCallback<T> action)
Description copied from interface: HbaseOperations
Executes the given action against the specified table handling resource management.

Application exceptions thrown by the action object get propagated to the caller (can only be unchecked). Allows for returning a result object (typically a domain object or collection of domain objects).

Specified by:
execute in interface HbaseOperations
Parameters:
tableName - the target table
action - callback object that specifies the action
Returns:
the result object of the callback action, or null

convertHbaseAccessException

public DataAccessException convertHbaseAccessException(Exception ex)

find

public <T> T find(String tableName,
                  String family,
                  ResultsExtractor<T> action)
Description copied from interface: HbaseOperations
Scans the target table, using the given family. The content is processed by the given action typically returning a domain object or collection of domain objects.

Specified by:
find in interface HbaseOperations
Parameters:
tableName - target table
family - column family
action - action handling the scanner results
Returns:
the result object of the callback action, or null

find

public <T> T find(String tableName,
                  String family,
                  String qualifier,
                  ResultsExtractor<T> action)
Description copied from interface: HbaseOperations
Scans the target table, using the given column family and qualifier. The content is processed by the given action typically returning a domain object or collection of domain objects.

Specified by:
find in interface HbaseOperations
Parameters:
tableName - target table
family - column family
qualifier - column qualifier
action - action handling the scanner results
Returns:
the result object of the callback action, or null

find

public <T> T find(String tableName,
                  Scan scan,
                  ResultsExtractor<T> action)
Description copied from interface: HbaseOperations
Scans the target table using the given Scan object. Suitable for maximum control over the scanning process. The content is processed by the given action typically returning a domain object or collection of domain objects.

Specified by:
find in interface HbaseOperations
Parameters:
tableName - target table
scan - table scanner
action - action handling the scanner results
Returns:
the result object of the callback action, or null

find

public <T> List<T> find(String tableName,
                        String family,
                        RowMapper<T> action)
Description copied from interface: HbaseOperations
Scans the target table, using the given column family. The content is processed row by row by the given action, returning a list of domain objects.

Specified by:
find in interface HbaseOperations
Parameters:
tableName - target table
family - column family
action - row mapper handling the scanner results
Returns:
a list of objects mapping the scanned rows

find

public <T> List<T> find(String tableName,
                        String family,
                        String qualifier,
                        RowMapper<T> action)
Description copied from interface: HbaseOperations
Scans the target table, using the given column family. The content is processed row by row by the given action, returning a list of domain objects.

Specified by:
find in interface HbaseOperations
Parameters:
tableName - target table
family - column family
qualifier - column qualifier
action - row mapper handling the scanner results
Returns:
a list of objects mapping the scanned rows

find

public <T> List<T> find(String tableName,
                        Scan scan,
                        RowMapper<T> action)
Description copied from interface: HbaseOperations
Scans the target table using the given Scan object. Suitable for maximum control over the scanning process. The content is processed row by row by the given action, returning a list of domain objects.

Specified by:
find in interface HbaseOperations
Parameters:
tableName - target table
scan - table scanner
action - row mapper handling the scanner results
Returns:
a list of objects mapping the scanned rows

get

public <T> T get(String tableName,
                 String rowName,
                 RowMapper<T> mapper)
Description copied from interface: HbaseOperations
Gets an individual row from the given table. The content is mapped by the given action.

Specified by:
get in interface HbaseOperations
Parameters:
tableName - target table
rowName - row name
mapper - row mapper
Returns:
object mapping the target row

get

public <T> T get(String tableName,
                 String rowName,
                 String familyName,
                 RowMapper<T> mapper)
Description copied from interface: HbaseOperations
Gets an individual row from the given table. The content is mapped by the given action.

Specified by:
get in interface HbaseOperations
Parameters:
tableName - target table
rowName - row name
familyName - column family
mapper - row mapper
Returns:
object mapping the target row

get

public <T> T get(String tableName,
                 String rowName,
                 String familyName,
                 String qualifier,
                 RowMapper<T> mapper)
Description copied from interface: HbaseOperations
Gets an individual row from the given table. The content is mapped by the given action.

Specified by:
get in interface HbaseOperations
Parameters:
tableName - target table
rowName - row name
familyName - family
qualifier - column qualifier
mapper - row mapper
Returns:
object mapping the target row

setAutoFlush

public void setAutoFlush(boolean autoFlush)
Sets the auto flush.

Parameters:
autoFlush - The autoFlush to set.

setTableFactory

public void setTableFactory(HTableInterfaceFactory tableFactory)
Sets the table factory.

Parameters:
tableFactory - The tableFactory to set.

setEncoding

public void setEncoding(String encoding)
Sets the encoding.

Parameters:
encoding - The encoding to set.

setConfiguration

public void setConfiguration(Configuration configuration)
Sets the configuration.

Parameters:
configuration - The configuration to set.