KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

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

48     public AbstractEsqlQuery newInstance(ResultSet JavaDoc resultSet) {
49         return(new SybaseEsqlQuery(resultSet));
50     }
51
52     public String JavaDoc getQueryString() throws SQLException JavaDoc {
53         if (getMaxRows() > -1) {
54             String JavaDoc original = super.getQueryString().trim();
55             int command = original.indexOf(' ');
56             return (new StringBuffer JavaDoc()
57                     .append(original.substring(0,command))
58                     .append(" TOP ").append(getMaxRows()+1 + getSkipRows())
59                     .append(original.substring(command))
60                     .toString());
61         }
62         else {
63             return (super.getQueryString());
64         }
65     }
66
67     public PreparedStatement JavaDoc prepareStatement() throws SQLException JavaDoc {
68         return (
69                 setPreparedStatement(
70                         getConnection().prepareStatement(
71                                 getQueryString(),
72                                 ResultSet.TYPE_SCROLL_INSENSITIVE,
73                                 ResultSet.CONCUR_READ_ONLY)
74                 ));
75     }
76
77     public CallableStatement JavaDoc prepareCall() throws SQLException JavaDoc {
78         return (
79                 (CallableStatement JavaDoc) setPreparedStatement(
80                         getConnection().prepareCall(
81                                 getQueryString(),
82                                 ResultSet.TYPE_SCROLL_INSENSITIVE,
83                                 ResultSet.CONCUR_READ_ONLY
84                         )
85                 )
86                 );
87     }
88
89     public void getResultRows() throws SQLException JavaDoc {
90         final int skip = getSkipRows();
91         if (skip > 0) {
92             getResultSet().absolute(skip);
93         }
94         setPosition(skip);
95     }
96
97 }
98
Popular Tags