Java Code Examples for androidx.sqlite.db.SupportSQLiteDatabase

The following examples show how to use androidx.sqlite.db.SupportSQLiteDatabase. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: sqlitemagic   Source File: DefaultDbDowngrader.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onDowngrade(SupportSQLiteDatabase db, int oldVersion, int newVersion) {
  if (SqliteMagic.LOGGING_ENABLED) {
    LogUtil.logDebug("Downgrading database from " + oldVersion + " to " + newVersion);
  }
  final Cursor c = db.query("SELECT name FROM sqlite_master " +
      "WHERE type='table' AND name != 'android_metadata' AND name NOT LIKE 'sqlite%'");
  try {
    while (c.moveToNext()) {
      final String tableName = c.getString(0);
      db.execSQL("DROP TABLE IF EXISTS " + tableName);
    }
  } finally {
    c.close();
  }

  SqlUtil.createSchema(db);
}
 
Example 2
Source Project: kripton   Source File: BindAppDataSource.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * <p>Executes a batch. This method <strong>is thread safe</strong> to avoid concurrent problems. The drawback is only one transaction at time can be executed. if <code>writeMode</code> is set to false, multiple batch operations is allowed.</p>
 *
 * @param commands
 * 	batch to execute
 * @param writeMode
 * 	true to open connection in write mode, false to open connection in read only mode
 */
public <T> T executeBatch(Batch<T> commands, boolean writeMode) {
  // open database in thread safe mode
  Pair<Boolean, SupportSQLiteDatabase> _status=openDatabaseThreadSafeMode(writeMode);
  DataSourceSingleThread currentDaoFactory=new DataSourceSingleThread();
  currentDaoFactory.onSessionOpened();
  try {
    if (commands!=null) {
      return commands.onExecute(currentDaoFactory);
    }
  } catch(Throwable e) {
    Logger.error(e.getMessage());
    e.printStackTrace();
    throw(e);
  } finally {
    // close database in thread safe mode
    closeThreadSafeMode(_status);
    currentDaoFactory.onSessionClosed();
  }
  return null;
}
 
Example 3
Source Project: bcm-android   Source File: GroupDatabase.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public void migrate(SupportSQLiteDatabase database) {
    ALog.i("GroupDatabase", "upgrade database MIGRATION_9_10");
    try {
        database.execSQL("CREATE TABLE IF NOT EXISTS `draw_history` (`_d_id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `_g_id` INTEGER NOT NULL, `user_id` TEXT, `draw_type` TEXT, `draw_time` INTEGER NOT NULL, `hash` TEXT, `amount` TEXT, `zero_bits` INTEGER NOT NULL, `draw_flag` INTEGER NOT NULL, `memo` TEXT, FOREIGN KEY(`_g_id`) REFERENCES `game_history`(`_g_id`) ON UPDATE NO ACTION ON DELETE CASCADE )");
        database.execSQL("CREATE  INDEX `index_draw_history__g_id` ON `draw_history` (`_g_id`)");
        database.execSQL("CREATE  INDEX `index_draw_history_user_id` ON `draw_history` (`user_id`)");
        database.execSQL("CREATE TABLE IF NOT EXISTS `game_history` (`_g_id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `gid` INTEGER NOT NULL, `group_hash` TEXT, `game_type` TEXT, `start_time` INTEGER NOT NULL, `end_time` INTEGER NOT NULL)");
        database.execSQL("CREATE UNIQUE INDEX `index_game_history_game_type_start_time_end_time` ON `game_history` (`game_type`, `start_time`, `end_time`)");
        database.execSQL("CREATE  INDEX `index_game_history_gid` ON `game_history` (`gid`)");
        database.execSQL("CREATE TABLE IF NOT EXISTS `wallet_data` (`_w_id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `owner` TEXT, `balance` TEXT, `extra` TEXT)");
        database.execSQL("CREATE  INDEX `index_wallet_data__w_id` ON `wallet_data` (`_w_id`)");
        database.execSQL("CREATE  INDEX `index_wallet_data_owner` ON `wallet_data` (`owner`)");
        database.execSQL("CREATE TABLE IF NOT EXISTS `wallet_transaction` (`_t_id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `_w_id` INTEGER NOT NULL, `tx_id` TEXT, `op_type` TEXT, `amount` TEXT, `from` TEXT, `to` TEXT, `timestamp` INTEGER NOT NULL, `memo` TEXT, FOREIGN KEY(`_w_id`) REFERENCES `wallet_data`(`_w_id`) ON UPDATE NO ACTION ON DELETE CASCADE )");
        database.execSQL("CREATE  INDEX `index_wallet_transaction__t_id` ON `wallet_transaction` (`_t_id`)");
        database.execSQL("CREATE  INDEX `index_wallet_transaction__w_id` ON `wallet_transaction` (`_w_id`)");
        database.execSQL("CREATE  INDEX `index_wallet_transaction_tx_id` ON `wallet_transaction` (`tx_id`)");
    } catch (Exception e) {
        ALog.e("Database", "+++++++++++++++++++++++database upgrade(9,10)  error " + e);
    }

}
 
Example 4
Source Project: kripton   Source File: BindAppWithConfigDataSource.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * onCreate
 */
@Override
protected void onCreate(SupportSQLiteDatabase database) {
  // generate tables
  // log section create BEGIN
  if (this.logEnabled) {
    if (options.inMemory) {
      Logger.info("Create database in memory");
    } else {
      Logger.info("Create database '%s' version %s",this.name, this.version);
    }
  }
  // log section create END
  // log section create BEGIN
  if (this.logEnabled) {
    Logger.info("DDL: %s",PersonTable.CREATE_TABLE_SQL);
  }
  // log section create END
  database.execSQL(PersonTable.CREATE_TABLE_SQL);
  if (options.databaseLifecycleHandler != null) {
    options.databaseLifecycleHandler.onCreate(database);
  }
  justCreated=true;
}
 
Example 5
Source Project: kripton   Source File: BindDummy01DataSource.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * onCreate
 */
@Override
protected void onCreate(SupportSQLiteDatabase database) {
  // generate tables
  // log section create BEGIN
  if (this.logEnabled) {
    if (options.inMemory) {
      Logger.info("Create database in memory");
    } else {
      Logger.info("Create database '%s' version %s",this.name, this.version);
    }
  }
  // log section create END
  // log section create BEGIN
  if (this.logEnabled) {
    Logger.info("DDL: %s",Bean01Table.CREATE_TABLE_SQL);
  }
  // log section create END
  database.execSQL(Bean01Table.CREATE_TABLE_SQL);
  if (options.databaseLifecycleHandler != null) {
    options.databaseLifecycleHandler.onCreate(database);
  }
  justCreated=true;
}
 
Example 6
Source Project: kripton   Source File: BindFamilyDataSource.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * <p>Executes a batch. This method <strong>is thread safe</strong> to avoid concurrent problems. The drawback is only one transaction at time can be executed. if <code>writeMode</code> is set to false, multiple batch operations is allowed.</p>
 *
 * @param commands
 * 	batch to execute
 * @param writeMode
 * 	true to open connection in write mode, false to open connection in read only mode
 */
public <T> T executeBatch(Batch<T> commands, boolean writeMode) {
  // open database in thread safe mode
  Pair<Boolean, SupportSQLiteDatabase> _status=openDatabaseThreadSafeMode(writeMode);
  DataSourceSingleThread currentDaoFactory=new DataSourceSingleThread();
  currentDaoFactory.onSessionOpened();
  try {
    if (commands!=null) {
      return commands.onExecute(currentDaoFactory);
    }
  } catch(Throwable e) {
    Logger.error(e.getMessage());
    e.printStackTrace();
    throw(e);
  } finally {
    // close database in thread safe mode
    closeThreadSafeMode(_status);
    currentDaoFactory.onSessionClosed();
  }
  return null;
}
 
Example 7
Source Project: kripton   Source File: BindAppDataSource.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * onCreate
 */
@Override
protected void onCreate(SupportSQLiteDatabase database) {
  // generate tables
  // log section create BEGIN
  if (this.logEnabled) {
    if (options.inMemory) {
      Logger.info("Create database in memory");
    } else {
      Logger.info("Create database '%s' version %s",this.name, this.version);
    }
  }
  // log section create END
  // log section create BEGIN
  if (this.logEnabled) {
    Logger.info("DDL: %s",AlbumTable.CREATE_TABLE_SQL);
  }
  // log section create END
  database.execSQL(AlbumTable.CREATE_TABLE_SQL);
  if (options.databaseLifecycleHandler != null) {
    options.databaseLifecycleHandler.onCreate(database);
  }
  justCreated=true;
}
 
Example 8
Source Project: kripton   Source File: BindWhisperDataSource.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * onCreate
 */
@Override
protected void onCreate(SupportSQLiteDatabase database) {
  // generate tables
  // log section create BEGIN
  if (this.logEnabled) {
    if (options.inMemory) {
      Logger.info("Create database in memory");
    } else {
      Logger.info("Create database '%s' version %s",this.name, this.version);
    }
  }
  // log section create END
  // log section create BEGIN
  if (this.logEnabled) {
    Logger.info("DDL: %s",MessageEntityTable.CREATE_TABLE_SQL);
  }
  // log section create END
  database.execSQL(MessageEntityTable.CREATE_TABLE_SQL);
  if (options.databaseLifecycleHandler != null) {
    options.databaseLifecycleHandler.onCreate(database);
  }
  justCreated=true;
}
 
Example 9
Source Project: kripton   Source File: BindAppDataSource.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * <p>Executes a batch. This method <strong>is thread safe</strong> to avoid concurrent problems. The drawback is only one transaction at time can be executed. if <code>writeMode</code> is set to false, multiple batch operations is allowed.</p>
 *
 * @param commands
 * 	batch to execute
 * @param writeMode
 * 	true to open connection in write mode, false to open connection in read only mode
 */
public <T> T executeBatch(Batch<T> commands, boolean writeMode) {
  // open database in thread safe mode
  Pair<Boolean, SupportSQLiteDatabase> _status=openDatabaseThreadSafeMode(writeMode);
  DataSourceSingleThread currentDaoFactory=new DataSourceSingleThread();
  currentDaoFactory.onSessionOpened();
  try {
    if (commands!=null) {
      return commands.onExecute(currentDaoFactory);
    }
  } catch(Throwable e) {
    Logger.error(e.getMessage());
    e.printStackTrace();
    throw(e);
  } finally {
    // close database in thread safe mode
    closeThreadSafeMode(_status);
    currentDaoFactory.onSessionClosed();
  }
  return null;
}
 
Example 10
Source Project: kripton   Source File: BindByteDataSource.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * onCreate
 */
@Override
protected void onCreate(SupportSQLiteDatabase database) {
  // generate tables
  // log section create BEGIN
  if (this.logEnabled) {
    if (options.inMemory) {
      Logger.info("Create database in memory");
    } else {
      Logger.info("Create database '%s' version %s",this.name, this.version);
    }
  }
  // log section create END
  // log section create BEGIN
  if (this.logEnabled) {
    Logger.info("DDL: %s",ByteBeanTable.CREATE_TABLE_SQL);
  }
  // log section create END
  database.execSQL(ByteBeanTable.CREATE_TABLE_SQL);
  if (options.databaseLifecycleHandler != null) {
    options.databaseLifecycleHandler.onCreate(database);
  }
  justCreated=true;
}
 
Example 11
Source Project: kripton   Source File: BindBeanDataSource.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * onCreate
 */
@Override
protected void onCreate(SupportSQLiteDatabase database) {
  // generate tables
  // log section create BEGIN
  if (this.logEnabled) {
    if (options.inMemory) {
      Logger.info("Create database in memory");
    } else {
      Logger.info("Create database '%s' version %s",this.name, this.version);
    }
  }
  // log section create END
  // log section create BEGIN
  if (this.logEnabled) {
    Logger.info("DDL: %s",BeanTable.CREATE_TABLE_SQL);
  }
  // log section create END
  database.execSQL(BeanTable.CREATE_TABLE_SQL);
  if (options.databaseLifecycleHandler != null) {
    options.databaseLifecycleHandler.onCreate(database);
  }
  justCreated=true;
}
 
Example 12
Source Project: kripton   Source File: BindSchoolDataSource.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * <p>Executes a batch. This method <strong>is thread safe</strong> to avoid concurrent problems. The drawback is only one transaction at time can be executed. if <code>writeMode</code> is set to false, multiple batch operations is allowed.</p>
 *
 * @param commands
 * 	batch to execute
 * @param writeMode
 * 	true to open connection in write mode, false to open connection in read only mode
 */
public <T> T executeBatch(Batch<T> commands, boolean writeMode) {
  // open database in thread safe mode
  Pair<Boolean, SupportSQLiteDatabase> _status=openDatabaseThreadSafeMode(writeMode);
  DataSourceSingleThread currentDaoFactory=new DataSourceSingleThread();
  currentDaoFactory.onSessionOpened();
  try {
    if (commands!=null) {
      return commands.onExecute(currentDaoFactory);
    }
  } catch(Throwable e) {
    Logger.error(e.getMessage());
    e.printStackTrace();
    throw(e);
  } finally {
    // close database in thread safe mode
    closeThreadSafeMode(_status);
    currentDaoFactory.onSessionClosed();
  }
  return null;
}
 
Example 13
Source Project: kripton   Source File: BindApp0DataSource.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * <p>Executes a batch. This method <strong>is thread safe</strong> to avoid concurrent problems. The drawback is only one transaction at time can be executed. if <code>writeMode</code> is set to false, multiple batch operations is allowed.</p>
 *
 * @param commands
 * 	batch to execute
 * @param writeMode
 * 	true to open connection in write mode, false to open connection in read only mode
 */
public <T> T executeBatch(Batch<T> commands, boolean writeMode) {
  // open database in thread safe mode
  Pair<Boolean, SupportSQLiteDatabase> _status=openDatabaseThreadSafeMode(writeMode);
  DataSourceSingleThread currentDaoFactory=new DataSourceSingleThread();
  currentDaoFactory.onSessionOpened();
  try {
    if (commands!=null) {
      return commands.onExecute(currentDaoFactory);
    }
  } catch(Throwable e) {
    Logger.error(e.getMessage());
    e.printStackTrace();
    throw(e);
  } finally {
    // close database in thread safe mode
    closeThreadSafeMode(_status);
    currentDaoFactory.onSessionClosed();
  }
  return null;
}
 
Example 14
Source Project: kripton   Source File: BindAppDataSource.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * <p>Executes a batch. This method <strong>is thread safe</strong> to avoid concurrent problems. The drawback is only one transaction at time can be executed. if <code>writeMode</code> is set to false, multiple batch operations is allowed.</p>
 *
 * @param commands
 * 	batch to execute
 * @param writeMode
 * 	true to open connection in write mode, false to open connection in read only mode
 */
public <T> T executeBatch(Batch<T> commands, boolean writeMode) {
  // open database in thread safe mode
  Pair<Boolean, SupportSQLiteDatabase> _status=openDatabaseThreadSafeMode(writeMode);
  DataSourceSingleThread currentDaoFactory=new DataSourceSingleThread();
  currentDaoFactory.onSessionOpened();
  try {
    if (commands!=null) {
      return commands.onExecute(currentDaoFactory);
    }
  } catch(Throwable e) {
    Logger.error(e.getMessage());
    e.printStackTrace();
    throw(e);
  } finally {
    // close database in thread safe mode
    closeThreadSafeMode(_status);
    currentDaoFactory.onSessionClosed();
  }
  return null;
}
 
Example 15
Source Project: FairEmail   Source File: RoomOpenHelper.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onCreate(SupportSQLiteDatabase db) {
    boolean isEmptyDatabase = hasEmptySchema(db);
    mDelegate.createAllTables(db);
    if (!isEmptyDatabase) {
        // A 0 version pre-populated database goes through the create path because the
        // framework's SQLiteOpenHelper thinks the database was just created from scratch. If we
        // find the database not to be empty, then it is a pre-populated, we must validate it to
        // see if its suitable for usage.
        ValidationResult result = mDelegate.onValidateSchema(db);
        if (!result.isValid) {
            throw new IllegalStateException("Pre-packaged database has an invalid schema: "
                    + result.expectedFoundMsg);
        }
    }
    updateIdentity(db);
    mDelegate.onCreate(db);
}
 
Example 16
Source Project: kripton   Source File: BindBeanDataSource.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * <p>Executes a batch. This method <strong>is thread safe</strong> to avoid concurrent problems. The drawback is only one transaction at time can be executed. if <code>writeMode</code> is set to false, multiple batch operations is allowed.</p>
 *
 * @param commands
 * 	batch to execute
 * @param writeMode
 * 	true to open connection in write mode, false to open connection in read only mode
 */
public <T> T executeBatch(Batch<T> commands, boolean writeMode) {
  // open database in thread safe mode
  Pair<Boolean, SupportSQLiteDatabase> _status=openDatabaseThreadSafeMode(writeMode);
  DataSourceSingleThread currentDaoFactory=new DataSourceSingleThread();
  currentDaoFactory.onSessionOpened();
  try {
    if (commands!=null) {
      return commands.onExecute(currentDaoFactory);
    }
  } catch(Throwable e) {
    Logger.error(e.getMessage());
    e.printStackTrace();
    throw(e);
  } finally {
    // close database in thread safe mode
    closeThreadSafeMode(_status);
    currentDaoFactory.onSessionClosed();
  }
  return null;
}
 
Example 17
Source Project: kripton   Source File: BindInsertRawPersonDataSource.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * onCreate
 */
@Override
protected void onCreate(SupportSQLiteDatabase database) {
  // generate tables
  // log section create BEGIN
  if (this.logEnabled) {
    if (options.inMemory) {
      Logger.info("Create database in memory");
    } else {
      Logger.info("Create database '%s' version %s",this.name, this.version);
    }
  }
  // log section create END
  // log section create BEGIN
  if (this.logEnabled) {
    Logger.info("DDL: %s",PersonTable.CREATE_TABLE_SQL);
  }
  // log section create END
  database.execSQL(PersonTable.CREATE_TABLE_SQL);
  if (options.databaseLifecycleHandler != null) {
    options.databaseLifecycleHandler.onCreate(database);
  }
  justCreated=true;
}
 
Example 18
Source Project: kripton   Source File: BindPersonDataSource.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * <p>Executes a batch. This method <strong>is thread safe</strong> to avoid concurrent problems. The drawback is only one transaction at time can be executed. if <code>writeMode</code> is set to false, multiple batch operations is allowed.</p>
 *
 * @param commands
 * 	batch to execute
 * @param writeMode
 * 	true to open connection in write mode, false to open connection in read only mode
 */
public <T> T executeBatch(Batch<T> commands, boolean writeMode) {
  // open database in thread safe mode
  Pair<Boolean, SupportSQLiteDatabase> _status=openDatabaseThreadSafeMode(writeMode);
  DataSourceSingleThread currentDaoFactory=new DataSourceSingleThread();
  currentDaoFactory.onSessionOpened();
  try {
    if (commands!=null) {
      return commands.onExecute(currentDaoFactory);
    }
  } catch(Throwable e) {
    Logger.error(e.getMessage());
    e.printStackTrace();
    throw(e);
  } finally {
    // close database in thread safe mode
    closeThreadSafeMode(_status);
    currentDaoFactory.onSessionClosed();
  }
  return null;
}
 
Example 19
Source Project: kripton   Source File: BindAppDataSource.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * onCreate
 */
@Override
protected void onCreate(SupportSQLiteDatabase database) {
  // generate tables
  // log section create BEGIN
  if (this.logEnabled) {
    if (options.inMemory) {
      Logger.info("Create database in memory");
    } else {
      Logger.info("Create database '%s' version %s",this.name, this.version);
    }
  }
  // log section create END
  // log section create BEGIN
  if (this.logEnabled) {
    Logger.info("DDL: %s",PersonTable.CREATE_TABLE_SQL);
  }
  // log section create END
  database.execSQL(PersonTable.CREATE_TABLE_SQL);
  if (options.databaseLifecycleHandler != null) {
    options.databaseLifecycleHandler.onCreate(database);
  }
  justCreated=true;
}
 
Example 20
Source Project: kripton   Source File: BindAppDataSource.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * <p>Executes a batch. This method <strong>is thread safe</strong> to avoid concurrent problems. The drawback is only one transaction at time can be executed. if <code>writeMode</code> is set to false, multiple batch operations is allowed.</p>
 *
 * @param commands
 * 	batch to execute
 * @param writeMode
 * 	true to open connection in write mode, false to open connection in read only mode
 */
public <T> T executeBatch(Batch<T> commands, boolean writeMode) {
  // open database in thread safe mode
  Pair<Boolean, SupportSQLiteDatabase> _status=openDatabaseThreadSafeMode(writeMode);
  DataSourceSingleThread currentDaoFactory=new DataSourceSingleThread();
  currentDaoFactory.onSessionOpened();
  try {
    if (commands!=null) {
      return commands.onExecute(currentDaoFactory);
    }
  } catch(Throwable e) {
    Logger.error(e.getMessage());
    e.printStackTrace();
    throw(e);
  } finally {
    // close database in thread safe mode
    closeThreadSafeMode(_status);
    currentDaoFactory.onSessionClosed();
  }
  return null;
}
 
Example 21
Source Project: kripton   Source File: BindDummy01DataSource.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * onCreate
 */
@Override
protected void onCreate(SupportSQLiteDatabase database) {
  // generate tables
  // log section create BEGIN
  if (this.logEnabled) {
    if (options.inMemory) {
      Logger.info("Create database in memory");
    } else {
      Logger.info("Create database '%s' version %s",this.name, this.version);
    }
  }
  // log section create END
  // log section create BEGIN
  if (this.logEnabled) {
    Logger.info("DDL: %s",Bean01Table.CREATE_TABLE_SQL);
  }
  // log section create END
  database.execSQL(Bean01Table.CREATE_TABLE_SQL);
  if (options.databaseLifecycleHandler != null) {
    options.databaseLifecycleHandler.onCreate(database);
  }
  justCreated=true;
}
 
Example 22
Source Project: kripton   Source File: BindCharDataSource.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * <p>Executes a batch. This method <strong>is thread safe</strong> to avoid concurrent problems. The drawback is only one transaction at time can be executed. if <code>writeMode</code> is set to false, multiple batch operations is allowed.</p>
 *
 * @param commands
 * 	batch to execute
 * @param writeMode
 * 	true to open connection in write mode, false to open connection in read only mode
 */
public <T> T executeBatch(Batch<T> commands, boolean writeMode) {
  // open database in thread safe mode
  Pair<Boolean, SupportSQLiteDatabase> _status=openDatabaseThreadSafeMode(writeMode);
  DataSourceSingleThread currentDaoFactory=new DataSourceSingleThread();
  currentDaoFactory.onSessionOpened();
  try {
    if (commands!=null) {
      return commands.onExecute(currentDaoFactory);
    }
  } catch(Throwable e) {
    Logger.error(e.getMessage());
    e.printStackTrace();
    throw(e);
  } finally {
    // close database in thread safe mode
    closeThreadSafeMode(_status);
    currentDaoFactory.onSessionClosed();
  }
  return null;
}
 
Example 23
Source Project: kripton   Source File: BindAppDataSource.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * <p>Executes a batch. This method <strong>is thread safe</strong> to avoid concurrent problems. The drawback is only one transaction at time can be executed. if <code>writeMode</code> is set to false, multiple batch operations is allowed.</p>
 *
 * @param commands
 * 	batch to execute
 * @param writeMode
 * 	true to open connection in write mode, false to open connection in read only mode
 */
public <T> T executeBatch(Batch<T> commands, boolean writeMode) {
  // open database in thread safe mode
  Pair<Boolean, SupportSQLiteDatabase> _status=openDatabaseThreadSafeMode(writeMode);
  DataSourceSingleThread currentDaoFactory=new DataSourceSingleThread();
  currentDaoFactory.onSessionOpened();
  try {
    if (commands!=null) {
      return commands.onExecute(currentDaoFactory);
    }
  } catch(Throwable e) {
    Logger.error(e.getMessage());
    e.printStackTrace();
    throw(e);
  } finally {
    // close database in thread safe mode
    closeThreadSafeMode(_status);
    currentDaoFactory.onSessionClosed();
  }
  return null;
}
 
Example 24
Source Project: kripton   Source File: BindDummy02DataSource.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * onCreate
 */
@Override
protected void onCreate(SupportSQLiteDatabase database) {
  // generate tables
  // log section create BEGIN
  if (this.logEnabled) {
    if (options.inMemory) {
      Logger.info("Create database in memory");
    } else {
      Logger.info("Create database '%s' version %s",this.name, this.version);
    }
  }
  // log section create END
  // log section create BEGIN
  if (this.logEnabled) {
    Logger.info("DDL: %s",Bean02Table.CREATE_TABLE_SQL);
  }
  // log section create END
  database.execSQL(Bean02Table.CREATE_TABLE_SQL);
  if (options.databaseLifecycleHandler != null) {
    options.databaseLifecycleHandler.onCreate(database);
  }
  justCreated=true;
}
 
Example 25
Source Project: kripton   Source File: BindDocumentDataSource.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * onCreate
 */
@Override
protected void onCreate(SupportSQLiteDatabase database) {
  // generate tables
  // log section create BEGIN
  if (this.logEnabled) {
    if (options.inMemory) {
      Logger.info("Create database in memory");
    } else {
      Logger.info("Create database '%s' version %s",this.name, this.version);
    }
  }
  // log section create END
  // log section create BEGIN
  if (this.logEnabled) {
    Logger.info("DDL: %s",DocumentTable.CREATE_TABLE_SQL);
  }
  // log section create END
  database.execSQL(DocumentTable.CREATE_TABLE_SQL);
  if (options.databaseLifecycleHandler != null) {
    options.databaseLifecycleHandler.onCreate(database);
  }
  justCreated=true;
}
 
Example 26
Source Project: kripton   Source File: BindAppDataSource.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * onCreate
 */
@Override
protected void onCreate(SupportSQLiteDatabase database) {
  // generate tables
  // log section create BEGIN
  if (this.logEnabled) {
    if (options.inMemory) {
      Logger.info("Create database in memory");
    } else {
      Logger.info("Create database '%s' version %s",this.name, this.version);
    }
  }
  // log section create END
  // log section create BEGIN
  if (this.logEnabled) {
    Logger.info("DDL: %s",CityTable.CREATE_TABLE_SQL);
  }
  // log section create END
  database.execSQL(CityTable.CREATE_TABLE_SQL);
  if (options.databaseLifecycleHandler != null) {
    options.databaseLifecycleHandler.onCreate(database);
  }
  justCreated=true;
}
 
Example 27
Source Project: bcm-android   Source File: GroupDatabase.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void migrate(SupportSQLiteDatabase database) {
    try {
        database.execSQL("ALTER TABLE group_live_info "
                + " ADD COLUMN 'source_type' INTEGER NOT NULL DEFAULT 0");
    } catch (Exception e) {
        ALog.e("Database", "+++++++++++++++++++++++database upgrade(6,7)  error " + e);
    }

}
 
Example 28
Source Project: kripton   Source File: BindRssDataSource.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * onCreate
 */
@Override
protected void onCreate(SupportSQLiteDatabase database) {
  // generate tables
  // log section create BEGIN
  if (this.logEnabled) {
    if (options.inMemory) {
      Logger.info("Create database in memory");
    } else {
      Logger.info("Create database '%s' version %s",this.name, this.version);
    }
  }
  // log section create END
  // log section create BEGIN
  if (this.logEnabled) {
    Logger.info("DDL: %s",RssFeedTable.CREATE_TABLE_SQL);
  }
  // log section create END
  database.execSQL(RssFeedTable.CREATE_TABLE_SQL);
  // log section create BEGIN
  if (this.logEnabled) {
    Logger.info("DDL: %s",ChannelTable.CREATE_TABLE_SQL);
  }
  // log section create END
  database.execSQL(ChannelTable.CREATE_TABLE_SQL);
  // log section create BEGIN
  if (this.logEnabled) {
    Logger.info("DDL: %s",ArticleTable.CREATE_TABLE_SQL);
  }
  // log section create END
  database.execSQL(ArticleTable.CREATE_TABLE_SQL);
  if (options.databaseLifecycleHandler != null) {
    options.databaseLifecycleHandler.onCreate(database);
  }
  justCreated=true;
}
 
Example 29
Source Project: cwac-saferoom   Source File: DecryptTest.java    License: Apache License 2.0 5 votes vote down vote up
private void assertOriginalContent(SupportSQLiteDatabase db) {
  Cursor c=db.query("SELECT bar, goo FROM foo;");

  assertNotNull(c);
  assertEquals(1, c.getCount());
  assertTrue(c.moveToFirst());
  assertEquals(1, c.getInt(0));
  assertEquals("two", c.getString(1));
  c.close();
}
 
Example 30
Source Project: zephyr   Source File: V1ToV2AddAppInfoTable.java    License: MIT License 5 votes vote down vote up
public void migrate(@NonNull SupportSQLiteDatabase database) {
    // Create app_info table
    database.execSQL("CREATE TABLE IF NOT EXISTS app_info (packageName TEXT NOT NULL, title TEXT, color INTEGER NOT NULL, PRIMARY KEY(packageName))");
    database.execSQL("CREATE UNIQUE INDEX IF NOT EXISTS index_app_info_packageName ON app_info (packageName)");

    // Populate app_info table with data from notification_preferences
    database.execSQL("INSERT INTO `app_info` (packageName, title, color) SELECT packageName, title, color FROM `notification_preferences`");

    // Re-create notification_preferences table with updated columns
    database.execSQL("CREATE TABLE notification_preferences_migrated (packageName TEXT NOT NULL, enabled INTEGER NOT NULL, PRIMARY KEY(packageName))");
    database.execSQL("INSERT INTO notification_preferences_migrated (packageName, enabled) SELECT packageName, enabled FROM notification_preferences");
    database.execSQL("DROP TABLE notification_preferences");
    database.execSQL("ALTER TABLE notification_preferences_migrated RENAME TO notification_preferences");
    database.execSQL("CREATE UNIQUE INDEX IF NOT EXISTS index_notification_preferences_packageName ON notification_preferences (packageName)");
}