androidx.sqlite.db.SupportSQLiteDatabase Java Examples

The following examples show how to use androidx.sqlite.db.SupportSQLiteDatabase. 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 File: BindInsertRawPersonDataSource.java    From kripton with 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 #2
Source File: GroupDatabase.java    From bcm-android with 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 #3
Source File: BindFamilyDataSource.java    From kripton with 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 #4
Source File: BindDummy01DataSource.java    From kripton with 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 #5
Source File: BindAppWithConfigDataSource.java    From kripton with 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 #6
Source File: BindCharDataSource.java    From kripton with 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 File: BindAppDataSource.java    From kripton with 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 #8
Source File: BindAppDataSource.java    From kripton with 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 #9
Source File: DefaultDbDowngrader.java    From sqlitemagic with 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 #10
Source File: BindDummy02DataSource.java    From kripton with 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 #11
Source File: BindAppDataSource.java    From kripton with 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 #12
Source File: BindAppDataSource.java    From kripton with 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 #13
Source File: BindWhisperDataSource.java    From kripton with 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 #14
Source File: BindBeanDataSource.java    From kripton with 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 #15
Source File: BindByteDataSource.java    From kripton with 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 #16
Source File: BindBeanDataSource.java    From kripton with 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 File: RoomOpenHelper.java    From FairEmail with 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 #18
Source File: BindPersonDataSource.java    From kripton with 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 File: BindAppDataSource.java    From kripton with 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 #20
Source File: BindApp0DataSource.java    From kripton with 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 File: BindAppDataSource.java    From kripton with 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 #22
Source File: BindDocumentDataSource.java    From kripton with 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 #23
Source File: BindAppDataSource.java    From kripton with 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 File: BindSchoolDataSource.java    From kripton with 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 #25
Source File: BindDummy01DataSource.java    From kripton with 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 #26
Source File: BindAppDataSource.java    From kripton with 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 #27
Source File: BindAppDataSource.java    From kripton with 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",AlbumTable.CREATE_TABLE_SQL);
  }
  // log section create END
  database.execSQL(AlbumTable.CREATE_TABLE_SQL);
  // log section create BEGIN
  if (this.logEnabled) {
    Logger.info("DDL: %s",SongTable.CREATE_TABLE_SQL);
  }
  // log section create END
  database.execSQL(SongTable.CREATE_TABLE_SQL);
  // log section create BEGIN
  if (this.logEnabled) {
    Logger.info("DDL: %s",ZArtistTable.CREATE_TABLE_SQL);
  }
  // log section create END
  database.execSQL(ZArtistTable.CREATE_TABLE_SQL);
  if (options.databaseLifecycleHandler != null) {
    options.databaseLifecycleHandler.onCreate(database);
  }
  justCreated=true;
}
 
Example #28
Source File: V1ToV2AddAppInfoTable.java    From zephyr with 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)");
}
 
Example #29
Source File: BindPersonCirtyErr3DataSource.java    From kripton with 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",PersonTable.CREATE_TABLE_SQL);
  }
  // log section create END
  database.execSQL(PersonTable.CREATE_TABLE_SQL);
  // 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);
  // log section create BEGIN
  if (this.logEnabled) {
    Logger.info("DDL: %s",PersonCityErr3Table.CREATE_TABLE_SQL);
  }
  // log section create END
  database.execSQL(PersonCityErr3Table.CREATE_TABLE_SQL);
  if (options.databaseLifecycleHandler != null) {
    options.databaseLifecycleHandler.onCreate(database);
  }
  justCreated=true;
}
 
Example #30
Source File: SQLiteCopyOpenHelper.java    From FairEmail with GNU General Public License v3.0 5 votes vote down vote up
@Override
public synchronized SupportSQLiteDatabase getWritableDatabase() {
    if (!mVerified) {
        verifyDatabaseFile();
        mVerified = true;
    }
    return mDelegate.getWritableDatabase();
}