1 24 25 package com.mckoi.database.interpret; 26 27 import com.mckoi.database.*; 28 import com.mckoi.database.sql.ParseException; 29 import com.mckoi.database.sql.SQLConstants; 30 import com.mckoi.database.sql.Token; 31 import com.mckoi.database.global.SQLTypes; 32 import java.util.ArrayList ; 33 34 39 40 public final class ColumnDef 41 implements java.io.Serializable , StatementTreeObject, Cloneable { 42 43 static final long serialVersionUID = 8347617136528650961L; 44 45 47 String name; 48 49 58 TType type; 59 String index_str; 60 61 Expression default_expression; 62 Expression original_default_expression; 63 64 private boolean not_null = false; 65 private boolean primary_key = false; 66 private boolean unique = false; 67 68 public ColumnDef() { 69 } 71 72 75 public boolean isPrimaryKey() { 76 return primary_key; 77 } 78 79 82 public boolean isUnique() { 83 return unique; 84 } 85 86 89 public boolean isNotNull() { 90 return not_null; 91 } 92 93 96 public void setName(String name) { 97 this.name = name; 98 } 99 100 103 public void addConstraint(String constraint) { 104 if (constraint.equals("NOT NULL")) { 105 not_null = true; 106 } 108 else if (constraint.equals("NULL")) { 109 not_null = false; 110 } 112 else if (constraint.equals("PRIMARY")) { 113 primary_key = true; 114 } 115 else if (constraint.equals("UNIQUE")) { 116 unique = true; 117 } 118 else { 119 throw new RuntimeException ("Unknown constraint: " + constraint); 120 } 121 } 122 123 126 public void setDataType(TType type) { 127 this.type = type; 128 } 129 130 284 287 public void setIndex(Token t) throws ParseException { 288 if (t.kind == SQLConstants.INDEX_NONE) { 289 index_str = "BlindSearch"; 290 } 292 else if (t.kind == SQLConstants.INDEX_BLIST) { 293 index_str = "InsertSearch"; 294 } 296 else { 297 throw new ParseException("Unrecognized indexing scheme."); 298 } 299 } 300 301 304 public void setDefaultExpression(Expression exp) { 305 default_expression = exp; 306 try { 307 original_default_expression = (Expression) exp.clone(); 308 } 309 catch (CloneNotSupportedException e) { 310 throw new Error (e.getMessage()); 311 } 312 } 313 314 315 public void prepareExpressions(ExpressionPreparer preparer) 317 throws DatabaseException { 318 if (default_expression != null) { 319 default_expression.prepare(preparer); 320 } 321 } 322 323 public Object clone() throws CloneNotSupportedException { 324 ColumnDef v = (ColumnDef) super.clone(); 325 if (default_expression != null) { 326 v.default_expression = (Expression) default_expression.clone(); 327 } 328 return v; 329 } 330 331 } 332 | Popular Tags |