KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.apache.cocoon.components.language.markup.xsp.AbstractEsqlQuery;
20
21 import java.sql.SQLException JavaDoc;
22 import java.sql.ResultSet JavaDoc;
23 import java.sql.Connection JavaDoc;
24
25 /**
26  * @author <a HREF="mailto:tcurdt@apache.org">Torsten Curdt</a>
27  * @version CVS $Id: MysqlEsqlQuery.java 30932 2004-07-29 17:35:38Z vgritsenko $
28  */

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

39     private MysqlEsqlQuery(final ResultSet JavaDoc resultSet) {
40         super(resultSet);
41     }
42
43     /**
44      * Create a EsqlQuery of the same type
45      * @param resultSet
46      */

47     public AbstractEsqlQuery newInstance(ResultSet JavaDoc resultSet) {
48         return( new MysqlEsqlQuery(resultSet) );
49     }
50
51     public String JavaDoc getQueryString() throws SQLException JavaDoc {
52         if (getSkipRows() > 0) {
53             if (getMaxRows() > -1) {
54                 return (new StringBuffer JavaDoc(super.getQueryString())
55                         .append(" LIMIT ").append(getSkipRows())
56                         .append(",").append(getMaxRows()+1)
57                         .toString());
58             }
59             else {
60                 throw new SQLException JavaDoc("MySQL does not support a skip of rows only. Please also provide the max amount of rows");
61             }
62         }
63         else {
64             if (getMaxRows() > -1) {
65                 return (new StringBuffer JavaDoc(super.getQueryString())
66                         .append(" LIMIT ").append(getMaxRows()+1)
67                         .toString());
68             }
69             else {
70                 return (super.getQueryString());
71             }
72         }
73     }
74
75     public void getResultRows() throws SQLException JavaDoc {
76         setPosition(getSkipRows());
77     }
78 }
79
Popular Tags