KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > store > access > sort > SortBufferScan


1 /*
2
3    Derby - Class org.apache.derby.impl.store.access.sort.SortBufferScan
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.store.access.sort;
23
24 import org.apache.derby.iapi.services.sanity.SanityManager;
25
26 import org.apache.derby.iapi.error.StandardException;
27 import org.apache.derby.iapi.store.access.ScanController;
28 import org.apache.derby.iapi.store.access.conglomerate.TransactionManager;
29
30 /**
31
32   A sort scan that just reads rows out of a sorter.
33
34 **/

35
36 public class SortBufferScan extends SortScan
37 {
38     /**
39     The sorter we're returning rows from.
40     **/

41     protected SortBuffer sortBuffer;
42
43     /*
44      * Constructors.
45      */

46
47     SortBufferScan(
48     MergeSort sort,
49     TransactionManager tran,
50     SortBuffer sortBuffer,
51     boolean hold)
52     {
53         super(sort, tran, hold);
54
55         if (SanityManager.DEBUG)
56             SanityManager.ASSERT(sortBuffer != null);
57
58         this.sortBuffer = sortBuffer;
59     }
60
61     /*
62      * Methods of MergeSortScan
63      */

64
65     /**
66     Move to the next position in the scan.
67     @see ScanController#next
68     **/

69     public boolean next()
70         throws StandardException
71     {
72         if (SanityManager.DEBUG)
73         {
74             SanityManager.ASSERT(
75                 sortBuffer != null,
76                 "next() called on scan after scan was closed.");
77         }
78
79         super.current = sortBuffer.removeFirst();
80         return (super.current != null);
81     }
82
83     /**
84     Close the scan.
85     **/

86     public boolean closeForEndTransaction(boolean closeHeldScan)
87     {
88         if (closeHeldScan || !hold)
89         {
90             close();
91             return(true);
92         }
93         else
94         {
95             return(false);
96         }
97
98     }
99
100     /**
101     Close the scan.
102     @see ScanController#close
103     **/

104     public void close()
105     {
106         if (super.sort != null)
107         {
108             sort.doneScanning(this, sortBuffer);
109             sortBuffer = null;
110         }
111         super.close();
112     }
113
114 }
115
Popular Tags