예제 #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;
      }
    }
예제 #2
0
 public LIST(Class<T> beanClass, String name, DBColumn fkColumn, boolean preFetch) {
   super(name, false, false);
   this.beanClass = beanClass;
   this.fkColumn = fkColumn;
   this.preFetch = preFetch;
   this.dao = DBContext.getDAO(beanClass);
 }
  public DBContextTest(String templateFile) {
    try {
      RuntimeSingleton.init(new Properties());

      Template template = RuntimeSingleton.getTemplate(templateFile);

      DBContext dbc = new DBContext();

      Hashtable h = new Hashtable();
      h.put("Bar", "this is from a hashtable!");

      dbc.put("string", "Hello!");
      dbc.put("hashtable", h);

      Writer writer = new BufferedWriter(new OutputStreamWriter(System.out));

      template.merge(dbc, writer);

      writer.flush();
      writer.close();
    } catch (Exception e) {
      RuntimeSingleton.error(e);
    }
  }
예제 #4
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);
      }
    }
예제 #5
0
 public String getTypeInSQL(DBContext ctx) {
   return ctx.getDBType().getStringType(30);
 }
예제 #6
0
 public String getValueInSQL(DBContext ctx, Object value) {
   Date v = (Date) value;
   return ctx.getDBType().getValueInSQL(v);
 }
예제 #7
0
 public String getValueInSQL(DBContext ctx, Object value) {
   Boolean v = (Boolean) value;
   return ctx.getDBType().getValueInSQL(v.booleanValue());
 }
예제 #8
0
 public String getTypeInSQL(DBContext ctx) {
   return ctx.getDBType().getBooleanType();
 }
예제 #9
0
 public String getTypeInSQL(DBContext ctx) {
   return ctx.getDBType().getDoubleType();
 }
예제 #10
0
 private void init(Class<T> beanClass) {
   this.beanClass = beanClass;
   this.dao = DBContext.getDAO(beanClass);
   this.pkColumn = dao.getPKColumn();
 }