KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mckoi > database > DataIndexDef


1 /**
2  * com.mckoi.database.DataIndexDef 07 Sep 2002
3  *
4  * Mckoi SQL Database ( http://www.mckoi.com/database )
5  * Copyright (C) 2000, 2001, 2002 Diehl and Associates, Inc.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * Version 2 as published by the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License Version 2 for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * Version 2 along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19  *
20  * Change Log:
21  *
22  *
23  */

24
25 package com.mckoi.database;
26
27 import java.io.DataInput JavaDoc;
28 import java.io.DataOutput JavaDoc;
29 import java.io.IOException JavaDoc;
30
31 /**
32  * Represents index meta-information on a table. This information is part of
33  * DataIndexSetDef and is stored with the contents of a table.
34  *
35  * @author Tobias Downer
36  */

37
38 public class DataIndexDef {
39
40   /**
41    * The name of this index.
42    */

43   private String JavaDoc index_name;
44
45   /**
46    * The list of column name that this index represents. For example, if this
47    * is a composite primary key, this would contain each column name in the
48    * primary key.
49    */

50   private String JavaDoc[] column_names;
51
52   /**
53    * Returns the index set pointer of this index. This value is used when
54    * requesting the index from an IndexSet.
55    */

56   private int index_pointer;
57
58   /**
59    * The type of Index this is. Currently only 'BLIST' is supported.
60    */

61   private String JavaDoc index_type;
62
63   /**
64    * True if this index may only contain unique values.
65    */

66   private boolean unique;
67
68   /**
69    * Constructor.
70    */

71   public DataIndexDef(String JavaDoc index_name, String JavaDoc[] column_names,
72                       int index_pointer, String JavaDoc index_type, boolean unique) {
73
74     this.index_name = index_name;
75     this.column_names = (String JavaDoc[]) column_names.clone();
76     this.index_pointer = index_pointer;
77     this.index_type = index_type;
78     this.unique = unique;
79
80   }
81
82   public DataIndexDef(DataIndexDef def) {
83     this(def.index_name, def.column_names, def.index_pointer, def.index_type,
84          def.unique);
85   }
86   
87   /**
88    * Returns the name of this index.
89    */

90   public String JavaDoc getName() {
91     return index_name;
92   }
93
94   /**
95    * Returns the column names that make up this index.
96    */

97   public String JavaDoc[] getColumnNames() {
98     return column_names;
99   }
100
101   /**
102    * Returns the pointer to the index in the IndexSet.
103    */

104   public int getPointer() {
105     return index_pointer;
106   }
107   
108   /**
109    * Returns a String that describes the type of index this is.
110    */

111   public String JavaDoc getType() {
112     return index_type;
113   }
114   
115   /**
116    * Returns true if this is a unique index.
117    */

118   public boolean isUniqueIndex() {
119     return unique;
120   }
121   
122   /**
123    * Writes this object to the given DataOutputStream.
124    */

125   public void write(DataOutput JavaDoc dout) throws IOException JavaDoc {
126     dout.writeInt(1);
127     dout.writeUTF(index_name);
128     dout.writeInt(column_names.length);
129     for (int i = 0; i < column_names.length; ++i) {
130       dout.writeUTF(column_names[i]);
131     }
132     dout.writeInt(index_pointer);
133     dout.writeUTF(index_type);
134     dout.writeBoolean(unique);
135   }
136
137   /**
138    * Reads a DataIndexDef from the given DataInput object.
139    */

140   public static DataIndexDef read(DataInput JavaDoc din) throws IOException JavaDoc {
141     int version = din.readInt();
142     if (version != 1) {
143       throw new IOException JavaDoc("Don't understand version.");
144     }
145     String JavaDoc index_name = din.readUTF();
146     int sz = din.readInt();
147     String JavaDoc[] cols = new String JavaDoc[sz];
148     for (int i = 0; i < sz; ++i) {
149       cols[i] = din.readUTF();
150     }
151     int index_pointer = din.readInt();
152     String JavaDoc index_type = din.readUTF();
153     boolean unique = din.readBoolean();
154     
155     return new DataIndexDef(index_name, cols,
156                             index_pointer, index_type, unique);
157   }
158   
159 }
160
161
Popular Tags