1 21 22 package org.apache.derby.impl.sql.execute; 23 24 import org.apache.derby.iapi.sql.dictionary.ConsInfo; 25 import org.apache.derby.iapi.sql.dictionary.DataDictionary; 26 import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor; 27 import org.apache.derby.iapi.sql.dictionary.TableDescriptor; 28 import org.apache.derby.catalog.UUID; 29 30 import org.apache.derby.iapi.error.StandardException; 31 32 import org.apache.derby.iapi.services.io.StoredFormatIds; 33 import org.apache.derby.iapi.services.io.FormatIdUtil; 34 import org.apache.derby.iapi.services.io.ArrayUtil; 35 import org.apache.derby.iapi.services.io.Formatable; 36 37 import org.apache.derby.iapi.services.sanity.SanityManager; 38 39 import java.io.ObjectOutput ; 40 import java.io.ObjectInput ; 41 import java.io.IOException ; 42 48 public class ConstraintInfo implements ConsInfo 49 { 50 66 67 70 private String tableName; 71 private SchemaDescriptor tableSd; 72 private UUID tableSchemaId; 73 private String [] columnNames; 74 private int raDeleteRule; 75 private int raUpdateRule; 76 77 78 81 public ConstraintInfo() {} 82 83 87 public ConstraintInfo( 88 String tableName, 89 SchemaDescriptor tableSd, 90 String [] columnNames, 91 int raDeleteRule, 92 int raUpdateRule 93 ) 94 { 95 this.tableName = tableName; 96 this.tableSd = tableSd; 97 this.columnNames = columnNames; 98 this.raDeleteRule = raDeleteRule; 99 this.raUpdateRule = raUpdateRule; 100 } 101 102 114 public void writeExternal(ObjectOutput out) throws IOException 115 { 116 out.writeObject(tableName); 117 if (tableSd == null) 118 { 119 out.writeBoolean(false); 120 } 121 else 122 { 123 out.writeBoolean(true); 124 out.writeObject(tableSd.getUUID()); 125 } 126 127 if (columnNames == null) 128 { 129 out.writeBoolean(false); 130 } 131 else 132 { 133 out.writeBoolean(true); 134 ArrayUtil.writeArrayLength(out, columnNames); 135 ArrayUtil.writeArrayItems(out, columnNames); 136 } 137 138 out.writeInt(raDeleteRule); 140 out.writeInt(raUpdateRule); 141 } 142 143 151 public void readExternal(ObjectInput in) 152 throws IOException , ClassNotFoundException 153 { 154 tableName = (String )in.readObject(); 155 if (in.readBoolean()) 156 { 157 tableSchemaId = (UUID)in.readObject(); 158 } 159 160 if (in.readBoolean()) 161 { 162 columnNames = new String [ArrayUtil.readArrayLength(in)]; 163 ArrayUtil.readArrayItems(in, columnNames); 164 } 165 166 raDeleteRule = in.readInt(); 168 raUpdateRule = in.readInt(); 169 } 170 171 176 public int getTypeFormatId() { return StoredFormatIds.CONSTRAINT_INFO_V01_ID; } 177 178 public String toString() 184 { 185 if (SanityManager.DEBUG) 186 { 187 StringBuffer str = new StringBuffer (); 188 str.append("Referencing "); 189 str.append(tableName); 190 if (columnNames != null) 191 { 192 str.append("("); 193 for (int i = 0; i < columnNames.length; i++) 194 { 195 if (i > 0) 196 str.append(","); 197 198 str.append(columnNames[i]); 199 } 200 str.append(")"); 201 } 202 203 return str.toString(); 204 } 205 else 206 { 207 return ""; 208 } 209 } 210 211 public SchemaDescriptor getReferencedTableSchemaDescriptor(DataDictionary dd) 212 throws StandardException 213 { 214 if (tableSd != null) 215 { 216 return tableSd; 217 } 218 else 219 { 220 return dd.getSchemaDescriptor(tableSchemaId, null); 221 } 222 } 223 224 public TableDescriptor getReferencedTableDescriptor(DataDictionary dd) 225 throws StandardException 226 { 227 if (tableName == null) 228 { 229 return null; 230 } 231 232 return dd.getTableDescriptor(tableName, 233 getReferencedTableSchemaDescriptor(dd)); 234 } 235 236 242 public String [] getReferencedColumnNames() 243 { return columnNames; } 244 245 250 public String getReferencedTableName() 251 { return tableName; } 252 253 258 public int getReferentialActionUpdateRule() 259 { return raUpdateRule; } 260 261 262 267 public int getReferentialActionDeleteRule() 268 { return raDeleteRule; } 269 270 271 272 } 273 274 275 276 277 278 279 280 281 282 | Popular Tags |