001: /*
002:
003: Derby - Class org.apache.derby.impl.sql.execute.IndexRow
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to you under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021:
022: package org.apache.derby.impl.sql.execute;
023:
024: import org.apache.derby.iapi.services.sanity.SanityManager;
025:
026: import org.apache.derby.iapi.sql.execute.ExecIndexRow;
027: import org.apache.derby.iapi.sql.execute.ExecRow;
028:
029: import org.apache.derby.iapi.services.io.Formatable;
030: import org.apache.derby.iapi.services.io.StoredFormatIds;
031: import org.apache.derby.iapi.services.io.FormatIdUtil;
032:
033: import org.apache.derby.iapi.services.stream.HeaderPrintWriter;
034:
035: import java.io.ObjectOutput;
036: import java.io.ObjectInput;
037: import java.io.IOException;
038:
039: /**
040: Basic implementation of ExecIndexRow.
041:
042: @author jeff
043: */
044: public class IndexRow extends ValueRow implements ExecIndexRow {
045: /********************************************************
046: **
047: ** This class implements Formatable. That means that it
048: ** can write itself to and from a formatted stream. If
049: ** you add more fields to this class, make sure that you
050: ** also write/read them with the writeExternal()/readExternal()
051: ** methods.
052: **
053: ** If, inbetween releases, you add more fields to this class,
054: ** then you should bump the version number emitted by the getTypeFormatId()
055: ** method.
056: **
057: ********************************************************/
058:
059: ///////////////////////////////////////////////////////////////////////
060: //
061: // STATE
062: //
063: ///////////////////////////////////////////////////////////////////////
064:
065: private boolean[] orderedNulls;
066:
067: ///////////////////////////////////////////////////////////////////////
068: //
069: // CONSTRUCTORS
070: //
071: ///////////////////////////////////////////////////////////////////////
072:
073: /**
074: * Public niladic constructor. Needed for Formatable interface to work.
075: *
076: */
077: public IndexRow() {
078: }
079:
080: public IndexRow(int ncols) {
081: super (ncols);
082: orderedNulls = new boolean[ncols]; /* Initializes elements to false */
083: }
084:
085: ///////////////////////////////////////////////////////////////////////
086: //
087: // EXECINDEXROW INTERFACE
088: //
089: ///////////////////////////////////////////////////////////////////////
090:
091: /* Column positions are one-based, arrays are zero-based */
092: public void orderedNulls(int columnPosition) {
093: orderedNulls[columnPosition] = true;
094: }
095:
096: public boolean areNullsOrdered(int columnPosition) {
097: return orderedNulls[columnPosition];
098: }
099:
100: /**
101: * Turn the ExecRow into an ExecIndexRow.
102: */
103: public void execRowToExecIndexRow(ExecRow valueRow) {
104: if (SanityManager.DEBUG) {
105: SanityManager
106: .THROWASSERT("execRowToExecIndexRow() not expected to be called for IndexRow");
107: }
108: }
109:
110: ///////////////////////////////////////////////////////////////////////
111: //
112: // FORMATABLE INTERFACE
113: //
114: ///////////////////////////////////////////////////////////////////////
115:
116: /**
117: * Read this object from a stream of stored objects.
118: *
119: * @param in read this.
120: *
121: * @exception IOException thrown on error
122: * @exception ClassNotFoundException thrown on error
123: */
124: public void readExternal(ObjectInput in) throws IOException,
125: ClassNotFoundException {
126: super .readExternal(in);
127:
128: int colCount = nColumns();
129:
130: orderedNulls = new boolean[colCount];
131: for (int ictr = 0; ictr < colCount; ictr++) {
132: orderedNulls[ictr] = in.readBoolean();
133: }
134: }
135:
136: /**
137: * Write this object to a stream of stored objects.
138: *
139: * @param out write bytes here.
140: *
141: * @exception IOException thrown on error
142: */
143: public void writeExternal(ObjectOutput out) throws IOException {
144: super .writeExternal(out);
145: int colCount = nColumns();
146:
147: for (int ictr = 0; ictr < colCount; ictr++) {
148: out.writeBoolean(orderedNulls[ictr]);
149: }
150: }
151:
152: /**
153: * Get the formatID which corresponds to this class.
154: *
155: * @return the formatID of this class
156: */
157: public int getTypeFormatId() {
158: return StoredFormatIds.INDEX_ROW_V01_ID;
159: }
160:
161: ExecRow cloneMe() {
162: return new IndexRow(nColumns());
163: }
164: }
|