E - Entity, for which this service will be usedpublic class EntityService<E>
extends java.lang.Object
Entity classes, such getting them from the database or
saving them to the database.SQLiteDatabase. If you want only one db connection use
ConnectedEntityService| Constructor and Description |
|---|
EntityService(android.content.Context context,
java.lang.Class<E> entityClass)
Creates a
EntityService for the given Entity. |
EntityService(android.content.Context context,
java.lang.Class<E> entityClass,
ValidationToggle toggle)
Creates a
EntityService for the given Entity |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Deprecated.
|
protected void |
closeDB(android.database.sqlite.SQLiteDatabase database) |
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 |
protected android.database.sqlite.SQLiteDatabase |
openDB() |
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. |
protected DbCreator dbCreator
public EntityService(android.content.Context context,
java.lang.Class<E> entityClass)
context - Android contextentityClass - Class of the Entity, the service should be used forjava.lang.IllegalArgumentException - When the given entityClass is no Entitypublic EntityService(android.content.Context context,
java.lang.Class<E> entityClass,
ValidationToggle toggle)
EntityService for the given Entitycontext - Android contextentityClass - Class of the Entity, the service should be used fortoggle - Controls the use of validation on saving Entitysjava.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 returnedprotected void closeDB(android.database.sqlite.SQLiteDatabase database)
protected android.database.sqlite.SQLiteDatabase openDB()
public 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 determinedInvalidEntityException - when the given entity is invalid.public 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 determinedInvalidEntityException - when the given entity is invalid.public 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 determinedInvalidEntityException - when at least one of the given entities is invalid.public 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 determinedInvalidEntityException - when at least one of the given entities is invalid.public 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 id@Deprecated public void close()
ConnectedEntityService if you need only one db connection.Copyright © 2015 arconsis IT-Solutions GmbH. All Rights Reserved.