public class Mapper<T> extends Object
A Mapper
object is obtained from a MappingManager
using the
MappingManager.mapper(java.lang.Class<T>)
method.
Modifier and Type | Method and Description |
---|---|
void |
delete(Object... primaryKey)
Deletes an entity based on its primary key.
|
void |
delete(T entity)
Deletes an entity mapped by this mapper.
|
com.google.common.util.concurrent.ListenableFuture<Void> |
deleteAsync(Object... primaryKey)
Deletes an entity based on its primary key asynchronously.
|
com.google.common.util.concurrent.ListenableFuture<Void> |
deleteAsync(T entity)
Deletes an entity mapped by this mapper asynchronously.
|
Statement |
deleteQuery(Object... primaryKey)
Creates a query that can be used to delete an entity given its PRIMARY KEY.
|
Statement |
deleteQuery(T entity)
Creates a query that can be used to delete the provided entity.
|
T |
get(Object... primaryKey)
Fetch an entity based on its primary key.
|
com.google.common.util.concurrent.ListenableFuture<T> |
getAsync(Object... primaryKey)
Fetch an entity based on its primary key asynchronously.
|
MappingManager |
getManager()
The
MappingManager managing this mapper. |
Statement |
getQuery(Object... primaryKey)
Creates a query to fetch entity given its PRIMARY KEY.
|
Result<T> |
map(ResultSet resultSet)
Map the rows from a
ResultSet into the class this is mapper of. |
void |
save(T entity)
Save an entity mapped by this mapper.
|
com.google.common.util.concurrent.ListenableFuture<Void> |
saveAsync(T entity)
Save an entity mapped by this mapper asynchonously.
|
Statement |
saveQuery(T entity)
Creates a query that can be used to save the provided entity.
|
public MappingManager getManager()
MappingManager
managing this mapper.MappingManager
managing this mapper.public Statement saveQuery(T entity)
This method is useful if you want to setup a number of options (tracing,
conistency level, ...) of the returned statement before executing it manually
or need access to the ResultSet
object after execution (to get the
trace, the execution info, ...), but in other cases, calling save(T)
or saveAsync(T)
is shorter.
entity
- the entity to save.entity
(based on it's defined mapping).public void save(T entity)
This method is basically equivalent to: getManager().getSession().execute(saveQuery(entity))
.
entity
- the entity to save.public com.google.common.util.concurrent.ListenableFuture<Void> saveAsync(T entity)
This method is basically equivalent to: getManager().getSession().executeAsync(saveQuery(entity))
.
entity
- the entity to save.public Statement deleteQuery(T entity)
This method is a shortcut that extract the PRIMARY KEY from the
provided entity and call deleteQuery(Object...)
with it.
This method is useful if you want to setup a number of options (tracing,
conistency level, ...) of the returned statement before executing it manually
or need access to the ResultSet
object after execution (to get the
trace, the execution info, ...), but in other cases, calling delete(T)
or deleteAsync(T)
is shorter.
entity
- the entity to delete.entity
(based on it's defined mapping).public Statement deleteQuery(Object... primaryKey)
The values provided must correspond to the columns composing the PRIMARY KEY (in the order of said primary key).
This method is useful if you want to setup a number of options (tracing,
conistency level, ...) of the returned statement before executing it manually
or need access to the ResultSet
object after execution (to get the
trace, the execution info, ...), but in other cases, calling delete(T)
or deleteAsync(T)
is shorter.
primaryKey
- the primary key of the entity to delete, or more precisely
the values for the columns of said primary key in the order of the primary key.primaryKey
.IllegalArgumentException
- if the number of value provided differ from
the number of columns composing the PRIMARY KEY of the mapped class, or if
at least one of those values is null
.public void delete(T entity)
This method is basically equivalent to: getManager().getSession().execute(deleteQuery(entity))
.
entity
- the entity to delete.public com.google.common.util.concurrent.ListenableFuture<Void> deleteAsync(T entity)
This method is basically equivalent to: getManager().getSession().executeAsync(deleteQuery(entity))
.
entity
- the entity to delete.public void delete(Object... primaryKey)
This method is basically equivalent to: getManager().getSession().execute(deleteQuery(primaryKey))
.
primaryKey
- the primary key of the entity to delete, or more precisely
the values for the columns of said primary key in the order of the primary key.IllegalArgumentException
- if the number of value provided differ from
the number of columns composing the PRIMARY KEY of the mapped class, or if
at least one of those values is null
.public com.google.common.util.concurrent.ListenableFuture<Void> deleteAsync(Object... primaryKey)
This method is basically equivalent to: getManager().getSession().executeAsync(deleteQuery(primaryKey))
.
primaryKey
- the primary key of the entity to delete, or more precisely
the values for the columns of said primary key in the order of the primary key.IllegalArgumentException
- if the number of value provided differ from
the number of columns composing the PRIMARY KEY of the mapped class, or if
at least one of those values is null
.public Result<T> map(ResultSet resultSet)
ResultSet
into the class this is mapper of.resultSet
- the ResultSet
to map.resultSet
and so consuming results from this
returned mapped result set will consume results from resultSet
and vice-versa.public Statement getQuery(Object... primaryKey)
The values provided must correspond to the columns composing the PRIMARY KEY (in the order of said primary key).
This method is useful if you want to setup a number of options (tracing,
conistency level, ...) of the returned statement before executing it manually,
but in other cases, calling get(java.lang.Object...)
or getAsync(java.lang.Object...)
is shorter.
primaryKey
- the primary key of the entity to fetch, or more precisely
the values for the columns of said primary key in the order of the primary key.primaryKey
.IllegalArgumentException
- if the number of value provided differ from
the number of columns composing the PRIMARY KEY of the mapped class, or if
at least one of those values is null
.public T get(Object... primaryKey)
This method is basically equivalent to: map(getManager().getSession().execute(getQuery(primaryKey))).one()
.
primaryKey
- the primary key of the entity to fetch, or more precisely
the values for the columns of said primary key in the order of the primary key.null
if it doesn't exist.IllegalArgumentException
- if the number of value provided differ from
the number of columns composing the PRIMARY KEY of the mapped class, or if
at least one of those values is null
.public com.google.common.util.concurrent.ListenableFuture<T> getAsync(Object... primaryKey)
This method is basically equivalent to mapping the result of: getManager().getSession().executeAsync(getQuery(primaryKey))
.
primaryKey
- the primary key of the entity to fetch, or more precisely
the values for the columns of said primary key in the order of the primary key.null
if said entity doesn't exist.IllegalArgumentException
- if the number of value provided differ from
the number of columns composing the PRIMARY KEY of the mapped class, or if
at least one of those values is null
.Copyright © 2014. All rights reserved.