001: /*
002:
003: Derby - Class org.apache.derby.impl.sql.execute.IndexColumnOrder
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.store.access.ColumnOrdering;
025:
026: import org.apache.derby.iapi.services.io.StoredFormatIds;
027: import org.apache.derby.iapi.services.io.FormatIdUtil;
028: import org.apache.derby.iapi.services.io.Formatable;
029:
030: import java.io.ObjectOutput;
031: import java.io.ObjectInput;
032: import java.io.IOException;
033:
034: /**
035: Basic implementation of ColumnOrdering.
036: Not sure what to tell callers about 0-based versus 1-based numbering.
037: Assume 0-based for now.
038:
039: @author ames
040: */
041: public class IndexColumnOrder implements ColumnOrdering, Formatable {
042: /********************************************************
043: **
044: ** This class implements Formatable. That means that it
045: ** can write itself to and from a formatted stream. If
046: ** you add more fields to this class, make sure that you
047: ** also write/read them with the writeExternal()/readExternal()
048: ** methods.
049: **
050: ** If, inbetween releases, you add more fields to this class,
051: ** then you should bump the version number emitted by the getTypeFormatId()
052: ** method.
053: **
054: ********************************************************/
055:
056: int colNum;
057: boolean ascending;
058:
059: /*
060: * class interface
061: */
062:
063: /**
064: * Niladic constructor for formatable
065: */
066: public IndexColumnOrder() {
067: }
068:
069: public IndexColumnOrder(int colNum) {
070: this .colNum = colNum;
071: this .ascending = true;
072: }
073:
074: public IndexColumnOrder(int colNum, boolean ascending) {
075: this .colNum = colNum;
076: this .ascending = ascending;
077: }
078:
079: /*
080: * ColumnOrdering interface
081: */
082: public int getColumnId() {
083: return colNum;
084: }
085:
086: public boolean getIsAscending() {
087: return ascending;
088: }
089:
090: //////////////////////////////////////////////
091: //
092: // FORMATABLE
093: //
094: //////////////////////////////////////////////
095: /**
096: * Write this object out
097: *
098: * @param out write bytes here
099: *
100: * @exception IOException thrown on error
101: */
102: public void writeExternal(ObjectOutput out) throws IOException {
103: out.writeInt(colNum);
104: out.writeBoolean(ascending);
105: }
106:
107: /**
108: * Read this object from a stream of stored objects.
109: *
110: * @param in read this.
111: *
112: * @exception IOException thrown on error
113: * @exception ClassNotFoundException thrown on error
114: */
115: public void readExternal(ObjectInput in) throws IOException,
116: ClassNotFoundException {
117: colNum = in.readInt();
118: ascending = in.readBoolean();
119: }
120:
121: /**
122: * Get the formatID which corresponds to this class.
123: *
124: * @return the formatID of this class
125: */
126: public int getTypeFormatId() {
127: return StoredFormatIds.INDEX_COLUMN_ORDER_V01_ID;
128: }
129: }
|