コード例 #1
0
  public static Object deflateColumn(
      TableDetails tableDetails, TableDetails.ColumnDetails columnDetails, Object dataModelObject) {
    try {
      Object value = columnDetails.getColumnField().get(dataModelObject);

      if (value == null) return null;
      else return columnDetails.getColumnTypeMapping().toSqlType(value);
    } catch (IllegalAccessException e) {
      throw new QuantumFluxException(
          "Unable to access protected field, change the access level: "
              + columnDetails.getColumnName());
    }
  }
コード例 #2
0
  private static <T> void inflateColumn(
      Cursor cursor, T dataModelObject, TableDetails.ColumnDetails columnDetails, int columnIndex) {

    // If the column details is not required, then check if it is null
    if (!columnDetails.isRequired() && cursor.isNull(columnIndex)) {
      return;
    }

    try {
      columnDetails.setFieldValue(cursor, columnIndex, dataModelObject);
    } catch (IllegalAccessException e) {
      throw new QuantumFluxException(
          "Not allowed to alter the value of the field, please change the access level: "
              + columnDetails.getColumnName());
    }
  }
コード例 #3
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;
  }
コード例 #4
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;
  }