001: package com.quadcap.sql;
002:
003: /* Copyright 1999 - 2003 Quadcap Software. All rights reserved.
004: *
005: * This software is distributed under the Quadcap Free Software License.
006: * This software may be used or modified for any purpose, personal or
007: * commercial. Open Source redistributions are permitted. Commercial
008: * redistribution of larger works derived from, or works which bundle
009: * this software requires a "Commercial Redistribution License"; see
010: * http://www.quadcap.com/purchase.
011: *
012: * Redistributions qualify as "Open Source" under one of the following terms:
013: *
014: * Redistributions are made at no charge beyond the reasonable cost of
015: * materials and delivery.
016: *
017: * Redistributions are accompanied by a copy of the Source Code or by an
018: * irrevocable offer to provide a copy of the Source Code for up to three
019: * years at the cost of materials and delivery. Such redistributions
020: * must allow further use, modification, and redistribution of the Source
021: * Code under substantially the same terms as this license.
022: *
023: * Redistributions of source code must retain the copyright notices as they
024: * appear in each source code file, these license terms, and the
025: * disclaimer/limitation of liability set forth as paragraph 6 below.
026: *
027: * Redistributions in binary form must reproduce this Copyright Notice,
028: * these license terms, and the disclaimer/limitation of liability set
029: * forth as paragraph 6 below, in the documentation and/or other materials
030: * provided with the distribution.
031: *
032: * The Software is provided on an "AS IS" basis. No warranty is
033: * provided that the Software is free of defects, or fit for a
034: * particular purpose.
035: *
036: * Limitation of Liability. Quadcap Software shall not be liable
037: * for any damages suffered by the Licensee or any third party resulting
038: * from use of the Software.
039: */
040:
041: import java.util.Vector;
042:
043: import java.sql.SQLException;
044:
045: import com.quadcap.sql.types.Value;
046: import com.quadcap.sql.types.ValueBoolean;
047:
048: import com.quadcap.util.Debug;
049:
050: /**
051: * Cursor to support <b>HAVING</b> clause.
052: *
053: * <p>XXX Optimize this by use of a 'HavingRow' class which would perform less
054: * copying.</p>
055: *
056: * @author Stan Bailes
057: */
058: public class HavingCursor extends FilterCursor {
059: Row row = null;
060:
061: public HavingCursor(Session session, Cursor cursor)
062: throws SQLException {
063: super (session, cursor);
064: }
065:
066: public Row getRow() throws SQLException {
067: return row;
068: }
069:
070: public void updateRow(Row row) throws SQLException {
071: this .row = row;
072: Row t = new Row(row.size() - 1);
073: for (int i = 1; i <= row.size(); i++) {
074: t.set(i, row.item(i));
075: }
076: cursor.updateRow(t);
077: }
078:
079: public int getColumnCount() throws SQLException {
080: return cursor.getColumnCount() - 1;
081: }
082:
083: public boolean next() throws SQLException {
084: final int size = cursor.getColumnCount();
085: boolean have = false;
086: while (!have && cursor.next()) {
087: Row r = cursor.getRow();
088: Value val = r.item(size);
089: if (val instanceof ValueBoolean
090: && ((ValueBoolean) val).isTrue()) {
091: if (this .row == null) {
092: this .row = new Row(size - 1);
093: }
094: for (int i = 1; i < size; i++)
095: row.set(i, r.item(i));
096: have = true;
097: }
098: }
099: return have;
100: }
101:
102: }
|