E - Entity, for which this service will be usedpublic class EntityService<E>
extends java.lang.Object
implements java.io.Closeable
Entity classes, such getting them from the database or
saving them to the database.EntityService opens a connection to the SQLiteDatabase. Make sure to close the
connection with close() when you finished using the service.| Constructor and Description |
|---|
EntityService(android.content.Context context,
java.lang.Class<E> entityClass)
Creates a
EntityService for the given Entity |
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
boolean |
delete(E data)
Deletes the given
Entity from the database |
boolean |
delete(int id)
Deletes the data of the
Entity for the given id |
java.util.List<E> |
find(java.lang.String selection,
java.lang.String[] selectionArgs,
java.lang.String order)
Search for
Entitys in the database with basic SQL WHERE statements. |
java.util.List<E> |
get()
Reads all
Entitys of the service specific type from the database |
E |
get(int id)
Gets a specific
Entity according to the given id |
void |
resolveAssociations(E data)
Resolves the associations to a given
Entity object and all underlying associations within the object
graph. |
void |
resolveAssociations(E data,
int maxDepth)
Resolves the associations to a given
Entity object. |
void |
save(java.util.Collection<E> data)
Stores all given
Entitys in the Collection to the database. |
void |
save(java.util.Collection<E> data,
int maxDepth)
Stores all given
Entitys in the Collection to the database. |
int |
save(E data)
Stores the given
Entity to the database. |
int |
save(E data,
int maxDepth)
Stores the given
Entity to the database. |
public EntityService(android.content.Context context,
java.lang.Class<E> entityClass)
EntityService for the given Entitycontext - Android contextentityClass - Class of the Entity, the service should be used forjava.lang.IllegalArgumentException - When the given entityClass is no Entitypublic java.util.List<E> get()
Entitys of the service specific type from the databaseEntitys stored in the database, if non are found a empty list is returnedpublic java.util.List<E> find(java.lang.String selection, java.lang.String[] selectionArgs, java.lang.String order)
Entitys in the database with basic SQL WHERE statements.selection - SQL WHERE statementselectionArgs - Arguments for the WHERE statementorder - Sort order of the resultEntitys or an empty list of non are foundpublic void resolveAssociations(E data)
Entity object and all underlying associations within the object
graph.data - Entity on which the associations should be resolvedpublic void resolveAssociations(E data, int maxDepth)
Entity object. The associations will only be resolved to the given
depth within the object . graph.data - Entity on which the associations should be resolvedmaxDepth - The maximum depth to which the associations should be resolvedpublic int save(E data)
Entity to the database. All attached associations will be stored as well.data - Entity which should be storedjava.lang.IllegalStateException - When the PrimaryKey field and its value of the Entity could not be determinedpublic int save(E data, int maxDepth)
Entity to the database. Associated objects will be saved to the given maxDepth.Entity itself will be saved without associations.data - Entity which should be storedmaxDepth - The maximum depth of the associated objects which should also be saved.java.lang.IllegalStateException - When the PrimaryKey field and its value of the Entity could not be determinedpublic void save(java.util.Collection<E> data)
Entitys in the Collection to the database. All attached associations will be
stored as well.data - Entitys which should be storedjava.lang.IllegalStateException - When the PrimaryKey field and its value of the Entity could not be determinedpublic void save(java.util.Collection<E> data, int maxDepth)
Entitys in the Collection to the database. Associated objects will be saved to
the given maxDepth.Entity itself will be saved without associations.data - Entity which should be storedmaxDepth - The maximum depth of the associated objects which should also be saved.java.lang.IllegalStateException - When the PrimaryKey field and its value of the Entity could not be determinedpublic boolean delete(E data)
Entity from the databasedata - Entity that should be deletedtrue if the Entity could be deleted, false otherwisejava.lang.IllegalStateException - When the PrimaryKey field and its value of the Entity could not be determinedjava.lang.IllegalArgumentException - When the value of the PrimaryKey field is nullpublic boolean delete(int id)
Entity for the given idpublic void close()
close in interface java.io.Closeableclose in interface java.lang.AutoCloseableCopyright © 2014 arconsis IT-Solutions GmbH. All Rights Reserved.