use of org.nutz.dao.sql.PItem in project nutz by nutzam.
the class NutDao method doLinkQuery.
private LinkVisitor doLinkQuery(final EntityOperator opt, final Condition _cnd, final Map<String, Condition> cnds) {
return new LinkVisitor() {
public void visit(final Object obj, final LinkField lnk) {
Pojo pojo = opt.maker().makeQuery(lnk.getLinkedEntity());
pojo.setOperatingObject(obj);
PItem[] _cndItems = Pojos.Items.cnd(lnk.createCondition(obj));
pojo.append(_cndItems);
Condition cnd = _cnd;
if (_cnd == null && cnds != null)
cnd = cnds.get(lnk.getLinkedField().getName());
if (cnd != null) {
if (cnd instanceof Criteria) {
Criteria cri = (Criteria) cnd;
SqlExpressionGroup seg = cri.where();
if (_cndItems.length > 0 && seg != null && !seg.isEmpty()) {
seg.setTop(false);
pojo.append(Pojos.Items.wrap(" AND "));
}
pojo.append(cri);
if (cri.getPager() != null) {
pojo.setPager(cri.getPager());
expert.formatQuery(pojo);
}
} else // 普通条件
{
pojo.append(new ConditionPItem(cnd));
}
}
pojo.setAfter(lnk.getCallback());
pojo.setEntity(lnk.getLinkedEntity());
_exec(pojo);
lnk.setValue(obj, pojo.getResult());
}
};
}
use of org.nutz.dao.sql.PItem in project nutz by nutzam.
the class NutPojo method getParamMatrix.
public Object[][] getParamMatrix() {
Object[][] re;
/*
* 木有参数对象,但是有参数,循环一下,看看元素们会给出什么样的参数
*/
if (_params_count() > 0 && params.isEmpty()) {
re = new Object[1][_params_count()];
int i = 0;
for (PItem item : items) i = item.joinParams(getEntity(), null, re[0], i);
} else /*
* 依照参数列表循环获取参数矩阵
*/
{
re = new Object[params.size()][_params_count()];
int row = 0;
for (Object obj : params) {
int i = 0;
for (PItem item : items) i = item.joinParams(getEntity(), obj, re[row], i);
row++;
}
}
return re;
}
use of org.nutz.dao.sql.PItem in project nutz by nutzam.
the class NutPojo method getAdaptors.
public ValueAdaptor[] getAdaptors() {
ValueAdaptor[] adaptors = new ValueAdaptor[_params_count()];
int i = 0;
for (PItem item : items) i = item.joinAdaptor(getEntity(), adaptors, i);
return adaptors;
}
use of org.nutz.dao.sql.PItem in project nutz by nutzam.
the class NutSql method getAdaptors.
public ValueAdaptor[] getAdaptors() {
ValueAdaptor[] adaptors = new ValueAdaptor[_params_count()];
int i = 0;
for (PItem item : items) i = item.joinAdaptor(getEntity(), adaptors, i);
return adaptors;
}
use of org.nutz.dao.sql.PItem in project nutz by nutzam.
the class NutSql method setSourceSql.
public void setSourceSql(String sql) {
this.sourceSql = sql.trim();
SqlLiteral literal = literal();
this.varIndex = literal.getVarIndexes();
this.paramIndex = literal.getParamIndexes();
if (getSqlType() == null)
setSqlType(literal.getType());
String[] ss = literal.stack.cloneChain();
PItem[] tmp = new PItem[ss.length];
for (String var : varIndex.getOrders()) {
int[] is = varIndex.indexesOf(var);
if (is != null) {
for (int i : is) {
tmp[i] = new SqlVarPItem(var);
}
}
}
for (String param : paramIndex.getOrders()) {
int[] is = paramIndex.indexesOf(param);
if (is != null) {
for (int i : is) {
tmp[i] = new SqlParamPItem(param);
}
}
}
this.items = new ArrayList<PItem>();
for (int i = 0; i < tmp.length; i++) {
if (tmp[i] == null) {
tmp[i] = new StaticPItem(ss[i], true);
}
items.add(tmp[i]);
}
}
Aggregations