public interface Database
A Crux client database. Uses IndexedDB (http://www.w3.org/TR/IndexedDB/) like interface to store objects on application's client side.
To declare a new database, create a new interface extending Database and use DatabaseDef
annotation on it to specify database structure.
See the following example:
@DatabaseDef(name="CruxCompanyDatabase", version=1, defaultErrorHandler=CompanyDatabase.ErrorHandler.class, objectStores={@DatabaseDef.ObjectStoreDef(targetClass=Person.class)}) public interface CompanyDatabase extends Database{ public static class ErrorHandler implementsDatabaseErrorHandler{@Override public void onError(String message) { Crux.getErrorHandler().handleError(message); }@Override public void onError(String message, Throwable t) { Crux.getErrorHandler().handleError(message, t); } } }
To use the database, just call GWT.create on the given interface, or inject it on your class.
public class MyController {
@Inject
private CompanyDatabase database;
@Expose
public void myMethod() {
database.open(new DatabaseCallback(){
public void onSuccess(){
Window.alert("database ready for use");
}
});
}
}
| Modifier and Type | Method and Description |
|---|---|
<V> void |
add(List<V> objects,
String objectStore,
DatabaseCallback callback)
Insert all objects into its associated objectStore.
|
<V> void |
add(V[] objects,
String objectStore,
DatabaseCallback callback)
Insert all objects into its associated objectStore.
|
void |
close()
Close the current database.
|
void |
delete(DatabaseCallback callback)
Remove the current database from client browser.
|
<K> void |
delete(KeyRange<K> keyRange,
String objectStore,
DatabaseCallback callback)
Remove all objects in the given range from its associated objectStore.
|
<K> void |
delete(K key,
String objectStore,
DatabaseCallback callback)
Remove the object associated with the given key from its associated objectStore.
|
<K,V> void |
get(K key,
String objectStore,
DatabaseRetrieveCallback<V> callback)
Retrieve the object associated with the given key from its associated objectStore.
|
String |
getName()
Retrieve the database name.
|
Transaction |
getTransaction(String[] storeNames,
Transaction.Mode mode)
Create a new transaction targeting the given objectStores.
|
Transaction |
getTransaction(String[] storeNames,
Transaction.Mode mode,
Transaction.TransactionCallback callback)
Create a new transaction targeting the given objectStores.
|
int |
getVersion()
Retrieve the database version.
|
boolean |
isOpen()
Return true if the current database is open.
|
boolean |
isSupported()
Return true if Crux Database is supported by current browser.
|
void |
open(DatabaseCallback callback)
Open the database.
|
<V> void |
put(List<V> objects,
String objectStore,
DatabaseCallback callback)
Update all received objects into its associated objectStore.
|
<V> void |
put(V[] objects,
String objectStore,
DatabaseCallback callback)
Update all received objects into its associated objectStore.
|
void |
setDefaultErrorHandler(DatabaseErrorHandler errorHandler)
Sets an error handler to be called to handle uncaught errors.
|
void |
setName(String newName)
Change the database name.
|
void |
setVersion(int newVersion)
Change the database version.
|
void |
useIndexedDB()
Forces Crux to use Indexed DB implementation for its database.
|
void |
useWebSQL()
Forces Crux to use WEB SQL implementation for its database.
|
boolean isOpen()
String getName()
@DatabaseDef annotationvoid setName(String newName) throws DatabaseException
newName - new database nameDatabaseExceptionvoid setVersion(int newVersion)
throws DatabaseException
newVersion - new database versionDatabaseExceptionint getVersion()
@DatabaseDef annotationvoid open(DatabaseCallback callback)
callback - called when operation is completedvoid close()
void delete(DatabaseCallback callback)
callback - called when operation is completedTransaction getTransaction(String[] storeNames, Transaction.Mode mode)
storeNames - stores referenced by the transaction. You can not use any object store inside your transaction if it is not listed here.mode - transaction mode. See Mode for available modesTransaction getTransaction(String[] storeNames, Transaction.Mode mode, Transaction.TransactionCallback callback)
storeNames - stores referenced by the transaction. You can not use any object store inside your transaction if it is not listed here.mode - transaction mode. See Mode for available modescallback - called when operation is completedDatabaseException - if an unknown object store is informed<V> void add(V[] objects,
String objectStore,
DatabaseCallback callback)
DatabaseException is threwV - object typeobjectStore - object store name, where objects will be insertedobjects - objects to be insertedcallback - called when operation is completedDatabaseException - if no objectStore is associated with object informed<V> void add(List<V> objects, String objectStore, DatabaseCallback callback)
DatabaseException is threwV - object typeobjectStore - object store name, where objects will be insertedobjects - objects to be insertedcallback - called when operation is completedDatabaseException - if no objectStore is associated with object informed<V> void put(V[] objects,
String objectStore,
DatabaseCallback callback)
DatabaseException is threwV - object typeobjectStore - object store name, where objects will be savedobjects - objects to be savedcallback - called when operation is completedDatabaseException - if no objectStore is associated with object informed<V> void put(List<V> objects, String objectStore, DatabaseCallback callback)
DatabaseException is threwV - object typeobjectStore - object store name, where objects will be savedobjects - objects to be savedcallback - called when operation is completedDatabaseException - if no objectStore is associated with object informed<K,V> void get(K key,
String objectStore,
DatabaseRetrieveCallback<V> callback)
DatabaseException is threwK - key typeV - object typekey - object keyobjectStore - object store name, where objects will be loaded fromcallback - called when operation is completedDatabaseException - if no objectStore is associated with object informed<K> void delete(K key,
String objectStore,
DatabaseCallback callback)
DatabaseException is threwK - key typekey - object keyobjectStore - object store name, where objects will be loaded fromcallback - called when operation is completedDatabaseException - if no objectStore is associated with object informed<K> void delete(KeyRange<K> keyRange, String objectStore, DatabaseCallback callback)
DatabaseException is threwK - key typekeyRange - object key rangeobjectStore - object store name, where objects will be loaded fromcallback - called when operation is completedDatabaseException - if no objectStore is associated with object informedvoid setDefaultErrorHandler(DatabaseErrorHandler errorHandler)
errorHandler - the error handlerboolean isSupported()
void useWebSQL()
void useIndexedDB()
Copyright © 2015. All rights reserved.