예제 #1
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;
  }
예제 #2
0
  /**
   * DOCUMENT ME!
   *
   * @param object DOCUMENT ME!
   * @param fieldName DOCUMENT ME!
   * @param fieldType DOCUMENT ME!
   * @param value DOCUMENT ME!
   * @throws SecurityException DOCUMENT ME!
   * @throws NoSuchMethodException DOCUMENT ME!
   * @throws IllegalArgumentException DOCUMENT ME!
   * @throws IllegalAccessException DOCUMENT ME!
   * @throws InvocationTargetException DOCUMENT ME!
   * @throws IllegalStateException DOCUMENT ME!
   */
  public static void setProperty(Object object, String fieldName, Class fieldType, Object value)
      throws SecurityException, NoSuchMethodException, IllegalArgumentException,
          IllegalAccessException, InvocationTargetException {
    Method method = object.getClass().getMethod(getSetterMethodName(fieldName), fieldType);

    if (fieldType.equals(boolean.class) || fieldType.equals(Boolean.class)) {
      Integer temp = (Integer) value;

      if (temp.intValue() == 0) {
        value = Boolean.FALSE;
      } else if (temp.intValue() == 1) {
        value = Boolean.TRUE;
      } else {
        throw new IllegalStateException();
      }
    } else if (fieldType.equals(byte.class) || fieldType.equals(Byte.class)) {
      Integer temp = (Integer) value;

      value = new Byte(temp.byteValue());
    }

    Log.v(TAG, fieldName + " " + fieldType + " " + value);
    method.invoke(object, value);
  }
예제 #3
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;
  }