use of org.nutz.dao.Chain in project nutz by nutzam.
the class UpdateFieldsByChainPItem method joinParams.
public int joinParams(Entity<?> en, Object obj, Object[] params, int off) {
Chain c = chain.head();
while (c != null) {
params[off++] = c.value();
c = c.next();
}
return off;
}
use of org.nutz.dao.Chain in project nutz by nutzam.
the class ChainTest method test_chain_from_object.
/**
* Issue 93
*/
@Test
public void test_chain_from_object() {
Worker w = new Worker();
w.age = 20;
w.name = "zzh";
Chain c = Chain.from(w, FieldMatcher.make("age|name", null, true));
Map<String, Object> map = c.toMap();
assertEquals(2, map.size());
assertEquals("zzh", map.get("name"));
assertEquals(20, ((Short) map.get("age")).intValue());
}
use of org.nutz.dao.Chain in project nutz by nutzam.
the class EntityOperator method addInsertSelfOnly.
public Pojo addInsertSelfOnly(Entity<?> en, Object obj) {
if (null == en)
return null;
Pojo pojo;
if (obj instanceof Chain) {
pojo = dao.pojoMaker.makePojo(SqlType.INSERT);
pojo.append(Pojos.Items.entityTableName());
pojo.append(new InsertByChainPItem((Chain) obj));
pojo.setEntity(en);
} else {
pojo = dao.pojoMaker.makeInsert(en).setOperatingObject(obj);
}
pojoList.add(pojo);
return pojo;
}
use of org.nutz.dao.Chain in project nutz by nutzam.
the class UpdateFieldsByChainPItem method joinAdaptor.
public int joinAdaptor(Entity<?> en, ValueAdaptor[] adaptors, int off) {
Chain c = chain.head();
while (c != null) {
MappingField mf = en.getField(c.name());
// TODO 移除这种数组下标用++的写法!!!
if (c.adaptor() == null)
adaptors[off++] = (null == mf ? Jdbcs.getAdaptorBy(c.value()) : mf.getAdaptor());
else
adaptors[off++] = c.adaptor();
c = c.next();
}
return off;
}
use of org.nutz.dao.Chain in project nutz by nutzam.
the class UpdateFieldsByChainPItem method joinSql.
public void joinSql(Entity<?> en, StringBuilder sb) {
if (chain.size() > 0) {
sb.append(" SET ");
Chain c = chain.head();
while (c != null) {
sb.append(this._fmtcolnm(en, c.name()));
sb.append("=? ,");
c = c.next();
}
sb.deleteCharAt(sb.length() - 1);
sb.append(' ');
} else {
throw Lang.makeThrow("Entity chain for UPDATE '%s'", en.getType().getName());
}
}
Aggregations