Package org.eweb4j.util

Examples of org.eweb4j.util.ReflectUtil


    Class<?> clazz = t.getClass();
    String table = ORMConfigBeanUtil.getTable(clazz);
    StringBuilder condition = new StringBuilder();
    StringBuilder values = new StringBuilder();
    ReflectUtil ru = new ReflectUtil(t);
    String[] columns = ORMConfigBeanUtil.getColumns(clazz);
    String[] fields = ORMConfigBeanUtil.getFields(clazz);
    String idColumn = ORMConfigBeanUtil.getIdColumn(clazz);
    String idField = ORMConfigBeanUtil.getIdField(clazz);
    condition.append(idColumn + " = ");
    try {
      Method idGetter = ru.getGetter(idField);
      if (idGetter == null)
        throw new SqlCreateException("can not find id getter");

      condition.append("'" + idGetter.invoke(t) + "'");
      for (int i = 0; i < columns.length; i++) {
        String column = columns[i];
        String field = fields[i];

        // id 字段不允许
        if (idColumn != null && idColumn.equalsIgnoreCase(column))
          continue;

        Method getter = ru.getGetter(field);
        if (getter == null)
          continue;

        Object _value = getter.invoke(t);
        if (_value == null)
          continue;

        Object value = null;

        if (ClassUtil.isPojo(_value.getClass())) {
          Field f = ru.getField(field);
          OneToOne oneAnn = getter.getAnnotation(OneToOne.class);
          if (oneAnn == null)
            oneAnn = f.getAnnotation(OneToOne.class);
          if (oneAnn != null) {
            ReflectUtil tarRu = new ReflectUtil(_value);
            String tarFKField = ORMConfigBeanUtil.getIdField(_value
                .getClass());

            Method tarFKGetter = tarRu.getGetter(tarFKField);
            value = tarFKGetter.invoke(_value);
          }
        }

        if (value == null)
View Full Code Here


  private String makeSQL(T t, String[] fields) throws SqlCreateException {
    Class<?> clazz = t.getClass();
    String table = ORMConfigBeanUtil.getTable(clazz);
    StringBuilder condition = new StringBuilder();
    StringBuilder values = new StringBuilder();
    ReflectUtil ru = new ReflectUtil(t);
    String[] columns = ORMConfigBeanUtil.getColumns(clazz, fields);
    String idColumn = ORMConfigBeanUtil.getIdColumn(clazz);
    String idField = ORMConfigBeanUtil.getIdField(clazz);
    Method idGetter = ru.getGetter(idField);
    if (idGetter == null)
      throw new SqlCreateException("can not find id getter.");

    try {
      condition.append(idColumn).append(" = '")
          .append(idGetter.invoke(t)).append("'");
    } catch (Exception e) {
      throw new SqlCreateException(idGetter + " invoke exception "
          + e.toString());
    }

    for (int i = 0; i < fields.length; i++) {
      String field = fields[i];
      String column = columns[i];
      Method getter = ru.getGetter(field);
      if (getter == null)
        continue;

      try {
        Object _value = getter.invoke(t);
        if (_value == null)
          continue;

        Object value = null;

        if (ClassUtil.isPojo(_value.getClass())) {
          Field f = ru.getField(field);
          OneToOne oneAnn = getter.getAnnotation(OneToOne.class);
          if (oneAnn == null)
            oneAnn = f.getAnnotation(OneToOne.class);
          if (oneAnn != null) {
            ReflectUtil tarRu = new ReflectUtil(_value);
            String tarFKField = ORMConfigBeanUtil.getIdField(_value
                .getClass());

            Method tarFKGetter = tarRu.getGetter(tarFKField);
            value = tarFKGetter.invoke(_value);
          }
        }

        if (value == null)
View Full Code Here

  private String makeSQL(T t, String[] fields, String[] values)
      throws SqlCreateException {
    Class<?> clazz = t.getClass();
    String table = ORMConfigBeanUtil.getTable(clazz);
    ReflectUtil ru = new ReflectUtil(t);
    String[] columns = ORMConfigBeanUtil.getColumns(clazz, fields);
    String idColumn = ORMConfigBeanUtil.getIdColumn(clazz);
    String idField = ORMConfigBeanUtil.getIdField(clazz);
    Method idGetter = ru.getGetter(idField);
    if (idGetter == null)
      throw new SqlCreateException("can not find id getter.");

    StringBuilder condition = new StringBuilder();
    try {
View Full Code Here

        else
          condition.append(columns[i]).append(" ").append(type[0])
              .append(type[2]).append(values[i]).append(type[3]);

      else {
        ReflectUtil ru = new ReflectUtil(t);
        Method getter = ru.getGetter(fields[i]);
        if (getter == null)
          continue;
        try {
          Object _value = getter.invoke(t);

          if (_value == null)
            continue;

          Object value = null;
          if (ClassUtil.isPojo(_value.getClass())) {
            Field f = ru.getField(fields[i]);
            OneToOne oneAnn = getter.getAnnotation(OneToOne.class);
            if (oneAnn == null)
              oneAnn = f.getAnnotation(OneToOne.class);
           
            if (oneAnn != null) {
              ReflectUtil tarRu = new ReflectUtil(_value);
              String tarFKField = ORMConfigBeanUtil
                  .getIdField(_value.getClass());

              Method tarFKGetter = tarRu.getGetter(tarFKField);
              value = tarFKGetter.invoke(_value);
            }
          }

          if (value == null)
View Full Code Here

    return selectAll(null, OrderType.DESC_ORDER);
  }

  public String selectOne() throws SqlCreateException {
    // 反射工具
    ReflectUtil ru = new ReflectUtil(this.t);
    StringBuilder condition = new StringBuilder();

    Method m = ru.getGetter(idField);
    if (m == null) {
      throw new SqlCreateException("can not find id getter");
    }
    try {
      condition.append(idColumn).append(" = '").append(m.invoke(this.t))
View Full Code Here

  public String preOne() throws SqlCreateException {
    return this.nextOrPre(1, false);
  }

  public String nextOrPre(int num, boolean isNext) throws SqlCreateException {
    Method m = new ReflectUtil(t).getGetter(idField);
    if (m == null)
      throw new SqlCreateException("can not fine id getter");
    String idVal = "";
    try {
      idVal = String.valueOf(m.invoke(t));
View Full Code Here

  public String[] createByFieldsIsValues(String[][] fields, String[][] values)
      throws SqlCreateException {
    String[] sqls = new String[ts.length];
    for (int i = 0; i < ts.length; ++i) {
      T t = ts[i];
      ReflectUtil ru = new ReflectUtil(t);
      Class<?> clazz = t.getClass();
      String table = ORMConfigBeanUtil.getTable(clazz);
      StringBuilder columnSB = new StringBuilder();
      StringBuilder valueSB = new StringBuilder();
      for (int j = 0; j < fields[i].length; ++j) {
        String name = fields[i][j];
        Object _value = null;
        Object value = null;
        if (values == null) {
          Method getter = null;
          try {
            getter = ru.getGetter(name);
            if (getter == null)
              continue;

            _value = getter.invoke(t);
            if (_value == null)
              continue;

            if (ClassUtil.isPojo(_value.getClass())) {
              Field f = ru.getField(fields[i][j]);
              OneToOne oneAnn = getter
                  .getAnnotation(OneToOne.class);
              if (oneAnn == null)
                oneAnn = f.getAnnotation(OneToOne.class);
              if (oneAnn != null) {
                ReflectUtil tarRu = new ReflectUtil(_value);
                String tarFKField = ORMConfigBeanUtil
                    .getIdField(_value.getClass());

                Method tarFKGetter = tarRu
                    .getGetter(tarFKField);
                value = tarFKGetter.invoke(_value);
              }
            }
View Full Code Here

      T t = ts[index];
      Class<?> clazz = t.getClass();
      table = ORMConfigBeanUtil.getTable(clazz);
      String[] fields = ORMConfigBeanUtil.getFields(clazz);
      String[] _columns = ORMConfigBeanUtil.getColumns(clazz);
      ReflectUtil ru = new ReflectUtil(t);
      for (int i = 0; i < _columns.length; i++) {
        String column = _columns[i];
        String name = fields[i];

        Method getter = ru.getGetter(name);
        if (getter == null)
          continue;

        Object _value = null;
        Object value = null;
        try {
          _value = getter.invoke(t);
          if (_value == null)
            continue;

          if (ClassUtil.isPojo(_value.getClass())) {
            Field f = ru.getField(name);
            OneToOne oneAnn = getter.getAnnotation(OneToOne.class);
            if (oneAnn == null)
              oneAnn = f.getAnnotation(OneToOne.class);
            if (oneAnn != null) {
              ReflectUtil tarRu = new ReflectUtil(_value);
              String tarFKField = ORMConfigBeanUtil
                  .getIdField(_value.getClass());

              Method tarFKGetter = tarRu.getGetter(tarFKField);
              value = tarFKGetter.invoke(_value);
            }
          }

          if (value == null)
View Full Code Here

  }

  private String makeSQL(T t) throws SqlCreateException {
    Class<?> clazz = t.getClass();
    String idField = ORMConfigBeanUtil.getIdField(clazz);
    ReflectUtil ru = new ReflectUtil(t);
    Method method = ru.getGetter(idField);
    if (method == null) {
      throw new SqlCreateException("can not find id getter.");
    }
    String table = ORMConfigBeanUtil.getTable(clazz);
    String idColumn = ORMConfigBeanUtil.getIdColumn(clazz);
View Full Code Here

  private String makeSQL(T t, String... fields) throws SqlCreateException {
    Class<?> clazz = t.getClass();
    String table = ORMConfigBeanUtil.getTable(clazz);
    StringBuilder condition = new StringBuilder();
    ReflectUtil ru = new ReflectUtil(t);

    for (int i = 0; i < fields.length; i++) {
      if (condition.length() > 0)
        condition.append(" AND ");

      Method getter = ru.getGetter(fields[i]);
      if (getter == null)
        continue;

      String column = ORMConfigBeanUtil.getColumn(clazz, fields[i]);
      condition.append(column + " = ");

      Object _value = null;
      Object value = null;
      try {
        _value = getter.invoke(t);
        if (_value == null)
          continue;

        if (ClassUtil.isPojo(_value.getClass())) {
          Field f = ru.getField(fields[i]);
          OneToOne oneAnn = getter.getAnnotation(OneToOne.class);
          if (oneAnn == null)
            oneAnn = f.getAnnotation(OneToOne.class);
          if (oneAnn != null) {
            ReflectUtil tarRu = new ReflectUtil(_value);
            String tarFKField = ORMConfigBeanUtil.getIdField(_value
                .getClass());

            Method tarFKGetter = tarRu.getGetter(tarFKField);
            value = tarFKGetter.invoke(_value);
          }
        }

        if (value == null)
View Full Code Here

TOP

Related Classes of org.eweb4j.util.ReflectUtil

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.