1 33 34 35 36 package com.internetcds.jdbc.tds; 37 38 import java.util.Vector ; 39 import java.sql.Types ; 40 import com.internetcds.jdbc.tds.Column; 41 42 43 48 public class Columns 49 { 50 public static final String cvsVersion = "$Id: Columns.java,v 1.1 2006/06/23 10:39:04 sinisa Exp $"; 51 52 53 private Vector columns = null; 54 private int columnCount = 0; 55 56 public Columns() 57 { 58 columns = new Vector (); 59 columnCount = 0; 60 } 61 62 75 public Columns merge(Columns other) 76 throws TdsException 77 { 78 int tmp; 79 int i; 80 81 if (this.columns.size() != other.columns.size()) 82 { 83 throw new TdsException("Confused. Mismatch in number of columns"); 84 } 85 86 for(i=1; i<=columnCount; i++) 87 { 88 if (this.getName(i) == null) 89 { 90 this.setName(i, other.getName(i)); 91 } 92 else if (other.getName(i) == null) 93 { 94 } 96 else 97 { 98 throw new TdsException("Trying to merge two non-null columns"); 99 } 100 101 if (this.getDisplaySize(i) == -1) 102 { 103 this.setDisplaySize(i, other.getDisplaySize(i)); 104 } 105 else if (other.getDisplaySize(i) == -1) 106 { 107 } 109 else 110 { 111 throw new TdsException("Trying to merge two non-null columns"); 112 } 113 114 if (this.getLabel(i) == null) 115 { 116 this.setLabel(i, other.getLabel(i)); 117 } 118 else if (other.getLabel(i) == null) 119 { 120 } 122 else 123 { 124 throw new TdsException("Trying to merge two non-null columns"); 125 } 126 127 if (this.getType(i) == -1) 128 { 129 this.setType(i, other.getType(i)); 130 } 131 else if (other.getType(i) == -1) 132 { 133 } 135 else 136 { 137 throw new TdsException("Trying to merge two non-null columns"); 138 } 139 140 if (this.getPrecision(i) == -1) 141 { 142 this.setPrecision(i, other.getPrecision(i)); 143 } 144 else if (other.getPrecision(i) == -1) 145 { 146 } 148 else 149 { 150 throw new TdsException("Trying to merge two non-null columns"); 151 } 152 153 if (this.getScale(i) == -1) 154 { 155 this.setScale(i, other.getScale(i)); 156 } 157 else if (other.getScale(i) == -1) 158 { 159 } 161 else 162 { 163 throw new TdsException("Trying to merge two non-null columns"); 164 } 165 166 if ((this.nullableWasSet(i)) && (other.nullableWasSet(i))) 167 { 168 throw new TdsException("Trying to merge two non-null columns"); 169 } 170 else if ((! this.nullableWasSet(i)) && (other.nullableWasSet(i))) 171 { 172 this.setNullable (i, other.isNullable(i)); 173 } 174 else 175 { 176 } 178 179 if ((this.readOnlyWasSet(i)) && (other.readOnlyWasSet(i))) 180 { 181 throw new TdsException("Trying to merge two non-null columns"); 182 } 183 else if ((! this.readOnlyWasSet(i)) && (other.readOnlyWasSet(i))) 184 { 185 this.setReadOnly(i, other.isReadOnly(i)); 186 } 187 else 188 { 189 } 191 192 if ((this.autoIncrementWasSet(i)) && (other.autoIncrementWasSet(i))) 193 { 194 throw new TdsException("Trying to merge two non-null columns"); 195 } 196 else if ((! this.autoIncrementWasSet(i)) 197 && (other.autoIncrementWasSet(i))) 198 { 199 this.setAutoIncrement(i, other.isAutoIncrement(i)); 200 } 201 else 202 { 203 } 205 } 206 return this; 207 } 208 209 210 private void resize(int columnNumber) 211 { 212 if (columnNumber > columnCount) 213 { 214 columnCount = columnNumber; 215 } 216 217 if (columns.size() <= columnNumber) 218 { 219 columns.setSize(columnNumber+1); 220 } 221 222 if (columns.elementAt(columnNumber-1) == null) 223 { 224 columns.setElementAt(new Column(), columnNumber-1); 225 } 226 227 } 228 229 230 233 public int getColumnCount() 234 { 235 return columnCount; 236 } 237 238 239 public void setName(int columnNumber, String value) 240 { 241 resize(columnNumber); 242 if (columns.elementAt(columnNumber-1) == null) 243 { 244 columns.setElementAt(new Column(), columnNumber-1); 245 } 246 ((Column)(columns.elementAt(columnNumber-1))).setName(value); 247 } 248 249 public String getName(int columnNumber) 250 { 251 return ((Column)columns.elementAt(columnNumber-1)).getName(); 252 } 253 254 public void setDisplaySize(int columnNumber, int value) 255 { 256 resize(columnNumber); 257 ((Column)(columns.elementAt(columnNumber-1))).setDisplaySize(value); 258 } 259 260 public int getDisplaySize(int columnNumber) 261 { 262 return ((Column)columns.elementAt(columnNumber-1)).getDisplaySize(); 263 } 264 265 public void setLabel(int columnNumber, String value) 266 { 267 ((Column)(columns.elementAt(columnNumber-1))).setLabel(value); 268 } 269 270 public String getLabel(int columnNumber) 271 { 272 return ((Column)columns.elementAt(columnNumber-1)).getLabel(); 273 } 274 275 public void setType(int columnNumber, int value) 276 { 277 resize(columnNumber); 279 ((Column)(columns.elementAt(columnNumber-1))).setType(value); 280 } 281 282 public int getType(int columnNumber) 283 { 284 return ((Column)columns.elementAt(columnNumber-1)).getType(); 286 } 287 288 public void setPrecision(int columnNumber, int value) 289 { 290 resize(columnNumber); 291 ((Column)(columns.elementAt(columnNumber-1))).setPrecision(value); 292 } 293 294 public int getPrecision(int columnNumber) 295 { 296 return ((Column)columns.elementAt(columnNumber-1)).getPrecision(); 297 } 298 299 public void setScale(int columnNumber, int value) 300 { 301 resize(columnNumber); 302 ((Column)(columns.elementAt(columnNumber-1))).setScale(value); 303 } 304 305 public int getScale(int columnNumber) 306 { 307 return ((Column)columns.elementAt(columnNumber-1)).getScale(); 308 } 309 310 public boolean isAutoIncrement(int columnNumber) 311 { 312 return ((Column)columns.elementAt(columnNumber-1)).isAutoIncrement(); 313 } 314 315 public void setAutoIncrement(int columnNumber, boolean value) 316 { 317 resize(columnNumber); 318 ((Column)(columns.elementAt(columnNumber-1))).setAutoIncrement(value); 319 } 320 321 public boolean autoIncrementWasSet(int columnNumber) 322 { 323 return ((Column)(columns.elementAt(columnNumber-1))).autoIncrementWasSet(); 324 } 325 326 public int isNullable(int columnNumber) 327 { 328 return ((Column)columns.elementAt(columnNumber-1)).isNullable(); 329 } 330 331 public void setNullable(int columnNumber, int value) 332 { 333 resize(columnNumber); 334 ((Column)(columns.elementAt(columnNumber-1))).setNullable (value); 335 } 336 337 public boolean nullableWasSet(int columnNumber) 338 { 339 return (isNullable(columnNumber) 340 != java.sql.ResultSetMetaData.columnNullableUnknown); 341 } 342 343 public boolean isReadOnly(int columnNumber) 344 { 345 return ((Column)columns.elementAt(columnNumber-1)).isReadOnly(); 346 } 347 348 public void setReadOnly(int columnNumber, boolean value) 349 { 350 resize(columnNumber); 351 ((Column)columns.elementAt(columnNumber-1)).setReadOnly(value); 352 } 353 354 public boolean readOnlyWasSet(int columnNumber) 355 { 356 return ((Column)(columns.elementAt(columnNumber-1))).readOnlyWasSet(); 357 } 358 359 } 360 361 362 363 | Popular Tags |