KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Derby - Class org.apache.derby.impl.sql.execute.IndexColumnOrder
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.store.access.ColumnOrdering;
25
26 import org.apache.derby.iapi.services.io.StoredFormatIds;
27 import org.apache.derby.iapi.services.io.FormatIdUtil;
28 import org.apache.derby.iapi.services.io.Formatable;
29
30 import java.io.ObjectOutput JavaDoc;
31 import java.io.ObjectInput JavaDoc;
32 import java.io.IOException JavaDoc;
33 /**
34     Basic implementation of ColumnOrdering.
35     Not sure what to tell callers about 0-based versus 1-based numbering.
36     Assume 0-based for now.
37
38     @author ames
39  */

40 public class IndexColumnOrder implements ColumnOrdering, Formatable
41 {
42     /********************************************************
43     **
44     ** This class implements Formatable. That means that it
45     ** can write itself to and from a formatted stream. If
46     ** you add more fields to this class, make sure that you
47     ** also write/read them with the writeExternal()/readExternal()
48     ** methods.
49     **
50     ** If, inbetween releases, you add more fields to this class,
51     ** then you should bump the version number emitted by the getTypeFormatId()
52     ** method.
53     **
54     ********************************************************/

55
56     int colNum;
57     boolean ascending;
58
59     /*
60      * class interface
61      */

62
63     /**
64      * Niladic constructor for formatable
65      */

66     public IndexColumnOrder()
67     {
68     }
69
70     public IndexColumnOrder(int colNum) {
71          this.colNum = colNum;
72          this.ascending = true;
73     }
74
75     public IndexColumnOrder(int colNum, boolean ascending) {
76          this.colNum = colNum;
77          this.ascending = ascending;
78     }
79
80     /*
81      * ColumnOrdering interface
82      */

83     public int getColumnId() {
84         return colNum;
85     }
86
87     public boolean getIsAscending() {
88         return ascending;
89     }
90
91     //////////////////////////////////////////////
92
//
93
// FORMATABLE
94
//
95
//////////////////////////////////////////////
96
/**
97      * Write this object out
98      *
99      * @param out write bytes here
100      *
101      * @exception IOException thrown on error
102      */

103     public void writeExternal(ObjectOutput JavaDoc out) throws IOException JavaDoc
104     {
105         out.writeInt(colNum);
106         out.writeBoolean(ascending);
107     }
108
109     /**
110      * Read this object from a stream of stored objects.
111      *
112      * @param in read this.
113      *
114      * @exception IOException thrown on error
115      * @exception ClassNotFoundException thrown on error
116      */

117     public void readExternal(ObjectInput JavaDoc in)
118         throws IOException JavaDoc, ClassNotFoundException JavaDoc
119     {
120         colNum = in.readInt();
121         ascending = in.readBoolean();
122     }
123     
124     /**
125      * Get the formatID which corresponds to this class.
126      *
127      * @return the formatID of this class
128      */

129     public int getTypeFormatId() { return StoredFormatIds.INDEX_COLUMN_ORDER_V01_ID; }
130 }
131
Popular Tags