01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: package org.apache.cocoon.components.language.markup.xsp;
19:
20: import org.apache.cocoon.components.language.markup.xsp.AbstractEsqlQuery;
21:
22: import java.sql.SQLException;
23: import java.sql.ResultSet;
24: import java.sql.Connection;
25:
26: /**
27: * @author <a href="mailto:tcurdt@apache.org">Torsten Curdt</a>
28: * @version CVS $Id: MysqlEsqlQuery.java 433543 2006-08-22 06:22:54Z crossley $
29: */
30: final public class MysqlEsqlQuery extends AbstractEsqlQuery {
31:
32: public MysqlEsqlQuery(Connection connection, String query) {
33: super (connection, query);
34: }
35:
36: /**
37: * Only newInstance may use this contructor
38: * @param resultSet
39: */
40: private MysqlEsqlQuery(final ResultSet resultSet) {
41: super (resultSet);
42: }
43:
44: /**
45: * Create a EsqlQuery of the same type
46: * @param resultSet
47: */
48: public AbstractEsqlQuery newInstance(ResultSet resultSet) {
49: return (new MysqlEsqlQuery(resultSet));
50: }
51:
52: public String getQueryString() throws SQLException {
53: if (getSkipRows() > 0) {
54: if (getMaxRows() > -1) {
55: return (new StringBuffer(super .getQueryString())
56: .append(" LIMIT ").append(getSkipRows())
57: .append(",").append(getMaxRows() + 1)
58: .toString());
59: } else {
60: throw new SQLException(
61: "MySQL does not support a skip of rows only. Please also provide the max amount of rows");
62: }
63: } else {
64: if (getMaxRows() > -1) {
65: return (new StringBuffer(super .getQueryString())
66: .append(" LIMIT ").append(getMaxRows() + 1)
67: .toString());
68: } else {
69: return (super .getQueryString());
70: }
71: }
72: }
73:
74: public void getResultRows() throws SQLException {
75: setPosition(getSkipRows());
76: }
77: }
|