示例#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) {
       e.printStackTrace();
     }
   }
   pageSqlId = p.getProperty("pageSqlId");
   if (Tools.isEmpty(pageSqlId)) {
     try {
       throw new PropertyException("pageSqlId property is not found!");
     } catch (PropertyException e) {
       e.printStackTrace();
     }
   }
 }
示例#2
0
 /**
  * 根据数据库方言,生成特定的分页sql
  *
  * @param sql
  * @param page
  * @return
  */
 private String generatePageSql(String sql, Pagination page) {
   if (page != null && Tools.notEmpty(dialect)) {
     StringBuffer pageSql = new StringBuffer();
     if ("mysql".equals(dialect)) {
       pageSql.append(sql);
       pageSql.append(" limit " + page.getStartIndex() + "," + page.getNumPerPage());
     } else if ("oracle".equals(dialect)) {
       pageSql.append("select * from (select tmp_tb.*,ROWNUM row_id from (");
       pageSql.append(sql);
       if ("mysql".equals(dialect)) {
         pageSql.append(") as tmp_tb where ROWNUM<=");
       } else if ("oracle".equals(dialect)) {
         pageSql.append(") tmp_tb where ROWNUM<=");
       }
       pageSql.append(page.getStartIndex() + page.getNumPerPage());
       pageSql.append(") where row_id>");
       pageSql.append(page.getStartIndex());
     }
     return pageSql.toString();
   } else {
     return sql;
   }
 }