1 package de.webman.acl.db; 2 3 import java.sql.SQLException ; 4 import com.teamkonzept.db.TKDatabaseException; 5 import com.teamkonzept.db.TKDBManager; 6 import com.teamkonzept.db.TKDBVectorData; 7 import com.teamkonzept.db.TKDBVectorInterface; 8 import com.teamkonzept.db.TKSQLError; 9 import com.teamkonzept.lib.DatabaseErrorCodes; 10 import com.teamkonzept.lib.ErrorCodes; 11 import com.teamkonzept.lib.TKException; 12 import com.teamkonzept.webman.mainint.WebmanExceptionHandler; 13 14 24 public abstract class ObjectDBInterface 25 extends TKDBVectorInterface 26 { 27 28 30 33 private static final String [] TABLES = {""}; 34 35 36 38 41 private Class [] inserts = null; 42 43 46 private Class [] selects = null; 47 48 49 51 62 public ObjectDBInterface (Class primaryInsert, 63 Class primaryUpdate, 64 Class primarySelect, 65 Class primaryDelete, 66 Class [] dependentInserts, 67 Class [] dependentSelects, 68 Class dependentDelete) 69 { 70 super(primaryInsert, 71 primaryUpdate, 72 primarySelect, 73 primaryDelete, 74 TABLES, 75 dependentInserts, 76 dependentSelects, 77 dependentDelete); 78 79 this.inserts = dependentInserts; 81 this.selects = dependentSelects; 82 } 83 84 85 87 92 public abstract String getTableName (); 93 94 99 public abstract String getPrimaryKeyName (); 100 101 106 public abstract String getDependentKeyName (); 107 108 113 public abstract Class getSelectAllQuery (); 114 115 120 public abstract Class getSelectDependentQuery (); 121 122 127 public abstract Class getInsertDependentQuery (); 128 129 130 132 138 public final void selectPrimary (ObjectDBData data) 139 throws TKException 140 { 141 try 142 { 143 data.setIgnore(true); 145 146 getEntry(data); 148 } 149 catch (Throwable throwable) 150 { 151 throw WebmanExceptionHandler.getException(throwable); 152 } 153 } 154 155 161 public final void selectDependent (ObjectDBData data) 162 throws TKException 163 { 164 try 165 { 166 data.setIgnore(false); 168 169 this.selects[0] = data.getQuery(); 171 172 getEntryTables(data); 174 } 175 catch (Throwable throwable) 176 { 177 throw WebmanExceptionHandler.getException(throwable); 178 } 179 } 180 181 187 public final void selectFull (ObjectDBData data) 188 throws TKException 189 { 190 try 191 { 192 this.selects[0] = data.getQuery(); 194 195 getEntry(data); 197 } 198 catch (Throwable throwable) 199 { 200 throw WebmanExceptionHandler.getException(throwable); 201 } 202 } 203 204 210 public final void insert (ObjectDBData data) 211 throws TKException 212 { 213 try 214 { 215 newEntry(data); 217 } 218 catch (Throwable throwable) 219 { 220 throw WebmanExceptionHandler.getException(throwable); 221 } 222 } 223 224 230 public final void updatePrimary (ObjectDBData data) 231 throws TKException 232 { 233 try 234 { 235 TKDBManager.beginTransaction(); 240 241 updateEntry(data); 243 244 TKDBManager.commitTransaction(); 246 } 247 catch (Throwable throwable) 248 { 249 try 250 { 251 TKDBManager.safeRollbackTransaction(throwable); 253 } 254 catch (TKSQLError error) 255 { 256 throw WebmanExceptionHandler.getException(error); 257 } 258 } 259 } 260 261 267 public final void updateDependent (ObjectDBData data) 268 throws TKException 269 { 270 try 271 { 272 this.inserts[0] = data.getQuery(); 274 275 putEntryTables(data); 277 } 278 catch (Throwable throwable) 279 { 280 throw WebmanExceptionHandler.getException(throwable); 281 } 282 } 283 284 290 public final void updateFull (ObjectDBData data) 291 throws TKException 292 { 293 try 294 { 295 this.inserts[0] = data.getQuery(); 297 298 putEntry(data); 300 } 301 catch (Throwable throwable) 302 { 303 throw WebmanExceptionHandler.getException(throwable); 304 } 305 } 306 307 313 public final void delete (ObjectDBData data) 314 throws TKException 315 { 316 try 317 { 318 super.delEntry(data); 320 } 321 catch (Throwable throwable) 322 { 323 TKException exception = WebmanExceptionHandler.getException(throwable); 324 325 if (exception.getErrorCode() == DatabaseErrorCodes.FK_CONSTRAINT_VIOLATION) 326 { 327 throw new TKDatabaseException(getDescription(data), 328 DatabaseErrorCodes.OBJECT_IN_USE, 329 ErrorCodes.USER_SEVERITY, 330 true, 331 throwable); 332 } 333 334 throw exception; 335 } 336 } 337 338 339 341 347 public final void doNewEntryTables (TKDBVectorData data) 348 throws SQLException  349 { 350 } 352 353 354 356 362 private static final String getDescription (ObjectDBData data) 363 { 364 String name = data.getClass().getName(); 365 366 return name.substring(name.indexOf(".WM") + 3, name.indexOf("DBData")); 367 } 368 369 } 370 | Popular Tags |