Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

DTOResultSet.java

Go to the documentation of this file.
00001 package net.threebit.utils.sosc;
00002 
00003 /*
00004         Copyright 2003 Shawn Deleurme
00005         Copyright 2003 Kevin O'Donnell
00006 
00007         This program is free software; you can redistribute it and/or modify
00008         it under the terms of the GNU General public License as published by
00009         the Free Software Foundation; either version 2 of the License, or
00010         (at your option) any later version.
00011 
00012         This program is distributed in the hope that it will be useful,
00013         but WITHOUT ANY WARRANTY; without even the implied warranty of
00014         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015         GNU General public License for more details.
00016 
00017         You should have received a copy of the GNU General public License
00018         along with this program; if not, write to the Free Software
00019         Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 */
00021 
00022 import java.io.*;
00023 import java.sql.*;
00024 import java.util.*;
00025 import java.math.BigDecimal;
00026 import java.util.Calendar;
00027 
00124 public class DTOResultSet implements ResultSet,Serializable {
00125 
00127         private ArrayList rows = new ArrayList(100);
00128 
00130         private ArrayList columnNames = new ArrayList();
00131 
00133         private int cursor = 0;
00134 
00136         private ArrayList row = null;
00137 
00139         private ArrayList insertRow = null;
00140 
00142         boolean inserting = false;
00143 
00145         boolean lastGetColWasNull = false;
00146 
00148         DTOResultSetMetaData md = null;
00149 
00151         int[] types = new int[1024];
00152 
00158         public DTOResultSet(ResultSet r) throws SQLException {
00159 
00160                 // Collect what we need from the metadata
00161                 ResultSetMetaData md = r.getMetaData();
00162                 int columnCount = md.getColumnCount();
00163                 String[] columnNames = new String[ columnCount ];
00164                 int[] columnTypes = new int[ columnCount ];
00165                 for (int i=1; i <= columnCount; i++) {
00166                         columnNames[i-1] = md.getColumnName(i);
00167                         columnTypes[i-1] = md.getColumnType(i);
00168                 }
00169 
00170                 // If there is no current row then assume the caller 
00171                 // wanted us to start the the beginning.
00172                 if (r.getRow() == 0) { r.first(); }
00173 
00174                 // Position the DTO to insert.
00175                 moveToInsertRow();
00176 
00177                 // Copy all of the rows.
00178                 while (r.getRow() != 0) {
00179                         for (int i=1; i <= columnCount; i++) {
00180                                 if (columnTypes[i-1] == Types.VARCHAR) { updateString(columnNames[i-1], r.getString(i)); }
00181                                 else if (columnTypes[i-1] == Types.BOOLEAN) { updateBoolean(columnNames[i-1], r.getBoolean(i)); }
00182                                 else if (columnTypes[i-1] == Types.CHAR) { updateByte(columnNames[i-1], r.getByte(i)); }
00183                                 else if (columnTypes[i-1] == Types.SMALLINT) { updateShort(columnNames[i-1], r.getShort(i)); }
00184                                 else if (columnTypes[i-1] == Types.INTEGER) { updateInt(columnNames[i-1], r.getInt(i)); }
00185                                 else if (columnTypes[i-1] == Types.BIGINT) { updateLong(columnNames[i-1], r.getLong(i)); }
00186                                 else if (columnTypes[i-1] == Types.FLOAT) { updateFloat(columnNames[i-1], r.getFloat(i)); }
00187                                 else if (columnTypes[i-1] == Types.DECIMAL) { updateDouble(columnNames[i-1], r.getDouble(i)); }
00188                                 else if (columnTypes[i-1] == Types.DATE) { updateDate(columnNames[i-1], r.getDate(i)); }
00189                                 else { updateObject(columnNames[i-1], r.getObject(i)); }
00190                         }
00191                         insertRow();
00192                         if (! r.next()) { break; } // no more rows.
00193                 } 
00194                 beforeFirst();
00195         }
00196 
00200         public DTOResultSet() throws SQLException {
00201         }
00202 
00207         public int rows() {
00208                 return rows.size();
00209         }
00210 
00215         private void setCol (int index, Object value) throws SQLException {
00216                 if (row == null) { throw new SQLException("Current row is null!"); }
00217                 if (index < 0) { throw new SQLException("Invalid index number ("+index+")"); }
00218                 while (row.size() < (index)) { row.add(null); }
00219                 row.set((index-1),value);
00220         }
00221 
00225         private Object getCol (int index) throws SQLException {
00226                 // Convert from SQL index
00227                 index--;
00228                 if (row == null) { throw new SQLException("Current row is null!"); }
00229                 if (index < 0 || index >= row.size()) { throw new SQLException("Invalid index number ("+index+"); row.size(): " + row.size()); }
00230                 Object value = row.get(index);
00231                 if (value == null) { lastGetColWasNull = true; }
00232                 else { lastGetColWasNull = false; }
00233                 return value;
00234         }
00235 
00239         private int indexOf (String column) throws SQLException {
00240                 int index = columnNames.indexOf(column);
00241                 if (index == -1) {
00242                         columnNames.add(column);
00243                         index = columnNames.indexOf(column);
00244                         // Assertion.
00245                         if (index == -1) { throw new SQLException("Added column name but still can't find it!"); }
00246                 }
00247                 // SQL indexing starts at 1
00248                 return index+1;
00249         }
00250 
00252         // Methods from java.sql.ResultSet
00254 
00256         public void close() throws SQLException {
00257                 rows = null;
00258                 columnNames = null;
00259                 cursor = 0;
00260                 row = null;
00261                 insertRow = null;
00262         }
00263 
00265         public boolean wasNull() throws SQLException {
00266                 return lastGetColWasNull;
00267         }
00268 
00270         public ResultSetMetaData getMetaData() throws SQLException {
00271                 if (md == null) { md = new DTOResultSetMetaData(); }
00272                 return md;
00273         }
00274 
00276         public int findColumn(String columnName) throws SQLException {
00277                 int index = columnNames.indexOf(columnName);
00278                 if (index == -1) {
00279                         throw new SQLException("The column name '" + columnName + "' does not exist in the resultset.");
00280                 }
00281                 return index + 1;
00282 
00283         }
00284 
00286         // GETTER METHODS
00288 
00290         public String getString(int columnIndex) throws SQLException { 
00291                 Object o = getCol(columnIndex);
00292                 if (o == null) { return null; }
00293                 if (o instanceof String) return (String) o;
00294                 return o.toString();
00295         }
00296 
00298         public boolean getBoolean(int columnIndex) throws SQLException { 
00299                 Object o = getCol(columnIndex);
00300                 if (o == null) { return false; }
00301                 if (o instanceof Boolean) return ((Boolean) o).booleanValue();
00302                 try { return new Boolean(o.toString()).booleanValue(); } catch (Exception e) { throw new SQLException("Error converting '"+o+"'"); }
00303         }
00304 
00306         public byte getByte(int columnIndex) throws SQLException { 
00307                 Object o = getCol(columnIndex);
00308                 if (o == null) { return 0; }
00309                 if (o instanceof Number) return ((Number) o).byteValue();
00310                 try { return new Byte(o.toString()).byteValue(); } catch (Exception e) { throw new SQLException("Error converting '"+o+"'"); }
00311         }
00312 
00314         public short getShort(int columnIndex) throws SQLException { 
00315                 Object o = getCol(columnIndex);
00316                 if (o == null) { return 0; }
00317                 if (o instanceof Number) return ((Number) o).shortValue();
00318                 try { return new Short(o.toString()).shortValue(); } catch (Exception e) { throw new SQLException("Error converting '"+o+"'"); }
00319         }
00320 
00322         public int getInt(int columnIndex) throws SQLException { 
00323                 Object o = getCol(columnIndex);
00324                 if (o == null) { return 0; }
00325                 if (o instanceof Number) return ((Number) o).intValue();
00326                 try { return new Integer(o.toString()).intValue(); } catch (Exception e) { throw new SQLException("Error converting '"+o+"'"); }
00327         }
00328 
00330         public long getLong(int columnIndex) throws SQLException { 
00331                 Object o = getCol(columnIndex);
00332                 if (o == null) { return 0; }
00333                 if (o instanceof Number) return ((Number) o).longValue();
00334                 try { return new Long(o.toString()).longValue(); } catch (Exception e) { throw new SQLException("Error converting '"+o+"'"); }
00335         }
00336 
00338         public float getFloat(int columnIndex) throws SQLException { 
00339                 Object o = getCol(columnIndex);
00340                 if (o == null) { return 0; }
00341                 if (o instanceof Number) return ((Number) o).floatValue();
00342                 try { return new Float(o.toString()).floatValue(); } catch (Exception e) { throw new SQLException("Error converting '"+o+"'"); }
00343         }
00344 
00346         public double getDouble(int columnIndex) throws SQLException { 
00347                 Object o = getCol(columnIndex);
00348                 if (o == null) { return 0; }
00349                 if (o instanceof Number) return ((Number) o).doubleValue();
00350                 try { return new Double(o.toString()).doubleValue(); } catch (Exception e) { throw new SQLException("Error converting '"+o+"'"); }
00351         }
00352 
00354         public java.sql.Date getDate(int columnIndex) throws SQLException { 
00355                 Object o = getCol(columnIndex);
00356                 if (o == null) { return null; }
00357                 if (o instanceof java.sql.Date) return (java.sql.Date) getCol( columnIndex ); 
00358                 throw new SQLException("Cannot convert to java.sql.Date");
00359         }
00360 
00362         public String getString(String columnName) throws SQLException { 
00363                 return getString(indexOf(columnName));
00364         }
00365 
00367         public boolean getBoolean(String columnName) throws SQLException { 
00368                 return getBoolean(indexOf(columnName));
00369         }
00370 
00372         public byte getByte(String columnName) throws SQLException { 
00373                 return getByte(indexOf(columnName));
00374         }
00375 
00377         public short getShort(String columnName) throws SQLException { 
00378                 return getShort(indexOf(columnName));
00379         }
00380 
00382         public int getInt(String columnName) throws SQLException { 
00383                 return getInt(indexOf(columnName));
00384         }
00385 
00387         public long getLong(String columnName) throws SQLException { 
00388                 return getLong(indexOf(columnName));
00389         }
00390 
00392         public float getFloat(String columnName) throws SQLException { 
00393                 return getFloat(indexOf(columnName));
00394         }
00395 
00397         public double getDouble(String columnName) throws SQLException { 
00398                 return getDouble(indexOf(columnName));
00399         }
00400 
00402         public java.sql.Date getDate(String columnName) throws SQLException { 
00403                 return getDate(indexOf(columnName));
00404         }
00405 
00407         public Object getObject(int columnIndex) throws SQLException { 
00408                 return getCol(columnIndex);
00409         }
00410 
00412         public Object getObject(String columnName) throws SQLException { 
00413                 return getObject(indexOf(columnName));
00414         }
00415 
00417         // [END] GETTER METHODS
00419 
00421         public boolean isBeforeFirst() throws SQLException {
00422                 if (cursor <= -1) { return true; }
00423                 return false;
00424         }
00425 
00427         public boolean isAfterLast() throws SQLException {
00428                 if (cursor >= rows.size()) { return true; }
00429                 return false;
00430         }
00431 
00433         public boolean isFirst() throws SQLException {
00434                 if (cursor == 0) { return true; }
00435                 return false;
00436         }
00437 
00439         public boolean isLast() throws SQLException {
00440                 if (cursor == (rows.size()-1)) { return true; }
00441                 return false;
00442         }
00443 
00445         public void beforeFirst() throws SQLException {
00446                 cursor = -1;
00447                 row = null;
00448         }
00449 
00451         public void afterLast() throws SQLException {
00452                 cursor = rows.size();
00453                 row = null;
00454         }
00455 
00457         public boolean first() throws SQLException {
00458                 return absolute(1);
00459 
00460         }
00461 
00463         public boolean last() throws SQLException {
00464                 return absolute(rows.size());
00465         }
00466 
00468         public int getRow() throws SQLException {
00469                 if (cursor < 0) {
00470                         beforeFirst();
00471                         return 0;
00472                 }
00473                 if (cursor >= rows.size()) {
00474                         afterLast();
00475                         return 0;
00476                 }
00477                 // Convert to SQL indexing
00478                 return cursor+1;
00479         }
00480 
00482         public boolean absolute( int row ) throws SQLException {
00483                 // If negative, go recursive one level.
00484                 if (row < 0) {
00485                         row = row * -1;
00486                         return absolute( rows.size() + row );
00487                 }
00488 
00489                 // Convert from SQL index.
00490                 row--;
00491 
00492                 // Update the cursor
00493                 cursor = row;
00494 
00495                 // Fix any first/last overflows
00496                 if (getRow() == 0) {
00497                         this.row = null;
00498                         return false;
00499                 }
00500 
00501                 this.row = (ArrayList) rows.get(cursor);
00502                 return true;
00503         }
00504 
00506         public boolean relative( int rows ) throws SQLException {
00507                 if (rows >= 0) {
00508                         return absolute( getRow() + rows );
00509                 }
00510                 if (rows < 0) {
00511                         return absolute( getRow() - rows );
00512                 }
00513                 throw new RuntimeException("only NAN will cause this.");
00514         }
00515 
00517         public boolean next() throws SQLException {
00518                 return relative(1);
00519         }
00520 
00522         public boolean previous() throws SQLException {
00523                 return relative(-1);
00524         }
00525 
00527         public void setFetchDirection(int direction) throws SQLException { }
00528 
00530         public int getFetchDirection() throws SQLException { return FETCH_FORWARD; }
00531 
00533         public void setFetchSize(int rows) throws SQLException { }
00534 
00536         public int getFetchSize() throws SQLException { return 1; }
00537 
00539         public int getType() throws SQLException { return TYPE_SCROLL_INSENSITIVE; }
00540 
00542         public int getConcurrency() throws SQLException { return CONCUR_UPDATABLE; }
00543 
00545         public boolean rowUpdated() throws SQLException { return false; }
00546 
00548         public boolean rowInserted() throws SQLException { return false; }
00549 
00551         public boolean rowDeleted() throws SQLException { return false; }
00552 
00554         // Updater METHODS
00556 
00558         public void updateNull(int columnIndex) throws SQLException { setCol( columnIndex, null); }
00559 
00561         public void updateBoolean(int columnIndex, boolean x) throws SQLException { setCol( columnIndex, new Boolean(x)); }
00562 
00564         public void updateByte(int columnIndex, byte x) throws SQLException { setCol( columnIndex, new Byte(x)); }
00565 
00567         public void updateShort(int columnIndex, short x) throws SQLException { setCol( columnIndex, new Short(x)); }
00568 
00570         public void updateInt(int columnIndex, int x) throws SQLException { setCol( columnIndex, new Integer(x)); }
00571 
00573         public void updateLong(int columnIndex, long x) throws SQLException { setCol( columnIndex, new Long(x)); }
00574 
00576         public void updateFloat(int columnIndex, float x) throws SQLException { setCol( columnIndex, new Float(x)); }
00577 
00579         public void updateDouble(int columnIndex, double x) throws SQLException { setCol( columnIndex, new Double(x)); }
00580 
00582         public void updateBigDecimal(int columnIndex, BigDecimal x) throws SQLException { setCol( columnIndex, x); }
00583 
00585         public void updateString(int columnIndex, String x) throws SQLException { setCol( columnIndex, x); }
00586 
00588         public void updateDate(int columnIndex, java.sql.Date x) throws SQLException { setCol( columnIndex, x); }
00589 
00591         public void updateTime(int columnIndex, java.sql.Time x) throws SQLException { setCol( columnIndex, x); }
00592 
00594         public void updateTimestamp(int columnIndex, java.sql.Timestamp x) throws SQLException { setCol( columnIndex, x); }
00595 
00597         public void updateObject(int columnIndex, Object x) throws SQLException { setCol( columnIndex, x); }
00598 
00600         public void updateNull(String columnName) throws SQLException { setCol( indexOf(columnName), null); }
00601 
00603         public void updateBoolean(String columnName, boolean x) throws SQLException { setCol( indexOf(columnName), null); }
00604 
00606         public void updateByte(String columnName, byte x) throws SQLException { setCol( indexOf(columnName), new Byte(x)); }
00607 
00609         public void updateShort(String columnName, short x) throws SQLException { setCol(indexOf(columnName),new Short(x)); }
00610 
00612         public void updateInt(String columnName, int x) throws SQLException { setCol(indexOf(columnName),new Integer(x)); }
00613 
00615         public void updateLong(String columnName, long x) throws SQLException { setCol(indexOf(columnName),new Long(x)); }
00616 
00618         public void updateFloat(String columnName, float x) throws SQLException { setCol(indexOf(columnName),new Float(x)); }
00619 
00621         public void updateDouble(String columnName, double x) throws SQLException { setCol(indexOf(columnName),new Double(x)); }
00622 
00624         public void updateBigDecimal(String columnName, BigDecimal x) throws SQLException { setCol( indexOf(columnName), x); }
00625 
00627         public void updateString(String columnName, String x) throws SQLException { setCol( indexOf(columnName), x); }
00628 
00630         public void updateDate(String columnName, java.sql.Date x) throws SQLException { setCol( indexOf(columnName), x); }
00631 
00633         public void updateTime(String columnName, java.sql.Time x) throws SQLException { setCol( indexOf(columnName), x); }
00634 
00636         public void updateTimestamp(String columnName, java.sql.Timestamp x) throws SQLException { setCol( indexOf(columnName), x); }
00637 
00639         public void updateObject(String columnName, Object x) throws SQLException { setCol( indexOf(columnName), x); }
00640 
00642         // [END] Updater METHODS
00644 
00646         public void insertRow() throws SQLException {
00647 
00648                 // Add the row
00649                 rows.add(insertRow);
00650 
00651                 // Flag as not inserting
00652                 inserting = false;
00653 
00654                 // And redo the "start to insert logic"
00655                 moveToInsertRow();
00656 
00657         }
00658 
00660         public void updateRow() throws SQLException {
00661         }
00662 
00664         public void deleteRow() throws SQLException {
00665                 if (getRow() == 0) { throw new SQLException("Not on a valid row."); }
00666                 // Delete the current row
00667                 rows.remove(cursor);
00668                 // Update state of the same cursor point.
00669                 absolute(cursor);
00670         }
00671 
00673         public void refreshRow() throws SQLException {
00674                 if (inserting) { throw new SQLException("Cannot refresh the insert row."); }
00675         }
00676 
00678         public void cancelRowUpdates() throws SQLException { throw new SQLException("This should really be implemented. Implemented"); }
00679 
00681         public void moveToInsertRow() throws SQLException {
00682                 if (inserting) {
00683                         // Already inserting
00684                         row = insertRow;
00685                 }
00686                 else {
00687                         inserting = true;
00688                         insertRow = new ArrayList();
00689                         row = insertRow;
00690                 }
00691         }
00692 
00694         public void moveToCurrentRow() throws SQLException {
00695 
00696                 row = (ArrayList) rows.get(cursor);
00697 
00698         }
00699 
00700 
00702         // Will probably never be implemented.
00704 
00706         public Statement getStatement() throws SQLException { throw new SQLException("Not Implemented Yet"); }
00707 
00709         public void updateRef(int columnIndex, java.sql.Ref x) throws SQLException { throw new SQLException("Not Implemented Yet"); }
00710 
00712         public void updateRef(String columnName, java.sql.Ref x) throws SQLException { throw new SQLException("Not Implemented Yet"); }
00713 
00715         public void updateBlob(int columnIndex, java.sql.Blob x) throws SQLException { throw new SQLException("Not Implemented Yet"); }
00716 
00718         public void updateBlob(String columnName, java.sql.Blob x) throws SQLException { throw new SQLException("Not Implemented Yet"); }
00719 
00721         public void updateClob(int columnIndex, java.sql.Clob x) throws SQLException { throw new SQLException("Not Implemented Yet"); }
00722 
00724         public void updateClob(String columnName, java.sql.Clob x) throws SQLException { throw new SQLException("Not Implemented Yet"); }
00725 
00727         public void updateArray(int columnIndex, java.sql.Array x) throws SQLException { throw new SQLException("Not Implemented Yet"); }
00728 
00730         public void updateArray(String columnName, java.sql.Array x) throws SQLException { throw new SQLException("Not Implemented Yet"); }
00731 
00733         public void updateAsciiStream(String columnName, java.io.InputStream x, int length) throws SQLException { throw new SQLException("Not Implemented Yet"); }
00734 
00736         public void updateBinaryStream(String columnName, java.io.InputStream x, int length) throws SQLException { throw new SQLException("Not Implemented Yet"); }
00737 
00739         public void updateCharacterStream(String columnName, java.io.Reader reader, int length) throws SQLException { throw new SQLException("Not Implemented Yet"); }
00740 
00742         public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException { throw new SQLException("Not Implemented Yet"); }
00743 
00745         public byte[] getBytes(int columnIndex) throws SQLException { throw new SQLException("Not Implemented Yet"); }
00746 
00748         public java.sql.Time getTime(int columnIndex) throws SQLException { throw new SQLException("Not Implemented Yet"); }
00749 
00751         public java.sql.Timestamp getTimestamp(int columnIndex) throws SQLException { throw new SQLException("Not Implemented Yet"); }
00752 
00754         public java.io.InputStream getAsciiStream(int columnIndex) throws SQLException { throw new SQLException("Not Implemented Yet"); }
00755 
00757         public java.io.InputStream getUnicodeStream(int columnIndex) throws SQLException { throw new SQLException("Not Implemented Yet"); }
00758 
00760         public java.io.InputStream getBinaryStream(int columnIndex) throws SQLException { throw new SQLException("Not Implemented Yet"); }
00761 
00763         public BigDecimal getBigDecimal(String columnName, int scale) throws SQLException { throw new SQLException("Not Implemented Yet"); }
00764 
00766         public byte[] getBytes(String columnName) throws SQLException { throw new SQLException("Not Implemented Yet"); }
00767 
00769         public java.sql.Time getTime(String columnName) throws SQLException { throw new SQLException("Not Implemented Yet"); }
00770 
00772         public java.sql.Timestamp getTimestamp(String columnName) throws SQLException { throw new SQLException("Not Implemented Yet"); }
00773 
00775         public java.io.InputStream getAsciiStream(String columnName) throws SQLException { throw new SQLException("Not Implemented Yet"); }
00776 
00778         public java.io.InputStream getUnicodeStream(String columnName) throws SQLException { throw new SQLException("Not Implemented Yet"); }
00779 
00781         public java.io.InputStream getBinaryStream(String columnName) throws SQLException { throw new SQLException("Not Implemented Yet"); }
00782 
00784         public SQLWarning getWarnings() throws SQLException { throw new SQLException("Not Implemented Yet"); }
00785 
00787         public void clearWarnings() throws SQLException { throw new SQLException("Not Implemented Yet"); }
00788 
00790         public String getCursorName() throws SQLException { throw new SQLException("Not Implemented Yet"); }
00791 
00793         public java.io.Reader getCharacterStream(int columnIndex) throws SQLException { throw new SQLException("Not Implemented Yet"); }
00794 
00796         public java.io.Reader getCharacterStream(String columnName) throws SQLException { throw new SQLException("Not Implemented Yet"); }
00797 
00799         public BigDecimal getBigDecimal(int columnIndex) throws SQLException { throw new SQLException("Not Implemented Yet"); }
00800 
00802         public BigDecimal getBigDecimal(String columnName) throws SQLException { throw new SQLException("Not Implemented Yet"); }
00803 
00805         public Object getObject(int i, java.util.Map map) throws SQLException { throw new SQLException("Not Implemented Yet"); }
00806 
00808         public Ref getRef(int i) throws SQLException { throw new SQLException("Not Implemented Yet"); }
00809 
00811         public Blob getBlob(int i) throws SQLException { throw new SQLException("Not Implemented Yet"); }
00812 
00814         public Clob getClob(int i) throws SQLException { throw new SQLException("Not Implemented Yet"); }
00815 
00817         public Array getArray(int i) throws SQLException { throw new SQLException("Not Implemented Yet"); }
00818 
00820         public Object getObject(String colName, java.util.Map map) throws SQLException { throw new SQLException("Not Implemented Yet"); }
00821 
00823         public Ref getRef(String colName) throws SQLException { throw new SQLException("Not Implemented Yet"); }
00824 
00826         public Blob getBlob(String colName) throws SQLException { throw new SQLException("Not Implemented Yet"); }
00827 
00829         public Clob getClob(String colName) throws SQLException { throw new SQLException("Not Implemented Yet"); }
00830 
00832         public Array getArray(String colName) throws SQLException { throw new SQLException("Not Implemented Yet"); }
00833 
00835         public java.sql.Date getDate(int columnIndex, Calendar cal) throws SQLException { throw new SQLException("Not Implemented Yet"); }
00836 
00838         public java.sql.Date getDate(String columnName, Calendar cal) throws SQLException { throw new SQLException("Not Implemented Yet"); }
00839 
00841         public java.sql.Time getTime(int columnIndex, Calendar cal) throws SQLException { throw new SQLException("Not Implemented Yet"); }
00842 
00844         public java.sql.Time getTime(String columnName, Calendar cal) throws SQLException { throw new SQLException("Not Implemented Yet"); }
00845 
00847         public java.sql.Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException { throw new SQLException("Not Implemented Yet"); }
00848 
00850         public java.sql.Timestamp getTimestamp(String columnName, Calendar cal) throws SQLException { throw new SQLException("Not Implemented Yet"); }
00851 
00853         public java.net.URL getURL(int columnIndex) throws SQLException { throw new SQLException("Not Implemented Yet"); }
00854 
00856         public java.net.URL getURL(String columnName) throws SQLException { throw new SQLException("Not Implemented Yet"); }
00857 
00859         public void updateObject(String columnName, Object x, int scale) throws SQLException { throw new SQLException("Not Implemented Yet"); }
00860 
00862         public void updateBytes(int columnIndex, byte x[]) throws SQLException { throw new SQLException("Not Implemented Yet"); }
00863 
00865         public void updateAsciiStream(int columnIndex, java.io.InputStream x, int length) throws SQLException { throw new SQLException("Not Implemented Yet"); }
00866 
00868         public void updateBinaryStream(int columnIndex, java.io.InputStream x, int length) throws SQLException { throw new SQLException("Not Implemented Yet"); }
00869 
00871         public void updateCharacterStream(int columnIndex, java.io.Reader x,int length) throws SQLException { throw new SQLException("Not Implemented Yet"); }
00872 
00874         public void updateObject(int columnIndex, Object x, int scale) throws SQLException { throw new SQLException("Not Implemented Yet"); }
00875 
00877         public void updateBytes(String columnName, byte x[]) throws SQLException { throw new SQLException("Not Implemented Yet"); }
00878 
00882         public String toString() {
00883                 if (columnNames == null || rows == null) { return getClass().getName() + ":empty"; }
00884 
00885                 StringBuffer sb = new StringBuffer();
00886                 sb.append( getClass().getName() );
00887                 sb.append(": ");
00888                 for (int c = 0; c < columnNames.size(); c++) {
00889                         sb.append( columnNames.get(c) );
00890                         sb.append(",");
00891                 }
00892                 sb.deleteCharAt( sb.length()-1 ); 
00893                 sb.append("\n");
00894                 for (int r = 0; r < rows.size(); r++) {
00895                         List row = (List) rows.get(r);
00896                         sb.append(r + ": ");
00897                         for (int c = 0; c < row.size(); c++) {
00898                                 sb.append( row.get(c) );
00899                                 sb.append(", ");
00900                         }
00901                         if (row.size() > 0) { sb.deleteCharAt( sb.length()-1 ); }
00902                         sb.append("\n");
00903                 }
00904                 return sb.toString();
00905         }
00906 
00910         public class DTOResultSetMetaData implements ResultSetMetaData {
00911 
00915     public int getColumnType(int column) throws SQLException {
00916 
00917                         // search through the result set until we find a non-null entry for the
00918                         // requested column; when we do return the appropriate type.
00919                         for (int x = 0; x < DTOResultSet.this.rows.size(); x++) {
00920 
00921                                 ArrayList row = (ArrayList) DTOResultSet.this.rows.get(x);
00922                                 Object o = row.get(column-1);
00923 
00924                                 // Keep looking for a real value.
00925                                 if (o == null) { continue; }
00926                                 if (o instanceof String) { return Types.VARCHAR; }
00927                                 if (o instanceof Boolean) { return Types.BOOLEAN; }
00928                                 if (o instanceof Byte) { return Types.CHAR; }
00929                                 if (o instanceof Short) { return Types.SMALLINT; }
00930                                 if (o instanceof Integer) { return Types.INTEGER; }
00931                                 if (o instanceof Long) { return Types.BIGINT; }
00932                                 if (o instanceof Float) { return Types.FLOAT; }
00933                                 if (o instanceof Double) { return Types.DECIMAL; }
00934                                 if (o instanceof java.sql.Date) { return Types.DATE; }
00935                                 return Types.OTHER;
00936                         }
00937                         // Assume NULL
00938                         return Types.NULL;
00939                 }
00940 
00944     public String getColumnTypeName(int column) throws SQLException {
00945                         return "DTOResultSetColumn";
00946                 }
00947 
00951     public int getColumnCount() throws SQLException {
00952                         if (DTOResultSet.this.columnNames == null) { throw new SQLException("No column names defined"); }
00953                         return DTOResultSet.this.columnNames.size();
00954                 }
00955 
00959     public boolean isAutoIncrement(int column) throws SQLException { return false; }
00960 
00964     public boolean isCaseSensitive(int column) throws SQLException { return true; }
00965 
00969     public boolean isSearchable(int column) throws SQLException { return true; }
00970 
00974     public boolean isCurrency(int column) throws SQLException { return false; }
00975 
00979     public int isNullable(int column) throws SQLException { return columnNullable; }
00980 
00984     public boolean isSigned(int column) throws SQLException { return true; }
00985 
00989     public int getColumnDisplaySize(int column) throws SQLException { return 12; }
00990 
00994     public String getColumnLabel(int column) throws SQLException {
00995                         if (DTOResultSet.this.columnNames == null) { throw new SQLException("No column names defined"); }
00996                         return (String) DTOResultSet.this.columnNames.get(column-1);
00997                 }
00998 
01002     public String getColumnName(int column) throws SQLException {
01003                         if (DTOResultSet.this.columnNames == null) { throw new SQLException("No column names defined"); }
01004                         return (String) DTOResultSet.this.columnNames.get(column-1);
01005                 }
01006 
01010     public String getSchemaName(int column) throws SQLException { return "DTOResultSetSchema"; }
01011 
01015     public int getPrecision(int column) throws SQLException { return 2; }
01016 
01020     public int getScale(int column) throws SQLException { return 32; }
01021 
01025     public String getTableName(int column) throws SQLException { return "DTOTable"; }
01026 
01030     public String getCatalogName(int column) throws SQLException { return "DTOCatalog"; }
01031 
01035     public boolean isReadOnly(int column) throws SQLException { return false; }
01036 
01040     public boolean isWritable(int column) throws SQLException { return true; }
01041 
01045     public boolean isDefinitelyWritable(int column) throws SQLException { return true; }
01046 
01050     public String getColumnClassName(int column) throws SQLException { return "java.lang.Object"; }
01051 
01052         }
01053 
01054 }

Generated on Mon Jul 14 17:19:20 2003 for SOSC by doxygen1.2.15