com.netflix.astyanax.mapping
Class Mapping<T>

java.lang.Object
  extended by com.netflix.astyanax.mapping.Mapping<T>

public class Mapping<T>
extends Object

Utility for doing object/relational mapping between bean-like instances and Cassandra

The mapper stores values in Cassandra and maps in/out to native types. Column names must be strings. Annotate your bean with Id and Column. Or, provide an AnnotationSet that defines IDs and Columns in your bean.


Field Summary
static String DEFAULT_ID_COLUMN_NAME
          If the ID column does not have a Column annotation, this column name is used
 
Constructor Summary
Mapping(Class<T> clazz)
           
Mapping(Class<T> clazz, AnnotationSet<?,?> annotationSet)
           
 
Method Summary
 void fillMutation(T instance, ColumnListMutation<String> mutation)
          Map a bean to a column mutation.
 List<T> getAll(Rows<?,String> rows)
          Load a set of rows into new instances populated with values from the column lists
<V> V
getColumnValue(T instance, String columnName, Class<V> valueClass)
          Return the value for the given column from the given instance
<V> V
getIdValue(T instance, Class<V> valueClass)
          Return the value for the ID/Key column from the given instance
 Collection<String> getNames()
          Return the set of column names discovered from the bean class
 T initInstance(T instance, ColumnList<String> columns)
          Populate the given instance with the values from the given column list
static
<T> Mapping<T>
make(Class<T> clazz)
          Convenience for allocation a mapping object
static
<T> Mapping<T>
make(Class<T> clazz, AnnotationSet<?,?> annotationSet)
          Convenience for allocation a mapping object
 T newInstance(ColumnList<String> columns)
          Allocate a new instance and populate it with the values from the given column list
<V> void
setColumnValue(T instance, String columnName, V value)
          Set the value for the given column for the given instance
<V> void
setIdValue(T instance, V value)
          Set the value for the ID/Key column for the given instance
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_ID_COLUMN_NAME

public static final String DEFAULT_ID_COLUMN_NAME
If the ID column does not have a Column annotation, this column name is used

See Also:
Constant Field Values
Constructor Detail

Mapping

public Mapping(Class<T> clazz)
Parameters:
clazz - clazz type to map

Mapping

public Mapping(Class<T> clazz,
               AnnotationSet<?,?> annotationSet)
Parameters:
clazz - clazz type to map
annotationSet - annotations to use when analyzing a bean
Method Detail

make

public static <T> Mapping<T> make(Class<T> clazz)
Convenience for allocation a mapping object

Parameters:
clazz - clazz type to map
Returns:
mapper

make

public static <T> Mapping<T> make(Class<T> clazz,
                                  AnnotationSet<?,?> annotationSet)
Convenience for allocation a mapping object

Parameters:
clazz - clazz type to map
annotationSet - annotations to use when analyzing a bean
Returns:
mapper

getIdValue

public <V> V getIdValue(T instance,
                        Class<V> valueClass)
Return the value for the ID/Key column from the given instance

Parameters:
instance - the instance
valueClass - type of the value (must match the actual native type in the instance's class)
Returns:
value

getColumnValue

public <V> V getColumnValue(T instance,
                            String columnName,
                            Class<V> valueClass)
Return the value for the given column from the given instance

Parameters:
instance - the instance
columnName - name of the column (must match a corresponding annotated field in the instance's class)
valueClass - type of the value (must match the actual native type in the instance's class)
Returns:
value

setIdValue

public <V> void setIdValue(T instance,
                           V value)
Set the value for the ID/Key column for the given instance

Parameters:
instance - the instance
value - The value (must match the actual native type in the instance's class)

setColumnValue

public <V> void setColumnValue(T instance,
                               String columnName,
                               V value)
Set the value for the given column for the given instance

Parameters:
instance - the instance
columnName - name of the column (must match a corresponding annotated field in the instance's class)
value - The value (must match the actual native type in the instance's class)

fillMutation

public void fillMutation(T instance,
                         ColumnListMutation<String> mutation)
Map a bean to a column mutation. i.e. set the columns in the mutation to the corresponding values from the instance

Parameters:
instance - instance
mutation - mutation

newInstance

public T newInstance(ColumnList<String> columns)
              throws IllegalAccessException,
                     InstantiationException
Allocate a new instance and populate it with the values from the given column list

Parameters:
columns - column list
Returns:
the allocated instance
Throws:
IllegalAccessException - if a new instance could not be instantiated
InstantiationException - if a new instance could not be instantiated

initInstance

public T initInstance(T instance,
                      ColumnList<String> columns)
Populate the given instance with the values from the given column list

Parameters:
instance - instance
columns - column this
Returns:
instance (as a convenience for chaining)

getAll

public List<T> getAll(Rows<?,String> rows)
               throws InstantiationException,
                      IllegalAccessException
Load a set of rows into new instances populated with values from the column lists

Parameters:
rows - the rows
Returns:
list of new instances
Throws:
IllegalAccessException - if a new instance could not be instantiated
InstantiationException - if a new instance could not be instantiated

getNames

public Collection<String> getNames()
Return the set of column names discovered from the bean class

Returns:
column names


Copyright © 2012. All Rights Reserved.