org.cruxframework.crux.core.client.db
Class AbstractDatabase

java.lang.Object
  extended by org.cruxframework.crux.core.client.db.AbstractDatabase
All Implemented Interfaces:
Database
Direct Known Subclasses:
IDXAbstractDatabase, WSQLAbstractDatabase

public abstract class AbstractDatabase
extends Object
implements Database

CRUX INTERNAL CLASS. DO NOT USE IT DIRECTLY. Base class for Crux databases. Use the interface Database to define your databases

Author:
Thiago da Rosa de Bustamante

Field Summary
protected  DatabaseErrorHandler errorHandler
           
protected static Logger logger
           
protected  DBMessages messages
           
protected  String name
           
protected  int version
           
 
Constructor Summary
AbstractDatabase()
           
 
Method Summary
<V> void
add(List<V> objects, String objectStoreName, DatabaseCallback callback)
          Insert all objects into its associated objectStore.
<V> void
add(V[] objects, String objectStoreName, DatabaseCallback callback)
          Insert all objects into its associated objectStore.
protected abstract  Transaction createTransaction(String[] storeNames, Transaction.Mode mode)
           
<K> void
delete(KeyRange<K> keys, String objectStoreName, DatabaseCallback callback)
          Remove all objects in the given range from its associated objectStore.
<K> void
delete(K key, String objectStoreName, DatabaseCallback callback)
          Remove the object associated with the given key from its associated objectStore.
protected abstract  void doOpen(DatabaseCallback callback)
           
<K,V> void
get(K key, String objectStoreName, 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.
 void open(DatabaseCallback callback)
          Open the database.
<V> void
put(List<V> objects, String objectStoreName, DatabaseCallback callback)
          Update all received objects into its associated objectStore.
<V> void
put(V[] objects, String objectStoreName, 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.cruxframework.crux.core.client.db.Database
close, delete, isOpen, isSupported
 

Field Detail

logger

protected static Logger logger

messages

protected DBMessages messages

errorHandler

protected DatabaseErrorHandler errorHandler

name

protected String name

version

protected int version
Constructor Detail

AbstractDatabase

public AbstractDatabase()
Method Detail

getName

public String getName()
Description copied from interface: Database
Retrieve the database name. This information is extracted from @DatabaseDef annotation

Specified by:
getName in interface Database
Returns:
database name

setName

public void setName(String newName)
             throws DatabaseException
Description copied from interface: Database
Change the database name. This operation can not be executed on an open database.

Specified by:
setName in interface Database
Parameters:
newName - new database name
Throws:
DatabaseException

getVersion

public int getVersion()
Description copied from interface: Database
Retrieve the database version. This information is extracted from @DatabaseDef annotation

Specified by:
getVersion in interface Database
Returns:
database version

setVersion

public void setVersion(int newVersion)
                throws DatabaseException
Description copied from interface: Database
Change the database version. This operation can not be executed on an open database.

Specified by:
setVersion in interface Database
Parameters:
newVersion - new database version
Throws:
DatabaseException

open

public void open(DatabaseCallback callback)
Description copied from interface: Database
Open the database. If it does not exists, create a new database.

Specified by:
open in interface Database
Parameters:
callback - called when operation is completed

getTransaction

public Transaction getTransaction(String[] storeNames,
                                  Transaction.Mode mode)
Description copied from interface: Database
Create a new transaction targeting the given objectStores.

Specified by:
getTransaction in interface Database
Parameters:
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 modes
Returns:
the transaction

getTransaction

public Transaction getTransaction(String[] storeNames,
                                  Transaction.Mode mode,
                                  Transaction.TransactionCallback callback)
Description copied from interface: Database
Create a new transaction targeting the given objectStores. If an unknown object store is informed, a DatabaseException is threw

Specified by:
getTransaction in interface Database
Parameters:
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 modes
callback - called when operation is completed
Returns:
the transaction

add

public <V> void add(V[] objects,
                    String objectStoreName,
                    DatabaseCallback callback)
Description copied from interface: Database
Insert all objects into its associated objectStore. If no objectStore is associated with object informed, a DatabaseException is threw

Specified by:
add in interface Database
Type Parameters:
V - object type
Parameters:
objects - objects to be inserted
objectStoreName - object store name, where objects will be inserted
callback - called when operation is completed

add

public <V> void add(List<V> objects,
                    String objectStoreName,
                    DatabaseCallback callback)
Description copied from interface: Database
Insert all objects into its associated objectStore. If no objectStore is associated with object informed, a DatabaseException is threw

Specified by:
add in interface Database
Type Parameters:
V - object type
Parameters:
objects - objects to be inserted
objectStoreName - object store name, where objects will be inserted
callback - called when operation is completed

put

public <V> void put(V[] objects,
                    String objectStoreName,
                    DatabaseCallback callback)
Description copied from interface: Database
Update all received objects into its associated objectStore. If one object does not exists, create a new one. If no objectStore is associated with object store, a DatabaseException is threw

Specified by:
put in interface Database
Type Parameters:
V - object type
Parameters:
objects - objects to be saved
objectStoreName - object store name, where objects will be saved
callback - called when operation is completed

put

public <V> void put(List<V> objects,
                    String objectStoreName,
                    DatabaseCallback callback)
Description copied from interface: Database
Update all received objects into its associated objectStore. If one object does not exists, create a new one. If no objectStore is associated with object store, a DatabaseException is threw

Specified by:
put in interface Database
Type Parameters:
V - object type
Parameters:
objects - objects to be saved
objectStoreName - object store name, where objects will be saved
callback - called when operation is completed

get

public <K,V> void get(K key,
                      String objectStoreName,
                      DatabaseRetrieveCallback<V> callback)
Description copied from interface: Database
Retrieve the object associated with the given key from its associated objectStore. If no objectStore is associated with object store, a DatabaseException is threw

Specified by:
get in interface Database
Type Parameters:
K - key type
V - object type
Parameters:
key - object key
objectStoreName - object store name, where objects will be loaded from
callback - called when operation is completed

delete

public <K> void delete(K key,
                       String objectStoreName,
                       DatabaseCallback callback)
Description copied from interface: Database
Remove the object associated with the given key from its associated objectStore. If no objectStore is associated with object store, a DatabaseException is threw

Specified by:
delete in interface Database
Type Parameters:
K - key type
Parameters:
key - object key
objectStoreName - object store name, where objects will be loaded from
callback - called when operation is completed

delete

public <K> void delete(KeyRange<K> keys,
                       String objectStoreName,
                       DatabaseCallback callback)
Description copied from interface: Database
Remove all objects in the given range from its associated objectStore. If no objectStore is associated with object store, a DatabaseException is threw

Specified by:
delete in interface Database
Type Parameters:
K - key type
Parameters:
keys - object key range
objectStoreName - object store name, where objects will be loaded from
callback - called when operation is completed

setDefaultErrorHandler

public void setDefaultErrorHandler(DatabaseErrorHandler errorHandler)
Description copied from interface: Database
Sets an error handler to be called to handle uncaught errors.

Specified by:
setDefaultErrorHandler in interface Database
Parameters:
errorHandler - the error handler

useIndexedDB

public void useIndexedDB()
Description copied from interface: Database
Forces Crux to use Indexed DB implementation for its database. This method should be called only for tests purposes. Crux already can detect and choose the better native implementation.

Specified by:
useIndexedDB in interface Database

useWebSQL

public void useWebSQL()
Description copied from interface: Database
Forces Crux to use WEB SQL implementation for its database. This method should be called only for tests purposes. Crux already can detect and choose the better native implementation.

Specified by:
useWebSQL in interface Database

doOpen

protected abstract void doOpen(DatabaseCallback callback)

createTransaction

protected abstract Transaction createTransaction(String[] storeNames,
                                                 Transaction.Mode mode)


Copyright © 2014. All rights reserved.