1 24 25 package com.mckoi.database.interpret; 26 27 import com.mckoi.database.*; 28 import java.util.ArrayList ; 29 30 35 36 public final class ConstraintDef 37 implements java.io.Serializable , StatementTreeObject, Cloneable { 38 39 static final long serialVersionUID = -6648793780645431100L; 40 41 43 48 public static final int PRIMARY_KEY = 1; 49 50 54 public static final int UNIQUE = 2; 55 56 62 public static final int FOREIGN_KEY = 3; 63 64 69 public static final int CHECK = 4; 70 71 72 int type; 74 75 String name; 78 79 Expression check_expression; 81 Expression original_check_expression; 83 84 ArrayList column_list; 86 87 ArrayList column_list2; 89 90 String reference_table_name; 92 93 String update_rule; 95 96 String delete_rule; 98 99 short deferred = Transaction.INITIALLY_IMMEDIATE; 102 103 public ConstraintDef() { 104 } 105 106 109 public void setName(String name) { 110 this.name = name; 111 } 112 113 116 public void setPrimaryKey(ArrayList list) { 117 type = PRIMARY_KEY; 118 column_list = list; 119 } 120 121 124 public void setUnique(ArrayList list) { 125 type = UNIQUE; 126 column_list = list; 127 } 128 129 132 public void setCheck(Expression exp) { 133 type = CHECK; 134 check_expression = exp; 135 try { 136 original_check_expression = (Expression) exp.clone(); 137 } 138 catch (CloneNotSupportedException e) { 139 throw new Error (e.getMessage()); 140 } 141 } 142 143 146 public void setForeignKey(String ref_table, ArrayList col_list, 147 ArrayList ref_col_list, 148 String delete_rule, String update_rule) { 149 type = FOREIGN_KEY; 150 reference_table_name = ref_table; 151 column_list = col_list; 152 column_list2 = ref_col_list; 153 this.delete_rule = delete_rule; 154 this.update_rule = update_rule; 155 156 } 158 159 162 public void setInitiallyDeferred() { 163 deferred = Transaction.INITIALLY_DEFERRED; 164 } 165 166 169 public void setNotDeferrable() { 170 deferred = Transaction.NOT_DEFERRABLE; 171 } 172 173 174 175 178 public String [] getColumnList() { 179 return (String []) column_list.toArray(new String [column_list.size()]); 180 } 181 182 185 public String [] getColumnList2() { 186 return (String []) column_list2.toArray(new String [column_list2.size()]); 187 } 188 189 192 public String getDeleteRule() { 193 return delete_rule; 194 } 195 196 199 public String getUpdateRule() { 200 return update_rule; 201 } 202 203 204 public void prepareExpressions(ExpressionPreparer preparer) 206 throws DatabaseException { 207 if (check_expression != null) { 208 check_expression.prepare(preparer); 209 } 210 } 211 212 public Object clone() throws CloneNotSupportedException { 213 ConstraintDef v = (ConstraintDef) super.clone(); 214 if (check_expression != null) { 215 v.check_expression = (Expression) check_expression.clone(); 216 } 217 if (column_list != null) { 218 v.column_list = (ArrayList ) column_list.clone(); 219 } 220 if (column_list2 != null) { 221 v.column_list2 = (ArrayList ) column_list2.clone(); 222 } 223 return v; 224 } 225 226 } 227 | Popular Tags |