public class GenericDAO<T,PK>
extends java.lang.Object
| Constructor and Description |
|---|
GenericDAO(javax.inject.Provider<com.rethinkdb.net.Connection> connection,
java.lang.Class<T> clazz,
java.lang.String tableName,
java.lang.String primaryKey) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
addIndex(boolean geo,
java.lang.String fields) |
rx.Observable<ChangeFeedElement<T>> |
changes()
Provides a change feed of all changes which occur after subscribing to the returned
Observable. |
rx.Observable<ChangeFeedElement<T>> |
changes(java.util.function.Function<com.rethinkdb.gen.ast.Table,com.rethinkdb.gen.ast.ReqlExpr> filter)
Provides a change feed of all matching changes which occur after subscribing to the returned
Observable. |
void |
create(T model)
Creates a model in the RethinkDB database.
|
void |
delete(PK id)
Deletes a model from the database.
|
void |
initTable()
Initialize the table, automatically create the table and indices if they do not yet exist.
|
java.util.List<T> |
read() |
java.util.List<T> |
read(java.util.function.Function<com.rethinkdb.gen.ast.Table,com.rethinkdb.gen.ast.ReqlExpr> filter)
Retrieves a list of models matching the given filter.
|
java.util.Optional<T> |
read(PK id)
Retrieves a model with the given primary key.
|
void |
update(T model)
Updates a model.
|
void |
updateNonAtomic(T model)
Updates a model in the non atomic way.
|
public GenericDAO(javax.inject.Provider<com.rethinkdb.net.Connection> connection,
java.lang.Class<T> clazz,
java.lang.String tableName,
java.lang.String primaryKey)
protected void addIndex(boolean geo,
java.lang.String fields)
public void initTable()
public void create(T model)
model - Model which should be created.com.rethinkdb.gen.exc.ReqlClientError - Error is thrown when there was an error.
E.g. there was already a model with the same primary key.public java.util.List<T> read()
public java.util.Optional<T> read(PK id)
id - The primary key of the model which should be retrieved.public java.util.List<T> read(java.util.function.Function<com.rethinkdb.gen.ast.Table,com.rethinkdb.gen.ast.ReqlExpr> filter)
filter - The filter function which should be applied when executing the query.public void update(T model)
public void updateNonAtomic(T model)
public void delete(PK id)
id - The primary key of the model which should be removed.public rx.Observable<ChangeFeedElement<T>> changes()
Observable.Observable which subscribes to all changes made after the subscription started.public rx.Observable<ChangeFeedElement<T>> changes(java.util.function.Function<com.rethinkdb.gen.ast.Table,com.rethinkdb.gen.ast.ReqlExpr> filter)
Observable.filter - A filter for the change feed to only show changes matching the filter.Observable which subscribes to all matching changes made after the subscription started.