KickJava   Java API By Example, From Geeks To Geeks.

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


1 /**
2  * com.mckoi.database.DataTableColumnDef 27 Jul 2000
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.*;
28 import com.mckoi.database.global.ColumnDescription;
29 import com.mckoi.database.global.SQLTypes;
30
31 /**
32  * All the information regarding a column in a table.
33  *
34  * @author Tobias Downer
35  */

36
37 public class DataTableColumnDef {
38
39   /**
40    * A string that contains some constraints. This string contains
41    * information about whether the column is not null, unique, primary key,
42    * etc.
43    */

44   private byte[] constraints_format = new byte[16];
45
46   /**
47    * The name of the column.
48    */

49   private String JavaDoc name;
50
51   /**
52    * The sql column type (as defined in java.sql.Types).
53    */

54   private int sql_type;
55
56   /**
57    * The actual column type in the database (as defined in
58    * com.mckoi.database.global.Types).
59    */

60   private int db_type;
61
62   /**
63    * The size of the data.
64    */

65   private int size;
66
67   /**
68    * The scale of the data.
69    */

70   private int scale;
71
72   /**
73    * The locale string if this column represents a string. If this is an
74    * empty string, the column has no locale (the string is collated
75    * lexicographically).
76    */

77   private String JavaDoc locale_str = "";
78
79   /**
80    * The locale Collator strength if this column represents a string. The
81    * value here is taken from java.text.Collator.
82    */

83   private int str_strength;
84   
85   /**
86    * The locale Collator decomposition if this column represents a string. The
87    * value here is taken from java.text.Collator.
88    */

89   private int str_decomposition;
90
91   /**
92    * The default expression string.
93    */

94   private String JavaDoc default_expression_string;
95
96 // /**
97
// * The expression that is executed to set the default value.
98
// */
99
// private Expression default_exp;
100

101   /**
102    * If this is a foreign key, the table.column that this foreign key
103    * refers to.
104    * @deprecated
105    */

106   private String JavaDoc foreign_key = "";
107
108   /**
109    * The type of index to use on this column.
110    */

111   private String JavaDoc index_desc = "";
112
113   /**
114    * If this is a Java Object column, this is a constraint that the object
115    * must be derived from to be added to this column. If not specified,
116    * it defaults to 'java.lang.Object'.
117    */

118   private String JavaDoc class_constraint = "";
119
120   /**
121    * The constraining Class object itself.
122    */

123   private Class JavaDoc constraining_class;
124
125   /**
126    * The TType object for this column.
127    */

128   public TType type;
129
130
131
132   /**
133    * Constructs the column definition.
134    */

135   public DataTableColumnDef() {
136   }
137
138   /**
139    * Creates a copy of the given column definition.
140    */

141   public DataTableColumnDef(DataTableColumnDef column_def) {
142     System.arraycopy(column_def.constraints_format, 0,
143                      constraints_format, 0, constraints_format.length);
144     name = column_def.name;
145     sql_type = column_def.sql_type;
146     db_type = column_def.db_type;
147     size = column_def.size;
148     scale = column_def.scale;
149     locale_str = column_def.locale_str;
150     str_strength = column_def.str_strength;
151     str_decomposition = column_def.str_decomposition;
152     if (column_def.default_expression_string != null) {
153       default_expression_string = column_def.default_expression_string;
154 // default_exp = new Expression(column_def.default_exp);
155
}
156     foreign_key = column_def.foreign_key;
157     index_desc = column_def.index_desc;
158     class_constraint = column_def.class_constraint;
159     type = column_def.type;
160   }
161
162   // ---------- Set methods ----------
163

164   public void setName(String JavaDoc name) {
165     this.name = name;
166   }
167
168   public void setNotNull(boolean status) {
169     constraints_format[0] = (byte) (status ? 1 : 0);
170   }
171
172 // public void setUnique(boolean status) {
173
// constraints_format[1] = (byte) (status ? 1 : 0);
174
// }
175
//
176
// public void setPrimaryKey(boolean status) {
177
// constraints_format[2] = (byte) (status ? 1 : 0);
178
// }
179

180   public void setSQLType(int sql_type) {
181     this.sql_type = sql_type;
182     if (sql_type == SQLTypes.BIT ||
183         sql_type == SQLTypes.BOOLEAN) {
184       db_type = com.mckoi.database.global.Types.DB_BOOLEAN;
185     }
186     else if (sql_type == SQLTypes.TINYINT ||
187              sql_type == SQLTypes.SMALLINT ||
188              sql_type == SQLTypes.INTEGER ||
189              sql_type == SQLTypes.BIGINT ||
190              sql_type == SQLTypes.FLOAT ||
191              sql_type == SQLTypes.REAL ||
192              sql_type == SQLTypes.DOUBLE ||
193              sql_type == SQLTypes.NUMERIC ||
194              sql_type == SQLTypes.DECIMAL) {
195       db_type = com.mckoi.database.global.Types.DB_NUMERIC;
196     }
197     else if (sql_type == SQLTypes.CHAR ||
198              sql_type == SQLTypes.VARCHAR ||
199              sql_type == SQLTypes.LONGVARCHAR) {
200       db_type = com.mckoi.database.global.Types.DB_STRING;
201     }
202     else if (sql_type == SQLTypes.DATE ||
203              sql_type == SQLTypes.TIME ||
204              sql_type == SQLTypes.TIMESTAMP) {
205       db_type = com.mckoi.database.global.Types.DB_TIME;
206     }
207     else if (sql_type == SQLTypes.BINARY ||
208              sql_type == SQLTypes.VARBINARY ||
209              sql_type == SQLTypes.LONGVARBINARY) {
210       db_type = com.mckoi.database.global.Types.DB_BLOB;
211     }
212     else if (sql_type == SQLTypes.JAVA_OBJECT) {
213       db_type = com.mckoi.database.global.Types.DB_OBJECT;
214     }
215     else {
216       db_type = com.mckoi.database.global.Types.DB_UNKNOWN;
217     }
218   }
219
220   public void setDBType(int db_type) {
221     this.db_type = db_type;
222     if (db_type == com.mckoi.database.global.Types.DB_NUMERIC) {
223       sql_type = SQLTypes.NUMERIC;
224     }
225     else if (db_type == com.mckoi.database.global.Types.DB_STRING) {
226       sql_type = SQLTypes.LONGVARCHAR;
227     }
228     else if (db_type == com.mckoi.database.global.Types.DB_BOOLEAN) {
229       sql_type = SQLTypes.BIT;
230     }
231     else if (db_type == com.mckoi.database.global.Types.DB_TIME) {
232       sql_type = SQLTypes.TIMESTAMP;
233     }
234     else if (db_type == com.mckoi.database.global.Types.DB_BLOB) {
235       sql_type = SQLTypes.LONGVARBINARY;
236     }
237     else if (db_type == com.mckoi.database.global.Types.DB_OBJECT) {
238       sql_type = SQLTypes.JAVA_OBJECT;
239     }
240     else {
241       throw new Error JavaDoc("Unrecognised internal type.");
242     }
243   }
244
245   public void setSize(int size) {
246     this.size = size;
247   }
248
249   public void setScale(int scale) {
250     this.scale = scale;
251   }
252
253   public void setStringLocale(String JavaDoc locale_str,
254                               int strength, int decomposition) {
255     // Sets this column to be of the given locale. For example, the string
256
// "frFR" denotes french/france. See com/mckoi/database/TStringType.java
257
// for more information.
258
if (locale_str == null) {
259       this.locale_str = "";
260     }
261     else {
262       this.locale_str = locale_str;
263       this.str_strength = strength;
264       this.str_decomposition = decomposition;
265     }
266   }
267
268   public void setDefaultExpression(Expression expression) {
269     this.default_expression_string = new String JavaDoc(expression.text().toString());
270   }
271
272   /**
273    * @deprecated
274    */

275   public void setForeignKey(String JavaDoc foreign_key) {
276     this.foreign_key = foreign_key;
277   }
278
279   /**
280    * Sets the indexing scheme for this column. Either 'InsertSearch' or
281    * 'BlindSearch'. If not set, then default to insert search.
282    */

283   public void setIndexScheme(String JavaDoc index_scheme) {
284     index_desc = index_scheme;
285   }
286
287   /**
288    * If this column represents a Java object, this must be a class the object
289    * is derived from to be added to this column.
290    */

291   public void setClassConstraint(String JavaDoc class_constraint) {
292     this.class_constraint = class_constraint;
293     try {
294       // Denotes an array
295
if (class_constraint.endsWith("[]")) {
296         String JavaDoc array_class =
297                  class_constraint.substring(0, class_constraint.length() - 2);
298         Class JavaDoc ac;
299         // Arrays of primitive types,
300
if (array_class.equals("boolean")) {
301           ac = boolean.class;
302         }
303         else if (array_class.equals("byte")) {
304           ac = byte.class;
305         }
306         else if (array_class.equals("char")) {
307           ac = char.class;
308         }
309         else if (array_class.equals("short")) {
310           ac = short.class;
311         }
312         else if (array_class.equals("int")) {
313           ac = int.class;
314         }
315         else if (array_class.equals("long")) {
316           ac = long.class;
317         }
318         else if (array_class.equals("float")) {
319           ac = float.class;
320         }
321         else if (array_class.equals("double")) {
322           ac = double.class;
323         }
324         else {
325           // Otherwise a standard array.
326
ac = Class.forName(array_class);
327         }
328         // Make it into an array
329
constraining_class =
330                        java.lang.reflect.Array.newInstance(ac, 0).getClass();
331       }
332       else {
333         // Not an array
334
constraining_class = Class.forName(class_constraint);
335       }
336     }
337     catch (ClassNotFoundException JavaDoc e) {
338       throw new Error JavaDoc("Unable to resolve class: " + class_constraint);
339     }
340   }
341
342   /**
343    * Sets this DataTableColumnDef object up from information in the TType
344    * object. This is useful when we need to create a DataTableColumnDef object
345    * to store information based on nothing more than a TType object. This
346    * comes in useful for purely functional tables.
347    */

348   public void setFromTType(TType type) {
349     setSQLType(type.getSQLType());
350     if (type instanceof TStringType) {
351       TStringType str_type = (TStringType) type;
352       setSize(str_type.getMaximumSize());
353       setStringLocale(str_type.getLocaleString(),
354                       str_type.getStrength(), str_type.getDecomposition());
355     }
356     else if (type instanceof TNumericType) {
357       TNumericType num_type = (TNumericType) type;
358       setSize(num_type.getSize());
359       setScale(num_type.getScale());
360     }
361     else if (type instanceof TBooleanType) {
362       // Nothing necessary for booleans
363
// TBooleanType bool_type = (TBooleanType) type;
364
}
365     else if (type instanceof TDateType) {
366       // Nothing necessary for dates
367
// TDateType date_type = (TDateType) type;
368
}
369     else if (type instanceof TNullType) {
370       // Nothing necessary for nulls
371
}
372     else if (type instanceof TBinaryType) {
373       TBinaryType binary_type = (TBinaryType) type;
374       setSize(binary_type.getMaximumSize());
375     }
376     else if (type instanceof TJavaObjectType) {
377       TJavaObjectType java_object_type = (TJavaObjectType) type;
378       setClassConstraint(java_object_type.getJavaClassTypeString());
379     }
380     else {
381       throw new Error JavaDoc("Don't know how to handle this type: " +
382                       type.getClass());
383     }
384     this.type = type;
385     
386   }
387
388   /**
389    * Initializes the TType information for a column. This should be called
390    * at the last part of a DataTableColumnDef setup.
391    */

392   public void initTTypeInfo() {
393     if (type == null) {
394       type = createTTypeFor(getSQLType(), getSize(), getScale(),
395                           getLocaleString(), getStrength(), getDecomposition(),
396                           getClassConstraint());
397     }
398   }
399
400
401   // ---------- Get methods ----------
402

403   public String JavaDoc getName() {
404     return name;
405   }
406
407   public boolean isNotNull() {
408     return constraints_format[0] != 0;
409   }
410
411   public int getSQLType() {
412     return sql_type;
413   }
414
415   /**
416    * Returns the type as a String.
417    */

418   public String JavaDoc getSQLTypeString() {
419     return sqlTypeToString(getSQLType());
420   }
421
422   /**
423    * Returns the type as a String.
424    */

425   public String JavaDoc getDBTypeString() {
426     switch (getDBType()) {
427       case com.mckoi.database.global.Types.DB_NUMERIC:
428         return "DB_NUMERIC";
429       case com.mckoi.database.global.Types.DB_STRING:
430         return "DB_STRING";
431       case com.mckoi.database.global.Types.DB_BOOLEAN:
432         return "DB_BOOLEAN";
433       case com.mckoi.database.global.Types.DB_TIME:
434         return "DB_TIME";
435       case com.mckoi.database.global.Types.DB_BLOB:
436         return "DB_BLOB";
437       case com.mckoi.database.global.Types.DB_OBJECT:
438         return "DB_OBJECT";
439       default:
440         return "UNKNOWN(" + getDBType() + ")";
441     }
442   }
443
444   /**
445    * Returns the Class of Java object that represents this column.
446    */

447   public Class JavaDoc classType() {
448     return com.mckoi.database.global.TypeUtil.toClass(getDBType());
449   }
450
451   public int getDBType() {
452     return db_type;
453   }
454
455   public int getSize() {
456     return size;
457   }
458
459   public int getScale() {
460     return scale;
461   }
462
463   public String JavaDoc getLocaleString() {
464     return locale_str;
465   }
466
467   public int getStrength() {
468     return str_strength;
469   }
470   
471   public int getDecomposition() {
472     return str_decomposition;
473   }
474
475   public Expression getDefaultExpression(TransactionSystem system) {
476     if (default_expression_string == null) {
477       return null;
478     }
479     Expression exp = Expression.parse(default_expression_string);
480     return exp;
481   }
482
483   public String JavaDoc getDefaultExpressionString() {
484     return default_expression_string;
485   }
486
487   /**
488    * @deprecated
489    */

490   public String JavaDoc getForeignKey() {
491     return foreign_key;
492   }
493
494   /**
495    * Returns the name of the scheme we use to index this column. It will
496    * be either 'InsertSearch' or 'BlindSearch'.
497    */

498   public String JavaDoc getIndexScheme() {
499     if (index_desc.equals("")) {
500       return "InsertSearch";
501     }
502     return index_desc;
503   }
504
505   /**
506    * Returns true if this type of column is able to be indexed.
507    */

508   public boolean isIndexableType() {
509     if (getDBType() == com.mckoi.database.global.Types.DB_BLOB ||
510         getDBType() == com.mckoi.database.global.Types.DB_OBJECT) {
511       return false;
512     }
513     return true;
514   }
515
516   /**
517    * If this column represents a Java Object, this returns the name of the
518    * class the objects stored in the column must be derived from.
519    */

520   public String JavaDoc getClassConstraint() {
521     return class_constraint;
522   }
523
524   /**
525    * If this column represents a Java Object, this returns the class object
526    * that is the constraining class for the column.
527    */

528   public Class JavaDoc getClassConstraintAsClass() {
529     return constraining_class;
530   }
531
532   /**
533    * Returns the TType for this column.
534    */

535   public TType getTType() {
536     if (type == null) {
537       throw new Error JavaDoc("'type' variable was not set.");
538     }
539     return type;
540   }
541   
542 // /**
543
// * Returns this column as a TableField object.
544
// *
545
// * @deprecated TableField shouldn't be used anymore
546
// */
547
// public TableField tableFieldValue() {
548
// TableField field =
549
// new TableField(getName(), getDBType(), getSize(), isNotNull());
550
//// if (isUnique()) {
551
//// field.setUnique();
552
//// }
553
// field.setScale(getScale());
554
// field.setSQLType(getSQLType());
555
//
556
// return field;
557
// }
558

559   /**
560    * Returns this column as a ColumnDescription object and gives the column
561    * description the given name.
562    */

563   public ColumnDescription columnDescriptionValue(String JavaDoc column_name) {
564     ColumnDescription field =
565        new ColumnDescription(column_name, getDBType(), getSize(), isNotNull());
566     field.setScale(getScale());
567     field.setSQLType(getSQLType());
568
569     return field;
570   }
571
572   /**
573    * Dumps information about this object to the PrintStream.
574    */

575   public void dump(PrintStream out) {
576     out.print(getName());
577     out.print("(");
578     out.print(getSQLTypeString());
579     out.print(")");
580   }
581
582   // ---------- For compatibility with older versions only --------
583
// These are made available only because we need to convert from the
584
// pre table constraint versions.
585

586   boolean compatIsUnique() {
587     return constraints_format[1] != 0;
588   }
589
590   boolean compatIsPrimaryKey() {
591     return constraints_format[2] != 0;
592   }
593
594   // ---------- Convenient static methods ----------
595

596   /**
597    * Returns a string that represents the given SQLType enumeration passed
598    * to it. For example, pass SQLTypes.BIT and it returns the string "BIT"
599    */

600   public static String JavaDoc sqlTypeToString(int sql_type) {
601     switch (sql_type) {
602       case SQLTypes.BIT:
603         return "BIT";
604       case SQLTypes.TINYINT:
605         return "TINYINT";
606       case SQLTypes.SMALLINT:
607         return "SMALLINT";
608       case SQLTypes.INTEGER:
609         return "INTEGER";
610       case SQLTypes.BIGINT:
611         return "BIGINT";
612       case SQLTypes.FLOAT:
613         return "FLOAT";
614       case SQLTypes.REAL:
615         return "REAL";
616       case SQLTypes.DOUBLE:
617         return "DOUBLE";
618       case SQLTypes.NUMERIC:
619         return "NUMERIC";
620       case SQLTypes.DECIMAL:
621         return "DECIMAL";
622       case SQLTypes.CHAR:
623         return "CHAR";
624       case SQLTypes.VARCHAR:
625         return "VARCHAR";
626       case SQLTypes.LONGVARCHAR:
627         return "LONGVARCHAR";
628       case SQLTypes.DATE:
629         return "DATE";
630       case SQLTypes.TIME:
631         return "TIME";
632       case SQLTypes.TIMESTAMP:
633         return "TIMESTAMP";
634       case SQLTypes.BINARY:
635         return "BINARY";
636       case SQLTypes.VARBINARY:
637         return "VARBINARY";
638       case SQLTypes.LONGVARBINARY:
639         return "LONGVARBINARY";
640       case SQLTypes.JAVA_OBJECT:
641         return "JAVA_OBJECT";
642       case SQLTypes.NULL:
643         return "NULL";
644       case SQLTypes.BOOLEAN:
645         return "BOOLEAN";
646       default:
647         return "UNKNOWN(" + sql_type + ")";
648     }
649   }
650
651   /**
652    * Returns a TType object for a column with the given type information. The
653    * type information is the sql_type, the size and the scale of the type.
654    */

655   static TType createTTypeFor(int sql_type, int size, int scale,
656                         String JavaDoc locale, int str_strength, int str_decomposition,
657                         String JavaDoc java_class) {
658     switch (sql_type) {
659       case (SQLTypes.BIT):
660       case (SQLTypes.BOOLEAN):
661         return TType.BOOLEAN_TYPE;
662
663       case (SQLTypes.TINYINT):
664       case (SQLTypes.SMALLINT):
665       case (SQLTypes.INTEGER):
666       case (SQLTypes.BIGINT):
667       case (SQLTypes.FLOAT):
668       case (SQLTypes.REAL):
669       case (SQLTypes.DOUBLE):
670       case (SQLTypes.NUMERIC):
671       case (SQLTypes.DECIMAL):
672         return new TNumericType(sql_type, size, scale);
673
674       case (SQLTypes.CHAR):
675       case (SQLTypes.VARCHAR):
676       case (SQLTypes.LONGVARCHAR):
677       case (SQLTypes.CLOB):
678         return new TStringType(sql_type, size, locale,
679                                str_strength, str_decomposition);
680
681       case (SQLTypes.DATE):
682       case (SQLTypes.TIME):
683       case (SQLTypes.TIMESTAMP):
684         return new TDateType(sql_type);
685
686       case (SQLTypes.BINARY):
687       case (SQLTypes.VARBINARY):
688       case (SQLTypes.LONGVARBINARY):
689       case (SQLTypes.BLOB):
690         return new TBinaryType(sql_type, size);
691
692       case (SQLTypes.JAVA_OBJECT):
693         return new TJavaObjectType(java_class);
694
695       case (SQLTypes.ARRAY):
696         return TType.ARRAY_TYPE;
697
698       case (SQLTypes.NULL):
699         return TType.NULL_TYPE;
700         
701       default:
702         throw new Error JavaDoc("SQL type not recognized.");
703     }
704   }
705
706   /**
707    * Convenience helper - creates a DataTableColumnDef that
708    * holds a numeric value.
709    */

710   public static DataTableColumnDef createNumericColumn(String JavaDoc name) {
711     DataTableColumnDef column = new DataTableColumnDef();
712     column.setName(name);
713     column.setSQLType(java.sql.Types.NUMERIC);
714     column.initTTypeInfo();
715     return column;
716   }
717
718   /**
719    * Convenience helper - creates a DataTableColumnDef that
720    * holds a boolean value.
721    */

722   public static DataTableColumnDef createBooleanColumn(String JavaDoc name) {
723     DataTableColumnDef column = new DataTableColumnDef();
724     column.setName(name);
725     column.setSQLType(java.sql.Types.BIT);
726     column.initTTypeInfo();
727     return column;
728   }
729
730   /**
731    * Convenience helper - creates a DataTableColumnDef that
732    * holds a string value.
733    */

734   public static DataTableColumnDef createStringColumn(String JavaDoc name) {
735     DataTableColumnDef column = new DataTableColumnDef();
736     column.setName(name);
737     column.setSQLType(java.sql.Types.VARCHAR);
738     column.setSize(Integer.MAX_VALUE);
739     column.initTTypeInfo();
740     return column;
741   }
742
743   /**
744    * Convenience helper - creates a DataTableColumnDef that
745    * holds a binary value.
746    */

747   public static DataTableColumnDef createBinaryColumn(String JavaDoc name) {
748     DataTableColumnDef column = new DataTableColumnDef();
749     column.setName(name);
750     column.setSQLType(java.sql.Types.LONGVARBINARY);
751     column.setSize(Integer.MAX_VALUE);
752     column.setIndexScheme("BlindSearch");
753     column.initTTypeInfo();
754     return column;
755   }
756
757
758
759   // ---------- IO Methods ----------
760

761   /**
762    * Writes this column information out to a DataOutputStream.
763    */

764   void write(DataOutput out) throws IOException {
765
766     out.writeInt(2); // The version
767

768     out.writeUTF(name);
769     out.writeInt(constraints_format.length);
770     out.write(constraints_format);
771     out.writeInt(sql_type);
772     out.writeInt(db_type);
773     out.writeInt(size);
774     out.writeInt(scale);
775
776     if (default_expression_string != null) {
777       out.writeBoolean(true);
778       out.writeUTF(default_expression_string);
779                            //new String(default_exp.text().toString()));
780
}
781     else {
782       out.writeBoolean(false);
783     }
784
785     out.writeUTF(foreign_key);
786     out.writeUTF(index_desc);
787     out.writeUTF(class_constraint); // Introduced in version 2.
788

789     // Format the 'other' string
790
StringBuffer JavaDoc other = new StringBuffer JavaDoc();
791     other.append("|");
792     other.append(locale_str);
793     other.append("|");
794     other.append(str_strength);
795     other.append("|");
796     other.append(str_decomposition);
797     other.append("|");
798     // And write it
799
out.writeUTF(new String JavaDoc(other));
800   }
801
802   /**
803    * Reads this column from a DataInputStream.
804    */

805   static DataTableColumnDef read(DataInput in) throws IOException {
806
807     int ver = in.readInt();
808
809     DataTableColumnDef cd = new DataTableColumnDef();
810     cd.name = in.readUTF();
811     int len = in.readInt();
812     in.readFully(cd.constraints_format, 0, len);
813     cd.sql_type = in.readInt();
814     cd.db_type = in.readInt();
815     cd.size = in.readInt();
816     cd.scale = in.readInt();
817
818     boolean b = in.readBoolean();
819     if (b) {
820       cd.default_expression_string = in.readUTF();
821 // cd.default_exp = Expression.parse(in.readUTF());
822
}
823     cd.foreign_key = in.readUTF();
824     cd.index_desc = in.readUTF();
825     if (ver > 1) {
826       String JavaDoc cc = in.readUTF();
827       if (!cc.equals("")) {
828         cd.setClassConstraint(cc);
829       }
830     }
831     else {
832       cd.class_constraint = "";
833     }
834     
835     // Parse the 'other' string
836
String JavaDoc other = in.readUTF();
837     if (other.length() > 0) {
838       if (other.startsWith("|")) {
839         // Read the string locale, collation strength and disposition
840
int cur_i = 1;
841         int next_break = other.indexOf("|", cur_i);
842         cd.locale_str = other.substring(cur_i, next_break);
843
844         cur_i = next_break + 1;
845         next_break = other.indexOf("|", cur_i);
846         cd.str_strength =
847                         Integer.parseInt(other.substring(cur_i, next_break));
848         
849         cur_i = next_break + 1;
850         next_break = other.indexOf("|", cur_i);
851         cd.str_decomposition =
852                         Integer.parseInt(other.substring(cur_i, next_break));
853
854       }
855       else {
856         throw new Error JavaDoc("Incorrectly formatted DataTableColumnDef data.");
857       }
858     }
859     
860     cd.initTTypeInfo();
861     
862     return cd;
863   }
864
865 }
866
Popular Tags