1 19 20 package org.netbeans.lib.ddl.impl; 21 22 import java.io.Serializable ; 23 import java.util.Enumeration ; 24 import java.util.Hashtable ; 25 import java.util.Map ; 26 import java.util.Vector ; 27 28 import org.netbeans.lib.ddl.CheckConstraintDescriptor; 29 import org.netbeans.lib.ddl.DatabaseSpecification; 30 import org.netbeans.lib.ddl.DDLException; 31 import org.netbeans.lib.ddl.TableColumnDescriptor; 32 33 36 public class TableColumn extends AbstractTableColumn implements Serializable , TableColumnDescriptor, CheckConstraintDescriptor { 37 38 public static final String COLUMN = "COLUMN"; 40 public static final String CHECK = "CHECK"; 42 public static final String UNIQUE = "UNIQUE"; 44 public static final String PRIMARY_KEY = "PRIMARY_KEY"; 46 public static final String FOREIGN_KEY = "FOREIGN_KEY"; 48 public static final String CHECK_CONSTRAINT = "CHECK_CONSTRAINT"; 50 public static final String UNIQUE_CONSTRAINT = "UNIQUE_CONSTRAINT"; 52 public static final String PRIMARY_KEY_CONSTRAINT = "PRIMARY_KEY_CONSTRAINT"; 54 public static final String FOREIGN_KEY_CONSTRAINT = "FOREIGN_KEY_CONSTRAINT"; 56 57 int type; 58 59 60 int size; 61 62 63 int decsize; 64 65 66 boolean nullable; 67 68 69 String defval; 70 71 72 String checke; 73 74 75 Vector constraintColumns; 76 77 static final long serialVersionUID =4298150043758715392L; 78 79 public TableColumn() { 80 size = 0; 81 decsize = 0; 82 nullable = true; 83 } 84 85 86 public int getColumnType() { 87 return type; 88 } 89 90 91 public void setColumnType(int columnType) { 92 type = columnType; 93 } 94 95 96 public int getColumnSize() { 97 return size; 98 } 99 100 101 public void setColumnSize(int csize) { 102 size = csize; 103 } 104 105 106 public int getDecimalSize() { 107 return decsize; 108 } 109 110 111 public void setDecimalSize(int dsize) { 112 decsize = dsize; 113 } 114 115 116 public boolean isNullAllowed() { 117 return nullable; 118 } 119 120 121 public void setNullAllowed(boolean flag) { 122 nullable = flag; 123 } 124 125 126 public String getDefaultValue() { 127 return defval; 128 } 129 130 131 public void setDefaultValue(String val) { 132 defval = val; 133 } 134 135 136 public String getCheckCondition() { 137 return checke; 138 } 139 140 141 public void setCheckCondition(String val) { 142 checke = val; 143 } 144 145 146 public Vector getTableConstraintColumns() { 147 return constraintColumns; 148 } 149 150 151 public void setTableConstraintColumns(Vector columns) { 152 constraintColumns = columns; 153 } 154 155 165 public Map getColumnProperties(AbstractCommand cmd) throws DDLException { 166 DatabaseSpecification spec = cmd.getSpecification(); 167 Map args = super.getColumnProperties(cmd); 168 String stype = spec.getType(type); 169 Vector charactertypes = (Vector )spec.getProperties().get("CharacterTypes"); String strdelim = (String )spec.getProperties().get("StringDelimiter"); Vector sizelesstypes = (Vector )spec.getProperties().get("SizelessTypes"); String coldelim = (String )spec.getProperties().get("ArgumentListDelimiter"); 174 if (sizelesstypes != null && size > 0) { 176 if (!sizelesstypes.contains(stype)) { 177 if (size > 0) 178 args.put("column.size", String.valueOf(size)); if (decsize > 0) 180 args.put("column.decsize", String.valueOf(decsize)); } 182 } 183 184 String qdefval = defval; 185 186 if (qdefval != null && charactertypes.contains(spec.getType(type)) && !qdefval.startsWith(strdelim) && !qdefval.endsWith(strdelim)) 187 if (!qdefval.startsWith("(" + strdelim) && !qdefval.endsWith(strdelim + ")")) qdefval = strdelim + defval + strdelim; 189 190 String dbType = spec.getType(type); 191 String dbTypeSuffix = null; 192 Map suffixTypeMap = (Map )spec.getProperties().get("TypePrefixSuffixMap"); if (suffixTypeMap != null) { 194 Map dbTypePrefixSuffix = (Map )suffixTypeMap.get(dbType); 195 if (dbTypePrefixSuffix != null) { 196 dbType = (String )dbTypePrefixSuffix.get("Prefix"); dbTypeSuffix = (String )dbTypePrefixSuffix.get("Suffix"); } 199 } 200 args.put("column.type", dbType); 201 if (dbTypeSuffix != null) { 202 args.put("column.type.suffix", dbTypeSuffix); 203 } 204 205 if (!nullable) 206 args.put("column.notnull", ""); 208 if (!(! nullable && qdefval != null && (qdefval.equalsIgnoreCase("null") || qdefval.equalsIgnoreCase("'null'") || qdefval.equalsIgnoreCase("\"null\"")))) if (defval != null && !defval.equals("")) 210 args.put("default.value", qdefval); 212 if (checke != null) 213 args.put("check.condition", checke); if (constraintColumns != null) { 215 String cols = ""; 216 Enumeration col_e = constraintColumns.elements(); 217 while (col_e.hasMoreElements()) { 218 Object zrus = col_e.nextElement(); 219 Hashtable col = (Hashtable )zrus; 220 boolean inscomma = col_e.hasMoreElements(); 221 cols = cols + cmd.quote((String ) col.get("name")) + (inscomma ? coldelim : "" ); } 223 args.put("constraint.columns", cols); } 225 return args; 226 } 227 228 229 public void readObject(java.io.ObjectInputStream in) throws java.io.IOException , ClassNotFoundException { 230 super.readObject(in); 231 type = in.readInt(); 232 size = in.readInt(); 233 decsize = in.readInt(); 234 nullable = in.readBoolean(); 235 defval = (String )in.readObject(); 236 checke = (String )in.readObject(); 237 } 238 239 240 public void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { 241 super.writeObject(out); 242 out.writeInt(type); 243 out.writeInt(size); 244 out.writeInt(decsize); 245 out.writeBoolean(nullable); 246 out.writeObject(defval); 247 out.writeObject(checke); 248 } 249 } 250 | Popular Tags |