use of org.nutz.dao.sql.PItem in project nutz by nutzam.
the class NutPojoMaker method makeCountByJoin.
@Override
public Pojo makeCountByJoin(final Entity<?> en, String regex) {
final Pojo pojo = Pojos.pojo(expert, en, SqlType.SELECT);
pojo.setEntity(en);
pojo.append(Pojos.Items.wrap("count(1)"));
pojo.append(Pojos.Items.wrap("FROM"));
pojo.append(Pojos.Items.entityViewName());
en.visitOne(null, regex, new LinkVisitor() {
@Override
public void visit(Object obj, LinkField lnk) {
PItem item = expert.formatLeftJoinLink(obj, lnk, en);
if (item != null)
pojo.append(item);
}
});
return pojo;
}
use of org.nutz.dao.sql.PItem in project nutz by nutzam.
the class Sqlserver2005JdbcExpert method formatQuery.
public void formatQuery(Pojo pojo) {
Pager pager = pojo.getContext().getPager();
if (null != pager && pager.getPageNumber() > 0) {
// -----------------------------------------------------
// TODO XXX 这个写法灰常暴力!!But , it works!!!! 期待更好的写法
PItem pi = pojo.getItem(0);
StringBuilder sb = new StringBuilder();
pi.joinSql(pojo.getEntity(), sb);
String str = sb.toString();
if (str.trim().toLowerCase().startsWith("select")) {
pojo.setItem(0, Pojos.Items.wrap(str.substring(6)));
} else
// 以免出错.
return;
pojo.insertFirst(Pojos.Items.wrapf("select * from(select row_number()over(order by __tc__)__rn__,* from(select top %d 0 __tc__, ", pager.getOffset() + pager.getPageSize()));
pojo.append(Pojos.Items.wrapf(")t)tt where __rn__ > %d order by __rn__", pager.getOffset()));
}
}
Aggregations