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 | Class and Description |
---|---|
static class |
Mapper.Option
An option for a mapper operation.
|
Modifier and Type | Method and Description |
---|---|
void |
delete(Object... objects)
Deletes an entity based on its primary key.
|
void |
delete(T entity)
Deletes an entity mapped by this mapper.
|
void |
delete(T entity,
Mapper.Option... options)
Deletes an entity mapped by this mapper using provided options.
|
com.google.common.util.concurrent.ListenableFuture<Void> |
deleteAsync(Object... objects)
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.
|
com.google.common.util.concurrent.ListenableFuture<Void> |
deleteAsync(T entity,
Mapper.Option... options)
Deletes an entity mapped by this mapper asynchronously using provided options.
|
Statement |
deleteQuery(Object... objects)
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.
|
Statement |
deleteQuery(T entity,
Mapper.Option... options)
Creates a query that can be used to delete the provided entity.
|
T |
get(Object... objects)
Fetch an entity based on its primary key.
|
com.google.common.util.concurrent.ListenableFuture<T> |
getAsync(Object... objects)
Fetch an entity based on its primary key asynchronously.
|
MappingManager |
getManager()
The
MappingManager managing this mapper. |
Statement |
getQuery(Object... objects)
Creates a query to fetch entity given its PRIMARY KEY.
|
TableMetadata |
getTableMetadata()
The
TableMetadata for this mapper. |
Result<T> |
map(ResultSet resultSet)
Maps the rows from a
ResultSet into the class this is a mapper of. |
Result<T> |
mapAliased(ResultSet resultSet)
Maps the rows from a
ResultSet into the class this is a mapper of. |
void |
resetDefaultDeleteOptions()
Reset the default delete options for this object mapper.
|
void |
resetDefaultGetOptions()
Reset the default save options for this object mapper.
|
void |
resetDefaultSaveOptions()
Reset the default save options for this object mapper.
|
void |
save(T entity)
Save an entity mapped by this mapper.
|
void |
save(T entity,
Mapper.Option... options)
Save an entity mapped by this mapper and using special options for save.
|
com.google.common.util.concurrent.ListenableFuture<Void> |
saveAsync(T entity)
Save an entity mapped by this mapper asynchronously.
|
com.google.common.util.concurrent.ListenableFuture<Void> |
saveAsync(T entity,
Mapper.Option... options)
Save an entity mapped by this mapper asynchronously using special options for save.
|
Statement |
saveQuery(T entity)
Creates a query that can be used to save the provided entity.
|
Statement |
saveQuery(T entity,
Mapper.Option... options)
Creates a query that can be used to save the provided entity.
|
void |
setDefaultDeleteOptions(Mapper.Option... options)
Set the default delete
Mapper.Option for this object mapper, that will be used
in all delete operations unless overridden. |
void |
setDefaultGetOptions(Mapper.Option... options)
Set the default get
Mapper.Option for this object mapper, that will be used
in all get operations unless overridden. |
void |
setDefaultSaveOptions(Mapper.Option... options)
Set the default save
Mapper.Option for this object mapper, that will be used
in all save operations unless overridden. |
public TableMetadata getTableMetadata()
TableMetadata
for this mapper.TableMetadata
for this mapper or null
if keyspace is not set.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 Statement saveQuery(T entity, Mapper.Option... options)
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.
This method allows you to provide a suite of Mapper.Option
to include in
the SAVE query. Options currently supported for SAVE are :
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 void save(T entity, Mapper.Option... options)
Mapper.Option
to include in
the SAVE query. Options currently supported for SAVE are :
entity
- the entity to save.options
- the options object specified defining special options when saving.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 com.google.common.util.concurrent.ListenableFuture<Void> saveAsync(T entity, Mapper.Option... options)
This method is basically equivalent to: getManager().getSession().executeAsync(saveQuery(entity, options))
.
entity
- the entity to save.options
- the options object specified defining special options when saving.public Statement getQuery(Object... objects)
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.
This method allows you to provide a suite of Mapper.Option
to include in
the GET query. Options currently supported for GET are :
objects
- 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.
Can be followed by Mapper.Option
to include in the DELETE query.objects
.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... objects)
This method is basically equivalent to: map(getManager().getSession().execute(getQuery(objects))).one()
.
objects
- 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.
Can be followed by Mapper.Option
to include in the DELETE query.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... objects)
This method is basically equivalent to mapping the result of: getManager().getSession().executeAsync(getQuery(objects))
.
objects
- 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.
Can be followed by Mapper.Option
to include in the DELETE query.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
.public Statement deleteQuery(T entity, Mapper.Option... options)
This method is a shortcut that extract the PRIMARY KEY from the
provided entity and call deleteQuery(Object...)
with it.
This method allows you to provide a suite of Mapper.Option
to include in
the DELETE query. Note : currently, only Mapper.Option.Timestamp
is supported for DELETE queries.
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.
This method allows you to provide a suite of Mapper.Option
to include in
the DELETE query. Options currently supported for DELETE are :
entity
- the entity to delete.options
- the options to add to the DELETE query.entity
(based on it's defined mapping) with
provided USING options.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... objects)
The values provided must correspond to the columns composing the PRIMARY
KEY (in the order of said primary key). The values can also contain, after
specifying the primary keys columns, a suite of Mapper.Option
to include in
the DELETE query. Note : currently, only Mapper.Option.Timestamp
is supported for DELETE queries.
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.
This method allows you to provide a suite of Mapper.Option
to include in
the DELETE query. Options currently supported for DELETE are :
objects
- 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.
Can be followed by Mapper.Option
to include in the DELETE
query.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 void delete(T entity, Mapper.Option... options)
This method is basically equivalent to: getManager().getSession().execute(deleteQuery(entity, options))
.
entity
- the entity to delete.options
- the options to add to the DELETE query.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 com.google.common.util.concurrent.ListenableFuture<Void> deleteAsync(T entity, Mapper.Option... options)
This method is basically equivalent to: getManager().getSession().executeAsync(deleteQuery(entity, options))
.
entity
- the entity to delete.options
- the options to add to the DELETE query.public void delete(Object... objects)
This method is basically equivalent to: getManager().getSession().execute(deleteQuery(objects))
.
objects
- 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.Can be followed by Mapper.Option
to include
in the DELETE query.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... objects)
This method is basically equivalent to: getManager().getSession().executeAsync(deleteQuery(objects))
.
objects
- 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. Can be followed by Mapper.Option
to include
in the DELETE query.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 a mapper of.
Use this method to map a result set that was not generated by the mapper (e.g. a result set coming from a
manual query or an method
.
It expects that the result set contains all column mapped in the target class,
and that they are not aliased. Computed
fields will not be filled in mapped objects.
resultSet
- the ResultSet
to map.resultSet
and so consuming results from this
returned mapped result set will consume results from resultSet
and vice-versa.mapAliased(ResultSet)
public Result<T> mapAliased(ResultSet resultSet)
ResultSet
into the class this is a mapper of.
Use this method to map a result set coming from the execution of the Statement
returned by
getQuery(Object...)
. Computed
fields will be filled in the mapped object.
resultSet
- the ResultSet
to map.resultSet
and so consuming results from this
returned mapped result set will consume results from resultSet
and vice-versa.map(ResultSet)
public void setDefaultSaveOptions(Mapper.Option... options)
Mapper.Option
for this object mapper, that will be used
in all save operations unless overridden. Refer to save(Object, Option...)
)}
to check available save options.options
- the options to set. To reset, use resetDefaultSaveOptions()
.public void resetDefaultSaveOptions()
public void setDefaultGetOptions(Mapper.Option... options)
Mapper.Option
for this object mapper, that will be used
in all get operations unless overridden. Refer to get(Object...)
)} to check available
get options.options
- the options to set. To reset, use resetDefaultGetOptions()
.public void resetDefaultGetOptions()
public void setDefaultDeleteOptions(Mapper.Option... options)
Mapper.Option
for this object mapper, that will be used
in all delete operations unless overridden. Refer to delete(Object...)
)}
to check available delete options.options
- the options to set. To reset, use resetDefaultDeleteOptions()
.public void resetDefaultDeleteOptions()
Copyright © 2012–2015. All rights reserved.