use of org.nutz.dao.FieldMatcher in project nutz by nutzam.
the class EntityOperator method addUpdateForIgnoreNull.
public List<Pojo> addUpdateForIgnoreNull(final Entity<?> en, final Object obj, final FieldMatcher fm) {
if (null == en)
return null;
final FieldMatcher newFM;
if (null == fm)
newFM = FieldMatcher.make(null, null, true);
else {
newFM = fm;
newFM.setIgnoreNull(true);
}
final List<Pojo> re = new ArrayList<Pojo>(Lang.length(obj));
Lang.each(obj, new Each<Object>() {
public void invoke(int i, Object ele, int length) throws ExitLoop, LoopException {
Pojo pojo = dao.pojoMaker.makeUpdate(en, ele).append(Pojos.Items.cndAuto(en, ele)).setOperatingObject(ele);
pojo.getContext().setFieldMatcher(newFM);
re.add(pojo);
}
});
pojoList.addAll(re);
return re;
}
use of org.nutz.dao.FieldMatcher in project nutz by nutzam.
the class QueryEntityFieldsPItem method joinSql.
public void joinSql(Entity<?> en, StringBuilder sb) {
FieldMatcher fm = getFieldMatcher();
if (null == fm) {
sb.append("* ");
} else {
List<MappingField> efs = _en(en).getMappingFields();
int old = sb.length();
for (MappingField ef : efs) {
if (fm.match(ef.getName()))
sb.append(ef.getColumnNameInSql()).append(',');
}
if (sb.length() == old)
throw Lang.makeThrow("No columns be queryed: '%s'", _en(en));
sb.setCharAt(sb.length() - 1, ' ');
}
}
use of org.nutz.dao.FieldMatcher in project nutz by nutzam.
the class DoUpdateLinkVisitor method visit.
public void visit(Object obj, final LinkField lnk) {
Object value = lnk.getValue(obj);
if (Lang.length(value) == 0)
return;
if (value instanceof Map<?, ?>)
value = ((Map<?, ?>) value).values();
FieldMatcher fm = FieldFilter.get(lnk.getLinkedEntity().getType());
// 如果需要忽略 Null 字段,则为每个 POJO 都生成一条语句
if (null != fm && fm.isIgnoreNull()) {
opt.addUpdateForIgnoreNull(lnk.getLinkedEntity(), value, fm);
} else // 否则生成一条批处理语句
{
opt.addUpdate(lnk.getLinkedEntity(), value);
}
}
use of org.nutz.dao.FieldMatcher in project nutz by nutzam.
the class EntityCallback method invoke.
public Object invoke(Connection conn, ResultSet rs, Sql sql) throws SQLException {
Entity<?> en = sql.getEntity();
if (null == en)
throw Lang.makeThrow("SQL without entity : %s", sql.toString());
FieldMatcher fmh = sql.getContext().getFieldMatcher();
if (null == fmh)
sql.getContext().setFieldMatcher(FieldFilter.get(en.getType()));
return process(rs, en, sql.getContext());
}
Aggregations