Ejemplo n.º 1
0
  /**
   * DOCUMENT ME!
   *
   * @param objectClass DOCUMENT ME!
   * @return DOCUMENT ME!
   * @throws IllegalArgumentException DOCUMENT ME!
   */
  public static Field getIdField(Class objectClass) {
    if (objectClass == null) {
      throw new IllegalArgumentException("The class object cannot be null!");
    }

    Field idField = null;

    Field[] fields = objectClass.getDeclaredFields();

    if (Log.isLoggable(TAG, Log.DEBUG)) {
      Log.d(TAG, "Getting Id field from class: " + objectClass.getName());
      Log.d(TAG, "Amount of fields: " + fields.length);
    }

    for (Field field : fields) {
      org.floggy.persistence.android.Field fieldAnnotation =
          field.getAnnotation(org.floggy.persistence.android.Field.class);

      if ((fieldAnnotation != null) && fieldAnnotation.id()) {
        field.setAccessible(true);

        idField = field;

        break;
      }
    }

    if (Log.isLoggable(TAG, Log.DEBUG)) {
      if (idField != null) {
        Log.d(TAG, "Found Id field : " + idField.toGenericString());
      } else {
        Log.d(TAG, "Not found Id field");
      }
    }

    return idField;
  }
Ejemplo n.º 2
0
  /**
   * DOCUMENT ME!
   *
   * @param objectClass DOCUMENT ME!
   * @return DOCUMENT ME!
   */
  public static String getTableName(Class objectClass) {
    validatePersistableClassArgument(objectClass);

    Persistable annotation = (Persistable) objectClass.getAnnotation(Persistable.class);

    String tableName = annotation.table();

    if ("".equals(tableName)) {
      tableName = objectClass.getSimpleName();
    }

    if (Log.isLoggable(TAG, Log.DEBUG)) {
      Log.d(TAG, "Mapping class " + objectClass.getName() + " to table " + tableName);
    }

    return tableName;
  }