Class ThreadSafeDatabase

java.lang.Object
com.codename1.db.Database
com.codename1.db.ThreadSafeDatabase

public class ThreadSafeDatabase extends Database
Wraps all database calls in a single thread so they are all proxied thru that thread
  • Constructor Summary

    Constructors
    Constructor
    Description
    Wraps the given database with a threadsafe version
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Starts a transaction
    void
    Closes the database
    void
    Commits current transaction
    void
    Execute an update query.
    void
    execute(String sql, Object... params)
    Execute an update query with params.
    void
    execute(String sql, String[] params)
    Execute an update query with params.
    This method should be called with SELECT type statements that return row set.
    executeQuery(String sql, Object... params)
    This method should be called with SELECT type statements that return row set it accepts object with params.
    executeQuery(String sql, String[] params)
    This method should be called with SELECT type statements that return row set.
    Returns the underlying easy thread we can use to pipe tasks to the db thread
    void
    Rolls back current transaction

    Methods inherited from class Database

    delete, exists, getDatabasePath, isCustomPathSupported, openOrCreate, supportsWasNull, wasNull
    Modifier and Type
    Method
    Description
    static void
    delete(String databaseName)
    Deletes database
    static boolean
    exists(String databaseName)
    Indicates weather a database exists
    static String
    getDatabasePath(String databaseName)
    Returns the file path of the Database if exists and if supported on the platform.
    static boolean
    Checks if this platform supports custom database paths.
    static Database
    openOrCreate(String databaseName)
    Opens a database or create one if not exists.
    static boolean
    Checks to see if the given row supports #wasNull(com.codename1.db.Row).
    static boolean
    wasNull(Row row)
    Checks if the last value accessed from a given row was null.

    Methods inherited from class Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    Modifier and Type
    Method
    Description
    protected Object
     
    boolean
    Indicates whether some other object is "equal to" this one.
    final Class
    Returns the runtime class of an object.
    int
    Returns a hash code value for the object.
    final void
    Wakes up a single thread that is waiting on this object's monitor.
    final void
    Wakes up all threads that are waiting on this object's monitor.
    Returns a string representation of the object.
    final void
    Causes current thread to wait until another thread invokes the method or the method for this object.
    final void
    wait(long timeout)
    Causes current thread to wait until either another thread invokes the method or the method for this object, or a specified amount of time has elapsed.
    final void
    wait(long timeout, int nanos)
    Causes current thread to wait until another thread invokes the method or the method for this object, or some other thread interrupts the current thread, or a certain amount of real time has elapsed.
  • Constructor Details

    • ThreadSafeDatabase

      public ThreadSafeDatabase(Database db)

      Wraps the given database with a threadsafe version

      Parameters
      • db: the database
  • Method Details

    • getThread

      public EasyThread getThread()

      Returns the underlying easy thread we can use to pipe tasks to the db thread

      Returns

      the easy thread object

    • beginTransaction

      public void beginTransaction() throws IOException
      Description copied from class: Database

      Starts a transaction

      NOTE: Not supported in Javascript port. This method will do nothing when running in Javascript.

      Throws
      • IOException: if database is not opened
      Specified by:
      beginTransaction in class Database
      Throws:
      IOException
    • commitTransaction

      public void commitTransaction() throws IOException
      Description copied from class: Database

      Commits current transaction

      NOTE: Not supported in Javascript port. This method will do nothing when running in Javascript.

      Throws
      • IOException: if database is not opened or transaction was not started
      Specified by:
      commitTransaction in class Database
      Throws:
      IOException
    • rollbackTransaction

      public void rollbackTransaction() throws IOException
      Description copied from class: Database

      Rolls back current transaction

      NOTE: Not supported in Javascript port. This method will do nothing when running in Javascript.

      Throws
      • IOException: if database is not opened or transaction was not started
      Specified by:
      rollbackTransaction in class Database
      Throws:
      IOException
    • close

      public void close()
      Description copied from class: Database

      Closes the database

      Throws
      • IOException
      Specified by:
      close in class Database
    • execute

      public void execute(String sql) throws IOException
      Description copied from class: Database

      Execute an update query. Used for INSERT, UPDATE, DELETE and similar sql statements.

      Parameters
      • sql: the sql to execute
      Throws
      • IOException
      Specified by:
      execute in class Database
      Throws:
      IOException
    • execute

      public void execute(String sql, String[] params) throws IOException
      Description copied from class: Database

      Execute an update query with params. Used for INSERT, UPDATE, DELETE and similar sql statements. The sql can be constructed with '?' and the params will be binded to the query

      Parameters
      • sql: the sql to execute

      • params: to bind to the query where the '?' exists

      Throws
      • IOException
      Specified by:
      execute in class Database
      Throws:
      IOException
    • executeQuery

      public Cursor executeQuery(String sql, String[] params) throws IOException
      Description copied from class: Database

      This method should be called with SELECT type statements that return row set.

      Parameters
      • sql: the sql to execute

      • params: to bind to the query where the '?' exists

      Returns

      a cursor to iterate over the results

      Throws
      • IOException
      Specified by:
      executeQuery in class Database
      Throws:
      IOException
    • executeQuery

      public Cursor executeQuery(String sql) throws IOException
      Description copied from class: Database

      This method should be called with SELECT type statements that return row set.

      Parameters
      • sql: the sql to execute
      Returns

      a cursor to iterate over the results

      Throws
      • IOException
      Specified by:
      executeQuery in class Database
      Throws:
      IOException
    • executeQuery

      public Cursor executeQuery(String sql, Object... params) throws IOException
      Description copied from class: Database

      This method should be called with SELECT type statements that return row set it accepts object with params.

      Parameters
      • sql: the sql to execute

      • params: @param params to bind to the query where the '?' exists, supported object types are String, byte[], Double, Long and null

      Returns

      a cursor to iterate over the results

      Throws
      • IOException
      Overrides:
      executeQuery in class Database
      Throws:
      IOException
    • execute

      public void execute(String sql, Object... params) throws IOException
      Description copied from class: Database

      Execute an update query with params. Used for INSERT, UPDATE, DELETE and similar sql statements. The sql can be constructed with '?' and the params will be binded to the query

      Parameters
      • sql: the sql to execute

      • params: @param params to bind to the query where the '?' exists, supported object types are String, byte[], Double, Long and null

      Throws
      • IOException
      Overrides:
      execute in class Database
      Throws:
      IOException