Пример #1
0
 public <T> void setIdInEntity(T entity, String nameColumn, Object value) {
   try {
     Field[] fields = entity.getClass().getDeclaredFields();
     for (Field field : fields) {
       field.setAccessible(true);
       Column annt = field.getAnnotation(Column.class);
       boolean flagIsSelectable = annt != null && annt.name().equals(nameColumn);
       if (flagIsSelectable) field.set(entity, value);
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Пример #2
0
  /**
   * Retrieve an array with the name of the <b>id</b> columns.
   *
   * @param clazz
   * @return arraya with the name of the id columns
   */
  public <T> String[] getIdColumndName(Class<T> clazz) {
    try {
      List<String> lstResult = new ArrayList<String>();
      Field[] fields = clazz.getDeclaredFields();
      for (Field field : fields) {

        Column annt = field.getAnnotation(Column.class);
        boolean flagIsSelectable = true && annt != null && field.getAnnotation(Id.class) != null;

        if (flagIsSelectable) {
          lstResult.add(annt.name());
        }
      }
      return lstResult.toArray(new String[lstResult.size()]);
    } catch (Exception e) {
      e.printStackTrace();
      return null;
    }
  }
Пример #3
0
  public <T> void setValueInColumn(T data, String columnName, Object value) {

    String format = null;
    try {
      Field[] fields = data.getClass().getDeclaredFields();
      for (Field field : fields) {
        Column anntColumn = field.getAnnotation(Column.class);
        if (anntColumn != null
            && anntColumn.name().toLowerCase().equals(columnName.toLowerCase())) {
          format = value.getClass().getSimpleName() + " to " + field.getType();
          value =
              TypeConverterEnum.get(
                      value.getClass().getSimpleName(), field.getType().getSimpleName())
                  .converterData(value);
          field.setAccessible(true);
          field.set(data, value);
          break;
        }
      }
    } catch (Exception e) {
      log.error("Error format:" + format, e);
      e.printStackTrace();
    }
  }