KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > amber > query > ResultSetImpl


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  * Free Software Foundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Scott Ferguson
27  */

28
29 package com.caucho.amber.query;
30
31 import com.caucho.amber.entity.AmberEntityHome;
32 import com.caucho.amber.entity.Entity;
33 import com.caucho.amber.entity.EntityItem;
34 import com.caucho.amber.expr.AmberExpr;
35 import com.caucho.amber.expr.LoadEntityExpr;
36 import com.caucho.amber.manager.AmberConnection;
37 import com.caucho.util.L10N;
38
39 import java.io.InputStream JavaDoc;
40 import java.io.Reader JavaDoc;
41 import java.math.BigDecimal JavaDoc;
42 import java.net.URL JavaDoc;
43 import java.sql.*;
44 import java.util.ArrayList JavaDoc;
45 import java.util.Calendar JavaDoc;
46 import java.util.Map JavaDoc;
47 import java.util.logging.Level JavaDoc;
48 import java.util.logging.Logger JavaDoc;
49
50 /**
51  * The JDBC statement implementation.
52  */

53 public class ResultSetImpl implements ResultSet {
54   private static final Logger JavaDoc log
55     = Logger.getLogger(ResultSetImpl.class.getName());
56   private static final L10N L = new L10N(ResultSetImpl.class);
57
58   public static final int CACHE_CHUNK_SIZE = 64;
59
60   private UserQuery _userQuery;
61   private ResultSet _rs;
62   private ArrayList JavaDoc<FromItem> _fromList;
63   private ArrayList JavaDoc<AmberExpr> _resultList;
64   private Map JavaDoc<AmberExpr, String JavaDoc> _joinFetchMap;
65   private AmberConnection _session;
66
67   private QueryCacheKey _cacheKey;
68   private ResultSetCacheChunk _cacheChunk;
69   private ResultSetMetaData _cacheMetaData;
70   private boolean _isCache;
71
72   private int _firstResult;
73   private int _maxResults = Integer.MAX_VALUE / 2;
74   private int _row;
75
76   private int _numberOfLoadingColumns = 1;
77
78   public ResultSetImpl()
79   {
80   }
81
82   /**
83    * Sets the user query
84    */

85   public void setUserQuery(UserQuery userQuery)
86   {
87     _userQuery = userQuery;
88   }
89
90   /**
91    * Sets the result set.
92    */

93   public void setResultSet(ResultSet rs)
94     throws SQLException
95   {
96     _rs = rs;
97
98     if (rs != null)
99       _cacheMetaData = rs.getMetaData();
100   }
101
102   /**
103    * Sets the result set and meta data.
104    */

105   public void setResultSet(ResultSet rs,
106                            ResultSetMetaData metaData)
107   {
108     _rs = rs;
109     _cacheMetaData = metaData;
110   }
111
112   /**
113    * Sets the query.
114    */

115   public void setQuery(SelectQuery query)
116   {
117     _fromList = query.getFromList();
118     _resultList = query.getResultList();
119     _joinFetchMap = query.getJoinFetchMap();
120   }
121
122   /**
123    * Sets the session.
124    */

125   public void setSession(AmberConnection aConn)
126   {
127     _session = aConn;
128   }
129
130   /**
131    * Sets the first cache chunk
132    */

133   public void setCacheChunk(ResultSetCacheChunk cacheChunk,
134                             ResultSetMetaData metaData)
135   {
136     _cacheChunk = cacheChunk;
137     _cacheMetaData = metaData;
138     _isCache = true;
139   }
140
141   /**
142    * Sets the first result.
143    */

144   public void setFirstResult(int first)
145   {
146     _firstResult = first;
147   }
148
149   /**
150    * Sets the max result.
151    */

152   public void setMaxResults(int max)
153   {
154     if (max < 0)
155       _maxResults = Integer.MAX_VALUE / 2;
156     else
157       _maxResults = max;
158   }
159
160   /**
161    * Fills the cache chunk.
162    */

163   public void fillCacheChunk(ResultSetCacheChunk cacheChunk)
164     throws SQLException
165   {
166     int size = CACHE_CHUNK_SIZE;
167     int maxSize = Integer.MAX_VALUE / 2;
168     int i = 0;
169
170     ResultSetCacheChunk tail = cacheChunk;
171
172     // max length of the cached value
173
for (; maxSize-- > 0; i++) {
174       if (_rs.next()) {
175         if (size <= i) {
176           i = 0;
177
178           ResultSetCacheChunk next = new ResultSetCacheChunk(tail);
179           tail.setNext(next);
180           tail = next;
181         }
182
183         tail.newRow();
184
185         int len = _resultList.size();
186         int offset = 0;
187
188         for (int j = 0; j < len; j++) {
189           int index = getColumn(j + 1);
190
191           AmberExpr expr = _resultList.get(j);
192
193           if (expr instanceof LoadEntityExpr) {
194             LoadEntityExpr entityExpr = (LoadEntityExpr) expr;
195
196             Object JavaDoc obj = entityExpr.getCacheObject(_session,
197                                                    _rs,
198                                                    index + offset,
199                                                    _joinFetchMap);
200
201             tail.setValue(i, j, obj);
202
203             // jpa/11z1
204
offset += entityExpr.getIndex();
205           }
206           else {
207             Object JavaDoc obj = expr.getCacheObject(_session,
208                                              _rs,
209                                              index + offset);
210
211             tail.setValue(i, j, obj);
212           }
213         }
214       }
215       else {
216         tail.setLast(true);
217         return;
218       }
219     }
220
221     /*
222       if (! _rs.next()) {
223       tail.setLast(true);
224       }
225     */

226   }
227
228   /**
229    * Initialize
230    */

231   public void init()
232     throws SQLException
233   {
234     _row = 0;
235     _numberOfLoadingColumns = 1;
236
237     while (_row < _firstResult && next()) {
238     }
239   }
240
241   /**
242    * Returns the current row number.
243    */

244   public int getRow()
245     throws SQLException
246   {
247     return _rs.getRow();
248   }
249
250   /**
251    * Returns true before the first row.
252    */

253   public boolean isBeforeFirst()
254     throws SQLException
255   {
256     return _rs.isBeforeFirst();
257   }
258
259   /**
260    * Returns true if this is the first row.
261    */

262   public boolean isFirst()
263     throws SQLException
264   {
265     return _rs.isFirst();
266   }
267
268   /**
269    * Returns true if this is the last row.
270    */

271   public boolean isLast()
272     throws SQLException
273   {
274     return _rs.isLast();
275   }
276
277   /**
278    * Returns true if this is after the last row.
279    */

280   public boolean isAfterLast()
281     throws SQLException
282   {
283     return _rs.isAfterLast();
284   }
285
286   /**
287    * Returns the statement for the result.
288    */

289   public java.sql.Statement JavaDoc getStatement()
290     throws SQLException
291   {
292     return _rs.getStatement();
293   }
294
295   /**
296    * Returns the metadata.
297    */

298   public java.sql.ResultSetMetaData JavaDoc getMetaData()
299     throws SQLException
300   {
301     try {
302
303       if (_rs == null)
304         return _cacheMetaData;
305       else {
306         _cacheMetaData = _rs.getMetaData();
307
308         return _cacheMetaData;
309       }
310
311     } catch (NullPointerException JavaDoc ex) {
312     }
313
314     return null;
315   }
316
317   /**
318    * Returns the warnings.
319    */

320   public SQLWarning getWarnings()
321     throws SQLException
322   {
323     return _rs.getWarnings();
324   }
325
326   /**
327    * Clears the warnings.
328    */

329   public void clearWarnings()
330     throws SQLException
331   {
332     _rs.clearWarnings();
333   }
334
335   /**
336    * Returns the cursor name.
337    */

338   public String JavaDoc getCursorName()
339     throws SQLException
340   {
341     return _rs.getCursorName();
342   }
343
344   /**
345    * Sets the fetch size.
346    */

347   public void setFetchSize(int size)
348     throws SQLException
349   {
350     _rs.setFetchSize(size);
351   }
352
353   /**
354    * Gets the fetch size.
355    */

356   public int getFetchSize()
357     throws SQLException
358   {
359     return _rs.getFetchSize();
360   }
361
362   /**
363    * Gets the fetch direction.
364    */

365   public int getFetchDirection()
366     throws SQLException
367   {
368     return _rs.getFetchDirection();
369   }
370
371   /**
372    * Sets the fetch direction.
373    */

374   public void setFetchDirection(int dir)
375     throws SQLException
376   {
377     _rs.setFetchDirection(dir);
378   }
379
380   /**
381    * Gets the concurrency.
382    */

383   public int getConcurrency()
384     throws SQLException
385   {
386     return _rs.getConcurrency();
387   }
388
389   /**
390    * Returns the next row.
391    */

392   public boolean next()
393     throws SQLException
394   {
395     if (_firstResult + _maxResults <= _row)
396       return false;
397
398     int row = _row++;
399     ResultSetCacheChunk cacheChunk = _cacheChunk;
400
401     if (cacheChunk == null)
402       return _rs.next();
403     else if (row < cacheChunk.getRowCount()) {
404       return true;
405     }
406     else {
407       ResultSetCacheChunk next = cacheChunk.getNext();
408
409       if (next != null) {
410         _cacheChunk = next;
411         return true;
412       }
413
414       _isCache = false;
415       _cacheChunk = null;
416
417       if (cacheChunk.isLast()) {
418         _maxResults = 0;
419         return false;
420       }
421       else if (_rs != null)
422         return true;
423       else if (_userQuery != null) {
424         _rs = _userQuery.executeQuery(row, -1);
425
426         _cacheMetaData = _rs.getMetaData();
427
428         return _rs.next();
429       }
430       else {
431         return false;
432       }
433     }
434   }
435
436   /**
437    * Returns the previous row.
438    */

439   public boolean previous()
440     throws SQLException
441   {
442     if (_row <= _firstResult)
443       return false;
444
445     _row--;
446
447     return _rs.previous();
448   }
449
450   /**
451    * Move relative.
452    */

453   public boolean relative(int delta)
454     throws SQLException
455   {
456     return _rs.relative(delta);
457   }
458
459   /**
460    * Move absolute.
461    */

462   public boolean absolute(int delta)
463     throws SQLException
464   {
465     return _rs.absolute(delta);
466   }
467
468   /**
469    * Moves before the first row.
470    */

471   public void beforeFirst()
472     throws SQLException
473   {
474     _rs.beforeFirst();
475   }
476
477   /**
478    * Move to first
479    */

480   public boolean first()
481     throws SQLException
482   {
483     return _rs.first();
484   }
485
486   /**
487    * Move to last
488    */

489   public boolean last()
490     throws SQLException
491   {
492     return _rs.last();
493   }
494
495   /**
496    * Moves after the last row.
497    */

498   public void afterLast()
499     throws SQLException
500   {
501     _rs.afterLast();
502   }
503
504   /**
505    * Returns true if the last column read was null.
506    */

507   public boolean wasNull()
508     throws SQLException
509   {
510     return _rs.wasNull();
511   }
512
513   /**
514    * Returns the type of the last column.
515    */

516   public int getType()
517     throws SQLException
518   {
519     return _rs.getType();
520   }
521
522   /**
523    * Returns the external column id corresponding to the column name.
524    */

525   public int findColumn(String JavaDoc columnName)
526     throws SQLException
527   {
528     throw new UnsupportedOperationException JavaDoc();
529   }
530
531   /**
532    * Returns the boolean value for the column.
533    */

534   public boolean getBoolean(String JavaDoc columnName)
535     throws SQLException
536   {
537     int column = getColumn(columnName);
538
539     if (_cacheChunk != null)
540       return _cacheChunk.getBoolean(_row - 1, column - 1);
541     else
542       return _rs.getBoolean(column);
543   }
544
545   /**
546    * Returns the boolean value for the column.
547    */

548   public boolean getBoolean(int column)
549     throws SQLException
550   {
551     if (_cacheChunk != null)
552       return _cacheChunk.getBoolean(_row - 1, column - 1);
553     else
554       return _rs.getBoolean(column);
555   }
556
557   /**
558    * Returns the byte value for the column.
559    */

560   public byte getByte(String JavaDoc columnName)
561     throws SQLException
562   {
563     int column = getColumn(columnName);
564
565     if (_cacheChunk != null)
566       return _cacheChunk.getByte(_row - 1, column - 1);
567     else
568       return _rs.getByte(column);
569   }
570
571   /**
572    * Returns the byte value for the column.
573    */

574   public byte getByte(int column)
575     throws SQLException
576   {
577     if (_cacheChunk != null)
578       return _cacheChunk.getByte(_row - 1, column - 1);
579     else
580       return _rs.getByte(column);
581   }
582
583   /**
584    * Returns the short value for the column.
585    */

586   public short getShort(String JavaDoc columnName)
587     throws SQLException
588   {
589     int column = getColumn(columnName);
590
591     if (_cacheChunk != null)
592       return _cacheChunk.getShort(_row - 1, column - 1);
593     else
594       return _rs.getShort(column);
595   }
596
597   /**
598    * Returns the short value for the column.
599    */

600   public short getShort(int column)
601     throws SQLException
602   {
603     if (_cacheChunk != null)
604       return _cacheChunk.getShort(_row - 1, column - 1);
605     else
606       return _rs.getShort(column);
607   }
608
609   /**
610    * Returns the int value for the column.
611    */

612   public int getInt(String JavaDoc columnName)
613     throws SQLException
614   {
615     int column = getColumn(columnName);
616
617     if (_cacheChunk != null)
618       return _cacheChunk.getInt(_row - 1, column - 1);
619     else
620       return _rs.getInt(column);
621   }
622
623   /**
624    * Returns the int value for the column.
625    */

626   public int getInt(int column)
627     throws SQLException
628   {
629     if (_cacheChunk != null)
630       return _cacheChunk.getInt(_row - 1, column - 1);
631     else
632       return _rs.getInt(column);
633   }
634
635   /**
636    * Returns the long value for the column.
637    */

638   public long getLong(String JavaDoc columnName)
639     throws SQLException
640   {
641     int column = getColumn(columnName);
642
643     if (_cacheChunk != null)
644       return _cacheChunk.getLong(_row - 1, column - 1);
645     else
646       return _rs.getLong(column);
647   }
648
649   /**
650    * Returns the long value for the column.
651    */

652   public long getLong(int column)
653     throws SQLException
654   {
655     if (_cacheChunk != null)
656       return _cacheChunk.getLong(_row - 1, column - 1);
657     else
658       return _rs.getLong(column);
659   }
660
661   /**
662    * Returns the float value for the column.
663    */

664   public float getFloat(String JavaDoc columnName)
665     throws SQLException
666   {
667     int column = getColumn(columnName);
668
669     if (_cacheChunk != null)
670       return _cacheChunk.getFloat(_row - 1, column - 1);
671     else
672       return _rs.getFloat(column);
673   }
674
675   /**
676    * Returns the float value for the column.
677    */

678   public float getFloat(int column)
679     throws SQLException
680   {
681     if (_cacheChunk != null)
682       return _cacheChunk.getFloat(_row - 1, column - 1);
683     else
684       return _rs.getFloat(column);
685   }
686
687   /**
688    * Returns the double value for the column.
689    */

690   public double getDouble(String JavaDoc columnName)
691     throws SQLException
692   {
693     int column = getColumn(columnName);
694
695     if (_cacheChunk != null)
696       return _cacheChunk.getDouble(_row - 1, column - 1);
697     else
698       return _rs.getDouble(column);
699   }
700
701   /**
702    * Returns the double value for the column.
703    */

704   public double getDouble(int column)
705     throws SQLException
706   {
707     if (_cacheChunk != null)
708       return _cacheChunk.getDouble(_row - 1, column - 1);
709     else
710       return _rs.getDouble(column);
711   }
712
713   /**
714    * Returns the string value for the column.
715    */

716   public String JavaDoc getString(int column)
717     throws SQLException
718   {
719     if (_cacheChunk != null)
720       return _cacheChunk.getString(_row - 1, column - 1);
721     else
722       return _rs.getString(column);
723   }
724
725   /**
726    * Returns the string value for the column.
727    */

728   public String JavaDoc getString(String JavaDoc columnName)
729     throws SQLException
730   {
731     int column = getColumn(columnName);
732
733     if (_cacheChunk != null)
734       return _cacheChunk.getString(_row - 1, column - 1);
735     else
736       return _rs.getString(column);
737   }
738
739   /**
740    * Returns the bytes value for the column.
741    */

742   public byte []getBytes(int column)
743     throws SQLException
744   {
745     return _rs.getBytes(getColumn(column));
746   }
747
748   /**
749    * Returns the bytes value for the column.
750    */

751   public byte []getBytes(String JavaDoc column)
752     throws SQLException
753   {
754     return _rs.getBytes(getColumn(column));
755   }
756
757   /**
758    * Returns the column value as a date.
759    */

760   public java.sql.Date JavaDoc getDate(int column)
761     throws SQLException
762   {
763     return _rs.getDate(getColumn(column));
764   }
765
766   /**
767    * Returns the column value as a date.
768    */

769   public java.sql.Date JavaDoc getDate(String JavaDoc column)
770     throws SQLException
771   {
772     return _rs.getDate(getColumn(column));
773   }
774
775   /**
776    * Returns the column value as a date.
777    */

778   public java.sql.Date JavaDoc getDate(int column, Calendar JavaDoc cal)
779     throws SQLException
780   {
781     return _rs.getDate(getColumn(column), cal);
782   }
783
784   /**
785    * Returns the column value as a date.
786    */

787   public java.sql.Date JavaDoc getDate(String JavaDoc column, Calendar JavaDoc cal)
788     throws SQLException
789   {
790     return _rs.getDate(getColumn(column), cal);
791   }
792
793   /**
794    * Returns the time value for the column.
795    */

796   public Time getTime(int column)
797     throws SQLException
798   {
799     return _rs.getTime(getColumn(column));
800   }
801
802   /**
803    * Returns the time value for the column.
804    */

805   public Time getTime(String JavaDoc column)
806     throws SQLException
807   {
808     return _rs.getTime(getColumn(column));
809   }
810
811   /**
812    * Returns the time value for the column.
813    */

814   public Time getTime(int column, Calendar JavaDoc cal)
815     throws SQLException
816   {
817     return _rs.getTime(getColumn(column), cal);
818   }
819
820   /**
821    * Returns the time value for the column.
822    */

823   public Time getTime(String JavaDoc column, Calendar JavaDoc cal)
824     throws SQLException
825   {
826     return _rs.getTime(getColumn(column), cal);
827   }
828
829   /**
830    * Returns the column as a timestamp.
831    */

832   public Timestamp getTimestamp(int column)
833     throws SQLException
834   {
835     return _rs.getTimestamp(getColumn(column));
836   }
837
838   /**
839    * Returns the column as a timestamp.
840    */

841   public Timestamp getTimestamp(String JavaDoc column)
842     throws SQLException
843   {
844     return _rs.getTimestamp(getColumn(column));
845   }
846
847   /**
848    * Returns the column as a timestamp.
849    */

850   public Timestamp getTimestamp(int column, Calendar JavaDoc cal)
851     throws SQLException
852   {
853     return _rs.getTimestamp(getColumn(column), cal);
854   }
855
856   /**
857    * Returns the column as a timestamp.
858    */

859   public Timestamp getTimestamp(String JavaDoc column, Calendar JavaDoc cal)
860     throws SQLException
861   {
862     return _rs.getTimestamp(getColumn(column), cal);
863   }
864
865   /**
866    * Returns a ref value for the column.
867    */

868   public Ref getRef(int column)
869     throws SQLException
870   {
871     return _rs.getRef(getColumn(column));
872   }
873
874   /**
875    * Returns a ref value for the column.
876    */

877   public Ref getRef(String JavaDoc column)
878     throws SQLException
879   {
880     return _rs.getRef(getColumn(column));
881   }
882
883   /**
884    * Returns a clob value for the column.
885    */

886   public Clob getClob(int column)
887     throws SQLException
888   {
889     return _rs.getClob(getColumn(column));
890   }
891
892   /**
893    * Returns a clob value for the column.
894    */

895   public Clob getClob(String JavaDoc column)
896     throws SQLException
897   {
898     return _rs.getClob(getColumn(column));
899   }
900
901   /**
902    * Returns a blob value for the column.
903    */

904   public Blob getBlob(int column)
905     throws SQLException
906   {
907     return _rs.getBlob(getColumn(column));
908   }
909
910   /**
911    * Returns a blob value for the column.
912    */

913   public Blob getBlob(String JavaDoc column)
914     throws SQLException
915   {
916     return _rs.getBlob(getColumn(column));
917   }
918
919   /**
920    * Returns a character stream for the column.
921    */

922   public Reader JavaDoc getCharacterStream(int column)
923     throws SQLException
924   {
925     return _rs.getCharacterStream(getColumn(column));
926   }
927
928   /**
929    * Returns a character stream for the column.
930    */

931   public Reader JavaDoc getCharacterStream(String JavaDoc column)
932     throws SQLException
933   {
934     return _rs.getCharacterStream(getColumn(column));
935   }
936
937   /**
938    * Returns a binary stream for the column.
939    */

940   public InputStream JavaDoc getBinaryStream(int column)
941     throws SQLException
942   {
943     return _rs.getBinaryStream(getColumn(column));
944   }
945
946   /**
947    * Returns a binary stream for the column.
948    */

949   public InputStream JavaDoc getBinaryStream(String JavaDoc column)
950     throws SQLException
951   {
952     return _rs.getBinaryStream(getColumn(column));
953   }
954
955   /**
956    * Returns an ascii stream for the column.
957    */

958   public InputStream JavaDoc getAsciiStream(int column)
959     throws SQLException
960   {
961     return _rs.getAsciiStream(getColumn(column));
962   }
963
964   /**
965    * Returns an ascii stream for the column.
966    */

967   public InputStream JavaDoc getAsciiStream(String JavaDoc column)
968     throws SQLException
969   {
970     return _rs.getAsciiStream(getColumn(column));
971   }
972
973   /**
974    * Returns a unicode stream for the column.
975    */

976   public InputStream JavaDoc getUnicodeStream(int column)
977     throws SQLException
978   {
979     return _rs.getUnicodeStream(getColumn(column));
980   }
981
982   /**
983    * Returns a unicode stream for the column.
984    */

985   public InputStream JavaDoc getUnicodeStream(String JavaDoc column)
986     throws SQLException
987   {
988     return _rs.getUnicodeStream(getColumn(column));
989   }
990
991   /**
992    * Returns an array value for the column.
993    */

994   public Array getArray(int column)
995     throws SQLException
996   {
997     return _rs.getArray(getColumn(column));
998   }
999
1000  /**
1001   * Returns an array value for the column.
1002   */

1003  public Array getArray(String JavaDoc column)
1004    throws SQLException
1005  {
1006    return _rs.getArray(getColumn(column));
1007  }
1008
1009  /**
1010   * Returns a URL value for the column.
1011   */

1012  public URL JavaDoc getURL(int column)
1013    throws SQLException
1014  {
1015    return _rs.getURL(getColumn(column));
1016  }
1017
1018  /**
1019   * Returns a URL value for the column.
1020   */

1021  public URL JavaDoc getURL(String JavaDoc column)
1022    throws SQLException
1023  {
1024    return _rs.getURL(getColumn(column));
1025  }
1026
1027  /**
1028   * Returns a big decimal value for the column.
1029   */

1030  public BigDecimal JavaDoc getBigDecimal(int column)
1031    throws SQLException
1032  {
1033    return _rs.getBigDecimal(getColumn(column));
1034  }
1035
1036  /**
1037   * Returns a big decimal value for the column.
1038   */

1039  public BigDecimal JavaDoc getBigDecimal(String JavaDoc column)
1040    throws SQLException
1041  {
1042    return _rs.getBigDecimal(getColumn(column));
1043  }
1044
1045  /**
1046   * Returns a big decimal value for the column.
1047   */

1048  public BigDecimal JavaDoc getBigDecimal(int column, int digit)
1049    throws SQLException
1050  {
1051    return _rs.getBigDecimal(getColumn(column), digit);
1052  }
1053
1054  /**
1055   * Returns a big decimal value for the column.
1056   */

1057  public BigDecimal JavaDoc getBigDecimal(String JavaDoc column, int digit)
1058    throws SQLException
1059  {
1060    return _rs.getBigDecimal(getColumn(column), digit);
1061  }
1062
1063  /**
1064   * Returns the object value for the column.
1065   */

1066  public Object JavaDoc getObject(int column)
1067    throws SQLException
1068  {
1069    ResultSetCacheChunk cacheChunk = _cacheChunk;
1070
1071    if (cacheChunk != null) {
1072      Object JavaDoc obj = cacheChunk.getObject(_row - 1, column - 1);
1073
1074      if (obj instanceof EntityItem) {
1075        EntityItem entityItem = (EntityItem) obj;
1076
1077        Entity entity = entityItem.getEntity();
1078
1079        Object JavaDoc value = _session.loadProxy(entity.__caucho_getEntityType(),
1080                                          entity.__caucho_getPrimaryKey());
1081
1082        _numberOfLoadingColumns = entityItem.getNumberOfLoadingColumns();
1083
1084        return value;
1085      }
1086      else
1087        return obj;
1088    }
1089    else {
1090      int index = getColumn(column);
1091
1092      AmberExpr expr = _resultList.get(column - 1);
1093
1094      Object JavaDoc value = expr.getObject(_session, _rs, index);
1095
1096      if (expr instanceof LoadEntityExpr) {
1097        LoadEntityExpr entityExpr = (LoadEntityExpr) expr;
1098        _numberOfLoadingColumns = entityExpr.getIndex();
1099      }
1100
1101      return value;
1102    }
1103  }
1104
1105  /**
1106   * Returns the object value for the column.
1107   */

1108  public EntityItem findEntityItem(int column)
1109    throws SQLException
1110  {
1111    ResultSetCacheChunk cacheChunk = _cacheChunk;
1112
1113    if (cacheChunk != null) {
1114      Object JavaDoc obj = cacheChunk.getObject(_row - 1, column - 1);
1115
1116      if (obj instanceof EntityItem) {
1117        return (EntityItem) obj;
1118      }
1119      else
1120        throw new SQLException(L.l("'{0}' is an unexpected type.",
1121                                   obj));
1122    }
1123    else {
1124      int index = getColumn(column);
1125
1126      AmberExpr expr = _resultList.get(column - 1);
1127
1128      EntityItem item = expr.findItem(_session, _rs, index);
1129
1130      return item;
1131    }
1132    /*
1133      FromItem item = _fromList.get(column - 1);
1134      AmberEntityHome home = item.getEntityHome();
1135
1136      return home.load(_session, _rs, index);
1137    */

1138  }
1139
1140  /**
1141   * Returns the object value for the column.
1142   */

1143  public Object JavaDoc getObject(String JavaDoc column)
1144    throws SQLException
1145  {
1146    throw new UnsupportedOperationException JavaDoc();
1147  }
1148
1149  /**
1150   * Returns the object value for the column.
1151   */

1152  public Object JavaDoc getKey(int column)
1153    throws SQLException
1154  {
1155    int index = getColumn(column);
1156
1157    FromItem item = _fromList.get(column - 1);
1158    AmberEntityHome home = item.getEntityHome();
1159
1160    Object JavaDoc key = home.getEntityType().getId().getObject(_rs, index);
1161
1162    return key;
1163  }
1164
1165  /**
1166   * Returns the object value for the column.
1167   */

1168  public Object JavaDoc getObject(int column, Map JavaDoc<String JavaDoc,Class JavaDoc<?>> map)
1169    throws SQLException
1170  {
1171    throw new UnsupportedOperationException JavaDoc();
1172  }
1173
1174  /**
1175   * Returns the object value for the column.
1176   */

1177  public Object JavaDoc getObject(String JavaDoc column, Map JavaDoc<String JavaDoc,Class JavaDoc<?>> map)
1178    throws SQLException
1179  {
1180    throw new UnsupportedOperationException JavaDoc();
1181  }
1182
1183  /**
1184   * Updating a string column in the row.
1185   */

1186  public void updateString(String JavaDoc column, String JavaDoc value)
1187    throws SQLException
1188  {
1189    throw new UnsupportedOperationException JavaDoc();
1190  }
1191
1192  /**
1193   * Updating a string column in the row.
1194   */

1195  public void updateString(int column, String JavaDoc value)
1196    throws SQLException
1197  {
1198    throw new UnsupportedOperationException JavaDoc();
1199  }
1200
1201  /**
1202   * Updating an object column in the row.
1203   */

1204  public void updateObject(String JavaDoc column, Object JavaDoc value)
1205    throws SQLException
1206  {
1207    throw new UnsupportedOperationException JavaDoc();
1208  }
1209
1210  /**
1211   * Updating an object column in the row.
1212   */

1213  public void updateObject(int column, Object JavaDoc value)
1214    throws SQLException
1215  {
1216    throw new UnsupportedOperationException JavaDoc();
1217  }
1218
1219  /**
1220   * Updating an object column in the row.
1221   */

1222  public void updateObject(String JavaDoc column, Object JavaDoc value, int scale)
1223    throws SQLException
1224  {
1225    throw new UnsupportedOperationException JavaDoc();
1226  }
1227
1228  /**
1229   * Updating an object column in the row.
1230   */

1231  public void updateObject(int column, Object JavaDoc value, int scale)
1232    throws SQLException
1233  {
1234    throw new UnsupportedOperationException JavaDoc();
1235  }
1236
1237  /**
1238   * Updating a timestamp column in the row.
1239   */

1240  public void updateTimestamp(String JavaDoc column, Timestamp timestamp)
1241    throws SQLException
1242  {
1243    throw new UnsupportedOperationException JavaDoc();
1244  }
1245
1246  /**
1247   * Updating a timestamp column in the row.
1248   */

1249  public void updateTimestamp(int column, Timestamp timestamp)
1250    throws SQLException
1251  {
1252    throw new UnsupportedOperationException JavaDoc();
1253  }
1254
1255  /**
1256   * Updating a time column in the row.
1257   */

1258  public void updateTime(String JavaDoc column, Time time)
1259    throws SQLException
1260  {
1261    throw new UnsupportedOperationException JavaDoc();
1262  }
1263
1264  /**
1265   * Updating a time column in the row.
1266   */

1267  public void updateTime(int column, Time time)
1268    throws SQLException
1269  {
1270    throw new UnsupportedOperationException JavaDoc();
1271  }
1272
1273  /**
1274   * Updating a date column in the row.
1275   */

1276  public void updateDate(String JavaDoc column, java.sql.Date JavaDoc date)
1277    throws SQLException
1278  {
1279    throw new UnsupportedOperationException JavaDoc();
1280  }
1281
1282  /**
1283   * Updating a date column in the row.
1284   */

1285  public void updateDate(int column, java.sql.Date JavaDoc date)
1286    throws SQLException
1287  {
1288    throw new UnsupportedOperationException JavaDoc();
1289  }
1290
1291  /**
1292   * Updating a clob column in the row.
1293   */

1294  public void updateClob(String JavaDoc column, Clob clob)
1295    throws SQLException
1296  {
1297    throw new UnsupportedOperationException JavaDoc();
1298  }
1299
1300  /**
1301   * Updating a clob column in the row.
1302   */

1303  public void updateClob(int column, Clob clob)
1304    throws SQLException
1305  {
1306    throw new UnsupportedOperationException JavaDoc();
1307  }
1308
1309  /**
1310   * Updating a blob column in the row.
1311   */

1312  public void updateBlob(String JavaDoc column, Blob blob)
1313    throws SQLException
1314  {
1315    throw new UnsupportedOperationException JavaDoc();
1316  }
1317
1318  /**
1319   * Updating a blob column in the row.
1320   */

1321  public void updateBlob(int column, Blob blob)
1322    throws SQLException
1323  {
1324    throw new UnsupportedOperationException JavaDoc();
1325  }
1326
1327  /**
1328   * Updating an array column in the row.
1329   */

1330  public void updateArray(String JavaDoc column, Array array)
1331    throws SQLException
1332  {
1333    throw new UnsupportedOperationException JavaDoc();
1334  }
1335
1336  /**
1337   * Updating an array column in the row.
1338   */

1339  public void updateArray(int column, Array array)
1340    throws SQLException
1341  {
1342    throw new UnsupportedOperationException JavaDoc();
1343  }
1344
1345  /**
1346   * Updating a big decimal column in the row.
1347   */

1348  public void updateBigDecimal(String JavaDoc column, BigDecimal JavaDoc decimal)
1349    throws SQLException
1350  {
1351    throw new UnsupportedOperationException JavaDoc();
1352  }
1353
1354  /**
1355   * Updating a big decimal column in the row.
1356   */

1357  public void updateBigDecimal(int column, BigDecimal JavaDoc decimal)
1358    throws SQLException
1359  {
1360    throw new UnsupportedOperationException JavaDoc();
1361  }
1362
1363  /**
1364   * Updating a ref column in the row.
1365   */

1366  public void updateRef(String JavaDoc column, Ref ref)
1367    throws SQLException
1368  {
1369    throw new UnsupportedOperationException JavaDoc();
1370  }
1371
1372  /**
1373   * Updating a ref column in the row.
1374   */

1375  public void updateRef(int column, Ref ref)
1376    throws SQLException
1377  {
1378    throw new UnsupportedOperationException JavaDoc();
1379  }
1380
1381  /**
1382   * Updating a character stream.
1383   */

1384  public void updateCharacterStream(String JavaDoc column, Reader JavaDoc x, int length)
1385    throws SQLException
1386  {
1387    throw new UnsupportedOperationException JavaDoc();
1388  }
1389
1390  /**
1391   * Updating a character stream.
1392   */

1393  public void updateCharacterStream(int column, Reader JavaDoc x, int length)
1394    throws SQLException
1395  {
1396    throw new UnsupportedOperationException JavaDoc();
1397  }
1398
1399  /**
1400   * Updating a binary stream.
1401   */

1402  public void updateBinaryStream(String JavaDoc column, InputStream JavaDoc x, int length)
1403    throws SQLException
1404  {
1405    throw new UnsupportedOperationException JavaDoc();
1406  }
1407
1408  /**
1409   * Updating a binary stream.
1410   */

1411  public void updateBinaryStream(int column, InputStream JavaDoc x, int length)
1412    throws SQLException
1413  {
1414    throw new UnsupportedOperationException JavaDoc();
1415  }
1416
1417  /**
1418   * Updating an ascii stream.
1419   */

1420  public void updateAsciiStream(String JavaDoc column, InputStream JavaDoc x, int length)
1421    throws SQLException
1422  {
1423    throw new UnsupportedOperationException JavaDoc();
1424  }
1425
1426  /**
1427   * Updating an ascii stream.
1428   */

1429  public void updateAsciiStream(int column, InputStream JavaDoc x, int length)
1430    throws SQLException
1431  {
1432    throw new UnsupportedOperationException JavaDoc();
1433  }
1434
1435  /**
1436   * Updating a unicode stream.
1437   */

1438  public void updateUnicodeStream(String JavaDoc column, InputStream JavaDoc x, int length)
1439    throws SQLException
1440  {
1441    throw new UnsupportedOperationException JavaDoc();
1442  }
1443
1444  /**
1445   * Updating a unicode stream.
1446   */

1447  public void updateUnicodeStream(int column, InputStream JavaDoc x, int length)
1448    throws SQLException
1449  {
1450    throw new UnsupportedOperationException JavaDoc();
1451  }
1452
1453  /**
1454   * Updating bytes.
1455   */

1456  public void updateBytes(String JavaDoc column, byte []value)
1457    throws SQLException
1458  {
1459    throw new UnsupportedOperationException JavaDoc();
1460  }
1461
1462  /**
1463   * Updating bytes.
1464   */

1465  public void updateBytes(int column, byte []value)
1466    throws SQLException
1467  {
1468    throw new UnsupportedOperationException JavaDoc();
1469  }
1470
1471  /**
1472   * Updating boolean.
1473   */

1474  public void updateBoolean(String JavaDoc column, boolean value)
1475    throws SQLException
1476  {
1477    throw new UnsupportedOperationException JavaDoc();
1478  }
1479
1480  /**
1481   * Updating boolean.
1482   */

1483  public void updateBoolean(int column, boolean value)
1484    throws SQLException
1485  {
1486    throw new UnsupportedOperationException JavaDoc();
1487  }
1488
1489  /**
1490   * Updating byte.
1491   */

1492  public void updateByte(String JavaDoc column, byte value)
1493    throws SQLException
1494  {
1495    throw new UnsupportedOperationException JavaDoc();
1496  }
1497
1498  /**
1499   * Updating byte.
1500   */

1501  public void updateByte(int column, byte value)
1502    throws SQLException
1503  {
1504    throw new UnsupportedOperationException JavaDoc();
1505  }
1506
1507  /**
1508   * Updating short.
1509   */

1510  public void updateShort(String JavaDoc column, short value)
1511    throws SQLException
1512  {
1513    throw new UnsupportedOperationException JavaDoc();
1514  }
1515
1516  /**
1517   * Updating short.
1518   */

1519  public void updateShort(int column, short value)
1520    throws SQLException
1521  {
1522    throw new UnsupportedOperationException JavaDoc();
1523  }
1524
1525  /**
1526   * Updating int.
1527   */

1528  public void updateInt(String JavaDoc column, int value)
1529    throws SQLException
1530  {
1531    throw new UnsupportedOperationException JavaDoc();
1532  }
1533
1534  /**
1535   * Updating int.
1536   */

1537  public void updateInt(int column, int value)
1538    throws SQLException
1539  {
1540    throw new UnsupportedOperationException JavaDoc();
1541  }
1542
1543  /**
1544   * Updating long.
1545   */

1546  public void updateLong(String JavaDoc column, long value)
1547    throws SQLException
1548  {
1549    throw new UnsupportedOperationException JavaDoc();
1550  }
1551
1552  /**
1553   * Updating long.
1554   */

1555  public void updateLong(int column, long value)
1556    throws SQLException
1557  {
1558    throw new UnsupportedOperationException JavaDoc();
1559  }
1560
1561  /**
1562   * Updating float.
1563   */

1564  public void updateFloat(String JavaDoc column, float value)
1565    throws SQLException
1566  {
1567    throw new UnsupportedOperationException JavaDoc();
1568  }
1569
1570  /**
1571   * Updating float.
1572   */

1573  public void updateFloat(int column, float value)
1574    throws SQLException
1575  {
1576    throw new UnsupportedOperationException JavaDoc();
1577  }
1578
1579  /**
1580   * Updating double.
1581   */

1582  public void updateDouble(String JavaDoc column, double value)
1583    throws SQLException
1584  {
1585    throw new UnsupportedOperationException JavaDoc();
1586  }
1587
1588  /**
1589   * Updating double.
1590   */

1591  public void updateDouble(int column, double value)
1592    throws SQLException
1593  {
1594    throw new UnsupportedOperationException JavaDoc();
1595  }
1596
1597  /**
1598   * Updating null.
1599   */

1600  public void updateNull(String JavaDoc column)
1601    throws SQLException
1602  {
1603    throw new UnsupportedOperationException JavaDoc();
1604  }
1605
1606  /**
1607   * Updating null.
1608   */

1609  public void updateNull(int column)
1610    throws SQLException
1611  {
1612    throw new UnsupportedOperationException JavaDoc();
1613  }
1614
1615  /**
1616   * updates the row
1617   */

1618  public void updateRow()
1619    throws SQLException
1620  {
1621    throw new UnsupportedOperationException JavaDoc();
1622  }
1623
1624  /**
1625   * cancels the row updates.
1626   */

1627  public void cancelRowUpdates()
1628    throws SQLException
1629  {
1630    throw new UnsupportedOperationException JavaDoc();
1631  }
1632
1633  /**
1634   * refreshes the row
1635   */

1636  public void refreshRow()
1637    throws SQLException
1638  {
1639    throw new UnsupportedOperationException JavaDoc();
1640  }
1641
1642  /**
1643   * move to the current row
1644   */

1645  public void moveToCurrentRow()
1646    throws SQLException
1647  {
1648    throw new UnsupportedOperationException JavaDoc();
1649  }
1650
1651  /**
1652   * Updating
1653   */

1654  public boolean rowUpdated()
1655    throws SQLException
1656  {
1657    throw new UnsupportedOperationException JavaDoc();
1658  }
1659
1660  /**
1661   * True if the row was inserted.
1662   */

1663  public boolean rowInserted()
1664    throws SQLException
1665  {
1666    throw new UnsupportedOperationException JavaDoc();
1667  }
1668
1669  /**
1670   * move to insert the row
1671   */

1672  public void moveToInsertRow()
1673    throws SQLException
1674  {
1675    throw new UnsupportedOperationException JavaDoc();
1676  }
1677
1678  /**
1679   * insert the row
1680   */

1681  public void insertRow()
1682    throws SQLException
1683  {
1684    throw new UnsupportedOperationException JavaDoc();
1685  }
1686
1687  /**
1688   * True if the row was deleted.
1689   */

1690  public boolean rowDeleted()
1691    throws SQLException
1692  {
1693    throw new UnsupportedOperationException JavaDoc();
1694  }
1695
1696  /**
1697   * delete the row
1698   */

1699  public void deleteRow()
1700    throws SQLException
1701  {
1702    throw new UnsupportedOperationException JavaDoc();
1703  }
1704
1705  public int getNumberOfLoadingColumns()
1706  {
1707    return _numberOfLoadingColumns;
1708  }
1709
1710  private int getColumn(String JavaDoc name)
1711  {
1712    throw new UnsupportedOperationException JavaDoc();
1713  }
1714
1715  private int getColumn(int index)
1716  {
1717    return index;
1718  }
1719
1720  public void close()
1721  {
1722    ResultSet rs = _rs;
1723    _rs = null;
1724
1725    if (rs != null) {
1726      try {
1727    rs.close();
1728      } catch (SQLException e) {
1729    log.log(Level.FINE, e.toString(), e);
1730      }
1731    }
1732  }
1733}
1734
Popular Tags