public class

Mapping

extends Object
java.lang.Object
   ↳ com.netflix.astyanax.mapping.Mapping<T>

Class Overview

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.

Summary

Constants
String DEFAULT_ID_COLUMN_NAME If the ID column does not have a Column annotation, this column name is used
Public Constructors
Mapping(Class<T> clazz)
Mapping(Class<T> clazz, AnnotationSet<?, ?> annotationSet)
Public Methods
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
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final String DEFAULT_ID_COLUMN_NAME

If the ID column does not have a Column annotation, this column name is used

Constant Value: "ID"

Public Constructors

public Mapping (Class<T> clazz)

Parameters
clazz clazz type to map

public Mapping (Class<T> clazz, AnnotationSet<?, ?> annotationSet)

Parameters
clazz clazz type to map
annotationSet annotations to use when analyzing a bean

Public Methods

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

public List<T> getAll (Rows<?, String> rows)

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

public 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

public 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

public Collection<String> getNames ()

Return the set of column names discovered from the bean class

Returns
  • column names

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)

public static Mapping<T> make (Class<T> clazz)

Convenience for allocation a mapping object

Parameters
clazz clazz type to map
Returns
  • mapper

public static 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

public T newInstance (ColumnList<String> columns)

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

public 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)

public 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)