Exemplo n.º 1
0
 public void setProperties(Properties p) {
   dialect = p.getProperty("dialect");
   if (Tools.isEmpty(dialect)) {
     try {
       throw new PropertyException("dialect property is not found!");
     } catch (PropertyException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
     }
   }
   pageSqlId = p.getProperty("pageSqlId");
   if (Tools.isEmpty(pageSqlId)) {
     try {
       throw new PropertyException("pageSqlId property is not found!");
     } catch (PropertyException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
     }
   }
 }
Exemplo n.º 2
0
 /**
  * 根据数据库方言,生成特定的分页sql
  *
  * @param sql
  * @param page
  * @return
  */
 private String generatePageSql(String sql, Page page) {
   if (page != null && Tools.notEmpty(dialect)) {
     StringBuffer pageSql = new StringBuffer();
     if ("mysql".equals(dialect)) {
       pageSql.append(sql);
       pageSql.append(" limit " + page.getCurrentResult() + "," + page.getShowCount());
     } else if ("oracle".equals(dialect)) {
       pageSql.append("select * from (select tmp_tb.*,ROWNUM row_id from (");
       pageSql.append(sql);
       pageSql.append(") as tmp_tb where ROWNUM<=");
       pageSql.append(page.getCurrentResult() + page.getShowCount());
       pageSql.append(") where row_id>");
       pageSql.append(page.getCurrentResult());
     }
     return pageSql.toString();
   } else {
     return sql;
   }
 }