Code example for SQLiteDatabase

Methods: isOpen, isDbLockedByOtherThreads

0
    return getDatabase(); 
  } 
 
  private synchronized SQLiteDatabase getDatabase()
  { 
    if(db == null || !db.isOpen())
    { 
      db = super.getWritableDatabase();
      lockedAt = new Throwable();
    } 
 
    if(db.isDbLockedByOtherThreads())
    { 
      Log.v("DATABASE!", "Database is locked: ", new Throwable());
      Log.v("DATABASE!", "Locked at: ", lockedAt);
    } 
 
    return db;
  } 
 
  public synchronized <T> T executeWritableTask(WritableDatabaseTask<T> task)
  { 
    SQLiteDatabase database = getDatabase();
 
    T result;
    database.beginTransaction();
    try 
    { 
      result = measureExecution(task, database);
      database.setTransactionSuccessful();
    } 
    finally 
    { 
      database.endTransaction();
    } 
 
    return result;
  } 
 
  public synchronized <T> T executeReadOnlyTask(ReadOnlyDatabaseTask<T> task)
  { 
    SQLiteDatabase database = getDatabase();
 
    T result;
    result = measureExecution(task, database);
 
    return result;
  } 
 
  private <T> T measureExecution(DatabaseTask<T> task, SQLiteDatabase database)