KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Derby - Class org.apache.derby.impl.sql.execute.IndexRow
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.services.sanity.SanityManager;
25
26 import org.apache.derby.iapi.sql.execute.ExecIndexRow;
27 import org.apache.derby.iapi.sql.execute.ExecRow;
28
29 import org.apache.derby.iapi.services.io.Formatable;
30 import org.apache.derby.iapi.services.io.StoredFormatIds;
31 import org.apache.derby.iapi.services.io.FormatIdUtil;
32
33 import org.apache.derby.iapi.services.stream.HeaderPrintWriter;
34
35 import java.io.ObjectOutput JavaDoc;
36 import java.io.ObjectInput JavaDoc;
37 import java.io.IOException JavaDoc;
38
39
40 /**
41     Basic implementation of ExecIndexRow.
42
43     @author jeff
44  */

45 public class IndexRow extends ValueRow implements ExecIndexRow
46 {
47     /********************************************************
48     **
49     ** This class implements Formatable. That means that it
50     ** can write itself to and from a formatted stream. If
51     ** you add more fields to this class, make sure that you
52     ** also write/read them with the writeExternal()/readExternal()
53     ** methods.
54     **
55     ** If, inbetween releases, you add more fields to this class,
56     ** then you should bump the version number emitted by the getTypeFormatId()
57     ** method.
58     **
59     ********************************************************/

60
61     ///////////////////////////////////////////////////////////////////////
62
//
63
// STATE
64
//
65
///////////////////////////////////////////////////////////////////////
66

67
68     private boolean[] orderedNulls;
69
70     ///////////////////////////////////////////////////////////////////////
71
//
72
// CONSTRUCTORS
73
//
74
///////////////////////////////////////////////////////////////////////
75

76     /**
77      * Public niladic constructor. Needed for Formatable interface to work.
78      *
79      */

80     public IndexRow() {}
81
82     public IndexRow(int ncols) {
83          super(ncols);
84          orderedNulls = new boolean[ncols]; /* Initializes elements to false */
85     }
86
87     ///////////////////////////////////////////////////////////////////////
88
//
89
// EXECINDEXROW INTERFACE
90
//
91
///////////////////////////////////////////////////////////////////////
92

93     /* Column positions are one-based, arrays are zero-based */
94     public void orderedNulls(int columnPosition) {
95         orderedNulls[columnPosition] = true;
96     }
97
98     public boolean areNullsOrdered(int columnPosition) {
99         return orderedNulls[columnPosition];
100     }
101
102     /**
103      * Turn the ExecRow into an ExecIndexRow.
104      */

105     public void execRowToExecIndexRow(ExecRow valueRow)
106     {
107         if (SanityManager.DEBUG)
108         {
109             SanityManager.THROWASSERT(
110                 "execRowToExecIndexRow() not expected to be called for IndexRow");
111         }
112     }
113
114     ///////////////////////////////////////////////////////////////////////
115
//
116
// FORMATABLE INTERFACE
117
//
118
///////////////////////////////////////////////////////////////////////
119

120     /**
121      * Read this object from a stream of stored objects.
122      *
123      * @param in read this.
124      *
125      * @exception IOException thrown on error
126      * @exception ClassNotFoundException thrown on error
127      */

128     public void readExternal( ObjectInput JavaDoc in )
129          throws IOException JavaDoc, ClassNotFoundException JavaDoc
130     {
131         super.readExternal( in );
132
133         int colCount = nColumns();
134
135         orderedNulls = new boolean[ colCount ];
136         for ( int ictr = 0; ictr < colCount; ictr++ ) { orderedNulls[ ictr ] = in.readBoolean(); }
137     }
138
139     /**
140      * Write this object to a stream of stored objects.
141      *
142      * @param out write bytes here.
143      *
144      * @exception IOException thrown on error
145      */

146     public void writeExternal( ObjectOutput JavaDoc out )
147          throws IOException JavaDoc
148     {
149         super.writeExternal( out );
150         int colCount = nColumns();
151
152         for ( int ictr = 0; ictr < colCount; ictr++ ) { out.writeBoolean( orderedNulls[ ictr ] ); }
153     }
154
155     /**
156      * Get the formatID which corresponds to this class.
157      *
158      * @return the formatID of this class
159      */

160     public int getTypeFormatId() { return StoredFormatIds.INDEX_ROW_V01_ID; }
161
162     ExecRow cloneMe() {
163         return new IndexRow(nColumns());
164     }
165 }
166
Popular Tags