示例#1
0
  /**
   * restores one of the saved tables as the current table. Note that the table that was current up
   * to this point will be dropped. Also there will be one less 'saved' table after this operation.
   *
   * @param suffix the <code>String</code> to append to the name of the current table in order to
   *     form the old table name
   * @return success if true
   */
  public boolean loadFrom(String suffix) {
    if (!notNullOrEmpty(suffix)) return false;

    String oldTableName = ShareUtil.tableName(suffix);
    if (!savedTables().contains(oldTableName)) return false;

    for (int index : savedTableIndices()) {
      String newTableName = tableList.get(index);
      oldTableName = ShareUtil.tableName(newTableName, suffix);
      if (tableExists(oldTableName)) rename(oldTableName, newTableName);
      else create(newTableName);
    }

    Log.i(TAG, String.format("table loaded from '%s'", oldTableName));
    return true;
  }
示例#2
0
  /**
   * changes the name of the table that has been worked on (current table). Thus this table is
   * 'saved' in the same database. Note that the current table is non-existing after this operation.
   * In order to continue the current table has to be restored (loadFrom) or recreated (clear).
   *
   * @param suffix the <code>String</code> to append to the name of the current table in order to
   *     form the new table name
   * @return success if true
   */
  public boolean saveAs(String suffix) {
    if (!notNullOrEmpty(suffix)) return false;

    String newTableName = ShareUtil.tableName(suffix);
    if (savedTables().contains(newTableName)) return false;

    for (int index : savedTableIndices()) {
      String oldTableName = tableList.get(index);
      if (tableExists(oldTableName) && getCount(oldTableName) > 0) {
        newTableName = ShareUtil.tableName(oldTableName, suffix);
        rename(oldTableName, newTableName);
      } else drop(oldTableName);
    }

    Log.i(TAG, String.format("table saved as '%s'", newTableName));
    return true;
  }