예제 #1
0
  public static <T> T inflate(Cursor cursor, TableDetails tableDetails) {
    T dataModelObject;

    try {
      dataModelObject = (T) tableDetails.createNewModelInstance();
    } catch (Exception ex) {
      throw new QuantumFluxException(
          "Could not create a new instance of data model object: " + tableDetails.getTableName());
    }

    for (int i = 0; i < cursor.getColumnCount(); i++) {
      String columnName = cursor.getColumnName(i);
      TableDetails.ColumnDetails columnDetails = tableDetails.findColumn(columnName);
      inflateColumn(cursor, dataModelObject, columnDetails, i);
    }

    return dataModelObject;
  }
예제 #2
0
  public static ContentValues deflate(TableDetails tableDetails, Object dataModelObject) {
    List<TableDetails.ColumnDetails> columns = tableDetails.getColumns();
    ContentValues contentValues = new ContentValues(columns.size());

    for (int i = 0; i < columns.size(); i++) {
      TableDetails.ColumnDetails columnDetails = columns.get(i);

      if (columnDetails.isAutoIncrement()) continue;

      try {
        columnDetails.setContentValue(contentValues, dataModelObject);
      } catch (IllegalAccessException e) {
        throw new QuantumFluxException(
            "Unable to access protected field, change the access level: "
                + columnDetails.getColumnName());
      }
    }

    return contentValues;
  }
예제 #3
0
  public static ContentValues[] deflateAll(TableDetails tableDetails, Object... dataModelObjects) {
    List<TableDetails.ColumnDetails> columns = tableDetails.getColumns();
    ContentValues[] contentValuesArray = new ContentValues[dataModelObjects.length];
    for (int i = 0; i < dataModelObjects.length; i++) {
      contentValuesArray[i] = new ContentValues(columns.size());
    }

    for (int i = 0; i < columns.size(); i++) {
      TableDetails.ColumnDetails columnDetails = columns.get(i);

      if (columnDetails.isAutoIncrement()) continue;

      for (int j = 0; j < dataModelObjects.length; j++) {
        try {
          columnDetails.setContentValue(contentValuesArray[j], dataModelObjects[j]);
        } catch (IllegalAccessException e) {
          throw new QuantumFluxException(
              "Unable to access protected field, change the access level: "
                  + columnDetails.getColumnName());
        }
      }
    }
    return contentValuesArray;
  }