コード例 #1
0
  /** 更新对象 泛型扩展 * */
  public void updateTupple(T entity) {
    this.entity = entity;
    if (mSetArgs != null) {
      update(mSetArgs, mArgValues);
      return;
    }

    SQLiteDatabase mDatabase = Connector.getDatabase();
    SQLiteStatement mStmt = StmtProductor.generateStmt(this);
    if (mDatabase.isDbLockedByCurrentThread()) {
      mStmt.executeUpdateDelete();
    } else {
      mDatabase.beginTransaction();
      try {
        bindValues(mStmt, entity);
        mStmt.executeUpdateDelete();
        mDatabase.setTransactionSuccessful();
      } catch (Exception e) {
        e.printStackTrace();
      } finally {
        mDatabase.endTransaction();
      }
    }
  }
コード例 #2
0
  /** 更新列表 泛型扩展 * */
  public void updateAll(List<T> entities) {
    this.entitys = entities;
    if (mSetArgs != null) {
      update(mSetArgs, mArgValues);
      return;
    }

    SQLiteDatabase mDatabase = Connector.getDatabase();
    SQLiteStatement mStmt = StmtProductor.generateStmt(this);

    mDatabase.beginTransaction();
    try {
      for (T entity : entities) {
        bindValues(mStmt, entity);
        mStmt.executeUpdateDelete();
      }

      mDatabase.setTransactionSuccessful();
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      mDatabase.endTransaction();
    }
  }