public class Mapper<T> extends Object
Mapper
object is obtained from a MappingManager
using the
MappingManager.mapper(java.lang.Class<T>, java.lang.String)
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.
|
ListenableFuture<Void> |
deleteAsync(Object... objects)
Deletes an entity based on its primary key asynchronously.
|
ListenableFuture<Void> |
deleteAsync(T entity)
Deletes an entity mapped by this mapper asynchronously.
|
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.
|
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)
Deprecated.
you no longer need to specify whether a result set is aliased, it will be detected automatically. Use
map(ResultSet) instead of this method. |
ListenableFuture<Result<T>> |
mapAsync(ResultSetFuture resultSetFuture)
Asynchronously maps the rows from a
ResultSetFuture 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)
Saves an entity mapped by this mapper.
|
void |
save(T entity,
Mapper.Option... options)
Saves an entity mapped by this mapper and using special options for save.
|
ListenableFuture<Void> |
saveAsync(T entity)
Saves an entity mapped by this mapper asynchronously.
|
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)
ResultSet
object after execution (to get the
trace, the execution info, ...), but in other cases, calling save(T)
or saveAsync(T)
is shorter.
Note: this method might block if the query is not prepared yet.entity
- the entity to save.entity
(based on its defined mapping).public Statement saveQuery(T entity, Mapper.Option... options)
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 its defined mapping).public void save(T entity)
getManager().getSession().execute(saveQuery(entity))
.
Note: this method will block until the entity is fully saved.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 ListenableFuture<Void> saveAsync(T entity)
getManager().getSession().executeAsync(saveQuery(entity))
.entity
- the entity to save.public ListenableFuture<Void> saveAsync(T entity, Mapper.Option... options)
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)
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)
map(getManager().getSession().execute(getQuery(objects))).one()
.
Note: this method will block until the entity is fully fetched.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 ListenableFuture<T> getAsync(Object... objects)
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)
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,
consistency 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 its defined mapping) with
provided USING options.public Statement deleteQuery(T entity)
deleteQuery(Object...)
with it.
This method is useful if you want to setup a number of options (tracing,
consistency 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.
Note: this method might block if the query is not prepared yet.entity
- the entity to delete.entity
(based on its defined mapping).public Statement deleteQuery(Object... objects)
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,
consistency 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)
getManager().getSession().execute(deleteQuery(entity))
.
Note: this method will block until the entity is fully deleted.entity
- the entity to delete.public void delete(T entity, Mapper.Option... options)
getManager().getSession().execute(deleteQuery(entity, options))
.
Note: this method will block until the entity is fully deleted.entity
- the entity to delete.options
- the options to add to the DELETE query.public ListenableFuture<Void> deleteAsync(T entity)
getManager().getSession().executeAsync(deleteQuery(entity))
.entity
- the entity to delete.public ListenableFuture<Void> deleteAsync(T entity, Mapper.Option... options)
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)
getManager().getSession().execute(deleteQuery(objects))
.
Note: this method will block until the entity is fully deleted.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 ListenableFuture<Void> deleteAsync(Object... objects)
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.
If the query was user-generated (that is, passed directly to session.execute()
or configured with
@Query
in an
@Accessor
-annotated interface), then only the columns
present in the result set will be mapped to the corresponding fields, and Computed
fields will not be
populated.
If the query was generated by the mapper (for example with getQuery(Object...)
), all fields will be
mapped, as if the object came from a direct get(Object...)
call.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 ListenableFuture<Result<T>> mapAsync(ResultSetFuture resultSetFuture)
ResultSetFuture
into the class this is a mapper of.
Use this method to map a ResultSetFuture
that was not generated by the mapper
(e.g. a ResultSetFuture
coming from a manual query or an Accessor
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.resultSetFuture
- the ResultSetFuture
to map.resultSetFuture
and so consuming results from this
returned mapped result set will consume results from that result set
and vice-versa.@Deprecated public Result<T> mapAliased(ResultSet resultSet)
map(ResultSet)
instead of this method.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–2018. All rights reserved.