Package com.brightcove.player.store
Class BaseStore
- java.lang.Object
-
- com.brightcove.player.store.BaseStore
-
- Direct Known Subclasses:
OfflineStoreManager
public class BaseStore extends java.lang.Object
A base wrapper forEntityStore
.
-
-
Field Summary
Fields Modifier and Type Field Description protected android.content.Context
context
The context of the host application.protected io.requery.reactivex.ReactiveEntityStore<io.requery.Persistable>
dataStore
Reference to the data store.static int
MAX_SQL_EXPRESSIONS
The maximum of expressions allowed in the queries generation by this store.static int
MAX_SQL_VARIABLES
The maximum of variables allowed in the queries generation by this store.protected com.brightcove.player.store.BaseStore.Source
source
Reference to the backing store configuration.
-
Constructor Summary
Constructors Modifier Constructor Description protected
BaseStore(android.content.Context context, io.requery.meta.EntityModel model, int version)
Constructs a new instance ofBaseStore
protected
BaseStore(android.content.Context context, io.requery.meta.EntityModel model, java.lang.String name, int version)
Constructs a new instance ofBaseStore
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
compact()
Compacts the physical database file size by running the SQLite VACUUM statement.boolean
deleteEntity(IdentifiableEntity entity)
Deletes an identifiable entity from the store.protected static java.lang.String
getDefaultDatabaseName(android.content.Context context, io.requery.meta.EntityModel model)
Provides the default database name for the given application context/entity model.protected static java.lang.String
getDefaultDatabasePassword(android.content.Context context, io.requery.meta.EntityModel model)
Provides the default database password for the given application context/entity model.long
getFileSize()
Gets the size of the backing database file.protected void
onCreated(int version)
Called when newEntityDataStore
has been created.protected void
onUpgraded(int oldVersion, int newVersion)
Called when theEntityDataStore
has been upgraded from an previous version to a new version.<E extends IdentifiableEntity>
ErefreshEntity(E entity)
Refresh the given entity.<T extends IdentifiableEntity>
TsaveEntity(T entity)
Inserts or updates the given entity.
-
-
-
Field Detail
-
MAX_SQL_VARIABLES
public static final int MAX_SQL_VARIABLES
The maximum of variables allowed in the queries generation by this store. Please note the actual limit imposed by Sqlite database is typically 999. However we set the limit to a lower value to give enough headroom for the requery library to manipulate the final query.- See Also:
- Constant Field Values
-
MAX_SQL_EXPRESSIONS
public static final int MAX_SQL_EXPRESSIONS
The maximum of expressions allowed in the queries generation by this store. Please note the actual limit imposed by Sqlite database is typically 1000. However we set the limit to a lower value to give enough headroom for the requery library to manipulate the final query.- See Also:
- Constant Field Values
-
context
protected final android.content.Context context
The context of the host application.
-
source
protected final com.brightcove.player.store.BaseStore.Source source
Reference to the backing store configuration.
-
dataStore
protected final io.requery.reactivex.ReactiveEntityStore<io.requery.Persistable> dataStore
Reference to the data store.
-
-
Constructor Detail
-
BaseStore
protected BaseStore(@NonNull android.content.Context context, @NonNull io.requery.meta.EntityModel model, int version)
Constructs a new instance ofBaseStore
- Parameters:
context
- reference to the host application context.model
- the entity modelversion
- the schema version
-
BaseStore
protected BaseStore(@NonNull android.content.Context context, @NonNull io.requery.meta.EntityModel model, @NonNull java.lang.String name, int version)
Constructs a new instance ofBaseStore
- Parameters:
context
- reference to the host application context.model
- the entity modelname
- the name of the databaseversion
- the schema version
-
-
Method Detail
-
getFileSize
public long getFileSize()
Gets the size of the backing database file.- Returns:
- -1 if an error occured while trying to read the size, 0 if the database file does not exist, otherwise of the size of the database file expressed as total number of bytes.
-
compact
public boolean compact()
Compacts the physical database file size by running the SQLite VACUUM statement.- Returns:
- true if the operation was successful, otherwise false.
-
refreshEntity
@Nullable public <E extends IdentifiableEntity> E refreshEntity(@Nullable E entity)
Refresh the given entity. This refreshes the already loaded properties in the entity. If no properties are loaded then the default properties will be loaded.- Type Parameters:
E
- the expected type of the entity;- Parameters:
entity
- reference to the entity to be refreshed.- Returns:
- null if the entity is null or if it does not exist in the store, otherwise reference to the updated entity
-
onCreated
protected void onCreated(int version)
Called when newEntityDataStore
has been created. Override this method to setup the default state of the entity store.- Parameters:
version
- schema version of the store.
-
onUpgraded
protected void onUpgraded(int oldVersion, int newVersion)
Called when theEntityDataStore
has been upgraded from an previous version to a new version.- Parameters:
oldVersion
- the old schema versionnewVersion
- the new schema version
-
saveEntity
public <T extends IdentifiableEntity> T saveEntity(@NonNull T entity)
Inserts or updates the given entity.- Parameters:
entity
- the entity to be save.- Returns:
- the updated the entity.;
-
deleteEntity
public boolean deleteEntity(@Nullable IdentifiableEntity entity)
Deletes an identifiable entity from the store.- Parameters:
entity
- the entity to be deleted.- Returns:
- true if the entity was found and removed from the store, otherwise false.
-
getDefaultDatabaseName
protected static java.lang.String getDefaultDatabaseName(android.content.Context context, io.requery.meta.EntityModel model)
Provides the default database name for the given application context/entity model.- Parameters:
context
- the context of the host application.model
- reference to the entity model.- Returns:
- the default database name for this application and entity mode.
-
getDefaultDatabasePassword
@Nullable protected static java.lang.String getDefaultDatabasePassword(android.content.Context context, io.requery.meta.EntityModel model)
Provides the default database password for the given application context/entity model.- Parameters:
context
- the context of the host application.model
- reference to the entity model.- Returns:
- the default database name for this application and entity mode.
-
-