KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > sql > execute > GenericResultSetFactory


1 /*
2
3    Derby - Class org.apache.derby.impl.sql.execute.GenericResultSetFactory
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to you under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derby.impl.sql.execute;
23
24 import org.apache.derby.iapi.reference.SQLState;
25
26 import org.apache.derby.iapi.error.StandardException;
27
28 import org.apache.derby.iapi.sql.ResultSet;
29 import org.apache.derby.iapi.sql.ResultDescription;
30 import org.apache.derby.iapi.sql.Activation;
31
32 import org.apache.derby.iapi.sql.execute.ConstantAction;
33 import org.apache.derby.iapi.sql.execute.ExecutionContext;
34 import org.apache.derby.iapi.sql.execute.NoPutResultSet;
35
36 import org.apache.derby.iapi.sql.execute.ResultSetFactory;
37
38 import org.apache.derby.iapi.sql.Activation;
39
40 import org.apache.derby.iapi.services.sanity.SanityManager;
41
42 import org.apache.derby.iapi.services.loader.GeneratedMethod;
43
44 import org.apache.derby.iapi.sql.dictionary.TableDescriptor;
45 import org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor;
46 import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor;
47
48 import org.apache.derby.iapi.store.access.Qualifier;
49 import org.apache.derby.iapi.store.access.StaticCompiledOpenConglomInfo;
50
51 import org.apache.derby.iapi.sql.conn.Authorizer;
52 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
53
54 import java.util.Properties JavaDoc;
55 /**
56  * ResultSetFactory provides a wrapper around all of
57  * the result sets used in this execution implementation.
58  * This removes the need of generated classes to do a new
59  * and of the generator to know about all of the result
60  * sets. Both simply know about this interface to getting
61  * them.
62  * <p>
63  * In terms of modularizing, we can create just an interface
64  * to this class and invoke the interface. Different implementations
65  * would get the same information provided but could potentially
66  * massage/ignore it in different ways to satisfy their
67  * implementations. The practicality of this is to be seen.
68  * <p>
69  * The cost of this type of factory is that once you touch it,
70  * you touch *all* of the possible result sets, not just
71  * the ones you need. So the first time you touch it could
72  * be painful ... that might be a problem for execution.
73  *
74  * @author ames
75  */

76 public class GenericResultSetFactory implements ResultSetFactory
77 {
78     //
79
// ResultSetFactory interface
80
//
81
public GenericResultSetFactory()
82     {
83     }
84
85     /**
86         @see ResultSetFactory#getInsertResultSet
87         @exception StandardException thrown on error
88      */

89     public ResultSet getInsertResultSet(NoPutResultSet source,
90                                         GeneratedMethod checkGM)
91         throws StandardException
92     {
93         Activation activation = source.getActivation();
94         getAuthorizer(activation).authorize(activation, Authorizer.SQL_WRITE_OP);
95         return new InsertResultSet(source, checkGM, activation );
96     }
97
98     /**
99         @see ResultSetFactory#getInsertVTIResultSet
100         @exception StandardException thrown on error
101      */

102     public ResultSet getInsertVTIResultSet(NoPutResultSet source,
103                                         NoPutResultSet vtiRS
104                                         )
105         throws StandardException
106     {
107         Activation activation = source.getActivation();
108         getAuthorizer(activation).authorize(activation, Authorizer.SQL_WRITE_OP);
109         return new InsertVTIResultSet(source, vtiRS, activation );
110     }
111
112     /**
113         @see ResultSetFactory#getDeleteVTIResultSet
114         @exception StandardException thrown on error
115      */

116     public ResultSet getDeleteVTIResultSet(NoPutResultSet source)
117         throws StandardException
118     {
119         Activation activation = source.getActivation();
120         getAuthorizer(activation).authorize(activation, Authorizer.SQL_WRITE_OP);
121         return new DeleteVTIResultSet(source, activation);
122     }
123
124     /**
125         @see ResultSetFactory#getDeleteResultSet
126         @exception StandardException thrown on error
127      */

128     public ResultSet getDeleteResultSet(NoPutResultSet source)
129             throws StandardException
130     {
131         Activation activation = source.getActivation();
132         getAuthorizer(activation).authorize(activation, Authorizer.SQL_WRITE_OP);
133         return new DeleteResultSet(source, activation );
134     }
135
136
137     /**
138         @see ResultSetFactory#getDeleteCascadeResultSet
139         @exception StandardException thrown on error
140      */

141     public ResultSet getDeleteCascadeResultSet(NoPutResultSet source,
142                                                int constantActionItem,
143                                                ResultSet[] dependentResultSets,
144                                                String JavaDoc resultSetId)
145         throws StandardException
146     {
147         Activation activation = source.getActivation();
148         getAuthorizer(activation).authorize(activation, Authorizer.SQL_WRITE_OP);
149         return new DeleteCascadeResultSet(source, activation,
150                                           constantActionItem,
151                                           dependentResultSets,
152                                           resultSetId);
153     }
154
155
156
157     /**
158         @see ResultSetFactory#getUpdateResultSet
159         @exception StandardException thrown on error
160      */

161     public ResultSet getUpdateResultSet(NoPutResultSet source,
162                                         GeneratedMethod checkGM)
163             throws StandardException
164     {
165         Activation activation = source.getActivation();
166         //The stress test failed with null pointer exception in here once and then
167
//it didn't happen again. It can be a jit problem because after this null
168
//pointer exception, the cleanup code in UpdateResultSet got a null
169
//pointer exception too which can't happen since the cleanup code checks
170
//for null value before doing anything.
171
//In any case, if this ever happens again, hopefully the following
172
//assertion code will catch it.
173
if (SanityManager.DEBUG)
174         {
175             SanityManager.ASSERT(getAuthorizer(activation) != null, "Authorizer is null");
176         }
177         getAuthorizer(activation).authorize(activation, Authorizer.SQL_WRITE_OP);
178         return new UpdateResultSet(source, checkGM, activation);
179     }
180
181     /**
182         @see ResultSetFactory#getUpdateVTIResultSet
183         @exception StandardException thrown on error
184      */

185     public ResultSet getUpdateVTIResultSet(NoPutResultSet source)
186             throws StandardException
187     {
188         Activation activation = source.getActivation();
189         getAuthorizer(activation).authorize(activation, Authorizer.SQL_WRITE_OP);
190         return new UpdateVTIResultSet(source, activation);
191     }
192
193
194
195     /**
196         @see ResultSetFactory#getDeleteCascadeUpdateResultSet
197         @exception StandardException thrown on error
198      */

199     public ResultSet getDeleteCascadeUpdateResultSet(NoPutResultSet source,
200                                                      GeneratedMethod checkGM,
201                                                      int constantActionItem,
202                                                      int rsdItem)
203             throws StandardException
204     {
205         Activation activation = source.getActivation();
206         getAuthorizer(activation).authorize(activation, Authorizer.SQL_WRITE_OP);
207         return new UpdateResultSet(source, checkGM, activation,
208                                    constantActionItem, rsdItem);
209     }
210
211
212     /**
213         @see ResultSetFactory#getCallStatementResultSet
214         @exception StandardException thrown on error
215      */

216     public ResultSet getCallStatementResultSet(GeneratedMethod methodCall,
217                 Activation activation)
218             throws StandardException
219     {
220         getAuthorizer(activation).authorize(activation, Authorizer.SQL_CALL_OP);
221         return new CallStatementResultSet(methodCall, activation);
222     }
223
224     /**
225         @see ResultSetFactory#getProjectRestrictResultSet
226         @exception StandardException thrown on error
227      */

228     public NoPutResultSet getProjectRestrictResultSet(NoPutResultSet source,
229         GeneratedMethod restriction,
230         GeneratedMethod projection, int resultSetNumber,
231         GeneratedMethod constantRestriction,
232         int mapRefItem,
233         boolean reuseResult,
234         boolean doesProjection,
235         double optimizerEstimatedRowCount,
236         double optimizerEstimatedCost)
237             throws StandardException
238     {
239         return new ProjectRestrictResultSet(source, source.getActivation(),
240             restriction, projection, resultSetNumber,
241             constantRestriction, mapRefItem,
242             reuseResult,
243             doesProjection,
244             optimizerEstimatedRowCount,
245             optimizerEstimatedCost);
246     }
247
248     /**
249         @see ResultSetFactory#getHashTableResultSet
250         @exception StandardException thrown on error
251      */

252     public NoPutResultSet getHashTableResultSet(NoPutResultSet source,
253         GeneratedMethod singleTableRestriction,
254         Qualifier[][] equijoinQualifiers,
255         GeneratedMethod projection, int resultSetNumber,
256         int mapRefItem,
257         boolean reuseResult,
258         int keyColItem,
259         boolean removeDuplicates,
260         long maxInMemoryRowCount,
261         int initialCapacity,
262         float loadFactor,
263         double optimizerEstimatedRowCount,
264         double optimizerEstimatedCost)
265             throws StandardException
266     {
267         return new HashTableResultSet(source, source.getActivation(),
268             singleTableRestriction,
269             equijoinQualifiers,
270             projection, resultSetNumber,
271             mapRefItem,
272             reuseResult,
273             keyColItem, removeDuplicates,
274             maxInMemoryRowCount,
275             initialCapacity,
276             loadFactor,
277             true, // Skip rows with 1 or more null key columns
278
optimizerEstimatedRowCount,
279             optimizerEstimatedCost);
280     }
281
282     /**
283         @see ResultSetFactory#getSortResultSet
284         @exception StandardException thrown on error
285      */

286     public NoPutResultSet getSortResultSet(NoPutResultSet source,
287         boolean distinct,
288         boolean isInSortedOrder,
289         int orderItem,
290         GeneratedMethod rowAllocator,
291         int maxRowSize,
292         int resultSetNumber,
293         double optimizerEstimatedRowCount,
294         double optimizerEstimatedCost)
295             throws StandardException
296     {
297         return new SortResultSet(source,
298             distinct,
299             isInSortedOrder,
300             orderItem,
301             source.getActivation(),
302             rowAllocator,
303             maxRowSize,
304             resultSetNumber,
305             optimizerEstimatedRowCount,
306             optimizerEstimatedCost);
307     }
308
309     /**
310         @see ResultSetFactory#getScalarAggregateResultSet
311         @exception StandardException thrown on error
312      */

313     public NoPutResultSet getScalarAggregateResultSet(NoPutResultSet source,
314         boolean isInSortedOrder,
315         int aggregateItem,
316         int orderItem,
317         GeneratedMethod rowAllocator,
318         int maxRowSize,
319         int resultSetNumber,
320         boolean singleInputRow,
321         double optimizerEstimatedRowCount,
322         double optimizerEstimatedCost)
323             throws StandardException
324     {
325         return new ScalarAggregateResultSet(
326                         source, isInSortedOrder, aggregateItem, source.getActivation(),
327                         rowAllocator, resultSetNumber, singleInputRow,
328                         optimizerEstimatedRowCount,
329                         optimizerEstimatedCost);
330     }
331
332     /**
333         @see ResultSetFactory#getDistinctScalarAggregateResultSet
334         @exception StandardException thrown on error
335      */

336     public NoPutResultSet getDistinctScalarAggregateResultSet(NoPutResultSet source,
337         boolean isInSortedOrder,
338         int aggregateItem,
339         int orderItem,
340         GeneratedMethod rowAllocator,
341         int maxRowSize,
342         int resultSetNumber,
343         boolean singleInputRow,
344         double optimizerEstimatedRowCount,
345         double optimizerEstimatedCost)
346             throws StandardException
347     {
348         return new DistinctScalarAggregateResultSet(
349                         source, isInSortedOrder, aggregateItem, orderItem, source.getActivation(),
350                         rowAllocator, maxRowSize, resultSetNumber, singleInputRow,
351                         optimizerEstimatedRowCount,
352                         optimizerEstimatedCost);
353     }
354
355     /**
356         @see ResultSetFactory#getGroupedAggregateResultSet
357         @exception StandardException thrown on error
358      */

359     public NoPutResultSet getGroupedAggregateResultSet(NoPutResultSet source,
360         boolean isInSortedOrder,
361         int aggregateItem,
362         int orderItem,
363         GeneratedMethod rowAllocator,
364         int maxRowSize,
365         int resultSetNumber,
366         double optimizerEstimatedRowCount,
367         double optimizerEstimatedCost)
368             throws StandardException
369     {
370         return new GroupedAggregateResultSet(
371                         source, isInSortedOrder, aggregateItem, orderItem, source.getActivation(),
372                         rowAllocator, maxRowSize, resultSetNumber, optimizerEstimatedRowCount,
373                         optimizerEstimatedCost);
374     }
375
376     /**
377         @see ResultSetFactory#getDistinctGroupedAggregateResultSet
378         @exception StandardException thrown on error
379      */

380     public NoPutResultSet getDistinctGroupedAggregateResultSet(NoPutResultSet source,
381         boolean isInSortedOrder,
382         int aggregateItem,
383         int orderItem,
384         GeneratedMethod rowAllocator,
385         int maxRowSize,
386         int resultSetNumber,
387         double optimizerEstimatedRowCount,
388         double optimizerEstimatedCost)
389             throws StandardException
390     {
391         return new DistinctGroupedAggregateResultSet(
392                         source, isInSortedOrder, aggregateItem, orderItem, source.getActivation(),
393                         rowAllocator, maxRowSize, resultSetNumber, optimizerEstimatedRowCount,
394                         optimizerEstimatedCost);
395     }
396                                             
397
398     /**
399         @see ResultSetFactory#getAnyResultSet
400         @exception StandardException thrown on error
401      */

402     public NoPutResultSet getAnyResultSet(NoPutResultSet source,
403         GeneratedMethod emptyRowFun, int resultSetNumber,
404         int subqueryNumber, int pointOfAttachment,
405         double optimizerEstimatedRowCount,
406         double optimizerEstimatedCost)
407             throws StandardException
408     {
409         return new AnyResultSet(source,
410                      source.getActivation(), emptyRowFun, resultSetNumber,
411                      subqueryNumber, pointOfAttachment,
412                      optimizerEstimatedRowCount,
413                      optimizerEstimatedCost);
414     }
415
416     /**
417         @see ResultSetFactory#getOnceResultSet
418         @exception StandardException thrown on error
419      */

420     public NoPutResultSet getOnceResultSet(NoPutResultSet source,
421      GeneratedMethod emptyRowFun,
422         int cardinalityCheck, int resultSetNumber,
423         int subqueryNumber, int pointOfAttachment,
424         double optimizerEstimatedRowCount,
425         double optimizerEstimatedCost)
426             throws StandardException
427     {
428         return new OnceResultSet(source,
429                      source.getActivation(), emptyRowFun,
430                      cardinalityCheck, resultSetNumber,
431                      subqueryNumber, pointOfAttachment,
432                      optimizerEstimatedRowCount,
433                      optimizerEstimatedCost);
434     }
435
436     /**
437         @see ResultSetFactory#getRowResultSet
438      */

439     public NoPutResultSet getRowResultSet(Activation activation, GeneratedMethod row,
440                                      boolean canCacheRow,
441                                      int resultSetNumber,
442                                      double optimizerEstimatedRowCount,
443                                      double optimizerEstimatedCost)
444     {
445         return new RowResultSet(activation, row, canCacheRow, resultSetNumber,
446                                 optimizerEstimatedRowCount,
447                                 optimizerEstimatedCost);
448     }
449
450     /**
451         @see ResultSetFactory#getVTIResultSet
452         @exception StandardException thrown on error
453      */

454     public NoPutResultSet getVTIResultSet(Activation activation, GeneratedMethod row,
455                                      int resultSetNumber,
456                                      GeneratedMethod constructor,
457                                      String JavaDoc javaClassName,
458                                      Qualifier[][] pushedQualifiers,
459                                      int erdNumber,
460                                      boolean version2,
461                                      boolean reuseablePs,
462                                      int ctcNumber,
463                                      boolean isTarget,
464                                      int scanIsolationLevel,
465                                      double optimizerEstimatedRowCount,
466                                      double optimizerEstimatedCost)
467         throws StandardException
468     {
469         return new VTIResultSet(activation, row, resultSetNumber,
470                                 constructor,
471                                 javaClassName,
472                                 pushedQualifiers,
473                                 erdNumber,
474                                 version2, reuseablePs,
475                                 ctcNumber,
476                                 isTarget,
477                                 scanIsolationLevel,
478                                 optimizerEstimatedRowCount,
479                                 optimizerEstimatedCost);
480     }
481
482     /**
483         a hash scan generator, for ease of use at present.
484         @see ResultSetFactory#getHashScanResultSet
485         @exception StandardException thrown on error
486      */

487     public NoPutResultSet getHashScanResultSet(
488                                     Activation activation,
489                                     long conglomId,
490                                     int scociItem,
491                                     GeneratedMethod resultRowAllocator,
492                                     int resultSetNumber,
493                                     GeneratedMethod startKeyGetter,
494                                     int startSearchOperator,
495                                     GeneratedMethod stopKeyGetter,
496                                     int stopSearchOperator,
497                                     boolean sameStartStopPosition,
498                                     Qualifier[][] scanQualifiers,
499                                     Qualifier[][] nextQualifiers,
500                                     int initialCapacity,
501                                     float loadFactor,
502                                     int maxCapacity,
503                                     int hashKeyColumn,
504                                     String JavaDoc tableName,
505                                     String JavaDoc userSuppliedOptimizerOverrides,
506                                     String JavaDoc indexName,
507                                     boolean isConstraint,
508                                     boolean forUpdate,
509                                     int colRefItem,
510                                     int indexColItem,
511                                     int lockMode,
512                                     boolean tableLocked,
513                                     int isolationLevel,
514                                     double optimizerEstimatedRowCount,
515                                     double optimizerEstimatedCost)
516             throws StandardException
517     {
518         StaticCompiledOpenConglomInfo scoci = (StaticCompiledOpenConglomInfo)(activation.getPreparedStatement().
519                         getSavedObject(scociItem));
520
521         return new HashScanResultSet(
522                                 conglomId,
523                                 scoci,
524                                 activation,
525                                 resultRowAllocator,
526                                 resultSetNumber,
527                                 startKeyGetter,
528                                 startSearchOperator,
529                                 stopKeyGetter,
530                                 stopSearchOperator,
531                                 sameStartStopPosition,
532                                 scanQualifiers,
533                                 nextQualifiers,
534                                 initialCapacity,
535                                 loadFactor,
536                                 maxCapacity,
537                                 hashKeyColumn,
538                                 tableName,
539                                 userSuppliedOptimizerOverrides,
540                                 indexName,
541                                 isConstraint,
542                                 forUpdate,
543                                 colRefItem,
544                                 lockMode,
545                                 tableLocked,
546                                 isolationLevel,
547                                 true, // Skip rows with 1 or more null key columns
548
optimizerEstimatedRowCount,
549                                 optimizerEstimatedCost);
550     }
551
552     /**
553         a distinct scan generator, for ease of use at present.
554         @see ResultSetFactory#getHashScanResultSet
555         @exception StandardException thrown on error
556      */

557     public NoPutResultSet getDistinctScanResultSet(
558                                     Activation activation,
559                                     long conglomId,
560                                     int scociItem,
561                                     GeneratedMethod resultRowAllocator,
562                                     int resultSetNumber,
563                                     int hashKeyColumn,
564                                     String JavaDoc tableName,
565                                     String JavaDoc userSuppliedOptimizerOverrides,
566                                     String JavaDoc indexName,
567                                     boolean isConstraint,
568                                     int colRefItem,
569                                     int lockMode,
570                                     boolean tableLocked,
571                                     int isolationLevel,
572                                     double optimizerEstimatedRowCount,
573                                     double optimizerEstimatedCost)
574             throws StandardException
575     {
576         StaticCompiledOpenConglomInfo scoci = (StaticCompiledOpenConglomInfo)(activation.getPreparedStatement().
577                         getSavedObject(scociItem));
578         return new DistinctScanResultSet(
579                                 conglomId,
580                                 scoci,
581                                 activation,
582                                 resultRowAllocator,
583                                 resultSetNumber,
584                                 hashKeyColumn,
585                                 tableName,
586                                 userSuppliedOptimizerOverrides,
587                                 indexName,
588                                 isConstraint,
589                                 colRefItem,
590                                 lockMode,
591                                 tableLocked,
592                                 isolationLevel,
593                                 optimizerEstimatedRowCount,
594                                 optimizerEstimatedCost);
595     }
596
597     /**
598         a minimal table scan generator, for ease of use at present.
599         @see ResultSetFactory#getTableScanResultSet
600         @exception StandardException thrown on error
601      */

602     public NoPutResultSet getTableScanResultSet(
603                                     Activation activation,
604                                     long conglomId,
605                                     int scociItem,
606                                     GeneratedMethod resultRowAllocator,
607                                     int resultSetNumber,
608                                     GeneratedMethod startKeyGetter,
609                                     int startSearchOperator,
610                                     GeneratedMethod stopKeyGetter,
611                                     int stopSearchOperator,
612                                     boolean sameStartStopPosition,
613                                     Qualifier[][] qualifiers,
614                                     String JavaDoc tableName,
615                                     String JavaDoc userSuppliedOptimizerOverrides,
616                                     String JavaDoc indexName,
617                                     boolean isConstraint,
618                                     boolean forUpdate,
619                                     int colRefItem,
620                                     int indexColItem,
621                                     int lockMode,
622                                     boolean tableLocked,
623                                     int isolationLevel,
624                                     boolean oneRowScan,
625                                     double optimizerEstimatedRowCount,
626                                     double optimizerEstimatedCost)
627             throws StandardException
628     {
629         StaticCompiledOpenConglomInfo scoci = (StaticCompiledOpenConglomInfo)(activation.getPreparedStatement().
630                         getSavedObject(scociItem));
631         return new TableScanResultSet(
632                                 conglomId,
633                                 scoci,
634                                 activation,
635                                 resultRowAllocator,
636                                 resultSetNumber,
637                                 startKeyGetter,
638                                 startSearchOperator,
639                                 stopKeyGetter,
640                                 stopSearchOperator,
641                                 sameStartStopPosition,
642                                 qualifiers,
643                                 tableName,
644                                 userSuppliedOptimizerOverrides,
645                                 indexName,
646                                 isConstraint,
647                                 forUpdate,
648                                 colRefItem,
649                                 indexColItem,
650                                 lockMode,
651                                 tableLocked,
652                                 isolationLevel,
653                                 1, // rowsPerRead is 1 if not a bulkTableScan
654
oneRowScan,
655                                 optimizerEstimatedRowCount,
656                                 optimizerEstimatedCost);
657     }
658
659     /**
660         Table/Index scan where rows are read in bulk
661         @see ResultSetFactory#getBulkTableScanResultSet
662         @exception StandardException thrown on error
663      */

664     public NoPutResultSet getBulkTableScanResultSet(
665                                     Activation activation,
666                                     long conglomId,
667                                     int scociItem,
668                                     GeneratedMethod resultRowAllocator,
669                                     int resultSetNumber,
670                                     GeneratedMethod startKeyGetter,
671                                     int startSearchOperator,
672                                     GeneratedMethod stopKeyGetter,
673                                     int stopSearchOperator,
674                                     boolean sameStartStopPosition,
675                                     Qualifier[][] qualifiers,
676                                     String JavaDoc tableName,
677                                     String JavaDoc userSuppliedOptimizerOverrides,
678                                     String JavaDoc indexName,
679                                     boolean isConstraint,
680                                     boolean forUpdate,
681                                     int colRefItem,
682                                     int indexColItem,
683                                     int lockMode,
684                                     boolean tableLocked,
685                                     int isolationLevel,
686                                     int rowsPerRead,
687                                     boolean oneRowScan,
688                                     double optimizerEstimatedRowCount,
689                                     double optimizerEstimatedCost)
690             throws StandardException
691     {
692         //Prior to Cloudscape 10.0 release, holdability was false by default. Programmers had to explicitly
693
//set the holdability to true using JDBC apis. Since holdability was not true by default, we chose to disable the
694
//prefetching for RR and Serializable when holdability was explicitly set to true.
695
//But starting Cloudscape 10.0 release, in order to be DB2 compatible, holdability is set to true by default.
696
//Because of that, we can not continue to disable the prefetching for RR and Serializable, since it causes
697
//severe performance degradation - bug 5953.
698

699         StaticCompiledOpenConglomInfo scoci = (StaticCompiledOpenConglomInfo)(activation.getPreparedStatement().
700                         getSavedObject(scociItem));
701         return new BulkTableScanResultSet(
702                                 conglomId,
703                                 scoci,
704                                 activation,
705                                 resultRowAllocator,
706                                 resultSetNumber,
707                                 startKeyGetter,
708                                 startSearchOperator,
709                                 stopKeyGetter,
710                                 stopSearchOperator,
711                                 sameStartStopPosition,
712                                 qualifiers,
713                                 tableName,
714                                 userSuppliedOptimizerOverrides,
715                                 indexName,
716                                 isConstraint,
717                                 forUpdate,
718                                 colRefItem,
719                                 indexColItem,
720                                 lockMode,
721                                 tableLocked,
722                                 isolationLevel,
723                                 rowsPerRead,
724                                 oneRowScan,
725                                 optimizerEstimatedRowCount,
726                                 optimizerEstimatedCost);
727     }
728
729     /**
730         @see ResultSetFactory#getIndexRowToBaseRowResultSet
731         @exception StandardException Thrown on error
732      */

733     public NoPutResultSet getIndexRowToBaseRowResultSet(
734                                 long conglomId,
735                                 int scociItem,
736                                 NoPutResultSet source,
737                                 GeneratedMethod resultRowAllocator,
738                                 int resultSetNumber,
739                                 String JavaDoc indexName,
740                                 int heapColRefItem,
741                                 int indexColRefItem,
742                                 int indexColMapItem,
743                                 GeneratedMethod restriction,
744                                 boolean forUpdate,
745                                 double optimizerEstimatedRowCount,
746                                 double optimizerEstimatedCost)
747             throws StandardException
748     {
749         return new IndexRowToBaseRowResultSet(
750                                 conglomId,
751                                 scociItem,
752                                 source.getActivation(),
753                                 source,
754                                 resultRowAllocator,
755                                 resultSetNumber,
756                                 indexName,
757                                 heapColRefItem,
758                                 indexColRefItem,
759                                 indexColMapItem,
760                                 restriction,
761                                 forUpdate,
762                                 optimizerEstimatedRowCount,
763                                 optimizerEstimatedCost);
764     }
765
766     /**
767         @see ResultSetFactory#getNestedLoopJoinResultSet
768         @exception StandardException thrown on error
769      */

770
771     public NoPutResultSet getNestedLoopJoinResultSet(NoPutResultSet leftResultSet,
772                                    int leftNumCols,
773                                    NoPutResultSet rightResultSet,
774                                    int rightNumCols,
775                                    GeneratedMethod joinClause,
776                                    int resultSetNumber,
777                                    boolean oneRowRightSide,
778                                    boolean notExistsRightSide,
779                                    double optimizerEstimatedRowCount,
780                                    double optimizerEstimatedCost,
781                                    String JavaDoc userSuppliedOptimizerOverrides)
782             throws StandardException
783     {
784         return new NestedLoopJoinResultSet(leftResultSet, leftNumCols,
785                                            rightResultSet, rightNumCols,
786                                            leftResultSet.getActivation(), joinClause,
787                                            resultSetNumber,
788                                            oneRowRightSide,
789                                            notExistsRightSide,
790                                            optimizerEstimatedRowCount,
791                                            optimizerEstimatedCost,
792                                            userSuppliedOptimizerOverrides);
793     }
794
795     /**
796         @see ResultSetFactory#getHashJoinResultSet
797         @exception StandardException thrown on error
798      */

799
800     public NoPutResultSet getHashJoinResultSet(NoPutResultSet leftResultSet,
801                                    int leftNumCols,
802                                    NoPutResultSet rightResultSet,
803                                    int rightNumCols,
804                                    GeneratedMethod joinClause,
805                                    int resultSetNumber,
806                                    boolean oneRowRightSide,
807                                    boolean notExistsRightSide,
808                                    double optimizerEstimatedRowCount,
809                                    double optimizerEstimatedCost,
810                                    String JavaDoc userSuppliedOptimizerOverrides)
811             throws StandardException
812     {
813         return new HashJoinResultSet(leftResultSet, leftNumCols,
814                                            rightResultSet, rightNumCols,
815                                            leftResultSet.getActivation(), joinClause,
816                                            resultSetNumber,
817                                            oneRowRightSide,
818                                            notExistsRightSide,
819                                            optimizerEstimatedRowCount,
820                                            optimizerEstimatedCost,
821                                            userSuppliedOptimizerOverrides);
822     }
823
824     /**
825         @see ResultSetFactory#getNestedLoopLeftOuterJoinResultSet
826         @exception StandardException thrown on error
827      */

828
829     public NoPutResultSet getNestedLoopLeftOuterJoinResultSet(NoPutResultSet leftResultSet,
830                                    int leftNumCols,
831                                    NoPutResultSet rightResultSet,
832                                    int rightNumCols,
833                                    GeneratedMethod joinClause,
834                                    int resultSetNumber,
835                                    GeneratedMethod emptyRowFun,
836                                    boolean wasRightOuterJoin,
837                                    boolean oneRowRightSide,
838                                    boolean notExistsRightSide,
839                                    double optimizerEstimatedRowCount,
840                                    double optimizerEstimatedCost,
841                                    String JavaDoc userSuppliedOptimizerOverrides)
842             throws StandardException
843     {
844         return new NestedLoopLeftOuterJoinResultSet(leftResultSet, leftNumCols,
845                                            rightResultSet, rightNumCols,
846                                            leftResultSet.getActivation(), joinClause,
847                                            resultSetNumber,
848                                            emptyRowFun,
849                                            wasRightOuterJoin,
850                                            oneRowRightSide,
851                                            notExistsRightSide,
852                                            optimizerEstimatedRowCount,
853                                            optimizerEstimatedCost,
854                                            userSuppliedOptimizerOverrides);
855     }
856
857     /**
858         @see ResultSetFactory#getHashLeftOuterJoinResultSet
859         @exception StandardException thrown on error
860      */

861
862     public NoPutResultSet getHashLeftOuterJoinResultSet(NoPutResultSet leftResultSet,
863                                    int leftNumCols,
864                                    NoPutResultSet rightResultSet,
865                                    int rightNumCols,
866                                    GeneratedMethod joinClause,
867                                    int resultSetNumber,
868                                    GeneratedMethod emptyRowFun,
869                                    boolean wasRightOuterJoin,
870                                    boolean oneRowRightSide,
871                                    boolean notExistsRightSide,
872                                    double optimizerEstimatedRowCount,
873                                    double optimizerEstimatedCost,
874                                    String JavaDoc userSuppliedOptimizerOverrides)
875             throws StandardException
876     {
877         return new HashLeftOuterJoinResultSet(leftResultSet, leftNumCols,
878                                            rightResultSet, rightNumCols,
879                                            leftResultSet.getActivation(), joinClause,
880                                            resultSetNumber,
881                                            emptyRowFun,
882                                            wasRightOuterJoin,
883                                            oneRowRightSide,
884                                            notExistsRightSide,
885                                            optimizerEstimatedRowCount,
886                                            optimizerEstimatedCost,
887                                            userSuppliedOptimizerOverrides);
888     }
889
890     /**
891         @see ResultSetFactory#getSetTransactionResultSet
892         @exception StandardException thrown when unable to create the
893             result set
894      */

895     public ResultSet getSetTransactionResultSet(Activation activation)
896         throws StandardException
897     {
898         getAuthorizer(activation).authorize(activation, Authorizer.SQL_ARBITARY_OP);
899         return new SetTransactionResultSet(activation);
900     }
901
902     /**
903         @see ResultSetFactory#getMaterializedResultSet
904         @exception StandardException thrown on error
905      */

906     public NoPutResultSet getMaterializedResultSet(NoPutResultSet source,
907                             int resultSetNumber,
908                             double optimizerEstimatedRowCount,
909                             double optimizerEstimatedCost)
910         throws StandardException
911     {
912         return new MaterializedResultSet(source, source.getActivation(),
913                                       resultSetNumber,
914                                       optimizerEstimatedRowCount,
915                                       optimizerEstimatedCost);
916     }
917
918     /**
919         @see ResultSetFactory#getScrollInsensitiveResultSet
920         @exception StandardException thrown on error
921      */

922     public NoPutResultSet getScrollInsensitiveResultSet(NoPutResultSet source,
923                             Activation activation, int resultSetNumber,
924                             int sourceRowWidth,
925                             boolean scrollable,
926                             double optimizerEstimatedRowCount,
927                             double optimizerEstimatedCost)
928         throws StandardException
929     {
930         /* ResultSet tree is dependent on whether or not this is
931          * for a scroll insensitive cursor.
932          */

933
934         if (scrollable)
935         {
936             return new ScrollInsensitiveResultSet(source, activation,
937                                       resultSetNumber,
938                                       sourceRowWidth,
939                                       optimizerEstimatedRowCount,
940                                       optimizerEstimatedCost);
941         }
942         else
943         {
944             return source;
945         }
946     }
947
948     /**
949         @see ResultSetFactory#getNormalizeResultSet
950         @exception StandardException thrown on error
951      */

952     public NoPutResultSet getNormalizeResultSet(NoPutResultSet source,
953                             int resultSetNumber,
954                             int erdNumber,
955                             double optimizerEstimatedRowCount,
956                             double optimizerEstimatedCost,
957                             boolean forUpdate)
958         throws StandardException
959     {
960         return new NormalizeResultSet(source, source.getActivation(),
961                                       resultSetNumber, erdNumber,
962                                       optimizerEstimatedRowCount,
963                                       optimizerEstimatedCost, forUpdate);
964     }
965
966     /**
967         @see ResultSetFactory#getCurrentOfResultSet
968      */

969     public NoPutResultSet getCurrentOfResultSet(String JavaDoc cursorName,
970         Activation activation, int resultSetNumber, String JavaDoc psName)
971     {
972         return new CurrentOfResultSet(cursorName, activation, resultSetNumber, psName);
973     }
974
975     /**
976         @see ResultSetFactory#getDDLResultSet
977         @exception StandardException thrown on error
978      */

979     public ResultSet getDDLResultSet(Activation activation)
980                     throws StandardException
981     {
982         getAuthorizer(activation).authorize(activation, Authorizer.SQL_DDL_OP);
983         return getMiscResultSet( activation);
984     }
985
986     /**
987         @see ResultSetFactory#getMiscResultSet
988         @exception StandardException thrown on error
989      */

990     public ResultSet getMiscResultSet(Activation activation)
991                     throws StandardException
992     {
993         getAuthorizer(activation).authorize(activation, Authorizer.SQL_ARBITARY_OP);
994         return new MiscResultSet(activation);
995     }
996
997     /**
998         a minimal union scan generator, for ease of use at present.
999         @see ResultSetFactory#getUnionResultSet
1000        @exception StandardException thrown on error
1001     */

1002    public NoPutResultSet getUnionResultSet(NoPutResultSet leftResultSet,
1003                                   NoPutResultSet rightResultSet,
1004                                   int resultSetNumber,
1005                                   double optimizerEstimatedRowCount,
1006                                   double optimizerEstimatedCost)
1007            throws StandardException
1008    {
1009        return new UnionResultSet(leftResultSet, rightResultSet,
1010                                  leftResultSet.getActivation(),
1011                                  resultSetNumber,
1012                                  optimizerEstimatedRowCount,
1013                                  optimizerEstimatedCost);
1014    }
1015
1016    public NoPutResultSet getSetOpResultSet( NoPutResultSet leftSource,
1017                                             NoPutResultSet rightSource,
1018                                             Activation activation,
1019                                             int resultSetNumber,
1020                                             long optimizerEstimatedRowCount,
1021                                             double optimizerEstimatedCost,
1022                                             int opType,
1023                                             boolean all,
1024                                            int intermediateOrderByColumnsSavedObject,
1025                                             int intermediateOrderByDirectionSavedObject)
1026        throws StandardException
1027    {
1028        return new SetOpResultSet( leftSource,
1029                                   rightSource,
1030                                   activation,
1031                                   resultSetNumber,
1032                                   optimizerEstimatedRowCount,
1033                                   optimizerEstimatedCost,
1034                                   opType,
1035                                   all,
1036                                   intermediateOrderByColumnsSavedObject,
1037                                   intermediateOrderByDirectionSavedObject);
1038    }
1039
1040    /**
1041     * A last index key sresult set returns the last row from
1042     * the index in question. It is used as an ajunct to max().
1043     *
1044     * @param activation the activation for this result set,
1045     * which provides the context for the row allocation operation.
1046     * @param resultSetNumber The resultSetNumber for the ResultSet
1047     * @param resultRowAllocator a reference to a method in the activation
1048     * that creates a holder for the result row of the scan. May
1049     * be a partial row. <verbatim>
1050     * ExecRow rowAllocator() throws StandardException; </verbatim>
1051     * @param conglomId the conglomerate of the table to be scanned.
1052     * @param tableName The full name of the table
1053     * @param userSuppliedOptimizerOverrides Overrides specified by the user on the sql
1054     * @param indexName The name of the index, if one used to access table.
1055     * @param colRefItem An saved item for a bitSet of columns that
1056     * are referenced in the underlying table. -1 if
1057     * no item.
1058     * @param lockMode The lock granularity to use (see
1059     * TransactionController in access)
1060     * @param tableLocked Whether or not the table is marked as using table locking
1061     * (in sys.systables)
1062     * @param isolationLevel Isolation level (specified or not) to use on scans
1063     * @param optimizerEstimatedRowCount Estimated total # of rows by
1064     * optimizer
1065     * @param optimizerEstimatedCost Estimated total cost by optimizer
1066     *
1067     * @return the scan operation as a result set.
1068     *
1069     * @exception StandardException thrown when unable to create the
1070     * result set
1071     */

1072    public NoPutResultSet getLastIndexKeyResultSet
1073    (
1074        Activation activation,
1075        int resultSetNumber,
1076        GeneratedMethod resultRowAllocator,
1077        long conglomId,
1078        String JavaDoc tableName,
1079        String JavaDoc userSuppliedOptimizerOverrides,
1080        String JavaDoc indexName,
1081        int colRefItem,
1082        int lockMode,
1083        boolean tableLocked,
1084        int isolationLevel,
1085        double optimizerEstimatedRowCount,
1086        double optimizerEstimatedCost
1087    ) throws StandardException
1088    {
1089        return new LastIndexKeyResultSet(
1090                    activation,
1091                    resultSetNumber,
1092                    resultRowAllocator,
1093                    conglomId,
1094                    tableName,
1095                    userSuppliedOptimizerOverrides,
1096                    indexName,
1097                    colRefItem,
1098                    lockMode,
1099                    tableLocked,
1100                    isolationLevel,
1101                    optimizerEstimatedRowCount,
1102                    optimizerEstimatedCost);
1103    }
1104
1105
1106
1107    /**
1108     * a referential action dependent table scan generator.
1109     * @see ResultSetFactory#getTableScanResultSet
1110     * @exception StandardException thrown on error
1111     */

1112    public NoPutResultSet getRaDependentTableScanResultSet(
1113                                    Activation activation,
1114                                    long conglomId,
1115                                    int scociItem,
1116                                    GeneratedMethod resultRowAllocator,
1117                                    int resultSetNumber,
1118                                    GeneratedMethod startKeyGetter,
1119                                    int startSearchOperator,
1120                                    GeneratedMethod stopKeyGetter,
1121                                    int stopSearchOperator,
1122                                    boolean sameStartStopPosition,
1123                                    Qualifier[][] qualifiers,
1124                                    String JavaDoc tableName,
1125                                    String JavaDoc userSuppliedOptimizerOverrides,
1126                                    String JavaDoc indexName,
1127                                    boolean isConstraint,
1128                                    boolean forUpdate,
1129                                    int colRefItem,
1130                                    int indexColItem,
1131                                    int lockMode,
1132                                    boolean tableLocked,
1133                                    int isolationLevel,
1134                                    boolean oneRowScan,
1135                                    double optimizerEstimatedRowCount,
1136                                    double optimizerEstimatedCost,
1137                                    String JavaDoc parentResultSetId,
1138                                    long fkIndexConglomId,
1139                                    int fkColArrayItem,
1140                                    int rltItem)
1141            throws StandardException
1142    {
1143        StaticCompiledOpenConglomInfo scoci = (StaticCompiledOpenConglomInfo)(activation.getPreparedStatement().
1144                        getSavedObject(scociItem));
1145        return new DependentResultSet(
1146                                conglomId,
1147                                scoci,
1148                                activation,
1149                                resultRowAllocator,
1150                                resultSetNumber,
1151                                startKeyGetter,
1152                                startSearchOperator,
1153                                stopKeyGetter,
1154                                stopSearchOperator,
1155                                sameStartStopPosition,
1156                                qualifiers,
1157                                tableName,
1158                                userSuppliedOptimizerOverrides,
1159                                indexName,
1160                                isConstraint,
1161                                forUpdate,
1162                                colRefItem,
1163                                lockMode,
1164                                tableLocked,
1165                                isolationLevel,
1166                                1,
1167                                oneRowScan,
1168                                optimizerEstimatedRowCount,
1169                                optimizerEstimatedCost,
1170                                parentResultSetId,
1171                                fkIndexConglomId,
1172                                fkColArrayItem,
1173                                rltItem);
1174    }
1175    
1176    static private Authorizer getAuthorizer(Activation activation)
1177    {
1178        LanguageConnectionContext lcc = activation.getLanguageConnectionContext();
1179        return lcc.getAuthorizer();
1180    }
1181
1182
1183   /////////////////////////////////////////////////////////////////
1184
//
1185
// PUBLIC MINIONS
1186
//
1187
/////////////////////////////////////////////////////////////////
1188

1189}
1190
Popular Tags