KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > mlw > vlh > adapter > jdbc > util > SqlPagingSupport


1 /**
2  * Copyright (c) 2003 held jointly by the individual authors.
3  *
4  * This library is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU Lesser General Public License as published
6  * by the Free Software Foundation; either version 2.1 of the License, or
7  * (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; with out even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this library; if not, write to the Free Software Foundation,
16  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17  *
18  * > http://www.gnu.org/copyleft/lesser.html
19  * > http://www.opensource.org/licenses/lgpl-license.php
20  */

21 package net.mlw.vlh.adapter.jdbc.util;
22
23 /**
24  * @author Matthew L. Wilson
25  * @version $Revision: 1.2 $ $Date: 2006/04/18 17:14:19 $
26  */

27 public class SqlPagingSupport
28 {
29    public static final String JavaDoc ORACLE = "oracle";
30    
31    private String JavaDoc pagedQueryPreSql;
32    private String JavaDoc pagedQueryPostSql;
33    
34    public StringBuffer JavaDoc getPagedQuery(String JavaDoc sql)
35    {
36       StringBuffer JavaDoc buffer = new StringBuffer JavaDoc(500);
37       buffer.append(pagedQueryPreSql);
38       buffer.append(sql);
39       buffer.append(pagedQueryPostSql);
40       
41       return buffer;
42    }
43    
44    public StringBuffer JavaDoc getCountQuery(String JavaDoc sql)
45    {
46       StringBuffer JavaDoc buffer = new StringBuffer JavaDoc(sql.length() + 100);
47       return buffer.append("SELECT count(*) FROM (").append(sql).append(")");
48    }
49    
50    public void setDatabase(String JavaDoc 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 JavaDoc(database + " is not supported ("+ORACLE+").");
60       }
61    }
62    
63    public void setPagedQueryPostSql(String JavaDoc pagedQueryPostSql)
64    {
65       this.pagedQueryPostSql = pagedQueryPostSql;
66    }
67    public void setPagedQueryPreSql(String JavaDoc pagedQueryPreSql)
68    {
69       this.pagedQueryPreSql = pagedQueryPreSql;
70    }
71 }
72
Popular Tags