Example #1
0
    @SuppressWarnings("unchecked")
    protected boolean setValueFromResultSet(Object obj, ResultSet rs) throws SQLException {
      Object value = rs.getObject(this.getColumnName());
      if (value != null) {
        try {
          T bean = dao.newEntityInstance();
          FieldUtils.writeField(bean, dao.getPKColumn().getFieldName(), value, true);

          if (preFetch) {
            Class<T> beanClass = dao.getEnitityClass();
            bean = DBContext.getDAO(beanClass).queryByPK(DBContext.getContext(), bean);
          } else {
            Enhancer enhancer = new Enhancer();
            enhancer.setSuperclass(beanClass);
            enhancer.setCallback(new DBObjectProxy<T>(pkColumn, obj, bean, getFieldName()));
            bean = (T) enhancer.create();
            FieldUtils.writeField(bean, dao.getPKColumn().getFieldName(), value, true);
          }

          FieldUtils.writeField(obj, getFieldName(), bean, true);

          return true;
        } catch (Exception e) {
          throw new RuntimeException(e);
        }
      } else {
        return false;
      }
    }
Example #2
0
    @SuppressWarnings("unchecked")
    protected void setListValue(Object obj) {
      List<T> list = null;

      DBCondition condition = fkColumn.equalsTo(obj);
      if (preFetch) {
        list = dao.query(DBContext.getContext(), condition);
      } else {
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(ArrayList.class);
        enhancer.setCallback(new DBListProxy<T>(obj, beanClass, getFieldName(), condition));
        list = (List<T>) enhancer.create();
      }
      try {
        FieldUtils.writeField(obj, getFieldName(), list, true);
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }