1 package de.webman.acl.db; 2 3 import java.sql.ResultSet ; 4 import java.sql.SQLException ; 5 import com.teamkonzept.db.TKDBVectorData; 6 import com.teamkonzept.db.TKDBTableData; 7 import com.teamkonzept.db.TKQuery; 8 import com.teamkonzept.lib.TKVector; 9 import de.webman.acl.WMObject; 10 11 21 public abstract class ObjectDBData 22 extends TKDBVectorData 23 { 24 26 29 private boolean empty = true; 30 31 34 private boolean ignore = false; 35 36 39 private Class query = null; 40 41 44 private Integer id = null; 45 46 49 private TKVector collection = null; 50 51 54 private ObjectCollectionDBData prototype = null; 55 56 57 59 64 public ObjectDBData (Integer id) 65 { 66 this.id = id; 67 } 68 69 74 public ObjectDBData (WMObject object) 75 { 76 this(object.getID()); 77 } 78 79 80 82 87 public abstract ObjectDBInterface getDBInterface (); 88 89 90 92 101 public void insertPrimaryIntoQuery (TKQuery query) 102 throws SQLException  103 { 104 query.setQueryParams(getDBInterface().getPrimaryKeyName(), this.id); 105 } 106 107 115 public void insertIntoQuery (TKQuery query) 116 throws SQLException  117 { 118 insertPrimaryIntoQuery(query); 119 insertInitialIntoQuery(query); 120 121 if (this.prototype != null) 122 { 123 this.prototype.insertIntoQuery(query); 124 } 125 } 126 127 136 public void fill (ResultSet result) 137 throws SQLException  138 { 139 this.id = new Integer (result.getInt(getDBInterface().getPrimaryKeyName())); 140 this.empty = false; 141 } 142 143 149 public final TKVector getVector (String table) 150 { 151 if (this.collection == null) 152 { 153 this.collection = new TKVector(); 154 } 155 156 return this.collection; 157 } 158 159 165 public final TKDBTableData getProtoType (String table) 166 { 167 return getPrototype(); 168 } 169 170 178 public final boolean isIgnoreTable (String table) 179 { 180 return this.ignore; 181 } 182 183 184 186 192 public final boolean isEmpty () 193 { 194 return this.empty; 195 } 196 197 202 public final Integer getID () 203 { 204 return this.id; 205 } 206 207 213 public final void setIgnore (boolean ignore) 214 { 215 this.ignore = ignore; 216 } 217 218 223 public final Class getQuery () 224 { 225 return this.query; 226 } 227 228 233 public final void setQuery (Class query) 234 { 235 this.query = query; 236 } 237 238 243 public final TKVector getCollection () 244 { 245 return data2id(this.collection); 246 } 247 248 253 public final void setCollection (TKVector collection) 254 { 255 this.collection = id2data(collection); 256 } 257 258 263 public final ObjectCollectionDBData getPrototype () 264 { 265 return this.prototype; 266 } 267 268 273 public final void setPrototype (ObjectCollectionDBData prototype) 274 { 275 this.prototype = prototype; 276 } 277 278 283 private TKVector id2data (TKVector ids) 284 { 285 TKVector data = null; 286 287 if (ids != null) 288 { 289 int index = 0; 290 int size = ids.size(); 291 292 data = new TKVector(size); 293 294 while (index < size) 295 { 296 data.addElement(this.prototype.newFromValue((Integer ) ids.elementAt(index++))); 297 } 298 } 299 300 return data; 301 } 302 303 308 private TKVector data2id (TKVector data) 309 { 310 TKVector ids = null; 311 312 if (data != null && 313 data.size() > 0) 314 { 315 int index = 0; 316 317 ids = new TKVector(data.size()); 318 319 while (index < data.size()) 320 { 321 ids.addElement(((ObjectCollectionDBData) data.elementAt(index++)).getValue()); 322 } 323 } 324 325 return ids; 326 } 327 328 } 329 | Popular Tags |