cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tcu...@apache.org
Subject cvs commit: xml-cocoon2/src/blocks/databases/java/org/apache/cocoon/components/language/markup/xsp OracleEsqlQuery.java AbstractEsqlConnection.java AbstractEsqlQuery.java Cocoon2EsqlConnection.java JdbcEsqlQuery.java MysqlEsqlQuery.java PostgresEsqlQuery.java SybaseEsqlQuery.java
Date Sat, 07 Dec 2002 16:53:00 GMT
tcurdt      2002/12/07 08:53:00

  Modified:    src/blocks/databases/java/org/apache/cocoon/components/language/markup/xsp
                        AbstractEsqlConnection.java AbstractEsqlQuery.java
                        Cocoon2EsqlConnection.java JdbcEsqlQuery.java
                        MysqlEsqlQuery.java PostgresEsqlQuery.java
                        SybaseEsqlQuery.java
  Added:       src/blocks/databases/java/org/apache/cocoon/components/language/markup/xsp
                        OracleEsqlQuery.java
  Log:
  added javadocs,
  added Oracle specific EsqlQuery
  
  Revision  Changes    Path
  1.2       +25 -5     xml-cocoon2/src/blocks/databases/java/org/apache/cocoon/components/language/markup/xsp/AbstractEsqlConnection.java
  
  Index: AbstractEsqlConnection.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/blocks/databases/java/org/apache/cocoon/components/language/markup/xsp/AbstractEsqlConnection.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AbstractEsqlConnection.java	4 Dec 2002 21:51:38 -0000	1.1
  +++ AbstractEsqlConnection.java	7 Dec 2002 16:52:59 -0000	1.2
  @@ -57,8 +57,7 @@
   import java.sql.SQLException;
   
   /**
  - * based on the orginal esql.xsl
  - * @author <a href="mailto:tcurdt@dff.st">Torsten Curdt</a>
  + * @author <a href="mailto:tcurdt@apache.org>Torsten Curdt<a>
    */
   
   public abstract class AbstractEsqlConnection extends AbstractLogEnabled implements Connection
{
  @@ -73,7 +72,8 @@
       protected abstract Connection getConnection() throws SQLException;
   
   
  -    /** It appears that some commercial DBMSs like Oracle and Informix
  +    /**
  +     * It appears that some commercial DBMSs like Oracle and Informix
        * are broken in that they don't follow the JDBC standard and
        * calls to getUpdateCount after getMoreResults result either in
        * an exception (Informix) or return the same value (i.e. not -1) (Oracle).
  @@ -121,7 +121,17 @@
       }
   
   
  -
  +    /**
  +     * Factory method for creating an EsqlQuery object. If type is set to
  +     * "" or "auto" it will try to find type from the JDBC connection URL.
  +     * If this does not succeed the generic JDBC type will be assumed.
  +     * (This type does not work for some databases like mssql though)
  +     *
  +     * @param type {sybase|postgresql|mysql|oracle|jdbc}
  +     * @param queryString
  +     * @return implementation of the AbstractEsqlQuery
  +     * @throws SQLException
  +     */
       public AbstractEsqlQuery createQuery(final String type, final String queryString) throws
SQLException {
           AbstractEsqlQuery query;
           if ("".equals(type) || "auto".equalsIgnoreCase(type)) {
  @@ -136,6 +146,11 @@
               else if (url.startsWith("jdbc:sybase:")) {
                   query = new SybaseEsqlQuery(this,queryString);
               }
  +            /*
  +            else if (url.startsWith("jdbc:oracle:")) {
  +                query = new OracleEsqlQuery(this,queryString);
  +            }
  +            */
               else {
                   getLogger().warn("Cannot guess database type from jdbc url: " + String.valueOf(url)
+" - Defaulting to JDBC");
                   query = new JdbcEsqlQuery(this,queryString);
  @@ -150,6 +165,11 @@
           else if ("mysql".equalsIgnoreCase(type)) {
               query = new MysqlEsqlQuery(this,queryString);
           }
  +        /*
  +        else if ("oracle".equalsIgnoreCase(type)) {
  +            query = new OracleEsqlQuery(this,queryString);
  +        }
  +        */
           else if ("jdbc".equalsIgnoreCase(type)) {
               query = new JdbcEsqlQuery(this,queryString);
           }
  @@ -163,7 +183,7 @@
   
   
   
  -    /* */
  +    /* just wrap methods below */
   
       public java.sql.Statement createStatement() throws SQLException {
           return (getConnection().createStatement());
  
  
  
  1.2       +132 -64   xml-cocoon2/src/blocks/databases/java/org/apache/cocoon/components/language/markup/xsp/AbstractEsqlQuery.java
  
  Index: AbstractEsqlQuery.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/blocks/databases/java/org/apache/cocoon/components/language/markup/xsp/AbstractEsqlQuery.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AbstractEsqlQuery.java	4 Dec 2002 21:51:38 -0000	1.1
  +++ AbstractEsqlQuery.java	7 Dec 2002 16:52:59 -0000	1.2
  @@ -61,10 +61,9 @@
   import java.util.ArrayList;
   
   /**
  - * This one of the esql helper classes
  + * This is base class for all EsqlQueries
    *
  - * based on the orginal esql.xsl
  - * @author <a href="mailto:tcurdt@dff.st">Torsten Curdt</a>
  + * @author <a href="mailto:tcurdt@apache.org>Torsten Curdt<a>
    */
   
   public abstract class AbstractEsqlQuery extends AbstractLogEnabled {
  @@ -89,11 +88,21 @@
       private int changeLevel = -1;
   
   
  +    /**
  +     * Constructor
  +     *
  +     * @param connection
  +     * @param query - The SQL query string
  +     */
       protected AbstractEsqlQuery(AbstractEsqlConnection connection, String query) {
           this.connection = connection;
           this.query = query;
       }
   
  +    /**
  +     * Only newInstance may use this contructor
  +     * @param resultSet
  +     */
       protected AbstractEsqlQuery(final ResultSet resultSet) {
           this.connection = null;
           this.query = null;
  @@ -101,79 +110,58 @@
           this.hasResultSet = (resultSet != null);
       }
   
  +    /**
  +     * Create a EsqlQuery of the same type
  +     * @param resultSet
  +     * @return
  +     */
       public abstract AbstractEsqlQuery newInstance(final ResultSet resultSet);
   
  -    public Connection getConnection() {
  -        return (connection);
  -    }
  -
  -    public final int getSkipRows() {
  -        return (skipRows);
  -    }
  -
  -    public final void setSkipRows(int i) {
  -        skipRows = i;
  -    }
  -
  -    public final int getMaxRows() {
  -        return (maxRows);
  -    }
  -
  -    public final void setMaxRows(int i) {
  -        maxRows = i;
  -    }
  -
  -    protected final void setPosition(int p) {
  -        position = p;
  -    }
  -
  -    protected final PreparedStatement setPreparedStatement(final PreparedStatement ps)
{
  -        preparedStatement = ps;
  -        return (preparedStatement);
  -    }
  -
  -
  -    public final ResultSetMetaData getResultSetMetaData() {
  -        return (resultSetMetaData);
  -    }
  -
  -    public final PreparedStatement getPreparedStatement() {
  -        return (preparedStatement);
  -    }
  -
  -    public final CallableStatement getCallableStatement() {
  -        return ((CallableStatement) preparedStatement);
  -    }
  -
  -    public final ResultSet getResultSet() {
  -        return (resultSet);
  -    }
   
  +    /**
  +     * Return the query string ("select * from bla")
  +     *
  +     * NOTE: Might want to be overridden by indiviual EsqlQuery implementations
  +     *
  +     * @return
  +     * @throws SQLException
  +     */
       public String getQueryString() throws SQLException {
           return (query);
       }
   
  -
  +    /**
  +     * NOTE: Might want to be overridden by indiviual EsqlQuery implementations
  +     *
  +     * @return
  +     * @throws SQLException
  +     */
       public PreparedStatement prepareStatement() throws SQLException {
           preparedStatement = connection.prepareStatement(getQueryString());
           return (preparedStatement);
       }
   
  +    /**
  +     * NOTE: Might want to be overridden by indiviual EsqlQuery implementations
  +     *
  +     * @return
  +     * @throws SQLException
  +     */
       public CallableStatement prepareCall() throws SQLException {
           preparedStatement = connection.prepareCall(getQueryString());
           return ((CallableStatement) preparedStatement);
       }
   
   
  -    public final boolean nextRow() throws SQLException {
  -        position++;
  -        return (resultSet.next());
  -    }
  -
  -    public final int getCurrentRow() {
  -        return (position);
  -    }
  -
  +    /**
  +     * Gets the total number of rows of a the query WITHOUT the
  +     * limits of skip/max rows.
  +     *
  +     * NOTE: Might want to be overridden by indiviual EsqlQuery implementations
  +     *
  +     * @return total number of rows
  +     * @throws SQLException
  +     */
       public int getRowCount() throws SQLException {
           if (rowCount < 0) {
               String lowerQuery = query.toLowerCase();
  @@ -209,6 +197,13 @@
           return (rowCount);
       }
   
  +    /**
  +     * Move to the first row.
  +     *
  +     * NOTE: Might want to be overridden by indiviual EsqlQuery implementations
  +     *
  +     * @throws SQLException
  +     */
       public void getResultRows() throws SQLException {
           if (skipRows > 0) {
               while (resultSet.next()) {
  @@ -220,6 +215,64 @@
           }
       }
   
  +
  +    /* ************** FINAL methods *********************** */
  +
  +    protected final void setPosition(int p) {
  +        position = p;
  +    }
  +
  +    protected final PreparedStatement setPreparedStatement(final PreparedStatement ps)
{
  +        preparedStatement = ps;
  +        return (preparedStatement);
  +    }
  +
  +    public final Connection getConnection() {
  +        return (connection);
  +    }
  +
  +    public final int getSkipRows() {
  +        return (skipRows);
  +    }
  +
  +    public final void setSkipRows(int i) {
  +        skipRows = i;
  +    }
  +
  +    public final int getMaxRows() {
  +        return (maxRows);
  +    }
  +
  +    public final void setMaxRows(int i) {
  +        maxRows = i;
  +    }
  +
  +    public final ResultSetMetaData getResultSetMetaData() {
  +        return (resultSetMetaData);
  +    }
  +
  +    public final PreparedStatement getPreparedStatement() {
  +        return (preparedStatement);
  +    }
  +
  +    public final CallableStatement getCallableStatement() {
  +        return ((CallableStatement) preparedStatement);
  +    }
  +
  +    public final ResultSet getResultSet() {
  +        return (resultSet);
  +    }
  +
  +    public final boolean nextRow() throws SQLException {
  +        position++;
  +        return (resultSet.next());
  +    }
  +
  +    public final int getCurrentRow() {
  +        return (position);
  +    }
  +
  +
       public final boolean execute(int resultSetFromObject) throws SQLException {
           if (preparedStatement != null) {
               hasResultSet = preparedStatement.execute();
  @@ -276,6 +329,12 @@
           }
       }
   
  +    /**
  +     * Try to get the next ResultSet
  +     *
  +     * @return whether there is one or not
  +     * @throws SQLException
  +     */
       public final boolean getMoreResults() throws SQLException {
           if (preparedStatement != null) {
               hasResultSet = preparedStatement.getMoreResults();
  @@ -301,15 +360,26 @@
       }
   
   
  -    public final int getUpdateCount() throws SQLException {
  +    /**
  +     * Returns the how many rows where updated on last update
  +     * @return
  +     */
  +    public final int getUpdateCount() {
           return (updateCount);
       }
   
  -
  +    /**
  +     * Returns the number of query results
  +     * @return
  +     */
       public final int getQueryResultsCount() {
           return (queryResultsCount);
       }
   
  +    /**
  +     * Returns the number of update results
  +     * @return
  +     */
       public final int getUpdateResultsCount() {
           return (updateResultsCount);
       }
  @@ -323,7 +393,7 @@
           keepgoing = still;
       }
   
  -    /************************* GROUPING START ***********************************/
  +    /* ************************ GROUPING ************************ */
   
       public final void incGroupLevel() {
           groupLevel++;
  @@ -370,7 +440,7 @@
           }
       }
   
  -    class EsqlGroup {
  +    final class EsqlGroup {
           public String var = null;
           public Object value = null;
   
  @@ -379,7 +449,5 @@
               this.value = value;
           }
       }
  -
  -    /******** GROUPING END ********************/
   
   }
  
  
  
  1.2       +12 -4     xml-cocoon2/src/blocks/databases/java/org/apache/cocoon/components/language/markup/xsp/Cocoon2EsqlConnection.java
  
  Index: Cocoon2EsqlConnection.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/blocks/databases/java/org/apache/cocoon/components/language/markup/xsp/Cocoon2EsqlConnection.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Cocoon2EsqlConnection.java	4 Dec 2002 21:51:38 -0000	1.1
  +++ Cocoon2EsqlConnection.java	7 Dec 2002 16:52:59 -0000	1.2
  @@ -58,10 +58,8 @@
   
   /**
    * This is the Cocoon2 specific part of an AbstractEsqlConnection.
  - * This should only be in the C2 codebase
    *
  - * based on the orginal esql.xsl
  - * @author <a href="mailto:tcurdt@dff.st">Torsten Curdt</a>
  + * @author <a href="mailto:tcurdt@apache.org">Torsten Curdt</a>
    * @version CVS $Id$
    */
   
  @@ -74,11 +72,19 @@
           this.connection = null;
       }
   
  +    /**
  +     * Someone passed the connection
  +     * @param connection
  +     */
       public Cocoon2EsqlConnection( Connection connection ) {
           this.datasource = null;
           this.connection = connection;
       }
   
  +    /**
  +     * Get the connection from the pool
  +     * @param datasource
  +     */
       public Cocoon2EsqlConnection( DataSourceComponent datasource ) {
           this.datasource = datasource;
       }
  @@ -89,10 +95,12 @@
           }
           else {
               if (datasource != null) {
  +                // get the connection from the pool
                   connection = datasource.getConnection();
                   return(connection);
               }
               else {
  +                // open a new connection
                   connection = DriverManager.getConnection(getURL(), getProperties());
                   return(connection);
               }
  
  
  
  1.2       +19 -2     xml-cocoon2/src/blocks/databases/java/org/apache/cocoon/components/language/markup/xsp/JdbcEsqlQuery.java
  
  Index: JdbcEsqlQuery.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/blocks/databases/java/org/apache/cocoon/components/language/markup/xsp/JdbcEsqlQuery.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- JdbcEsqlQuery.java	4 Dec 2002 21:51:38 -0000	1.1
  +++ JdbcEsqlQuery.java	7 Dec 2002 16:52:59 -0000	1.2
  @@ -56,6 +56,15 @@
   import java.sql.ResultSet;
   import java.sql.CallableStatement;
   
  +/**
  + * This EsqlQuery only uses the standard JDBC API approaches.
  + * Please note that whether this is good, ok or bad depends
  + * on the driver implementation of your database vendor.
  + * It should work with all JDBC compliant databases.
  + * Unfortunately it seems NOT to work with mssql
  + *
  + * @author <a href="mailto:tcurdt@apache.org>Torsten Curdt<a>
  + */
   
   final public class JdbcEsqlQuery extends AbstractEsqlQuery {
   
  @@ -63,10 +72,19 @@
           super(connection, query);
       }
   
  +    /**
  +     * Only newInstance may use this contructor
  +     * @param resultSet
  +     */
       private JdbcEsqlQuery(final ResultSet resultSet) {
           super(resultSet);
       }
   
  +    /**
  +     * Create a EsqlQuery of the same type
  +     * @param resultSet
  +     * @return
  +     */
       public AbstractEsqlQuery newInstance(final ResultSet resultSet) {
           return(new JdbcEsqlQuery(resultSet));
       }
  @@ -98,9 +116,8 @@
        * of results. Unfortunately -at least some- driver implementation
        * are transfering the complete resultset when moving to the end.
        * Which is totally stupid for limit/paging purposes. So we probably
  -     * better stick with an additional count query.
  +     * better stick with an additional count query from the AbstractEsqlQuery
        */
  -
       /*
       public int getRowCount() throws SQLException {
           ResultSet rs = getResultSet();
  
  
  
  1.2       +13 -0     xml-cocoon2/src/blocks/databases/java/org/apache/cocoon/components/language/markup/xsp/MysqlEsqlQuery.java
  
  Index: MysqlEsqlQuery.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/blocks/databases/java/org/apache/cocoon/components/language/markup/xsp/MysqlEsqlQuery.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MysqlEsqlQuery.java	4 Dec 2002 21:51:38 -0000	1.1
  +++ MysqlEsqlQuery.java	7 Dec 2002 16:52:59 -0000	1.2
  @@ -56,16 +56,29 @@
   import java.sql.SQLException;
   import java.sql.ResultSet;
   
  +/**
  + * @author <a href="mailto:tcurdt@apache.org>Torsten Curdt<a>
  + */
  +
   final public class MysqlEsqlQuery extends AbstractEsqlQuery {
   
       public MysqlEsqlQuery(AbstractEsqlConnection connection, String query) {
           super(connection, query);
       }
   
  +    /**
  +     * Only newInstance may use this contructor
  +     * @param resultSet
  +     */
       private MysqlEsqlQuery(final ResultSet resultSet) {
           super(resultSet);
       }
   
  +    /**
  +     * Create a EsqlQuery of the same type
  +     * @param resultSet
  +     * @return
  +     */
       public AbstractEsqlQuery newInstance(ResultSet resultSet) {
           return( new MysqlEsqlQuery(resultSet) );
       }
  
  
  
  1.2       +13 -0     xml-cocoon2/src/blocks/databases/java/org/apache/cocoon/components/language/markup/xsp/PostgresEsqlQuery.java
  
  Index: PostgresEsqlQuery.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/blocks/databases/java/org/apache/cocoon/components/language/markup/xsp/PostgresEsqlQuery.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PostgresEsqlQuery.java	4 Dec 2002 21:51:38 -0000	1.1
  +++ PostgresEsqlQuery.java	7 Dec 2002 16:52:59 -0000	1.2
  @@ -54,16 +54,29 @@
   import java.sql.SQLException;
   import java.sql.ResultSet;
   
  +/**
  + * @author <a href="mailto:tcurdt@apache.org>Torsten Curdt<a>
  + */
  +
   final public class PostgresEsqlQuery extends AbstractEsqlQuery {
   
       public PostgresEsqlQuery(AbstractEsqlConnection connection, String query) {
           super(connection, query);
       }
   
  +    /**
  +     * Only newInstance may use this contructor
  +     * @param resultSet
  +     */
       private PostgresEsqlQuery(ResultSet resultSet) {
           super(resultSet);
       }
   
  +    /**
  +     * Create a EsqlQuery of the same type
  +     * @param resultSet
  +     * @return
  +     */
       public AbstractEsqlQuery newInstance(final ResultSet resultSet) {
           return(new PostgresEsqlQuery(resultSet));
       }
  
  
  
  1.2       +14 -0     xml-cocoon2/src/blocks/databases/java/org/apache/cocoon/components/language/markup/xsp/SybaseEsqlQuery.java
  
  Index: SybaseEsqlQuery.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/blocks/databases/java/org/apache/cocoon/components/language/markup/xsp/SybaseEsqlQuery.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SybaseEsqlQuery.java	4 Dec 2002 21:51:38 -0000	1.1
  +++ SybaseEsqlQuery.java	7 Dec 2002 16:52:59 -0000	1.2
  @@ -56,16 +56,30 @@
   import java.sql.ResultSet;
   import java.sql.CallableStatement;
   
  +/**
  + * Database specific EsqlQuery
  + * @author <a href="mailto:tcurdt@apache.org>Torsten Curdt<a>
  + */
  +
   final public class SybaseEsqlQuery extends AbstractEsqlQuery {
   
       public SybaseEsqlQuery(AbstractEsqlConnection connection, String query) {
           super(connection, query);
       }
   
  +    /**
  +     * Only newInstance may use this contructor
  +     * @param resultSet
  +     */
       private SybaseEsqlQuery(final ResultSet resultSet) {
           super(resultSet);
       }
   
  +    /**
  +     * Create a EsqlQuery of the same type
  +     * @param resultSet
  +     * @return
  +     */
       public AbstractEsqlQuery newInstance(ResultSet resultSet) {
           return(new SybaseEsqlQuery(resultSet));
       }
  
  
  
  1.1                  xml-cocoon2/src/blocks/databases/java/org/apache/cocoon/components/language/markup/xsp/OracleEsqlQuery.java
  
  Index: OracleEsqlQuery.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  
  package org.apache.cocoon.components.language.markup.xsp;
  
  import java.sql.ResultSet;
  import java.sql.SQLException;
  
  /**
   * @author <a href="mailto:tcurdt@apache.org>Torsten Curdt<a>
   */
  
  final public class OracleEsqlQuery extends AbstractEsqlQuery {
  
      public OracleEsqlQuery(AbstractEsqlConnection connection, String query) {
          super(connection, query);
      }
  
      /**
       * Only newInstance may use this contructor
       * @param resultSet
       */
      private OracleEsqlQuery(ResultSet resultSet) {
          super(resultSet);
      }
  
      /**
       * Create a EsqlQuery of the same type
       * @param resultSet
       * @return
       */
      public AbstractEsqlQuery newInstance(final ResultSet resultSet) {
          return(new OracleEsqlQuery(resultSet));
      }
  
      public String getQueryString() throws SQLException {
          if (getSkipRows() > 0) {
              if (getMaxRows() > -1) {
                  return (new StringBuffer("select * from (select a.*, rownum rnum from (")
                          .append(super.getQueryString())
                          .append(") a where rownum <= ")
                          .append(getSkipRows() + getMaxRows())
                          .append(") where rnum >= ")
                          .append(getSkipRows())
                          .append(")")
                          .toString());
              }
              else {
                  throw new SQLException("Skip without Max. Please add this functionality
to class OracleEsqlQuery");
              }
          }
          else {
              if (getMaxRows() > -1) {
                  throw new SQLException("Max without Skip. Please add this functionality
to class OracleEsqlQuery");
              }
              else {
                  return (super.getQueryString());
              }
          }
      }
  
      public void getResultRows() throws SQLException {
          setPosition(getSkipRows());
      }
  
  }
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          cocoon-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-cvs-help@xml.apache.org


Mime
View raw message