KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > components > language > markup > xsp > OracleEsqlQuery


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.cocoon.components.language.markup.xsp;
18
19 import java.sql.ResultSet JavaDoc;
20 import java.sql.SQLException JavaDoc;
21 import java.sql.Connection JavaDoc;
22
23 /**
24  * @author <a HREF="mailto:tcurdt@apache.org">Torsten Curdt</a>
25  * @version CVS $Id: OracleEsqlQuery.java 179114 2005-05-30 15:13:18Z sylvain $
26  */

27 final public class OracleEsqlQuery extends AbstractEsqlQuery {
28
29     public OracleEsqlQuery(Connection JavaDoc connection, String JavaDoc query) {
30         super(connection, query);
31     }
32
33     /**
34      * Only newInstance may use this contructor
35      * @param resultSet
36      */

37     private OracleEsqlQuery(ResultSet JavaDoc resultSet) {
38         super(resultSet);
39     }
40
41     /**
42      * Create a EsqlQuery of the same type
43      * @param resultSet
44      */

45     public AbstractEsqlQuery newInstance(final ResultSet JavaDoc resultSet) {
46         return(new OracleEsqlQuery(resultSet));
47     }
48
49     public String JavaDoc getQueryString() throws SQLException JavaDoc {
50         if (getSkipRows() > 0) {
51             if (getMaxRows() > -1) {
52                 return (new StringBuffer JavaDoc("select * from (select a.*, rownum rnum from (")
53                         .append(super.getQueryString())
54                         .append(") a where rownum <= ")
55                         .append(getSkipRows() + getMaxRows() + 1)
56                         .append(") where rnum > ")
57                         .append(getSkipRows())
58                         .toString());
59             }
60             else {
61                 return (new StringBuffer JavaDoc("select * from (select a.*, rownum rnum from (")
62                         .append(super.getQueryString())
63                         .append(") a ")
64                         .append(") where rnum > ")
65                         .append(getSkipRows())
66                         .toString());
67             }
68         }
69         else {
70             if (getMaxRows() > -1) {
71                 return (new StringBuffer JavaDoc("select * from (select a.*, rownum from (")
72                         .append(super.getQueryString())
73                         .append(") a where rownum <= ")
74                         .append(getMaxRows() + 1)
75                         .append(")").toString());
76             }
77             else {
78                 return (super.getQueryString());
79             }
80         }
81     }
82
83     public void getResultRows() throws SQLException JavaDoc {
84         setPosition(getSkipRows());
85     }
86
87 }
88
Popular Tags