@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; } }
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); } }
@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); } }
public String getTypeInSQL(DBContext ctx) { return ctx.getDBType().getStringType(30); }
public String getValueInSQL(DBContext ctx, Object value) { Date v = (Date) value; return ctx.getDBType().getValueInSQL(v); }
public String getValueInSQL(DBContext ctx, Object value) { Boolean v = (Boolean) value; return ctx.getDBType().getValueInSQL(v.booleanValue()); }
public String getTypeInSQL(DBContext ctx) { return ctx.getDBType().getBooleanType(); }
public String getTypeInSQL(DBContext ctx) { return ctx.getDBType().getDoubleType(); }
private void init(Class<T> beanClass) { this.beanClass = beanClass; this.dao = DBContext.getDAO(beanClass); this.pkColumn = dao.getPKColumn(); }