1 21 package net.mlw.vlh.adapter.jdbc.util; 22 23 27 public class SqlPagingSupport 28 { 29 public static final String ORACLE = "oracle"; 30 31 private String pagedQueryPreSql; 32 private String pagedQueryPostSql; 33 34 public StringBuffer getPagedQuery(String sql) 35 { 36 StringBuffer buffer = new StringBuffer (500); 37 buffer.append(pagedQueryPreSql); 38 buffer.append(sql); 39 buffer.append(pagedQueryPostSql); 40 41 return buffer; 42 } 43 44 public StringBuffer getCountQuery(String sql) 45 { 46 StringBuffer buffer = new StringBuffer (sql.length() + 100); 47 return buffer.append("SELECT count(*) FROM (").append(sql).append(")"); 48 } 49 50 public void setDatabase(String database) 51 { 52 if(ORACLE.equalsIgnoreCase(database)) 53 { 54 pagedQueryPreSql = "SELECT * FROM (SELECT INNER.*, ROWNUM as RECORDNUM FROM ("; 55 pagedQueryPostSql = ") INNER ) WRAPPED WHERE WRAPPED.RECORDNUM BETWEEN (([pagingPage]-1)*[pagingNumberPer]+1) AND (([pagingPage]-1)*[pagingNumberPer]+[pagingNumberPer])"; 56 } 57 else 58 { 59 throw new NullPointerException (database + " is not supported ("+ORACLE+")."); 60 } 61 } 62 63 public void setPagedQueryPostSql(String pagedQueryPostSql) 64 { 65 this.pagedQueryPostSql = pagedQueryPostSql; 66 } 67 public void setPagedQueryPreSql(String pagedQueryPreSql) 68 { 69 this.pagedQueryPreSql = pagedQueryPreSql; 70 } 71 } 72 | Popular Tags |