Search in sources :

Example 11 with PItem

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;
}
Also used : LinkVisitor(org.nutz.dao.entity.LinkVisitor) Pojo(org.nutz.dao.sql.Pojo) NoParamsPItem(org.nutz.dao.impl.sql.pojo.NoParamsPItem) PItem(org.nutz.dao.sql.PItem) LinkField(org.nutz.dao.entity.LinkField)

Example 12 with PItem

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()));
    }
}
Also used : Pager(org.nutz.dao.pager.Pager) PItem(org.nutz.dao.sql.PItem)

Aggregations

PItem (org.nutz.dao.sql.PItem)12 LinkField (org.nutz.dao.entity.LinkField)4 LinkVisitor (org.nutz.dao.entity.LinkVisitor)4 AbstractPItem (org.nutz.dao.impl.sql.pojo.AbstractPItem)4 StaticPItem (org.nutz.dao.impl.sql.pojo.StaticPItem)4 Pojo (org.nutz.dao.sql.Pojo)4 DoClearLinkVisitor (org.nutz.dao.impl.link.DoClearLinkVisitor)2 DoClearRelationByHostFieldLinkVisitor (org.nutz.dao.impl.link.DoClearRelationByHostFieldLinkVisitor)2 DoClearRelationByLinkedFieldLinkVisitor (org.nutz.dao.impl.link.DoClearRelationByLinkedFieldLinkVisitor)2 DoDeleteLinkVisitor (org.nutz.dao.impl.link.DoDeleteLinkVisitor)2 DoInsertLinkVisitor (org.nutz.dao.impl.link.DoInsertLinkVisitor)2 DoInsertRelationLinkVisitor (org.nutz.dao.impl.link.DoInsertRelationLinkVisitor)2 DoUpdateLinkVisitor (org.nutz.dao.impl.link.DoUpdateLinkVisitor)2 DoUpdateRelationLinkVisitor (org.nutz.dao.impl.link.DoUpdateRelationLinkVisitor)2 ConditionPItem (org.nutz.dao.impl.sql.pojo.ConditionPItem)2 NoParamsPItem (org.nutz.dao.impl.sql.pojo.NoParamsPItem)2 ValueAdaptor (org.nutz.dao.jdbc.ValueAdaptor)2 Criteria (org.nutz.dao.sql.Criteria)2 SqlExpressionGroup (org.nutz.dao.util.cri.SqlExpressionGroup)2 Condition (org.nutz.dao.Condition)1