1 package org.enhydra.shark.instancepersistence; 2 3 import java.math.BigDecimal ; 4 import java.util.*; 5 6 import org.enhydra.dods.DODS; 7 import org.enhydra.shark.api.RootException; 8 import org.enhydra.shark.api.SharkTransaction; 9 import org.enhydra.shark.api.internal.instancepersistence.*; 10 import org.enhydra.shark.api.internal.working.CallbackUtilities; 11 import org.enhydra.shark.instancepersistence.data.*; 12 import org.enhydra.shark.transaction.SharkDODSTransaction; 13 import org.enhydra.shark.utilities.MiscUtilities; 14 import org.enhydra.shark.utilities.dods.DODSUtilities; 15 16 import com.lutris.appserver.server.sql.DBTransaction; 17 import com.lutris.dods.builder.generator.query.QueryBuilder; 18 19 20 27 public class DODSPersistentManager implements PersistentManagerInterface { 28 29 protected static final String LOG_CHANNEL="Persistence"; 30 protected static final int RESOURCE_TYPE_OBJECT=0; 31 protected static final int PROCESS_DEFINITION_TYPE_OBJECT=1; 32 protected static final int PROCESS_TYPE_OBJECT=2; 33 protected static final int ACTIVITY_TYPE_OBJECT=3; 34 protected static final int ASSIGNMENT_TYPE_OBJECT=4; 35 36 protected static final String [] activityAndProcessStates={"open.running", 37 "open.not_running.not_started","open.not_running.suspended", 38 "closed.completed", "closed.terminated", "closed.aborted"}; 39 40 41 protected static final short DB_TYPE_BOOLEAN=0; 42 protected static final short DB_TYPE_LONG=1; 43 protected static final short DB_TYPE_DOUBLE=2; 44 protected static final short DB_TYPE_VCHAR=3; 45 protected static final short DB_TYPE_DATE=4; 46 protected static final short DB_TYPE_BLOB=5; 47 48 protected static final int MAX_VCHAR_SIZE_LIMIT=4000; 49 50 protected static int max_vchar_size=4000; 51 52 protected CallbackUtilities cus; 53 protected boolean deleteFinishedProcesses=false; 54 protected Map _prStates; 55 protected Map _acStates; 56 57 protected List _prClosedStatesBigDecimals; 58 protected List _actClosedStatesBigDecimals; 59 protected List _actOpenStatesBigDecimals; 60 61 protected boolean usingStandardVariableDataModel=true; 62 63 public void configure (CallbackUtilities cus) throws RootException { 64 this.cus=cus; 65 String del=cus.getProperty("DODSPersistentManager.deleteFinishedProcesses","false"); 66 deleteFinishedProcesses=new Boolean (del).booleanValue(); 67 String shtd=cus.getProperty("DatabaseManager.DB.sharkdb.Connection.ShutDownString",""); 68 String mvc=cus.getProperty("DODSPersistentManager.maxVARCHARSize","4000"); 69 try { 70 max_vchar_size=Integer.parseInt(mvc); 71 if (max_vchar_size>MAX_VCHAR_SIZE_LIMIT || max_vchar_size<1) { 72 max_vchar_size=MAX_VCHAR_SIZE_LIMIT; 73 cus.warn("Invalid value "+mvc+" for property DODSPersistentManager.maxVARCHARSize. Using default value "+max_vchar_size); 74 } 75 } catch (Exception e) { 76 cus.warn("Invalid value "+mvc+" for property DODSPersistentManager.maxVARCHARSize. Using default value "+max_vchar_size); 77 } 78 79 if (shtd.equals("SHUTDOWN")) { 80 cus.info(LOG_CHANNEL,"DODSPersistentManager -> Adding shutdown hook for HSQL DB"); 81 Runtime.getRuntime().addShutdownHook( 82 new Thread () { 83 public void run() { 84 try { 85 org.enhydra.dods.DODS.shutdown(); 86 } catch (Throwable thr) { 87 thr.printStackTrace(); 88 } 89 } 90 } 91 ); 92 } 93 usingStandardVariableDataModel=new Boolean (cus.getProperty("DODSPersistentManager.useStandardVariableDataModel","true")).booleanValue(); 94 95 _prStates = new HashMap(); 96 _acStates = new HashMap(); 97 _prClosedStatesBigDecimals = new ArrayList(); 98 _actClosedStatesBigDecimals = new ArrayList(); 99 _actOpenStatesBigDecimals = new ArrayList(); 100 101 try { 102 try { 103 DODSUtilities.init(cus.getProperties()); 104 } 105 catch (Throwable ex) { 106 ex.printStackTrace(); 107 } 108 initActivityAndProcessStatesTable(); 109 cus.info("DODSPersistentManager -> manager configured - working with DB "+cus.getProperty("DatabaseManager.DB.sharkdb.Connection.Url")); 110 cus.info("DODSPersistentManager -> - using DB Driver "+cus.getProperty("DatabaseManager.DB.sharkdb.JdbcDriver")); 111 cus.info("DODSPersistentManager -> - persisting String variables into BLOB for sizes greater than "+max_vchar_size); 112 } 113 catch (Throwable tr) { 114 tr.printStackTrace(); 115 cus.error(LOG_CHANNEL,"Problem with registering database manager with DODS !", new RootException(tr)); 116 throw new RootException("Problem with registering database manager with DODS !",tr); 117 } 118 } 119 120 128 protected void initActivityAndProcessStatesTable () throws PersistenceException { 129 DBTransaction t=null; 130 try { 131 t = DODS.getDatabaseManager().createTransaction(); 132 for (int i=0; i<activityAndProcessStates.length; i++) { 133 String state=activityAndProcessStates[i]; 134 ProcessStateDO psDO=getPersistedProcessStateObject(state,true,t); 135 if (!psDO.isPersistent()) { 136 psDO.setKeyValue(state); 137 } 138 psDO.setName(state); 139 psDO.save(t); 140 BigDecimal bd=psDO.get_OId().toBigDecimal(); 141 _prStates.put(state, bd); 142 if (state.startsWith("closed.")) { 143 _prClosedStatesBigDecimals.add(bd); 144 } 145 ActivityStateDO asDO=getPersistedActivityStateObject(state,true,t); 146 if (!asDO.isPersistent()) { 147 asDO.setKeyValue(state); 148 } 149 asDO.setName(state); 150 asDO.save(t); 151 152 BigDecimal bda=asDO.get_OId().toBigDecimal(); 153 _acStates.put(state, bda); 154 if (state.startsWith("closed.")) { 155 _actClosedStatesBigDecimals.add(bda); 156 } else { 157 _actOpenStatesBigDecimals.add(bda); 158 } 159 } 160 t.commit(); 161 } 162 catch (Throwable thr) { 163 throw new PersistenceException(thr); 164 } 165 finally { 166 try { 167 t.release(); 168 } catch (Exception ex) {} 169 } 170 } 171 172 public void shutdownDatabase () throws PersistenceException { 173 try { 174 DODS.shutdown(); 175 } 176 catch (Throwable tr) { 177 cus.error(LOG_CHANNEL,"Database is not properly shudown !", new RootException(tr)); 178 throw new PersistenceException("Database is not properly shudown !",tr); 179 } 180 } 181 182 public void persist (ProcessMgrPersistenceInterface pm,boolean isInitialPersistence,SharkTransaction ti) throws PersistenceException { 183 try { 184 ProcessDefinitionDO DO=null; 185 if (isInitialPersistence) { 186 DO=ProcessDefinitionDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction()); 187 } else { 188 DO=getPersistedObject(pm,ti); 189 } 190 if (isInitialPersistence) { 192 DO.setName(pm.getName()); 193 DO.setPackageId(pm.getPackageId()); 194 DO.setProcessDefinitionId(pm.getProcessDefinitionId()); 195 DO.setProcessDefinitionVersion(pm.getVersion()); 196 DO.setProcessDefinitionCreated(pm.getCreated()); 197 } 198 DO.setState(pm.getState()); 199 ((SharkDODSTransaction)ti).store(DO); 200 cus.info(LOG_CHANNEL,"ProcessDefinition[packageId="+pm.getPackageId()+",id="+pm.getProcessDefinitionId()+"] persisted"); 203 } 204 catch (Throwable tr) { 205 cus.error(LOG_CHANNEL,"Persisting of ProcessDefinition "+pm.getProcessDefinitionId()+" failed"); 206 throw new PersistenceException("Persisting of ProcessDefinition " 207 + pm.getProcessDefinitionId() 208 +" failed", tr); 209 } 210 } 211 212 public void persist (ProcessPersistenceInterface pr,boolean isInitialPersistence,SharkTransaction ti) throws PersistenceException { 213 try { 214 ProcessDO DO=null; 215 if (isInitialPersistence) { 216 DO=ProcessDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction()); 217 } else { 218 DO=getPersistedObject(pr,ti); 219 } 220 if (isInitialPersistence) { 222 DO.setId(pr.getId()); 223 DO.setProcessDefinition(getPersistedProcessMgrObject(pr.getProcessMgrName(),ti)); 224 ProcessRequesterDO rDO = ProcessRequesterDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction()); 226 rDO.setId(pr.getId()); 227 if (pr.getActivityRequesterId()!=null) { 228 rDO.setActivityRequester(getPersistedActivityObject(pr.getActivityRequesterId(),ti)); 229 } 230 rDO.setResourceRequester(getPersistedResourceObject(pr.getResourceRequesterId(),ti)); 231 DO.setPDefName(pr.getProcessMgrName()); 232 DO.setActivityRequesterId(pr.getActivityRequesterId()); 233 DO.setActivityRequesterProcessId(pr.getActivityRequestersProcessId()); 234 DO.setResourceRequesterId(pr.getResourceRequesterId()); 235 ((SharkDODSTransaction)ti).store(rDO); 236 } 237 DO.setExternalRequesterClassName(pr.getExternalRequesterClassName()); 238 239 DO.setName(pr.getName()); 241 DO.setDescription(pr.getDescription()); 242 DO.setPriority(pr.getPriority()); 243 DO.oid_setState((BigDecimal )_prStates.get(pr.getState())); 244 DO.setCreated(pr.getCreatedTime()); 245 DO.setStarted(pr.getStartedTime()); 246 DO.setLastStateTime(pr.getLastStateTime()); 247 DO.setLimitTime(pr.getLimitTime()); 248 ((SharkDODSTransaction)ti).store(DO); 249 cus.info(LOG_CHANNEL,"Process[id="+pr.getId()+"] persisted"); 252 } 253 catch (Throwable tr) { 254 cus.error(LOG_CHANNEL,"Persisting of Process "+pr.getId()+" failed"); 255 throw new PersistenceException("Persisting of Process " 256 + pr.getId() 257 +" failed", tr); 258 } 259 } 260 261 public void persist (ActivityPersistenceInterface act,boolean isInitialPersistence,SharkTransaction ti) throws PersistenceException { 262 try { 263 ActivityDO DO=null; 265 if (isInitialPersistence) { 266 DO=ActivityDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction()); 267 } else { 268 DO=getPersistedObject(act,ti); 269 } 270 if (isInitialPersistence) { 273 DO.setId(act.getId()); 274 DO.setActivitySetDefinitionId(act.getActivitySetDefinitionId()); 275 DO.setActivityDefinitionId(act.getActivityDefinitionId()); 276 DO.setPDefName(act.getProcessMgrName()); 277 DO.setProcess(getPersistedProcessObject(act.getProcessId(),ti)); 278 DO.setProcessId(act.getProcessId()); 279 String bActId=act.getBlockActivityId(); 280 if (bActId!=null) { 281 DO.setBlockActivityId(bActId); 283 } 284 } 285 DO.setPerformer(act.getSubflowProcessId()); 286 DO.setIsPerformerAsynchronous(act.isSubflowAsynchronous()); 287 DO.setName(act.getName()); 288 DO.setDescription(act.getDescription()); 289 DO.setPriority(act.getPriority()); 290 if (!isInitialPersistence && DO.getResourceId()!=act.getResourceUsername()) { 291 DO.setTheResource(getPersistedResourceObject(act.getResourceUsername(),ti)); 292 DO.setResourceId(act.getResourceUsername()); 293 } 294 DO.oid_setState((BigDecimal )_acStates.get(act.getState())); 295 DO.setLastStateTime(act.getLastStateTime()); 296 DO.setLimitTime(act.getLimitTime()); 297 DO.setAccepted(act.getAcceptedTime()); 298 DO.setActivated(act.getActivatedTime()); 299 300 ((SharkDODSTransaction)ti).store(DO); 301 cus.info(LOG_CHANNEL,"Activity[id="+act.getId()+",definitionId="+act.getActivityDefinitionId()+"] persisted"); 304 } 305 catch (Throwable tr) { 306 cus.error(LOG_CHANNEL,"Persisting of Activity "+act.getId()+" failed"); 307 throw new PersistenceException("Persisting of Activity " 308 + act.getId() 309 +" failed",tr); 310 } 311 } 312 313 public void persist (ResourcePersistenceInterface res,boolean isInitialPersistence,SharkTransaction ti) throws PersistenceException { 314 try { 315 ResourceDO DO=null; 316 if (isInitialPersistence) { 317 DO=ResourceDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction()); 318 } else { 319 DO=getPersistedObject(res,ti); 320 } 321 if (isInitialPersistence) { 323 DO.setUsername(res.getUsername()); 324 DO.setName(res.getName()); 325 } 326 ((SharkDODSTransaction)ti).store(DO); 327 cus.info(LOG_CHANNEL,"Resource[username="+res.getUsername()+"] persisted"); 330 } 331 catch (Throwable tr) { 332 cus.error(LOG_CHANNEL,"Persisting of Resource "+res.getUsername()+" failed"); 333 throw new PersistenceException("Persisting of Resource " 334 + res.getUsername()+" failed", tr); 335 } 336 } 337 338 public void persist (AssignmentPersistenceInterface ass,boolean isInitialPersistence,SharkTransaction ti) throws PersistenceException { 339 try { 340 AssignmentDO DO=null; 341 if (isInitialPersistence) { 342 DO=AssignmentDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction()); 343 } else { 344 DO=getPersistedObject(ass,ti); 345 } 346 if (isInitialPersistence) { 349 DO.setActivity(getPersistedActivityObject(ass.getActivityId(),ti)); 350 DO.setCNT(getNextDecId("_assignment_")); 351 DO.setActivityId(ass.getActivityId()); 352 DO.setActivityProcessId(ass.getProcessId()); 353 DO.setActivityProcessDefName(ass.getProcessMgrName()); 354 } 355 DO.setIsValid(ass.isValid()); 356 DO.setIsAccepted(ass.isAccepted()); 357 if (ass.getResourceUsername()!=DO.getResourceId()) { 358 DO.setResourceId(ass.getResourceUsername()); 359 DO.setTheResource(getPersistedResourceObject(ass.getResourceUsername(),ti)); 360 } 361 ((SharkDODSTransaction)ti).store(DO); 362 cus.info(LOG_CHANNEL,"Assignment[activityId="+ass.getActivityId()+", username="+ass.getResourceUsername()+"] persisted"); 365 } 366 catch (Throwable tr) { 367 cus.error(LOG_CHANNEL,"Persisting of Assignment failed"); 368 throw new PersistenceException("Persisting of Assignment failed", tr); 369 } 370 } 371 372 public void persist (AssignmentPersistenceInterface ass,String oldResUname,SharkTransaction ti) throws PersistenceException { 373 try { 374 AssignmentDO DO=getPersistedAssignmentObject(ass.getActivityId(),oldResUname,ti); 375 DO.setTheResource(getPersistedResourceObject(ass.getResourceUsername(),ti)); 376 DO.setResourceId(ass.getResourceUsername()); 377 DO.setIsValid(ass.isValid()); 378 DO.setIsAccepted(ass.isAccepted()); 379 ((SharkDODSTransaction)ti).store(DO); 380 cus.info(LOG_CHANNEL,"Assignment[activityId="+ass.getActivityId()+", username="+ass.getResourceUsername()+"] persisted"); 383 } 384 catch (Throwable tr) { 385 cus.error(LOG_CHANNEL,"Persisting of Assignment failed"); 386 throw new PersistenceException("Persisting of Assignment failed", tr); 387 } 388 } 389 390 public void persist (ProcessVariablePersistenceInterface var,boolean isInitialPersistence,SharkTransaction ti) throws PersistenceException { 391 if (usingStandardVariableDataModel) { 392 persistVariablesBLOB(var, isInitialPersistence, ti); 393 } else { 394 persistVariablesWOB(var, isInitialPersistence, ti); 395 } 396 } 397 398 protected void persistVariablesBLOB (ProcessVariablePersistenceInterface var,boolean isInitialPersistence,SharkTransaction ti) throws PersistenceException { 399 try { 400 ProcessDataDO DO=null; 401 if (isInitialPersistence) { 402 DO=ProcessDataDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction()); 403 } else { 404 DO=getPersistedObject(var,ti); 405 } 406 if (isInitialPersistence) { 408 DO.setProcess(getPersistedProcessObject(var.getProcessId(),ti)); 409 DO.setVariableDefinitionId(var.getDefinitionId()); 410 } 411 412 Object vv=var.getValue(); 413 boolean isBLOB=false; 414 boolean wasBLOB=false; 415 if (vv instanceof Boolean ) { 416 DO.setVariableValueBOOL(((Boolean )vv).booleanValue()); 417 DO.setVariableType(DODSPersistentManager.DB_TYPE_BOOLEAN); 418 } else if (vv instanceof Long ) { 419 DO.setVariableValueLONG(((Long )vv).longValue()); 420 DO.setVariableType(DODSPersistentManager.DB_TYPE_LONG); 421 } else if (vv instanceof String ) { 422 String sv=(String )vv; 423 if (sv.length()<=max_vchar_size) { 424 DO.setVariableValueVCHAR(sv); 425 wasBLOB=true; 426 DO.setVariableType(DODSPersistentManager.DB_TYPE_VCHAR); 427 } else { 428 DO.setVariableValueVCHAR(null); 429 isBLOB=true; 430 } 431 } else if (vv instanceof Double ) { 432 DO.setVariableValueDBL(((Double )vv).doubleValue()); 433 DO.setVariableType(DODSPersistentManager.DB_TYPE_DOUBLE); 434 } else if (vv instanceof java.util.Date ) { 435 DO.setVariableValueDATE(new java.sql.Timestamp (((java.util.Date )vv).getTime())); 436 DO.setVariableType(DODSPersistentManager.DB_TYPE_DATE); 437 } else if (vv==null) { 438 short vt=DO.getVariableType(); 439 if (vt==DODSPersistentManager.DB_TYPE_DATE) { 440 DO.setVariableValueDATE(null); 441 } else if (vt==DODSPersistentManager.DB_TYPE_VCHAR) { 442 DO.setVariableValueVCHAR(null); 443 } else { 444 DO.setVariableValue(null); 445 DO.setVariableType(DODSPersistentManager.DB_TYPE_BLOB); 446 } 447 } else { 448 isBLOB=true; 449 } 450 451 if (isBLOB) { 452 DO.setVariableValue(MiscUtilities.serialize(vv)); 453 DO.setVariableType(DODSPersistentManager.DB_TYPE_BLOB); 454 } 455 if (wasBLOB) { 456 DO.setVariableValue(null); 457 } 458 459 ((SharkDODSTransaction)ti).store(DO); 460 cus.info(LOG_CHANNEL,"ProcessVariable[processId="+var.getProcessId()+", definitionId="+var.getDefinitionId()+"] persisted"); 463 } 464 catch (Throwable tr) { 465 cus.error(LOG_CHANNEL,"Persisting of ProcessVariable failed"); 466 throw new PersistenceException("Persisting of ProcessVariable failed", tr); 467 } 468 } 469 470 protected void persistVariablesWOB (ProcessVariablePersistenceInterface var,boolean isInitialPersistence,SharkTransaction ti) throws PersistenceException { 471 try { 472 ProcessDataWOBDO DO=null; 473 if (isInitialPersistence) { 474 DO=ProcessDataWOBDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction()); 475 } else { 476 DO=getPersistedObject2(var,ti); 477 } 478 if (isInitialPersistence) { 480 DO.setProcess(getPersistedProcessObject(var.getProcessId(),ti)); 481 DO.setVariableDefinitionId(var.getDefinitionId()); 482 } 483 484 Object vv=var.getValue(); 485 boolean isBLOB=false; 486 boolean wasBLOB=false; 487 if (vv instanceof Boolean ) { 488 DO.setVariableValueBOOL(((Boolean )vv).booleanValue()); 489 DO.setVariableType(DODSPersistentManager.DB_TYPE_BOOLEAN); 490 } else if (vv instanceof Long ) { 491 DO.setVariableValueLONG(((Long )vv).longValue()); 492 DO.setVariableType(DODSPersistentManager.DB_TYPE_LONG); 493 } else if (vv instanceof String ) { 494 String sv=(String )vv; 495 if (sv.length()<=max_vchar_size) { 496 DO.setVariableValueVCHAR(sv); 497 wasBLOB=true; 498 DO.setVariableType(DODSPersistentManager.DB_TYPE_VCHAR); 499 } else { 500 DO.setVariableValueVCHAR(null); 501 isBLOB=true; 502 } 503 } else if (vv instanceof Double ) { 504 DO.setVariableValueDBL(((Double )vv).doubleValue()); 505 DO.setVariableType(DODSPersistentManager.DB_TYPE_DOUBLE); 506 } else if (vv instanceof java.util.Date ) { 507 DO.setVariableValueDATE(new java.sql.Timestamp (((java.util.Date )vv).getTime())); 508 DO.setVariableType(DODSPersistentManager.DB_TYPE_DATE); 509 } else if (vv==null) { 510 short vt=DO.getVariableType(); 511 if (vt==DODSPersistentManager.DB_TYPE_DATE) { 512 DO.setVariableValueDATE(null); 513 } else if (vt==DODSPersistentManager.DB_TYPE_VCHAR) { 514 DO.setVariableValueVCHAR(null); 515 } else { 516 ProcessDataBLOBDO bDO=null; 517 if (isInitialPersistence) { 518 bDO=ProcessDataBLOBDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction()); 519 } else { 520 bDO=getPersistedObject(DO, ti); 521 } 522 bDO.setProcessDataWOB(DO); 523 bDO.setVariableValue(null); 524 DO.setVariableType(DODSPersistentManager.DB_TYPE_BLOB); 525 ((SharkDODSTransaction)ti).store(bDO); 526 } 527 } else { 528 isBLOB=true; 529 } 530 531 if (isBLOB) { 532 ProcessDataBLOBDO bDO=null; 533 if (isInitialPersistence) { 534 bDO=ProcessDataBLOBDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction()); 535 } else { 536 bDO=getPersistedObject(DO, ti); 537 } 538 bDO.setProcessDataWOB(DO); 539 bDO.setVariableValue(MiscUtilities.serialize(vv)); 540 DO.setVariableType(DODSPersistentManager.DB_TYPE_BLOB); 541 ((SharkDODSTransaction)ti).store(bDO); 542 } 543 547 ((SharkDODSTransaction)ti).store(DO); 548 cus.info(LOG_CHANNEL,"ProcessVariable[processId="+var.getProcessId()+", definitionId="+var.getDefinitionId()+"] persisted"); 551 } 552 catch (Throwable tr) { 553 cus.error(LOG_CHANNEL,"Persisting of ProcessVariable failed"); 554 throw new PersistenceException("Persisting of ProcessVariable failed", tr); 555 } 556 } 557 558 public void persist (ActivityVariablePersistenceInterface var,boolean isInitialPersistence,SharkTransaction ti) throws PersistenceException { 559 if (usingStandardVariableDataModel) { 560 persistVariablesBLOB(var, isInitialPersistence, ti); 561 } else { 562 persistVariablesWOB(var, isInitialPersistence, ti); 563 } 564 } 565 566 public void persistVariablesBLOB (ActivityVariablePersistenceInterface var,boolean isInitialPersistence,SharkTransaction ti) throws PersistenceException { 567 try { 568 ActivityDataDO DO=null; 569 if (isInitialPersistence) { 570 DO=ActivityDataDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction()); 571 } else { 572 DO=getPersistedObject(var,ti); 573 } 574 if (isInitialPersistence) { 576 DO.setActivity(getPersistedActivityObject(var.getActivityId(),ti)); 577 DO.setVariableDefinitionId(var.getDefinitionId()); 578 } 579 580 Object vv=var.getValue(); 581 boolean isBLOB=false; 582 boolean wasBLOB=false; 583 if (vv instanceof Boolean ) { 584 DO.setVariableValueBOOL(((Boolean )vv).booleanValue()); 585 DO.setVariableType(DODSPersistentManager.DB_TYPE_BOOLEAN); 586 } else if (vv instanceof Long ) { 587 DO.setVariableValueLONG(((Long )vv).longValue()); 588 DO.setVariableType(DODSPersistentManager.DB_TYPE_LONG); 589 } else if (vv instanceof String ) { 590 String sv=(String )vv; 591 if (sv.length()<=max_vchar_size) { 592 DO.setVariableValueVCHAR(sv); 593 wasBLOB=true; 594 DO.setVariableType(DODSPersistentManager.DB_TYPE_VCHAR); 595 } else { 596 DO.setVariableValueVCHAR(null); 597 isBLOB=true; 598 } 599 } else if (vv instanceof Double ) { 600 DO.setVariableValueDBL(((Double )vv).doubleValue()); 601 DO.setVariableType(DODSPersistentManager.DB_TYPE_DOUBLE); 602 } else if (vv instanceof java.util.Date ) { 603 DO.setVariableValueDATE(new java.sql.Timestamp (((java.util.Date )vv).getTime())); 604 DO.setVariableType(DODSPersistentManager.DB_TYPE_DATE); 605 } else if (vv==null) { 606 short vt=DO.getVariableType(); 607 if (vt==DODSPersistentManager.DB_TYPE_DATE) { 608 DO.setVariableValueDATE(null); 609 } else if (vt==DODSPersistentManager.DB_TYPE_VCHAR) { 610 DO.setVariableValueVCHAR(null); 611 } else { 612 DO.setVariableValue(null); 613 DO.setVariableType(DODSPersistentManager.DB_TYPE_BLOB); 614 } 615 } else { 616 isBLOB=true; 617 } 618 619 if (isBLOB) { 620 DO.setVariableValue(MiscUtilities.serialize(vv)); 621 DO.setVariableType(DODSPersistentManager.DB_TYPE_BLOB); 622 } 623 if (wasBLOB) { 624 DO.setVariableValue(null); 625 } 626 627 DO.setIsResult(var.isResultVariable()); 628 ((SharkDODSTransaction)ti).store(DO); 629 cus.info(LOG_CHANNEL,"ActivityVariable[activityId="+var.getActivityId()+", definitionId="+var.getDefinitionId()+"] persisted"); 632 } 633 catch (Throwable tr) { 634 cus.error(LOG_CHANNEL,"Persisting of ActivityVariable failed"); 635 throw new PersistenceException("Persisting of ActivityVariable failed", tr); 636 } 637 } 638 639 public void persistVariablesWOB (ActivityVariablePersistenceInterface var,boolean isInitialPersistence,SharkTransaction ti) throws PersistenceException { 640 try { 641 ActivityDataWOBDO DO=null; 642 if (isInitialPersistence) { 643 DO=ActivityDataWOBDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction()); 644 } else { 645 DO=getPersistedObject2(var,ti); 646 } 647 if (isInitialPersistence) { 649 DO.setActivity(getPersistedActivityObject(var.getActivityId(),ti)); 650 DO.setVariableDefinitionId(var.getDefinitionId()); 651 } 652 653 Object vv=var.getValue(); 654 boolean isBLOB=false; 655 boolean wasBLOB=false; 656 if (vv instanceof Boolean ) { 657 DO.setVariableValueBOOL(((Boolean )vv).booleanValue()); 658 DO.setVariableType(DODSPersistentManager.DB_TYPE_BOOLEAN); 659 } else if (vv instanceof Long ) { 660 DO.setVariableValueLONG(((Long )vv).longValue()); 661 DO.setVariableType(DODSPersistentManager.DB_TYPE_LONG); 662 } else if (vv instanceof String ) { 663 String sv=(String )vv; 664 if (sv.length()<=max_vchar_size) { 665 DO.setVariableValueVCHAR(sv); 666 wasBLOB=true; 667 DO.setVariableType(DODSPersistentManager.DB_TYPE_VCHAR); 668 } else { 669 DO.setVariableValueVCHAR(null); 670 isBLOB=true; 671 } 672 } else if (vv instanceof Double ) { 673 DO.setVariableValueDBL(((Double )vv).doubleValue()); 674 DO.setVariableType(DODSPersistentManager.DB_TYPE_DOUBLE); 675 } else if (vv instanceof java.util.Date ) { 676 DO.setVariableValueDATE(new java.sql.Timestamp (((java.util.Date )vv).getTime())); 677 DO.setVariableType(DODSPersistentManager.DB_TYPE_DATE); 678 } else if (vv==null) { 679 short vt=DO.getVariableType(); 680 if (vt==DODSPersistentManager.DB_TYPE_DATE) { 681 DO.setVariableValueDATE(null); 682 } else if (vt==DODSPersistentManager.DB_TYPE_VCHAR) { 683 DO.setVariableValueVCHAR(null); 684 } else { 685 ActivityDataBLOBDO bDO=null; 686 if (isInitialPersistence) { 687 bDO=ActivityDataBLOBDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction()); 688 } else { 689 bDO=getPersistedObject(DO, ti); 690 } 691 bDO.setActivityDataWOB(DO); 692 bDO.setVariableValue(null); 693 DO.setVariableType(DODSPersistentManager.DB_TYPE_BLOB); 694 ((SharkDODSTransaction)ti).store(bDO); 695 } 696 } else { 697 isBLOB=true; 698 } 699 700 if (isBLOB) { 701 ActivityDataBLOBDO bDO=null; 702 if (isInitialPersistence) { 703 bDO=ActivityDataBLOBDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction()); 704 } else { 705 bDO=getPersistedObject(DO, ti); 706 } 707 bDO.setActivityDataWOB(DO); 708 bDO.setVariableValue(MiscUtilities.serialize(vv)); 709 DO.setVariableType(DODSPersistentManager.DB_TYPE_BLOB); 710 ((SharkDODSTransaction)ti).store(bDO); 711 } 712 716 DO.setIsResult(var.isResultVariable()); 717 ((SharkDODSTransaction)ti).store(DO); 718 cus.info(LOG_CHANNEL,"ActivityVariable[activityId="+var.getActivityId()+", definitionId="+var.getDefinitionId()+"] persisted"); 721 } 722 catch (Throwable tr) { 723 cus.error(LOG_CHANNEL,"Persisting of ActivityVariable failed"); 724 throw new PersistenceException("Persisting of ActivityVariable failed", tr); 725 } 726 } 727 728 public void persist (AndJoinEntryInterface aje,SharkTransaction ti) throws PersistenceException { 729 try { 730 AndJoinEntryDO DO=AndJoinEntryDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction()); 731 DO.setProcess(getPersistedProcessObject(aje.getProcessId(),ti)); 732 DO.setActivitySetDefinitionId(aje.getActivitySetDefinitionId()); 733 DO.setActivityDefinitionId(aje.getActivityDefinitionId()); 734 DO.setActivity(getPersistedActivityObject(aje.getActivityId(),ti)); 735 DO.setCNT(getNextDecId("andjoinentry")); 736 ((SharkDODSTransaction)ti).store(DO); 737 cus.info(LOG_CHANNEL,"AndJoinEntry[id="+aje.getProcessId()+",aDefId="+aje.getActivityDefinitionId()+",actId="+aje.getActivityId()+"] persisted"); 740 } 741 catch (Throwable tr) { 742 cus.error(LOG_CHANNEL,"Persisting of AndJoinEntry [id="+aje.getProcessId()+",aDefId="+aje.getActivityDefinitionId()+",actId="+aje.getActivityId()+"] failed"); 743 throw new PersistenceException( 744 "Persisting of AndJoinEntry [id="+aje.getProcessId()+ 745 ",aDefId="+aje.getActivityDefinitionId()+ 746 ",actId="+aje.getActivityId()+"] failed",tr); 747 } 748 } 749 750 public void persist(DeadlinePersistenceInterface dpe, boolean isInitialPersistence, SharkTransaction ti) throws PersistenceException { 751 try { 752 DeadlineDO DO=null; 753 if (isInitialPersistence) { 754 DO=DeadlineDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction()); 755 } else { 756 DO=getPersistedObject(dpe,ti); 757 } 758 if (isInitialPersistence) { 760 DO.setProcess(getPersistedProcessObject(dpe.getProcessId(),ti)); 761 DO.setActivity(getPersistedActivityObject(dpe.getActivityId(),ti)); 762 DO.setExceptionName(dpe.getExceptionName()); 763 DO.setTimeLimit(dpe.getTimeLimit()); 764 DO.setIsSynchronous(dpe.isSynchronous()); 765 DO.setCNT(getNextDecId("deadline")); 766 } else { 767 DO.setIsExecuted(dpe.isExecuted()); 768 } 769 ((SharkDODSTransaction)ti).store(DO); 770 cus.info(LOG_CHANNEL,"Deadline[actId="+dpe.getActivityId()+",ExcName="+dpe.getExceptionName()+"] persisted"); 773 } 774 catch (Throwable tr) { 775 cus.error(LOG_CHANNEL,"Persisting of Deadline[actId="+dpe.getActivityId()+",ExcName="+dpe.getExceptionName()+"] failed"); 776 throw new PersistenceException( 777 "Persisting of Deadline[actId="+dpe.getActivityId()+",ExcName="+dpe.getExceptionName()+"] failed",tr); 778 } 779 } 780 781 public ProcessMgrPersistenceInterface restoreProcessMgr (String mgrName,SharkTransaction ti) throws PersistenceException { 782 return restore(getPersistedProcessMgrObject(mgrName,ti)); 783 } 784 785 protected ProcessMgrPersistenceInterface restore (ProcessDefinitionDO DO) throws PersistenceException { 786 if (DO==null) return null; 787 ProcessMgrPersistenceInterface engineObj=new DODSProcessMgr(); 788 789 try { 790 engineObj.setName(DO.getName()); 791 engineObj.setPackageId(DO.getPackageId()); 792 engineObj.setProcessDefinitionId(DO.getProcessDefinitionId()); 793 engineObj.setVersion(DO.getProcessDefinitionVersion()); 794 engineObj.setCreated(DO.getProcessDefinitionCreated()); 795 engineObj.setState(DO.getState()); 796 cus.debug(LOG_CHANNEL,"ProcessDefinition[packageId="+DO.getPackageId()+",id="+DO.getProcessDefinitionId()+" restored"); 797 } 798 catch (Throwable tr) { 799 cus.error(LOG_CHANNEL,"Restoring of ProcessDefinition failed"); 800 throw new PersistenceException 801 ("Restoring of ProcessDefinition failed", tr); 802 } 803 return engineObj; 804 } 805 806 public ProcessPersistenceInterface restoreProcess (String procId,SharkTransaction ti) throws PersistenceException { 807 return restore(getPersistedProcessObject(procId,ti)); 808 } 809 810 protected ProcessPersistenceInterface restore (ProcessDO DO) throws PersistenceException { 811 if (DO==null) return null; 812 813 ProcessPersistenceInterface engineObj=new DODSProcess(); 814 try { 815 engineObj.setId(DO.getId()); 816 engineObj.setProcessMgrName(DO.getPDefName()); 818 engineObj.setName(DO.getName()); 819 engineObj.setDescription(DO.getDescription()); 820 engineObj.setPriority(DO.getPriority()); 821 engineObj.setState(DO.getState().getName()); 822 engineObj.setCreatedTime(DO.getCreated()); 823 engineObj.setStartedTime(DO.getStarted()); 824 engineObj.setLastStateTime(DO.getLastStateTime()); 825 engineObj.setLimitTime(DO.getLimitTime()); 826 827 843 engineObj.setActivityRequesterId(DO.getActivityRequesterId()); 844 engineObj.setActivityRequestersProcessId(DO.getActivityRequesterProcessId()); 845 engineObj.setResourceRequesterId(DO.getResourceRequesterId()); 846 engineObj.setExternalRequesterClassName(DO.getExternalRequesterClassName()); 847 848 cus.debug(LOG_CHANNEL,"Process[id="+DO.getId()+"] restored"); 849 } 850 catch (Throwable tr) { 851 cus.error(LOG_CHANNEL,"Restoring of Process failed"); 852 throw new PersistenceException 853 ("Restoring of Process "+engineObj.getId()+" failed", tr); 854 } 855 return engineObj; 856 } 857 858 public ActivityPersistenceInterface restoreActivity (String actId,SharkTransaction ti) throws PersistenceException { 859 return restore(getPersistedActivityObject(actId,ti)); 860 } 861 862 protected ActivityPersistenceInterface restore (ActivityDO DO) throws PersistenceException { 863 if (DO==null) return null; 864 865 ActivityPersistenceInterface engineObj=new DODSActivity(); 866 try { 867 engineObj.setActivitySetDefinitionId(DO.getActivitySetDefinitionId()); 868 engineObj.setActivityDefinitionId(DO.getActivityDefinitionId()); 869 engineObj.setId(DO.getId()); 870 engineObj.setProcessMgrName(DO.getPDefName()); 871 engineObj.setProcessId(DO.getProcessId()); 873 876 engineObj.setResourceUsername(DO.getResourceId()); 877 878 engineObj.setSubflowProcessId(DO.getPerformer()); 879 engineObj.setSubflowAsynchronous(DO.getIsPerformerAsynchronous()); 880 engineObj.setName(DO.getName()); 881 engineObj.setDescription(DO.getDescription()); 882 engineObj.setPriority(DO.getPriority()); 883 engineObj.setState(DO.getState().getName()); 884 engineObj.setLastStateTime(DO.getLastStateTime()); 885 engineObj.setLimitTime(DO.getLimitTime()); 886 engineObj.setAcceptedTime(DO.getAccepted()); 887 engineObj.setActivatedTime(DO.getActivated()); 888 891 engineObj.setBlockActivityId(DO.getBlockActivityId()); 892 cus.debug(LOG_CHANNEL,"Activity[id="+DO.getId()+",definitionId="+DO.getActivityDefinitionId()+"] restored"); 893 } 894 catch (Throwable tr) { 895 cus.error(LOG_CHANNEL,"Restoring of Activity failed"); 896 throw new PersistenceException 897 ("Restoring of Activity failed", tr); 898 } 899 return engineObj; 900 } 901 902 public ResourcePersistenceInterface restoreResource (String resUsername,SharkTransaction ti) throws PersistenceException { 903 return restore(getPersistedResourceObject(resUsername,ti)); 904 } 905 906 protected ResourcePersistenceInterface restore (ResourceDO DO) throws PersistenceException { 907 if (DO==null) return null; 908 909 ResourcePersistenceInterface engineObj=new DODSResource(); 910 try { 911 engineObj.setName(DO.getName()); 912 engineObj.setUsername(DO.getUsername()); 913 cus.debug(LOG_CHANNEL,"Resource[username="+DO.getUsername()+"] restored"); 914 } 915 catch (Throwable tr) { 916 cus.error(LOG_CHANNEL,"Restoring of Resource failed"); 917 throw new PersistenceException 918 ("Restoring of Resource failed", tr); 919 } 920 return engineObj; 921 } 922 923 public AssignmentPersistenceInterface restoreAssignment (String actId,String resUsername,SharkTransaction ti) throws PersistenceException { 924 return restore(getPersistedAssignmentObject(actId,resUsername,ti)); 925 } 926 927 protected AssignmentPersistenceInterface restore (AssignmentDO DO) throws PersistenceException { 928 if (DO==null) return null; 929 930 AssignmentPersistenceInterface engineObj=new DODSAssignment(); 931 try { 932 String actId=DO.getActivityId(); 933 String username=DO.getResourceId(); 934 String processId=DO.getActivityProcessId(); 935 938 engineObj.setActivityId(actId); 939 engineObj.setResourceUsername(username); 940 engineObj.setProcessId(processId); 941 engineObj.setProcessMgrName(DO.getActivityProcessDefName()); 942 engineObj.setValid(DO.getIsValid()); 943 engineObj.setAccepted(DO.getIsAccepted()); 944 cus.debug(LOG_CHANNEL,"Assignment[activityId="+actId+", username="+username+"] restored"); 945 } 946 catch (Throwable tr) { 947 cus.error(LOG_CHANNEL,"Restoring of Assignment failed"); 948 throw new PersistenceException 949 ("Restoring of Assignment failed", tr); 950 } 951 return engineObj; 952 } 953 954 public boolean restore (ProcessVariablePersistenceInterface var,SharkTransaction ti) throws PersistenceException { 955 if (usingStandardVariableDataModel) { 956 return restoreBLOB(var,getPersistedObject(var,ti)); 957 } else { 958 return restoreWOB(var,getPersistedObject2(var,ti)); 959 } 960 } 961 962 protected boolean restoreBLOB (ProcessVariablePersistenceInterface engineObj, 963 ProcessDataDO DO) throws PersistenceException { 964 if (DO==null) return false; 965 966 try { 967 engineObj.setProcessId(DO.getProcess().getId()); 968 engineObj.setDefinitionId(DO.getVariableDefinitionId()); 969 970 short vtype=DO.getVariableType(); 971 switch (vtype) { 972 case DODSPersistentManager.DB_TYPE_BOOLEAN : 973 engineObj.setValue(new Boolean (DO.getVariableValueBOOL())); 974 break; 975 case DODSPersistentManager.DB_TYPE_LONG: 976 engineObj.setValue(new Long (DO.getVariableValueLONG())); 977 break; 978 case DODSPersistentManager.DB_TYPE_DOUBLE: 979 engineObj.setValue(new Double (DO.getVariableValueDBL())); 980 break; 981 case DODSPersistentManager.DB_TYPE_VCHAR: 982 engineObj.setValue(DO.getVariableValueVCHAR()); 983 break; 984 case DODSPersistentManager.DB_TYPE_DATE: 985 java.sql.Timestamp d=DO.getVariableValueDATE(); 986 if (d!=null) { 987 engineObj.setValue(new java.util.Date (d.getTime())); 988 } else { 989 engineObj.setValue(null); 990 } 991 break; 992 default: 993 byte[] v=DO.getVariableValue(); 994 if (v!=null && v.length>0) { 995 engineObj.setValue(MiscUtilities.deserialize(v)); 996 } else { 997 engineObj.setValue(null); 998 } 999 } 1000 1001 1002 cus.debug(LOG_CHANNEL,"ProcessVariable[processId="+engineObj.getProcessId()+", definitionId="+engineObj.getDefinitionId()+"] restored"); 1003 } 1004 catch (Throwable tr) { 1005 cus.error(LOG_CHANNEL,"Restoring of ProcessVariable failed"); 1006 throw new PersistenceException 1007 ("Restoring of ProcessVariable failed", tr); 1008 } 1009 return true; 1010 } 1011 1012 protected boolean restoreWOB (ProcessVariablePersistenceInterface engineObj, 1013 ProcessDataWOBDO DO) throws PersistenceException { 1014 1015 if (DO==null) return false; 1016 1017 try { 1018 engineObj.setProcessId(DO.getProcess().getId()); 1019 engineObj.setDefinitionId(DO.getVariableDefinitionId()); 1020 1021 short vtype=DO.getVariableType(); 1022 switch (vtype) { 1023 case DODSPersistentManager.DB_TYPE_BOOLEAN : 1024 engineObj.setValue(new Boolean (DO.getVariableValueBOOL())); 1025 break; 1026 case DODSPersistentManager.DB_TYPE_LONG: 1027 engineObj.setValue(new Long (DO.getVariableValueLONG())); 1028 break; 1029 case DODSPersistentManager.DB_TYPE_DOUBLE: 1030 engineObj.setValue(new Double (DO.getVariableValueDBL())); 1031 break; 1032 case DODSPersistentManager.DB_TYPE_VCHAR: 1033 engineObj.setValue(DO.getVariableValueVCHAR()); 1034 break; 1035 case DODSPersistentManager.DB_TYPE_DATE: 1036 java.sql.Timestamp d=DO.getVariableValueDATE(); 1037 if (d!=null) { 1038 engineObj.setValue(new java.util.Date (d.getTime())); 1039 } else { 1040 engineObj.setValue(null); 1041 } 1042 break; 1043 default: 1044 byte[] v=DO.getProcessDataBLOBDO().getVariableValue(); 1045 if (v!=null && v.length>0) { 1046 engineObj.setValue(MiscUtilities.deserialize(v)); 1047 } else { 1048 engineObj.setValue(null); 1049 } 1050 } 1051 1052 cus.debug(LOG_CHANNEL,"ProcessVariable[processId="+engineObj.getProcessId()+", definitionId="+engineObj.getDefinitionId()+"] restored"); 1053 } 1054 catch (Throwable tr) { 1055 cus.error(LOG_CHANNEL,"Restoring of ProcessVariable failed"); 1056 throw new PersistenceException 1057 ("Restoring of ProcessVariable failed", tr); 1058 } 1059 return true; 1060 } 1061 1062 public boolean restore (ActivityVariablePersistenceInterface var,SharkTransaction ti) throws PersistenceException { 1063 if (usingStandardVariableDataModel) { 1064 return restoreBLOB(var,getPersistedObject(var,ti)); 1065 } else { 1066 return restoreWOB(var,getPersistedObject2(var,ti)); 1067 } 1068 } 1069 1070 protected boolean restoreBLOB (ActivityVariablePersistenceInterface engineObj, 1071 ActivityDataDO DO) throws PersistenceException { 1072 if (DO==null) return false; 1073 1074 try { 1075 engineObj.setActivityId(DO.getActivity().getId()); 1076 engineObj.setDefinitionId(DO.getVariableDefinitionId()); 1077 1078 short vtype=DO.getVariableType(); 1079 switch (vtype) { 1080 case DODSPersistentManager.DB_TYPE_BOOLEAN : 1081 engineObj.setValue(new Boolean (DO.getVariableValueBOOL())); 1082 break; 1083 case DODSPersistentManager.DB_TYPE_LONG: 1084 engineObj.setValue(new Long (DO.getVariableValueLONG())); 1085 break; 1086 case DODSPersistentManager.DB_TYPE_DOUBLE: 1087 engineObj.setValue(new Double (DO.getVariableValueDBL())); 1088 break; 1089 case DODSPersistentManager.DB_TYPE_VCHAR: 1090 engineObj.setValue(DO.getVariableValueVCHAR()); 1091 break; 1092 case DODSPersistentManager.DB_TYPE_DATE: 1093 java.sql.Timestamp d=DO.getVariableValueDATE(); 1094 if (d!=null) { 1095 engineObj.setValue(new java.util.Date (d.getTime())); 1096 } else { 1097 engineObj.setValue(null); 1098 } 1099 break; 1100 default: 1101 byte[] v=DO.getVariableValue(); 1102 if (v!=null && v.length>0) { 1103 engineObj.setValue(MiscUtilities.deserialize(v)); 1104 } else { 1105 engineObj.setValue(null); 1106 } 1107 } 1108 1109 engineObj.setResultVariable(DO.getIsResult()); 1110 cus.debug(LOG_CHANNEL,"ActivityVariable[activityId="+engineObj.getActivityId()+", definitionId="+engineObj.getDefinitionId()+"] restored"); 1111 } 1112 catch (Throwable tr) { 1113 cus.error(LOG_CHANNEL,"Restoring of Variable failed"); 1114 throw new PersistenceException 1115 ("Restoring of Variable failed", tr); 1116 } 1117 return true; 1118 } 1119 1120 protected boolean restoreWOB (ActivityVariablePersistenceInterface engineObj, 1121 ActivityDataWOBDO DO) throws PersistenceException { 1122 if (DO==null) return false; 1123 try { 1124 engineObj.setActivityId(DO.getActivity().getId()); 1125 engineObj.setDefinitionId(DO.getVariableDefinitionId()); 1126 1127 short vtype=DO.getVariableType(); 1128 switch (vtype) { 1129 case DODSPersistentManager.DB_TYPE_BOOLEAN : 1130 engineObj.setValue(new Boolean (DO.getVariableValueBOOL())); 1131 break; 1132 case DODSPersistentManager.DB_TYPE_LONG: 1133 engineObj.setValue(new Long (DO.getVariableValueLONG())); 1134 break; 1135 case DODSPersistentManager.DB_TYPE_DOUBLE: 1136 engineObj.setValue(new Double (DO.getVariableValueDBL())); 1137 break; 1138 case DODSPersistentManager.DB_TYPE_VCHAR: 1139 engineObj.setValue(DO.getVariableValueVCHAR()); 1140 break; 1141 case DODSPersistentManager.DB_TYPE_DATE: 1142 java.sql.Timestamp d=DO.getVariableValueDATE(); 1143 if (d!=null) { 1144 engineObj.setValue(new java.util.Date (d.getTime())); 1145 } else { 1146 engineObj.setValue(null); 1147 } 1148 break; 1149 default: 1150 byte[] v=DO.getActivityDataBLOBDO().getVariableValue(); 1151 if (v!=null && v.length>0) { 1152 engineObj.setValue(MiscUtilities.deserialize(v)); 1153 } else { 1154 engineObj.setValue(null); 1155 } 1156 } 1157 1158 engineObj.setResultVariable(DO.getIsResult()); 1159 cus.debug(LOG_CHANNEL,"ActivityVariable[activityId="+engineObj.getActivityId()+", definitionId="+engineObj.getDefinitionId()+"] restored"); 1160 } 1161 catch (Throwable tr) { 1162 cus.error(LOG_CHANNEL,"Restoring of Variable failed"); 1163 throw new PersistenceException 1164 ("Restoring of Variable failed", tr); 1165 } 1166 return true; 1167 } 1168 1169 public void deleteProcessMgr (String mgrName,SharkTransaction ti) throws PersistenceException { 1170 try { 1171 ProcessDefinitionDO DO=getPersistedProcessMgrObject(mgrName,ti); 1172 if (DO.getProcessDOArrayCount()>0) return; 1173 ((SharkDODSTransaction)ti).erase(DO); 1174 cus.info(LOG_CHANNEL,"ProcessDefinition[name="+mgrName+"] deleted"); 1177 } catch (Throwable tr) { 1178 cus.error(LOG_CHANNEL,"Deleting of ProcessDefinition failed"); 1179 throw new PersistenceException 1180 ("Deleting of ProcessDefinition failed", tr); 1181 } 1182 } 1183 1184 public void deleteProcess (String procId,boolean administrative,SharkTransaction ti) throws PersistenceException { 1185 if (!deleteFinishedProcesses && !administrative) return; 1186 try { 1187 Set procIds=new HashSet(); 1188 performCascadeDeletion(procId,procIds,(SharkDODSTransaction)ti); 1189 procIds.remove(procId); 1190 cus.info(LOG_CHANNEL,"Main Process[id="+procId+"] deleted"); 1191 cus.info(LOG_CHANNEL,"Sub-Processes "+procIds+"] deleted"); 1192 } catch (Throwable tr) { 1195 cus.error(LOG_CHANNEL,"Deleting of Process failed"); 1196 throw new PersistenceException 1197 ("Deleting of Process failed", tr); 1198 } 1199 } 1200 1201 protected void performCascadeDeletion (String procId,Set procIds,SharkDODSTransaction ti) throws Exception { 1202 ProcessDO pDO=getPersistedProcessObject(procId,ti); 1203 ProcessRequesterDO pReqDO=getPersistedRequesterObject(procId,ti); 1204 ((SharkDODSTransaction)ti).erase(pDO); 1205 ((SharkDODSTransaction)ti).erase(pReqDO); 1206 if (pDO==null) { 1207 return; 1209 } 1210 procIds.add(procId); 1211 performCascadeErasageFromBuffer(pDO,procIds,(SharkDODSTransaction)ti); 1212 String SQLWHERE="Activities.Process="+pDO.get_Handle()+" AND Activities.Performer IS NOT NULL"; ActivityQuery query=new ActivityQuery(ti.getDODSTransaction()); 1215 QueryBuilder qb=qb=query.getQueryBuilder(); 1216 qb.addWhere(SQLWHERE); 1217 ActivityDO[] DOs = query.getDOArray(); 1219 Set deleteFurther=new HashSet(); 1220 if (DOs!=null) { 1221 for (int i=0;i<DOs.length; i++) { 1222 if (!DOs[i].getIsPerformerAsynchronous()) { 1223 deleteFurther.add(DOs[i].getPerformer()); 1224 } 1225 } 1226 } 1227 deleteFurther.removeAll(procIds); 1228 Iterator it=deleteFurther.iterator(); 1230 while (it.hasNext()) { 1231 String fpid=(String )it.next(); 1232 performCascadeDeletion(fpid, procIds, ti); 1233 } 1234 1235 } 1236 1237 protected void performCascadeErasageFromBuffer (ProcessDO pDO,Set procIds,SharkDODSTransaction sdt) throws Exception { 1238 try { 1239 BigDecimal pOId = pDO.get_OId().toBigDecimal(); 1241 Set actOIdsToRemove=new HashSet(); 1242 Set procIdsToRemove=new HashSet(); 1243 Set toRemove=new HashSet(); 1244 for (Iterator it = sdt.iterator4type("class org.enhydra.shark.instancepersistence.data.ActivityDO"); 1245 it.hasNext();) { 1246 ActivityDO o = (ActivityDO)it.next(); 1247 if (pOId.equals(o.oid_getProcess())) { 1248 toRemove.add(o); 1249 actOIdsToRemove.add(o.get_OId().toBigDecimal()); 1250 if (o.getPerformer()!=null && !o.getIsPerformerAsynchronous()) { 1251 procIdsToRemove.add(o.getPerformer()); 1252 } 1253 } 1254 } 1255 for (Iterator it = sdt.iterator4type("class org.enhydra.shark.instancepersistence.data.ProcessDataDO"); 1256 it.hasNext();) { 1257 ProcessDataDO o = (ProcessDataDO)it.next(); 1258 if (pOId.equals(o.oid_getProcess())) { 1259 toRemove.add(o); 1260 } 1261 } 1262 for (Iterator it = sdt.iterator4type("class org.enhydra.shark.instancepersistence.data.DeadlineDO"); 1263 it.hasNext();) { 1264 DeadlineDO o = (DeadlineDO)it.next(); 1265 if (pOId.equals(o.oid_getProcess())) { 1266 toRemove.add(o); 1267 } 1268 } 1269 for (Iterator it = sdt.iterator4type("class org.enhydra.shark.instancepersistence.data.AndJoinEntryDO"); 1270 it.hasNext();) { 1271 AndJoinEntryDO o = (AndJoinEntryDO)it.next(); 1272 if (pOId.equals(o.oid_getProcess())) { 1273 toRemove.add(o); 1274 } 1275 } 1276 1277 for (Iterator it = sdt.iterator4type("class org.enhydra.shark.instancepersistence.data.AssignmentDO"); 1278 it.hasNext();) { 1279 AssignmentDO o = (AssignmentDO)it.next(); 1280 if (actOIdsToRemove.contains(o.oid_getActivity())) { 1281 toRemove.add(o); 1282 } 1283 } 1284 for (Iterator it = sdt.iterator4type("class org.enhydra.shark.instancepersistence.data.ActivityDataDO"); 1285 it.hasNext();) { 1286 ActivityDataDO o = (ActivityDataDO)it.next(); 1287 if (actOIdsToRemove.contains(o.oid_getActivity())) { 1288 toRemove.add(o); 1289 } 1290 } 1291 for (Iterator it = sdt.iterator4type("class org.enhydra.shark.instancepersistence.data.ProcessRequesterDO"); 1292 it.hasNext();) { 1293 ProcessRequesterDO o = (ProcessRequesterDO)it.next(); 1294 if (actOIdsToRemove.contains(o.oid_getActivityRequester()) || o.getId().equals(pDO.getId())) { 1295 toRemove.add(o); 1296 } 1297 } 1298 sdt.erase(toRemove); 1299 Iterator it=procIdsToRemove.iterator(); 1300 while (it.hasNext()) { 1301 performCascadeDeletion((String )it.next(), procIds, sdt); 1302 } 1303 } catch (Throwable tr) { 1304 throw new PersistenceException("Problems while performing cascade deletion from Buffer",tr); 1305 } 1306 } 1307 1308 public void deleteActivity (String actId,SharkTransaction ti) throws PersistenceException { 1309 if (true) return; 1311 try { 1312 ActivityDO DO=getPersistedActivityObject(actId,ti); 1313 DO.delete(((SharkDODSTransaction)ti).getDODSTransaction()); 1314 (((SharkDODSTransaction)ti).getDODSTransaction()).write(); 1315 cus.info(LOG_CHANNEL,"Activity[id="+actId+"] deleted"); 1316 } catch (Throwable tr) { 1317 cus.error(LOG_CHANNEL,"Deleting of Activity failed"); 1318 throw new PersistenceException 1319 ("Deleting of Activity failed", tr); 1320 } 1321 } 1322 1323 public void deleteResource (String resUsername,SharkTransaction ti) throws PersistenceException { 1324 if (true) return; 1326 try { 1327 ResourceDO DO=getPersistedResourceObject(resUsername,ti); 1328 DO.delete(((SharkDODSTransaction)ti).getDODSTransaction()); 1329 (((SharkDODSTransaction)ti).getDODSTransaction()).write(); 1330 cus.info(LOG_CHANNEL,"Resource[username="+resUsername+"] deleted"); 1331 } catch (Throwable tr) { 1332 cus.error(LOG_CHANNEL,"Deleting of Resource failed"); 1333 throw new PersistenceException 1334 ("Deleting of Resource failed", tr); 1335 } 1336 } 1337 1338 public void deleteAssignment(String actId,String resUsername,SharkTransaction ti) throws PersistenceException { 1339 try { 1341 AssignmentDO DO=getPersistedAssignmentObject(actId,resUsername,ti); 1342 ((SharkDODSTransaction)ti).erase(DO); 1343 cus.info(LOG_CHANNEL,"Assignment[activityId="+actId+", username="+resUsername+"] deleted"); 1346 } catch (Throwable tr) { 1347 cus.error(LOG_CHANNEL,"Deleting of Assignment failed"); 1348 throw new PersistenceException 1349 ("Deleting of Assignment failed", tr); 1350 } 1351 } 1352 1353 public void deleteAndJoinEntries (String procId, 1354 String asDefId, 1355 String aDefId, 1356 SharkTransaction ti) throws PersistenceException { 1357 try { 1358 AndJoinEntryDO[] DOs=getPersistedAndJoinEntries(procId,asDefId,aDefId,ti); 1359 if (DOs!=null) { 1360 for (int i=0; i<DOs.length; i++) { 1361 ((SharkDODSTransaction)ti).erase(DOs[i]); 1362 } 1364 cus.info(LOG_CHANNEL,"AndJoinEntries for [procId="+procId+", aDefId="+aDefId+"] deleted"); 1365 } else { 1366 cus.info(LOG_CHANNEL,"There are no AndJoinEntries for [procId="+procId+", aDefId="+aDefId+"] to delete"); 1367 } 1368 } catch (Throwable tr) { 1370 cus.error(LOG_CHANNEL,"Deleting of AndJoinEntries for [procId="+procId+", aDefId="+aDefId+"] failed"); 1371 throw new PersistenceException 1372 ("Deleting of AndJoinEntries for [procId="+procId+", aDefId="+aDefId+"] failed", tr); 1373 } 1374 1375 } 1376 1377 public void deleteDeadlines (String procId, 1378 SharkTransaction ti) throws PersistenceException { 1379 if (true) return; 1380 try { 1381 DeadlineDO[] DOs=getPersistedDeadlines(procId,-1,ti); 1382 if (DOs!=null) { 1383 for (int i=0; i<DOs.length; i++) { 1384 ((SharkDODSTransaction)ti).erase(DOs[i]); 1385 } 1387 cus.info(LOG_CHANNEL,"Deadlines for process "+procId+" deleted"); 1388 } else { 1389 cus.info(LOG_CHANNEL,"There are no Deadlines defined for the proces "+procId); 1390 } 1391 } catch (Throwable tr) { 1393 cus.error(LOG_CHANNEL,"Deleting deadlines for the process "+procId+" failed"); 1394 throw new PersistenceException 1395 ("Deleting deadlines for the process "+procId+" failed", tr); 1396 } 1397 } 1398 1399 public void deleteDeadlines (String procId, 1400 String actId, 1401 SharkTransaction ti) throws PersistenceException { 1402 if (true) return; 1403 try { 1404 DeadlineDO[] DOs=getActivitiesPersistedDeadlines(actId,-1,ti); 1405 if (DOs!=null) { 1406 for (int i=0; i<DOs.length; i++) { 1407 ((SharkDODSTransaction)ti).erase(DOs[i]); 1408 } 1410 cus.info(LOG_CHANNEL,"Deadlines for activity "+actId+" deleted"); 1411 } else { 1412 cus.info(LOG_CHANNEL,"There are no Deadlines defined for the activity "+actId); 1413 } 1414 } catch (Throwable tr) { 1416 cus.error(LOG_CHANNEL,"Deleting deadlines for the activity "+actId+" failed"); 1417 throw new PersistenceException 1418 ("Deleting deadlines for the activity "+actId+" failed", tr); 1419 } 1420 } 1421 1422 public void delete (ProcessVariablePersistenceInterface var,SharkTransaction ti) throws PersistenceException { 1423 if (true) return; 1425 try { 1426 ProcessDataDO DO=getPersistedObject(var,ti); 1427 DO.delete(((SharkDODSTransaction)ti).getDODSTransaction()); 1428 (((SharkDODSTransaction)ti).getDODSTransaction()).write(); 1429 cus.info(LOG_CHANNEL,"ProcessVariable[processId="+var.getProcessId()+", definitionId="+var.getDefinitionId()+"] deleted"); 1430 } catch (Throwable tr) { 1431 cus.error(LOG_CHANNEL,"Deleting of ProcessVariable failed"); 1432 throw new PersistenceException 1433 ("Deleting of ProcessVariable failed", tr); 1434 } 1435 } 1436 1437 public void delete (ActivityVariablePersistenceInterface var,SharkTransaction ti) throws PersistenceException { 1438 if (true) return; 1440 try { 1441 ActivityDataDO DO=getPersistedObject(var,ti); 1442 DO.delete(((SharkDODSTransaction)ti).getDODSTransaction()); 1443 (((SharkDODSTransaction)ti).getDODSTransaction()).write(); 1444 cus.info(LOG_CHANNEL,"ActivityVariable[activityId="+var.getActivityId()+", definitionId="+var.getDefinitionId()+"] deleted"); 1445 } catch (Throwable tr) { 1446 cus.error(LOG_CHANNEL,"Deleting of ActivityVariable failed"); 1447 throw new PersistenceException 1448 ("Deleting of ActivityVariable failed", tr); 1449 } 1450 } 1451 1452 public List getAllProcessMgrs (SharkTransaction ti) throws PersistenceException { 1453 List ret=new ArrayList(); 1454 1455 ProcessDefinitionDO[] mgrs=getAllPersistedProcessMgrs(ti,null,null,null,null); 1456 if (mgrs!=null) { 1457 for (int i=0;i<mgrs.length; i++) { 1458 ProcessMgrPersistenceInterface mgr=restore(mgrs[i]); 1459 ret.add(mgr); 1460 } 1461 } 1462 return ret; 1463 } 1464 1465 public List getAllProcesses (SharkTransaction ti) throws PersistenceException { 1466 List ret=new ArrayList(); 1467 1468 ProcessDO[] procs=getPersistedProcesses(ti,0,null,null,null,null,null); 1469 try { 1470 if (procs!=null) { 1471 for (int i=0;i<procs.length; i++) { 1472 ProcessPersistenceInterface proc=restore(procs[i]); 1473 ret.add(proc); 1474 } 1475 } 1476 return ret; 1477 } catch (Throwable e) { 1478 throw new PersistenceException(e); 1479 } 1480 } 1481 1482 public List getAllRunningProcesses(SharkTransaction ti) throws PersistenceException { 1483 List ret=new ArrayList(); 1484 1485 ProcessDO[] procs=getPersistedProcesses(ti,1,null,null,null,null,null); 1486 try { 1487 if (procs!=null) { 1488 for (int i=0;i<procs.length; i++) { 1489 ProcessPersistenceInterface proc=restore(procs[i]); 1490 ret.add(proc); 1491 } 1492 } 1493 return ret; 1494 } catch (Throwable e) { 1495 throw new PersistenceException(e); 1496 } 1497 } 1498 1499 public List getAllFinishedProcesses(SharkTransaction ti) throws PersistenceException { 1500 List ret=new ArrayList(); 1501 1502 ProcessDO[] procs=getPersistedProcesses(ti,-1,null,null,null,null,null); 1503 try { 1504 if (procs!=null) { 1505 for (int i=0;i<procs.length; i++) { 1506 ProcessPersistenceInterface proc=restore(procs[i]); 1507 ret.add(proc); 1508 } 1509 } 1510 return ret; 1511 } catch (Throwable e) { 1512 throw new PersistenceException(e); 1513 } 1514 } 1515 1516 public List getAllFinishedProcesses(SharkTransaction ti,java.util.Date finishedBefore) throws PersistenceException { 1517 List ret=new ArrayList(); 1518 1519 ProcessDO[] procs=getPersistedProcesses(ti,-1,null,null,null,finishedBefore,null); 1520 try { 1521 if (procs!=null) { 1522 for (int i=0;i<procs.length; i++) { 1523 ProcessPersistenceInterface proc=restore(procs[i]); 1524 ret.add(proc); 1525 } 1526 } 1527 return ret; 1528 } catch (Throwable e) { 1529 throw new PersistenceException(e); 1530 } 1531 } 1532 1533 public List getAllFinishedProcesses(SharkTransaction ti,String pkgId) throws PersistenceException { 1534 List ret=new ArrayList(); 1535 1536 ProcessDO[] procs=getPersistedProcesses(ti,-1,pkgId,null,null,null,null); 1537 try { 1538 if (procs!=null) { 1539 for (int i=0;i<procs.length; i++) { 1540 ProcessPersistenceInterface proc=restore(procs[i]); 1541 ret.add(proc); 1542 } 1543 } 1544 return ret; 1545 } catch (Throwable e) { 1546 throw new PersistenceException(e); 1547 } 1548 } 1549 1550 public List getAllFinishedProcesses(SharkTransaction ti,String pkgId,String procDefId) throws PersistenceException { 1551 List ret=new ArrayList(); 1552 1553 ProcessDO[] procs=getPersistedProcesses(ti,-1,pkgId,procDefId,null,null,null); 1554 try { 1555 if (procs!=null) { 1556 for (int i=0;i<procs.length; i++) { 1557 ProcessPersistenceInterface proc=restore(procs[i]); 1558 ret.add(proc); 1559 } 1560 } 1561 return ret; 1562 } catch (Throwable e) { 1563 throw new PersistenceException(e); 1564 } 1565 } 1566 1567 public List getAllFinishedProcesses(SharkTransaction ti,String pkgId,String procDefId,String pkgVer) throws PersistenceException { 1568 List ret=new ArrayList(); 1569 1570 ProcessDO[] procs=getPersistedProcesses(ti,-1,pkgId,procDefId,pkgVer,null,null); 1571 try { 1572 if (procs!=null) { 1573 for (int i=0;i<procs.length; i++) { 1574 ProcessPersistenceInterface proc=restore(procs[i]); 1575 ret.add(proc); 1576 } 1577 } 1578 return ret; 1579 } catch (Throwable e) { 1580 throw new PersistenceException(e); 1581 } 1582 } 1583 1584 public List getAllActivities (SharkTransaction ti) throws PersistenceException { 1585 List ret=new ArrayList(); 1586 1587 ActivityDO[] acts=getPersistedActivities(ti,0,null,null); 1588 if (acts!=null) { 1589 for (int i=0;i<acts.length; i++) { 1590 ActivityPersistenceInterface act=restore(acts[i]); 1591 ret.add(act); 1592 } 1593 } 1594 return ret; 1595 } 1596 1597 public List getAllResources (SharkTransaction ti) throws PersistenceException { 1598 List ret=new ArrayList(); 1599 1600 ResourceDO[] ress=getAllPersistedResources(ti, null); 1601 if (ress!=null) { 1602 for (int i=0;i<ress.length; i++) { 1603 ResourcePersistenceInterface res=restore(ress[i]); 1604 ret.add(res); 1605 } 1606 } 1607 return ret; 1608 } 1609 1610 public List getAllAssignments (SharkTransaction ti) throws PersistenceException { 1611 List ret=new ArrayList(); 1612 1613 AssignmentDO[] ass=getAllPersistedAssignments(ti,null); 1614 if (ass!=null) { 1615 for (int i=0;i<ass.length; i++) { 1616 AssignmentPersistenceInterface as=restore(ass[i]); 1617 ret.add(as); 1618 } 1619 } 1620 return ret; 1621 } 1622 1623 public List getAllProcessesForMgr (String mgrName,SharkTransaction ti) throws PersistenceException { 1624 List ret=new ArrayList(); 1625 1626 try { 1627 ProcessDefinitionDO pDO=getPersistedProcessMgrObject(mgrName,ti); 1628 if (pDO!=null) { 1629 ProcessDO[] procs=pDO.getProcessDOArray(); 1630 BigDecimal pOId = pDO.get_OId().toBigDecimal(); 1631 List list = new ArrayList(Arrays.asList(procs)); 1632 1633 for (Iterator it = ((SharkDODSTransaction)ti).iterator4typeDeleted("class org.enhydra.shark.instancepersistence.data.ProcessDO"); 1634 it.hasNext();) { 1635 ProcessDO o = (ProcessDO)it.next(); 1636 if (pOId.equals(o.oid_getProcessDefinition())) { 1637 int index = list.indexOf(o); 1638 if (-1 != index) 1639 list.remove(o); 1640 } 1641 } 1642 for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.ProcessDO"); 1643 it.hasNext();) { 1644 ProcessDO o = (ProcessDO)it.next(); 1645 if (pOId.equals(o.oid_getProcessDefinition())) { 1646 int index = list.indexOf(o); 1647 if (-1 == index) 1648 list.add(o); 1649 else { 1650 list.set(index, o); 1651 } 1652 } 1653 } 1654 procs = new ProcessDO[list.size()]; 1655 list.toArray(procs); 1656 for (int j=0; j<procs.length; j++) { 1657 ProcessPersistenceInterface proc=restore(procs[j]); 1658 ret.add(proc); 1659 } 1660 } 1661 return ret; 1662 } 1663 catch (Throwable t) { 1664 throw new PersistenceException(t); 1665 } 1666 } 1667 1668 public List getProcessesForMgr (String mgrName,String procState,SharkTransaction ti) throws PersistenceException { 1669 List ret=new ArrayList(); 1670 1671 ProcessDO[] DOs=null; 1672 ProcessQuery query = null; 1673 try { 1674 query=new ProcessQuery(((SharkDODSTransaction)ti).getDODSTransaction()); 1675 BigDecimal state=(BigDecimal )_prStates.get(procState); 1676 QueryBuilder qb=qb=query.getQueryBuilder(); 1677 qb.addWhere(ProcessDO.State,state,QueryBuilder.EQUAL); 1678 DOs = query.getDOArray(); 1679 List list = new ArrayList(Arrays.asList(DOs)); 1680 1681 for (Iterator it = ((SharkDODSTransaction)ti).iterator4typeDeleted("class org.enhydra.shark.instancepersistence.data.ProcessDO"); 1682 it.hasNext();) { 1683 list.remove(it.next()); 1684 } 1685 for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.ProcessDO"); 1686 it.hasNext();) { 1687 ProcessDO o = (ProcessDO)it.next(); 1688 boolean stateOK=o.oid_getState().equals(state); 1689 int index = list.indexOf(o); 1690 if (-1 == index) { 1691 if (stateOK) { 1692 list.add(o); 1693 } 1694 } else { 1695 if (stateOK) { 1696 list.set(index, o); 1697 } else { 1698 list.remove(o); 1699 } 1700 } 1701 } 1702 DOs = new ProcessDO[list.size()]; 1703 list.toArray(DOs); 1704 for (int j=0; j<DOs.length; j++) { 1705 ProcessPersistenceInterface proc=restore(DOs[j]); 1706 ret.add(proc); 1707 } 1708 1709 return ret; 1710 } catch (Throwable t) { 1711 throw new PersistenceException(t); 1712 } 1713 } 1714 1715 public List getAllActivitiesForProcess(String procId,SharkTransaction ti) throws PersistenceException { 1716 List ret=new ArrayList(); 1717 1718 try { 1719 ProcessDO pDO=getPersistedProcessObject(procId,ti); 1720 if (pDO!=null) { 1721 ActivityDO[] acts=pDO.getActivityDOArray(); 1722 BigDecimal pOId = pDO.get_OId().toBigDecimal(); 1723 List list = new ArrayList(Arrays.asList(acts)); 1724 1725 for (Iterator it = ((SharkDODSTransaction)ti).iterator4typeDeleted("class org.enhydra.shark.instancepersistence.data.ActivityDO"); 1726 it.hasNext();) { 1727 ActivityDO o = (ActivityDO)it.next(); 1728 if (pOId.equals(o.oid_getProcess())) { 1729 int index = list.indexOf(o); 1730 if (-1 != index) 1731 list.remove(o); 1732 } 1733 } 1734 for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.ActivityDO"); 1735 it.hasNext();) { 1736 ActivityDO o = (ActivityDO)it.next(); 1737 if (pOId.equals(o.oid_getProcess())) { 1738 int index = list.indexOf(o); 1739 if (-1 == index) 1740 list.add(o); 1741 else { 1742 list.set(index, o); 1743 } 1744 } 1745 } 1746 acts = new ActivityDO[list.size()]; 1747 list.toArray(acts); 1748 for (int j=0; j<acts.length; j++) { 1749 ActivityPersistenceInterface act=restore(acts[j]); 1751 ret.add(act); 1752 } 1753 } 1754 return ret; 1755 } 1756 catch (Throwable t) { 1757 throw new PersistenceException(t); 1758 } 1759 } 1760 1761 public List getActivitiesForProcess(String procId,String actState,SharkTransaction ti) throws PersistenceException { 1762 List ret=new ArrayList(); 1763 try { 1764 ProcessDO pDO=getPersistedProcessObject(procId,ti); 1765 BigDecimal pOId = pDO.get_OId().toBigDecimal(); 1766 BigDecimal state=(BigDecimal )_acStates.get(actState); 1767 1768 ActivityDO[] DOs=null; 1769 ActivityQuery query = null; 1770 query=new ActivityQuery(((SharkDODSTransaction)ti).getDODSTransaction()); 1771 QueryBuilder qb=qb=query.getQueryBuilder(); 1772 1773 qb.addWhere(ActivityDO.Process,pOId,QueryBuilder.EQUAL); 1774 qb.addWhere(ActivityDO.State,state,QueryBuilder.EQUAL); 1775 DOs = query.getDOArray(); 1776 List list = new ArrayList(Arrays.asList(DOs)); 1777 for (Iterator it = ((SharkDODSTransaction)ti).iterator4typeDeleted("class org.enhydra.shark.instancepersistence.data.ActivityDO"); 1778 it.hasNext();) { 1779 list.remove(it.next()); 1780 } 1781 for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.ActivityDO"); 1782 it.hasNext();) { 1783 ActivityDO o = (ActivityDO)it.next(); 1784 boolean stateOK=o.oid_getState().equals(state); 1785 int index = list.indexOf(o); 1786 if (-1 == index) { 1787 if (stateOK) { 1788 list.add(o); 1789 } 1790 } else { 1791 if (stateOK) { 1792 list.set(index, o); 1793 } else { 1794 list.remove(o); 1795 } 1796 } 1797 } 1798 DOs = new ActivityDO[list.size()]; 1799 list.toArray(DOs); 1800 for (int j=0; j<DOs.length; j++) { 1801 ActivityPersistenceInterface act=restore(DOs[j]); 1802 ret.add(act); 1803 } 1804 1805 return ret; 1806 } 1807 catch (Throwable t) { 1808 throw new PersistenceException(t); 1809 } 1810 1811 } 1812 1813 public List getAllFinishedActivitiesForProcess(String procId,SharkTransaction ti) throws PersistenceException { 1814 List ret=new ArrayList(); 1815 1816 try { 1817 ProcessDO pDO=getPersistedProcessObject(procId,ti); 1818 if (pDO!=null) { 1819 BigDecimal pOId = pDO.get_OId().toBigDecimal(); 1820 ActivityDO[] acts=getPersistedActivities(ti,-1,pOId,null); 1821 1822 if (acts!=null) { 1823 for (int j=0; j<acts.length; j++) { 1824 ActivityPersistenceInterface act=restore(acts[j]); 1826 ret.add(act); 1827 } 1828 } 1829 } 1830 return ret; 1831 } 1832 catch (Throwable t) { 1833 throw new PersistenceException(t); 1834 } 1835 } 1836 1837 1838 public List getAllActiveActivitiesForProcess(String procId,SharkTransaction ti) throws PersistenceException { 1839 List ret=new ArrayList(); 1840 1841 try { 1842 ProcessDO pDO=getPersistedProcessObject(procId,ti); 1843 if (pDO!=null) { 1844 BigDecimal pOId = pDO.get_OId().toBigDecimal(); 1845 ActivityDO[] acts=getPersistedActivities(ti,1,pOId,null); 1846 1847 if (acts!=null) { 1848 for (int j=0; j<acts.length; j++) { 1849 ActivityPersistenceInterface act=restore(acts[j]); 1851 ret.add(act); 1852 } 1853 } 1854 } 1855 return ret; 1856 } 1857 catch (Throwable t) { 1858 throw new PersistenceException(t); 1859 } 1860 } 1861 1862 1866 public List getAllAssignmentsForResource (String resUsername,SharkTransaction ti) throws PersistenceException { 1867 List ret=new ArrayList(); 1868 1869 try { 1870 ResourceDO rDO=getPersistedResourceObject(resUsername,ti); 1872 if (rDO!=null) { 1873 AssignmentDO[] ass=rDO.getAssignmentDOArray(); 1874 BigDecimal rOId = rDO.get_OId().toBigDecimal(); 1875 List list = new ArrayList(Arrays.asList(ass)); 1876 1877 for (Iterator it = ((SharkDODSTransaction)ti).iterator4typeDeleted("class org.enhydra.shark.instancepersistence.data.AssignmentDO"); 1878 it.hasNext();) { 1879 AssignmentDO o = (AssignmentDO)it.next(); 1880 if (rOId.equals(o.oid_getTheResource())) { 1881 int index = list.indexOf(o); 1882 if (-1 != index) 1883 list.remove(o); 1884 } 1885 } 1886 for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.AssignmentDO"); 1887 it.hasNext();) { 1888 AssignmentDO o = (AssignmentDO)it.next(); 1889 if (rOId.equals(o.oid_getTheResource())) { 1890 int index = list.indexOf(o); 1891 if (-1 == index) 1892 list.add(o); 1893 else { 1894 list.set(index, o); 1895 } 1896 } 1897 } 1898 ass = new AssignmentDO[list.size()]; 1899 list.toArray(ass); 1900 for (int i=0;i<ass.length; i++) { 1901 AssignmentDO assDO=ass[i]; 1902 AssignmentPersistenceInterface as=restore(assDO); 1903 ret.add(as); 1904 } 1905 } 1906 return ret; 1907 } 1908 catch (Throwable t) { 1909 throw new PersistenceException(t); 1910 } 1911 } 1912 1913 1917 1967 1968 1975 public List getAllValidAssignmentsForResource (String resUsername,SharkTransaction ti) throws PersistenceException { 1976 List ret=new ArrayList(); 1977 1978 try { 1979 ResourceDO rDO=getPersistedResourceObject(resUsername,ti); 1981 if (rDO!=null) { 1982 AssignmentDO[] ass=rDO.getAssignmentDOArray(); 1983 BigDecimal rOId = rDO.get_OId().toBigDecimal(); 1984 List list = new ArrayList(Arrays.asList(ass)); 1985 1986 for (Iterator it = ((SharkDODSTransaction)ti).iterator4typeDeleted("class org.enhydra.shark.instancepersistence.data.AssignmentDO"); 1987 it.hasNext();) { 1988 AssignmentDO o = (AssignmentDO)it.next(); 1989 if (rOId.equals(o.oid_getTheResource())) { 1991 int index = list.indexOf(o); 1992 if (-1 != index) 1993 list.remove(o); 1994 } 1995 } 1996 for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.AssignmentDO"); 1997 it.hasNext();) { 1998 AssignmentDO o = (AssignmentDO)it.next(); 1999 if (rOId.equals(o.oid_getTheResource()) && o.getIsValid()) { 2000 int index = list.indexOf(o); 2001 if (-1 == index) 2002 list.add(o); 2003 else { 2004 list.set(index, o); 2005 } 2006 } 2007 } 2008 ass = new AssignmentDO[list.size()]; 2009 list.toArray(ass); 2010 for (int i=0;i<ass.length; i++) { 2011 AssignmentDO assDO=ass[i]; 2012 2018 if (assDO.getIsValid()) { 2022 AssignmentPersistenceInterface as=restore(assDO); 2023 ret.add(as); 2024 } 2025 } 2026 } 2027 return ret; 2028 } 2029 catch (Throwable t) { 2030 throw new PersistenceException(t); 2031 } 2032 } 2033 2034 2038 public List getAllAssignmentsForActivity (String actId,SharkTransaction ti) throws PersistenceException { 2039 List ret=new ArrayList(); 2040 try { 2041 ActivityDO aDO=getPersistedActivityObject(actId,ti); 2043 if (aDO!=null) { 2044 AssignmentDO[] ass=aDO.getAssignmentDOArray(); 2045 BigDecimal aOId = aDO.get_OId().toBigDecimal(); 2046 List list = new ArrayList(Arrays.asList(ass)); 2047 2048 for (Iterator it = ((SharkDODSTransaction)ti).iterator4typeDeleted("class org.enhydra.shark.instancepersistence.data.AssignmentDO"); 2049 it.hasNext();) { 2050 AssignmentDO o = (AssignmentDO)it.next(); 2051 if (aOId.equals(o.oid_getActivity())) { 2052 int index = list.indexOf(o); 2053 if (-1 != index) 2054 list.remove(o); 2055 } 2056 } 2057 for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.AssignmentDO"); 2058 it.hasNext();) { 2059 AssignmentDO o = (AssignmentDO)it.next(); 2060 if (aOId.equals(o.oid_getActivity())) { 2061 int index = list.indexOf(o); 2062 if (-1 == index) 2063 list.add(o); 2064 else { 2065 list.set(index, o); 2066 } 2067 } 2068 } 2069 ass = new AssignmentDO[list.size()]; 2070 list.toArray(ass); 2071 for (int i=0;i<ass.length; i++) { 2072 AssignmentDO assDO=ass[i]; 2073 AssignmentPersistenceInterface as=restore(assDO); 2074 ret.add(as); 2075 } 2076 } 2077 2078 return ret; 2079 } 2080 catch (Throwable t) { 2081 throw new PersistenceException(t); 2082 } 2083 } 2084 2085 2090 2139 2140 2146 public List getAllValidAssignmentsForActivity (String actId,SharkTransaction ti) throws PersistenceException { 2147 List ret=new ArrayList(); 2148 try { 2149 ActivityDO aDO=getPersistedActivityObject(actId,ti); 2151 2153 if (aDO!=null) { 2154 String actState=aDO.getState().getKeyValue(); 2155 if (!actState.startsWith("closed")) { 2156 AssignmentDO[] ass=aDO.getAssignmentDOArray(); 2157 BigDecimal aOId = aDO.get_OId().toBigDecimal(); 2158 List list = new ArrayList(Arrays.asList(ass)); 2159 2160 for (Iterator it = ((SharkDODSTransaction)ti).iterator4typeDeleted("class org.enhydra.shark.instancepersistence.data.AssignmentDO"); 2161 it.hasNext();) { 2162 AssignmentDO o = (AssignmentDO)it.next(); 2163 if (aOId.equals(o.oid_getActivity())) { 2164 int index = list.indexOf(o); 2165 if (-1 != index) 2166 list.remove(o); 2167 } 2168 } 2169 for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.AssignmentDO"); 2170 it.hasNext();) { 2171 AssignmentDO o = (AssignmentDO)it.next(); 2172 if (aOId.equals(o.oid_getActivity()) && o.getIsValid()) { 2173 int index = list.indexOf(o); 2174 if (-1 == index) 2175 list.add(o); 2176 else { 2177 list.set(index, o); 2178 } 2179 } 2180 } 2181 ass = new AssignmentDO[list.size()]; 2182 list.toArray(ass); 2183 for (int i=0;i<ass.length; i++) { 2184 AssignmentDO assDO=ass[i]; 2185 if (assDO.getIsValid()) { 2188 AssignmentPersistenceInterface as=restore(assDO); 2189 ret.add(as); 2190 } 2191 } 2192 } 2193 } 2194 2195 return ret; 2196 } 2197 catch (Throwable t) { 2198 throw new PersistenceException(t); 2199 } 2200 } 2201 2202 public List getAllVariablesForProcess (String procId,SharkTransaction ti) throws PersistenceException { 2203 if (usingStandardVariableDataModel) { 2204 return getAllVariablesForProcessBLOB(procId, ti); 2205 } else { 2206 return getAllVariablesForProcessWOB(procId, ti); 2207 } 2208 } 2209 2210 protected List getAllVariablesForProcessBLOB (String procId,SharkTransaction ti) throws PersistenceException { 2211 List ret=new ArrayList(); 2212 try { 2213 ProcessDO pDO=getPersistedProcessObject(procId,ti); 2214 if (pDO!=null) { 2215 ProcessDataDO[] DOs=pDO.getProcessDataDOArray(); 2216 BigDecimal pOId = pDO.get_OId().toBigDecimal(); 2217 List list = new ArrayList(Arrays.asList(DOs)); 2218 2219 for (Iterator it = ((SharkDODSTransaction)ti).iterator4typeDeleted("class org.enhydra.shark.instancepersistence.data.ProcessDataDO"); 2220 it.hasNext();) { 2221 ProcessDataDO o = (ProcessDataDO)it.next(); 2222 if (pOId.equals(o.oid_getProcess())) { 2223 int index = list.indexOf(o); 2224 if (-1 != index) 2225 list.remove(o); 2226 } 2227 } 2228 for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.ProcessDataDO"); 2229 it.hasNext();) { 2230 ProcessDataDO o = (ProcessDataDO)it.next(); 2231 if (pOId.equals(o.oid_getProcess())) { 2232 int index = list.indexOf(o); 2233 if (-1 == index) 2234 list.add(o); 2235 else { 2236 list.set(index, o); 2237 } 2238 } 2239 } 2240 DOs = new ProcessDataDO[list.size()]; 2241 list.toArray(DOs); 2242 for (int i=0;i<DOs.length; i++) { 2243 ProcessDataDO DO=DOs[i]; 2244 ProcessVariablePersistenceInterface var=new DODSProcessVariable(); 2245 restoreBLOB(var,DO); 2246 ret.add(var); 2247 } 2248 } 2249 2250 return ret; 2251 } 2252 catch (Throwable t) { 2253 throw new PersistenceException(t); 2255 } 2256 } 2257 2258 protected List getAllVariablesForProcessWOB (String procId,SharkTransaction ti) throws PersistenceException { 2259 List ret=new ArrayList(); 2260 try { 2261 ProcessDO pDO=getPersistedProcessObject(procId,ti); 2262 if (pDO!=null) { 2263 ProcessDataWOBDO[] DOs=pDO.getProcessDataWOBDOArray(); 2264 BigDecimal pOId = pDO.get_OId().toBigDecimal(); 2265 List list = new ArrayList(Arrays.asList(DOs)); 2266 2267 for (Iterator it = ((SharkDODSTransaction)ti).iterator4typeDeleted("class org.enhydra.shark.instancepersistence.data.ProcessDataWOBDO"); 2268 it.hasNext();) { 2269 ProcessDataWOBDO o = (ProcessDataWOBDO)it.next(); 2270 if (pOId.equals(o.oid_getProcess())) { 2271 int index = list.indexOf(o); 2272 if (-1 != index) 2273 list.remove(o); 2274 } 2275 } 2276 for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.ProcessDataWOBDO"); 2277 it.hasNext();) { 2278 ProcessDataWOBDO o = (ProcessDataWOBDO)it.next(); 2279 if (pOId.equals(o.oid_getProcess())) { 2280 int index = list.indexOf(o); 2281 if (-1 == index) 2282 list.add(o); 2283 else { 2284 list.set(index, o); 2285 } 2286 } 2287 } 2288 DOs = new ProcessDataWOBDO[list.size()]; 2289 list.toArray(DOs); 2290 for (int i=0;i<DOs.length; i++) { 2291 ProcessDataWOBDO DO=DOs[i]; 2292 ProcessVariablePersistenceInterface var=new DODSProcessVariable(); 2293 restoreWOB(var,DO); 2294 ret.add(var); 2295 } 2296 } 2297 2298 return ret; 2299 } 2300 catch (Throwable t) { 2301 throw new PersistenceException(t); 2303 } 2304 } 2305 2306 public List getProcessVariables(String procId,List variableIds,SharkTransaction ti) throws PersistenceException { 2307 if (usingStandardVariableDataModel) { 2308 return getProcessVariablesBLOB(procId, variableIds, ti); 2309 } else { 2310 return getProcessVariablesWOB(procId, variableIds, ti); 2311 } 2312 } 2313 2314 public List getProcessVariablesBLOB(String procId,List variableIds,SharkTransaction ti) throws PersistenceException { 2315 List ret=new ArrayList(); 2316 try { 2317 Map map=new HashMap(); 2318 ProcessDO pDO=getPersistedProcessObject(procId,ti); 2319 if (pDO!=null) { 2320 BigDecimal pOId = pDO.get_OId().toBigDecimal(); 2321 for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.ProcessDataDO"); 2322 it.hasNext();) { 2323 ProcessDataDO o = (ProcessDataDO)it.next(); 2324 if (pOId.equals(o.oid_getProcess()) && variableIds.contains(o.getVariableDefinitionId())) { 2325 map.put(o.getVariableDefinitionId(),o); 2326 } 2328 } 2329 } 2330 2331 2333 if (pDO.isPersistent() && map.size()!=variableIds.size()) { 2334 if (variableIds.size()-map.size()>1) { 2335 ProcessDataDO[] DOs=pDO.getProcessDataDOArray(); 2337 for (int i=0; i<DOs.length; i++) { 2338 if (!map.containsKey(DOs[i].getVariableDefinitionId())) { 2339 map.put(DOs[i].getVariableDefinitionId(),DOs[i]); 2340 ((SharkDODSTransaction)ti)._read(DOs[i]); 2341 } 2342 } 2344 } else { 2345 DBTransaction dbt=((SharkDODSTransaction)ti).getDODSTransaction(); 2346 for (int i=0; i<variableIds.size(); i++) { 2347 String varId=(String )variableIds.get(i); 2348 if (map.containsKey(varId)) continue; 2349 ProcessDataQuery q=new ProcessDataQuery(dbt); 2350 q.setQueryProcess(pDO); 2351 q.setQueryVariableDefinitionId(varId); 2352 ProcessDataDO DO=q.getNextDO(); 2353 if (DO!=null) { 2354 map.put(varId,DO); 2356 ((SharkDODSTransaction)ti)._read(DO); 2357 } else { 2358 } 2360 } 2361 } 2362 } 2363 2365 ProcessDataDO[] DOs = new ProcessDataDO[map.size()]; 2366 DOs = (ProcessDataDO[])map.values().toArray(DOs); 2367 if (DOs!=null) { 2368 for (int i=0;i<DOs.length; i++) { 2369 ProcessDataDO DO=DOs[i]; 2370 ProcessVariablePersistenceInterface var=new DODSProcessVariable(); 2371 restoreBLOB(var,DO); 2372 ret.add(var); 2373 } 2374 } 2375 2376 2377 return ret; 2378 } 2379 catch (Throwable t) { 2380 throw new PersistenceException(t); 2382 } 2383 2384 } 2385 2386 public List getProcessVariablesWOB(String procId,List variableIds,SharkTransaction ti) throws PersistenceException { 2387 List ret=new ArrayList(); 2388 try { 2389 Map map=new HashMap(); 2390 ProcessDO pDO=getPersistedProcessObject(procId,ti); 2391 if (pDO!=null) { 2392 BigDecimal pOId = pDO.get_OId().toBigDecimal(); 2393 for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.ProcessDataWOBDO"); 2394 it.hasNext();) { 2395 ProcessDataWOBDO o = (ProcessDataWOBDO)it.next(); 2396 if (pOId.equals(o.oid_getProcess()) && variableIds.contains(o.getVariableDefinitionId())) { 2397 map.put(o.getVariableDefinitionId(),o); 2398 } 2400 } 2401 } 2402 2403 2405 if (pDO.isPersistent() && map.size()!=variableIds.size()) { 2406 if (variableIds.size()-map.size()>1) { 2407 ProcessDataWOBDO[] DOs=pDO.getProcessDataWOBDOArray(); 2409 for (int i=0; i<DOs.length; i++) { 2410 if (!map.containsKey(DOs[i].getVariableDefinitionId())) { 2411 map.put(DOs[i].getVariableDefinitionId(),DOs[i]); 2412 ((SharkDODSTransaction)ti)._read(DOs[i]); 2413 } 2414 } 2416 } else { 2417 DBTransaction dbt=((SharkDODSTransaction)ti).getDODSTransaction(); 2418 for (int i=0; i<variableIds.size(); i++) { 2419 String varId=(String )variableIds.get(i); 2420 if (map.containsKey(varId)) continue; 2421 ProcessDataWOBQuery q=new ProcessDataWOBQuery(dbt); 2422 q.setQueryProcess(pDO); 2423 q.setQueryVariableDefinitionId(varId); 2424 ProcessDataWOBDO DO=q.getNextDO(); 2425 if (DO!=null) { 2426 map.put(varId,DO); 2428 ((SharkDODSTransaction)ti)._read(DO); 2429 } else { 2430 } 2432 } 2433 } 2434 } 2435 2437 ProcessDataWOBDO[] DOs = new ProcessDataWOBDO[map.size()]; 2438 DOs = (ProcessDataWOBDO[])map.values().toArray(DOs); 2439 if (DOs!=null) { 2440 for (int i=0;i<DOs.length; i++) { 2441 ProcessDataWOBDO DO=DOs[i]; 2442 ProcessVariablePersistenceInterface var=new DODSProcessVariable(); 2443 restoreWOB(var,DO); 2444 ret.add(var); 2445 } 2446 } 2447 2448 2449 return ret; 2450 } 2451 catch (Throwable t) { 2452 throw new PersistenceException(t); 2454 } 2455 2456 } 2457 2458 public List getAllVariablesForActivity (String actId,SharkTransaction ti) throws PersistenceException { 2459 if (usingStandardVariableDataModel) { 2460 return getAllVariablesForActivityBLOB(actId, ti); 2461 } else { 2462 return getAllVariablesForActivityWOB(actId, ti); 2463 } 2464 } 2465 2466 public List getAllVariablesForActivityBLOB (String actId,SharkTransaction ti) throws PersistenceException { 2467 List ret=new ArrayList(); 2468 try { 2469 ActivityDO aDO=getPersistedActivityObject(actId,ti); 2470 if (aDO!=null) { 2471 ActivityDataDO[] DOs=aDO.getActivityDataDOArray(); 2472 BigDecimal aOId = aDO.get_OId().toBigDecimal(); 2473 List list = new ArrayList(Arrays.asList(DOs)); 2474 2475 for (Iterator it = ((SharkDODSTransaction)ti).iterator4typeDeleted("class org.enhydra.shark.instancepersistence.data.ActivityDataDO"); 2476 it.hasNext();) { 2477 ActivityDataDO o = (ActivityDataDO)it.next(); 2478 if (aOId.equals(o.oid_getActivity())) { 2479 int index = list.indexOf(o); 2480 if (-1 != index) 2481 list.remove(o); 2482 } 2483 } 2484 for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.ActivityDataDO"); 2485 it.hasNext();) { 2486 ActivityDataDO o = (ActivityDataDO)it.next(); 2487 if (aOId.equals(o.oid_getActivity())) { 2488 int index = list.indexOf(o); 2489 if (-1 == index) 2490 list.add(o); 2491 else { 2492 list.set(index, o); 2493 } 2494 } 2495 } 2496 DOs = new ActivityDataDO[list.size()]; 2497 list.toArray(DOs); 2498 for (int i=0;i<DOs.length; i++) { 2499 ActivityDataDO DO=DOs[i]; 2500 ActivityVariablePersistenceInterface var=new DODSActivityVariable(); 2501 restoreBLOB(var,DO); 2502 ret.add(var); 2503 } 2504 } 2505 2506 return ret; 2507 } 2508 catch (Throwable t) { 2509 throw new PersistenceException(t); 2510 } 2511 } 2512 2513 public List getAllVariablesForActivityWOB (String actId,SharkTransaction ti) throws PersistenceException { 2514 List ret=new ArrayList(); 2515 try { 2516 ActivityDO aDO=getPersistedActivityObject(actId,ti); 2517 if (aDO!=null) { 2518 ActivityDataWOBDO[] DOs=aDO.getActivityDataWOBDOArray(); 2519 BigDecimal aOId = aDO.get_OId().toBigDecimal(); 2520 List list = new ArrayList(Arrays.asList(DOs)); 2521 2522 for (Iterator it = ((SharkDODSTransaction)ti).iterator4typeDeleted("class org.enhydra.shark.instancepersistence.data.ActivityDataWOBDO"); 2523 it.hasNext();) { 2524 ActivityDataWOBDO o = (ActivityDataWOBDO)it.next(); 2525 if (aOId.equals(o.oid_getActivity())) { 2526 int index = list.indexOf(o); 2527 if (-1 != index) 2528 list.remove(o); 2529 } 2530 } 2531 for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.ActivityDataWOBDO"); 2532 it.hasNext();) { 2533 ActivityDataWOBDO o = (ActivityDataWOBDO)it.next(); 2534 if (aOId.equals(o.oid_getActivity())) { 2535 int index = list.indexOf(o); 2536 if (-1 == index) 2537 list.add(o); 2538 else { 2539 list.set(index, o); 2540 } 2541 } 2542 } 2543 DOs = new ActivityDataWOBDO[list.size()]; 2544 list.toArray(DOs); 2545 for (int i=0;i<DOs.length; i++) { 2546 ActivityDataWOBDO DO=DOs[i]; 2547 ActivityVariablePersistenceInterface var=new DODSActivityVariable(); 2548 restoreWOB(var,DO); 2549 ret.add(var); 2550 } 2551 } 2552 2553 return ret; 2554 } 2555 catch (Throwable t) { 2556 throw new PersistenceException(t); 2557 } 2558 } 2559 2560 public List getActivityVariables(String actId,List variableIds,SharkTransaction ti) throws PersistenceException { 2561 if (usingStandardVariableDataModel) { 2562 return getActivityVariablesBLOB(actId, variableIds, ti); 2563 } else { 2564 return getActivityVariablesWOB(actId, variableIds, ti); 2565 } 2566 } 2567 2568 public List getActivityVariablesBLOB(String actId,List variableIds,SharkTransaction ti) throws PersistenceException { 2569 List ret=new ArrayList(); 2570 try { 2571 Map map=new HashMap(); 2572 ActivityDO aDO=getPersistedActivityObject(actId,ti); 2573 if (aDO!=null) { 2574 BigDecimal aOId = aDO.get_OId().toBigDecimal(); 2575 for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.ActivityDataDO"); 2576 it.hasNext();) { 2577 ActivityDataDO o = (ActivityDataDO)it.next(); 2578 if (aOId.equals(o.oid_getActivity()) && variableIds.contains(o.getVariableDefinitionId())) { 2579 map.put(o.getVariableDefinitionId(),o); 2580 } 2582 } 2583 } 2584 2585 2587 if (aDO.isPersistent() && map.size()!=variableIds.size()) { 2588 if (map.size()==0) { 2589 ActivityDataDO[] DOs=aDO.getActivityDataDOArray(); 2591 for (int i=0; i<DOs.length; i++) { 2592 if (!map.containsKey(DOs[i].getVariableDefinitionId())) { 2593 map.put(DOs[i].getVariableDefinitionId(),DOs[i]); 2594 ((SharkDODSTransaction)ti)._read(DOs[i]); 2595 } 2596 } 2598 } else { 2599 DBTransaction dbt=((SharkDODSTransaction)ti).getDODSTransaction(); 2600 for (int i=0; i<variableIds.size(); i++) { 2601 String varId=(String )variableIds.get(i); 2602 if (map.containsKey(varId)) continue; 2603 ActivityDataQuery q=new ActivityDataQuery(dbt); 2604 q.setQueryActivity(aDO); 2605 q.setQueryVariableDefinitionId(varId); 2606 ActivityDataDO DO=q.getNextDO(); 2607 if (DO!=null) { 2608 map.put(varId,DO); 2610 ((SharkDODSTransaction)ti)._read(DO); 2611 } else { 2612 } 2614 } 2615 } 2616 } 2617 2619 ActivityDataDO[] DOs = new ActivityDataDO[map.size()]; 2620 DOs = (ActivityDataDO[])map.values().toArray(DOs); 2621 if (DOs!=null) { 2622 for (int i=0;i<DOs.length; i++) { 2623 ActivityDataDO DO=DOs[i]; 2624 ActivityVariablePersistenceInterface var=new DODSActivityVariable(); 2625 restoreBLOB(var,DO); 2626 ret.add(var); 2627 } 2628 } 2629 2630 2631 return ret; 2632 } 2633 catch (Throwable t) { 2634 throw new PersistenceException(t); 2636 } 2637 2638 } 2639 2640 public List getActivityVariablesWOB(String actId,List variableIds,SharkTransaction ti) throws PersistenceException { 2641 List ret=new ArrayList(); 2642 try { 2643 Map map=new HashMap(); 2644 ActivityDO aDO=getPersistedActivityObject(actId,ti); 2645 if (aDO!=null) { 2646 BigDecimal aOId = aDO.get_OId().toBigDecimal(); 2647 for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.ActivityDataWOBDO"); 2648 it.hasNext();) { 2649 ActivityDataWOBDO o = (ActivityDataWOBDO)it.next(); 2650 if (aOId.equals(o.oid_getActivity()) && variableIds.contains(o.getVariableDefinitionId())) { 2651 map.put(o.getVariableDefinitionId(),o); 2652 } 2654 } 2655 } 2656 2657 2659 if (aDO.isPersistent() && map.size()!=variableIds.size()) { 2660 if (map.size()==0) { 2661 ActivityDataWOBDO[] DOs=aDO.getActivityDataWOBDOArray(); 2663 for (int i=0; i<DOs.length; i++) { 2664 if (!map.containsKey(DOs[i].getVariableDefinitionId())) { 2665 map.put(DOs[i].getVariableDefinitionId(),DOs[i]); 2666 ((SharkDODSTransaction)ti)._read(DOs[i]); 2667 } 2668 } 2670 } else { 2671 DBTransaction dbt=((SharkDODSTransaction)ti).getDODSTransaction(); 2672 for (int i=0; i<variableIds.size(); i++) { 2673 String varId=(String )variableIds.get(i); 2674 if (map.containsKey(varId)) continue; 2675 ActivityDataWOBQuery q=new ActivityDataWOBQuery(dbt); 2676 q.setQueryActivity(aDO); 2677 q.setQueryVariableDefinitionId(varId); 2678 ActivityDataWOBDO DO=q.getNextDO(); 2679 if (DO!=null) { 2680 map.put(varId,DO); 2682 ((SharkDODSTransaction)ti)._read(DO); 2683 } else { 2684 } 2686 } 2687 } 2688 } 2689 2691 ActivityDataWOBDO[] DOs = new ActivityDataWOBDO[map.size()]; 2692 DOs = (ActivityDataWOBDO[])map.values().toArray(DOs); 2693 if (DOs!=null) { 2694 for (int i=0;i<DOs.length; i++) { 2695 ActivityDataWOBDO DO=DOs[i]; 2696 ActivityVariablePersistenceInterface var=new DODSActivityVariable(); 2697 restoreWOB(var,DO); 2698 ret.add(var); 2699 } 2700 } 2701 2702 return ret; 2703 } 2704 catch (Throwable t) { 2705 throw new PersistenceException(t); 2707 } 2708 2709 } 2710 2711 public List getResourceRequestersProcessIds (String resUsername,SharkTransaction ti) throws PersistenceException { 2712 List ret=new ArrayList(); 2713 try { 2714 ResourceDO rDO=getPersistedResourceObject(resUsername,ti); 2715 if (rDO!=null) { 2716 ProcessRequesterDO[] DOs=rDO.getProcessRequesterDOArray(); 2717 BigDecimal rOId = rDO.get_OId().toBigDecimal(); 2718 List list = new ArrayList(Arrays.asList(DOs)); 2719 if (DOs!=null) { 2721 for (int i=0; i<DOs.length; i++) { 2722 if (DOs[i].getActivityRequester()!=null) { 2723 list.remove(DOs[i]); 2724 } 2725 } 2726 } 2727 2728 for (Iterator it = ((SharkDODSTransaction)ti).iterator4typeDeleted("class org.enhydra.shark.instancepersistence.data.ProcessRequesterDO"); 2729 it.hasNext();) { 2730 ProcessRequesterDO o = (ProcessRequesterDO)it.next(); 2731 if (rOId.equals(o.oid_getResourceRequester())) { 2732 int index = list.indexOf(o); 2733 if (-1 != index) 2734 list.remove(o); 2735 } 2736 } 2737 for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.ProcessRequesterDO"); 2738 it.hasNext();) { 2739 ProcessRequesterDO o = (ProcessRequesterDO)it.next(); 2740 if (rOId.equals(o.oid_getResourceRequester()) && o.getActivityRequester()==null) { 2741 int index = list.indexOf(o); 2742 if (-1 == index) 2743 list.add(o); 2744 else { 2745 list.set(index, o); 2746 } 2747 } 2748 } 2749 DOs = new ProcessRequesterDO[list.size()]; 2750 list.toArray(DOs); 2751 for (int i=0;i<DOs.length; i++) { 2752 ret.add(DOs[i].getId()); 2753 } 2754 } 2755 return ret; 2756 } 2757 catch (Throwable t) { 2758 throw new PersistenceException(t); 2759 } 2760 } 2761 2762 public List getAndJoinEntries (String procId, 2763 String asDefId, 2764 String aDefId, 2765 SharkTransaction ti) throws PersistenceException { 2766 List ret=new ArrayList(); 2767 try { 2768 AndJoinEntryDO[] DOs=getPersistedAndJoinEntries(procId,asDefId,aDefId,ti); 2769 if (DOs!=null) { 2770 for (int i=0;i<DOs.length; i++) { 2771 AndJoinEntryDO DO=DOs[i]; 2772 AndJoinEntryInterface aj=new DODSAndJoinEntry(); 2773 aj.setProcessId(DO.getProcess().getId()); 2775 aj.setActivitySetDefinitionId(DO.getActivitySetDefinitionId()); 2776 aj.setActivityDefinitionId(DO.getActivityDefinitionId()); 2777 aj.setActivityId(DO.getActivity().getId()); 2778 ((SharkDODSTransaction)ti)._read(DO); 2779 ret.add(aj); 2780 } 2781 } 2782 2783 return ret; 2784 } 2785 catch (Throwable t) { 2786 throw new PersistenceException(t); 2787 } 2788 } 2789 2790 public int howManyAndJoinEntries (String procId, 2791 String asDefId, 2792 String aDefId, 2793 SharkTransaction ti) throws PersistenceException { 2794 try { 2795 AndJoinEntryDO[] DOs=getPersistedAndJoinEntries(procId,asDefId,aDefId,ti); 2796 if (DOs!=null) { 2797 return DOs.length; 2798 } else { 2799 return 0; 2800 } 2801 } catch (Throwable tr) { 2802 throw new PersistenceException(tr); 2803 } 2804 } 2805 2806 public int getExecuteCount(String procId, 2807 String asDefId, 2808 String aDefId, 2809 SharkTransaction ti) throws PersistenceException { 2810 ActivityQuery qry = new ActivityQuery(((SharkDODSTransaction)ti).getDODSTransaction()); 2811 try { 2812 qry.setQueryProcess(getPersistedProcessObject(procId, ti)); 2813 qry.setQueryActivitySetDefinitionId(asDefId); 2814 qry.setQueryActivityDefinitionId(aDefId); 2815 return qry.getCount(); 2816 } catch (Throwable e) { 2817 throw new PersistenceException(e); 2818 } 2819 } 2820 2821 public List getAllDeadlinesForProcess (String procId, 2822 SharkTransaction ti) throws PersistenceException { 2823 List ret=new ArrayList(); 2824 try { 2825 DeadlineDO[] DOs=getPersistedDeadlines(procId,-1,ti); 2826 if (DOs!=null) { 2827 for (int i=0;i<DOs.length; i++) { 2828 DeadlineDO DO=DOs[i]; 2829 DeadlinePersistenceInterface dl=new DODSDeadline(); 2830 dl.setProcessId(procId); 2832 dl.setActivityId(DO.getActivity().getId()); 2833 dl.setExceptionName(DO.getExceptionName()); 2834 dl.setSynchronous(DO.getIsSynchronous()); 2835 dl.setExecuted(DO.getIsExecuted()); 2836 dl.setUniqueId(DO.getCNT().toString()); 2837 dl.setTimeLimit(DO.getTimeLimit()); 2838 ((SharkDODSTransaction)ti)._read(DO); 2839 ret.add(dl); 2840 } 2841 } 2842 2843 return ret; 2844 } 2845 catch (Throwable t) { 2846 throw new PersistenceException(t); 2847 } 2848 } 2849 2850 public List getAllDeadlinesForProcess (String procId, 2851 long timeLimitBoundary, 2852 SharkTransaction ti) throws PersistenceException { 2853 List ret=new ArrayList(); 2854 try { 2855 DeadlineDO[] DOs=getPersistedDeadlines(procId,timeLimitBoundary,ti); 2856 if (DOs!=null) { 2857 for (int i=0;i<DOs.length; i++) { 2858 DeadlineDO DO=DOs[i]; 2859 DeadlinePersistenceInterface dl=new DODSDeadline(); 2860 dl.setProcessId(procId); 2862 dl.setActivityId(DO.getActivity().getId()); 2863 dl.setExceptionName(DO.getExceptionName()); 2864 dl.setSynchronous(DO.getIsSynchronous()); 2865 dl.setExecuted(DO.getIsExecuted()); 2866 dl.setUniqueId(DO.getCNT().toString()); 2867 dl.setTimeLimit(DO.getTimeLimit()); 2868 ((SharkDODSTransaction)ti)._read(DO); 2869 ret.add(dl); 2870 } 2871 } 2872 2873 return ret; 2874 } 2875 catch (Throwable t) { 2876 throw new PersistenceException(t); 2877 } 2878 } 2879 2880 public List getAllDeadlinesForActivity (String procId, 2881 String actId, 2882 SharkTransaction ti) throws PersistenceException { 2883 List ret=new ArrayList(); 2884 try { 2885 DeadlineDO[] DOs=getActivitiesPersistedDeadlines(actId,-1,ti); 2886 if (DOs!=null) { 2887 for (int i=0;i<DOs.length; i++) { 2888 DeadlineDO DO=DOs[i]; 2889 DeadlinePersistenceInterface dl=new DODSDeadline(); 2890 dl.setProcessId(procId); 2892 dl.setActivityId(actId); 2893 dl.setExceptionName(DO.getExceptionName()); 2894 dl.setSynchronous(DO.getIsSynchronous()); 2895 dl.setExecuted(DO.getIsExecuted()); 2896 dl.setUniqueId(DO.getCNT().toString()); 2897 dl.setTimeLimit(DO.getTimeLimit()); 2898 ((SharkDODSTransaction)ti)._read(DO); 2899 ret.add(dl); 2900 } 2901 } 2902 2903 return ret; 2904 } 2905 catch (Throwable t) { 2906 throw new PersistenceException(t); 2907 } 2908 } 2909 2910 public List getAllDeadlinesForActivity (String procId, 2911 String actId, 2912 long timeLimitBoundary, 2913 SharkTransaction ti) throws PersistenceException { 2914 List ret=new ArrayList(); 2915 try { 2916 DeadlineDO[] DOs=getActivitiesPersistedDeadlines(actId,timeLimitBoundary,ti); 2917 if (DOs!=null) { 2918 for (int i=0;i<DOs.length; i++) { 2919 DeadlineDO DO=DOs[i]; 2920 DeadlinePersistenceInterface dl=new DODSDeadline(); 2921 dl.setProcessId(procId); 2923 dl.setActivityId(actId); 2924 dl.setExceptionName(DO.getExceptionName()); 2925 dl.setSynchronous(DO.getIsSynchronous()); 2926 dl.setExecuted(DO.getIsExecuted()); 2927 dl.setUniqueId(DO.getCNT().toString()); 2928 dl.setTimeLimit(DO.getTimeLimit()); 2929 ((SharkDODSTransaction)ti)._read(DO); 2930 ret.add(dl); 2931 } 2932 } 2933 2934 return ret; 2935 } 2936 catch (Throwable t) { 2937 throw new PersistenceException(t); 2938 } 2939 } 2940 2941 public List getAllIdsForProcessesWithExpiriedDeadlines (long timeLimitBoundary,SharkTransaction ti) throws PersistenceException { 2942 List ret=new ArrayList(); 2943 try { 2944 BigDecimal procOpenRunningState=(BigDecimal )_prStates.get("open.running"); 2945 BigDecimal actNotStartedState=(BigDecimal )_acStates.get("open.not_running.not_started"); 2946 BigDecimal actRunningState=(BigDecimal )_acStates.get("open.running"); 2947 String oidCol=ProcessDO.get_OIdColumnName(); 2948 String sqlWherePS="Processes.State="+procOpenRunningState; 2949 String sqlWhereLT="Processes.Id NOT IN (SELECT LockTable.Id FROM LockTable)"; 2950 String sqlWhereDL="Processes."+oidCol+" IN (SELECT Deadlines.Process FROM Deadlines WHERE Deadlines.TimeLimit < "+timeLimitBoundary+" AND (SELECT COUNT(*) AS counter FROM Activities WHERE Activities."+oidCol+"=Deadlines.Activity AND (Activities.State="+actNotStartedState+" OR Activities.State="+actRunningState+"))>0)"; 2951 ProcessDO[] DOs=null; 2952 ProcessQuery query = null; 2953 query=new ProcessQuery(((SharkDODSTransaction)ti).getDODSTransaction()); 2954 QueryBuilder qb=qb=query.getQueryBuilder(); 2955 qb.addWhere(sqlWherePS); 2956 qb.addWhere(sqlWhereLT); 2957 qb.addWhere(sqlWhereDL); 2958 DOs = query.getDOArray(); 2960 if (DOs!=null) { 2961 for (int i=0;i<DOs.length; i++) { 2962 ret.add(DOs[i].getId()); 2963 } 2964 } 2965 2966 } catch (Throwable t) { 2967 throw new PersistenceException(t); 2968 } 2969 return ret; 2970 } 2971 2972 protected ProcessDefinitionDO getPersistedObject (ProcessMgrPersistenceInterface mgr,SharkTransaction ti) throws PersistenceException { 2973 ProcessDefinitionDO DO=getPersistedProcessMgrObject(mgr.getName(),ti); 2974 2975 try { 2976 if (DO==null) { 2977 DO=ProcessDefinitionDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction()); 2978 } 2979 return DO; 2980 } 2981 catch (Throwable t) { 2982 throw new PersistenceException(t); 2983 } 2984 2985 } 2986 2987 protected ProcessDefinitionDO getPersistedProcessMgrObject (String name,SharkTransaction ti) throws PersistenceException { 2988 ProcessDefinitionDO DO=null; 2989 ProcessDefinitionQuery query = null; 2990 try { 2991 for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.ProcessDefinitionDO"); 2992 it.hasNext();) { 2993 DO = (ProcessDefinitionDO)it.next(); 2994 if (name.equals(DO.getName())) 2995 return DO; 2996 } 2997 for (Iterator it = ((SharkDODSTransaction)ti).iterator4typeDeleted("class org.enhydra.shark.instancepersistence.data.ProcessDefinitionDO"); 2998 it.hasNext();) { 2999 DO = (ProcessDefinitionDO)it.next(); 3000 if (name.equals(DO.getName())) 3001 return null; 3002 } 3003 query=new ProcessDefinitionQuery(((SharkDODSTransaction)ti).getDODSTransaction()); 3004 query.setQueryName(name); 3006 query.requireUniqueInstance(); 3008 DO = query.getNextDO(); 3009 ((SharkDODSTransaction)ti)._read(DO); 3010 return DO; 3011 } 3012 catch (Throwable t) { 3013 throw new PersistenceException(t); 3014 } 3015 } 3016 3017 protected ProcessDefinitionDO[] getAllPersistedProcessMgrs (SharkTransaction ti,String pkgId,String pDefId,String pkgVersion, String where) throws PersistenceException { 3018 ProcessDefinitionDO[] DOs=null; 3019 3020 ProcessDefinitionQuery query = null; 3021 try { 3022 query=new ProcessDefinitionQuery(((SharkDODSTransaction)ti).getDODSTransaction()); 3023 if (pkgId!=null) { 3024 query.setQueryPackageId(pkgId); 3025 if (pkgVersion!=null) { 3026 query.setQueryProcessDefinitionVersion(pkgVersion); 3027 } 3028 if (pDefId!=null) { 3029 query.setQueryProcessDefinitionId(pDefId); 3030 } 3031 } else if (null != where) { 3032 query.getQueryBuilder().addWhere(where); 3033 } 3034 DOs = query.getDOArray(); 3035 List list = new ArrayList(Arrays.asList(DOs)); 3036 for (Iterator it = ((SharkDODSTransaction)ti).iterator4typeDeleted("class org.enhydra.shark.instancepersistence.data.ProcessDefinitionDO"); 3037 it.hasNext();) { 3038 ProcessDefinitionDO o = (ProcessDefinitionDO)it.next(); 3039 if (pkgId!=null) { 3040 if(!pkgId.equals(o.getPackageId())) continue; 3041 if (pkgVersion!=null && !pkgVersion.equals(o.getProcessDefinitionVersion())) continue; 3042 if (pDefId!=null && !pDefId.equals(o.getProcessDefinitionId())) continue; 3043 } 3044 3045 int index = list.indexOf(o); 3046 if (-1 != index) 3047 list.remove(o); 3048 } 3049 for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.ProcessDefinitionDO"); 3050 it.hasNext();) { 3051 ProcessDefinitionDO o = (ProcessDefinitionDO)it.next(); 3052 if (pkgId!=null) { 3053 if(!pkgId.equals(o.getPackageId())) continue; 3054 if (pkgVersion!=null && !pkgVersion.equals(o.getProcessDefinitionVersion())) continue; 3055 if (pDefId!=null && !pDefId.equals(o.getProcessDefinitionId())) continue; 3056 } 3057 3058 int index = list.indexOf(o); 3059 if (-1 == index) 3060 list.add(o); 3061 else { 3062 list.set(index, o); 3063 } 3064 } 3067 DOs = new ProcessDefinitionDO[list.size()]; 3068 list.toArray(DOs); 3069 return DOs; 3070 } catch (Throwable t) { 3071 throw new PersistenceException(t); 3072 } 3073 } 3074 3075 protected ProcessDO getPersistedObject (ProcessPersistenceInterface proc,SharkTransaction ti) throws PersistenceException { 3076 ProcessDO DO=getPersistedProcessObject(proc.getId(),ti); 3077 3078 try { 3079 if (DO==null) { 3080 DO=ProcessDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction()); 3081 } 3082 return DO; 3083 } 3084 catch (Throwable t) { 3085 throw new PersistenceException(t); 3086 } 3087 } 3088 3089 protected ProcessDO[] getPersistedProcesses(SharkTransaction ti, 3094 int type, 3095 String pkgId, 3096 String pDefId, 3097 String pkgVer, 3098 java.util.Date lastStateTimeBoundary, 3099 String sqlWhere) throws PersistenceException { 3100 3101 ProcessDefinitionDO[] pdefDOs=null; 3102 if (pkgId!=null) { 3103 pdefDOs = getAllPersistedProcessMgrs(ti, pkgId, pDefId, pkgVer, null); 3104 } 3105 3106 long lstb=-1; 3107 if (lastStateTimeBoundary!=null) { 3108 lstb=lastStateTimeBoundary.getTime(); 3109 } 3110 3111 ProcessDO[] DOs=null; 3112 ProcessQuery query = null; 3113 try { 3114 query=new ProcessQuery(((SharkDODSTransaction)ti).getDODSTransaction()); 3115 BigDecimal openRunningState=null; 3116 QueryBuilder qb=qb=query.getQueryBuilder(); 3117 if (lastStateTimeBoundary!=null) { 3118 qb.addWhere(ProcessDO.LastStateTime,lstb,QueryBuilder.LESS_THAN); 3119 } 3120 if (pkgId!=null) { 3121 if (pdefDOs!=null && pdefDOs.length>0) { 3122 qb.addWhereOpenParen(); 3123 for (int i=0; i<pdefDOs.length; i++) { 3124 qb.addWhere(ProcessDO.ProcessDefinition, 3125 pdefDOs[i].get_OId().toBigDecimal(), 3126 QueryBuilder.EQUAL); 3127 if (i<pdefDOs.length-1) { 3128 qb.addWhereOr(); 3129 } 3130 3131 } 3132 qb.addWhereCloseParen(); 3133 } 3134 3135 } 3136 3137 if (type==1) { 3138 openRunningState=(BigDecimal )_prStates.get("open.running"); 3139 qb.addWhere(ProcessDO.State,openRunningState,QueryBuilder.EQUAL); 3140 } else if (type==-1) { 3141 qb.addWhereOpenParen(); 3142 for (int i=0; i<_prClosedStatesBigDecimals.size(); i++) { 3143 qb.addWhere(ProcessDO.State, 3144 (BigDecimal )_prClosedStatesBigDecimals.get(i), 3145 QueryBuilder.EQUAL); 3146 if (i<_prClosedStatesBigDecimals.size()-1) { 3147 qb.addWhereOr(); 3148 } 3149 } 3150 qb.addWhereCloseParen(); 3151 } 3152 if (null != sqlWhere) { 3153 qb.addWhere(sqlWhere); 3154 } 3155 DOs = query.getDOArray(); 3156 List list = new ArrayList(Arrays.asList(DOs)); 3157 3158 for (Iterator it = ((SharkDODSTransaction)ti).iterator4typeDeleted("class org.enhydra.shark.instancepersistence.data.ProcessDO"); 3159 it.hasNext();) { 3160 ProcessDO o = (ProcessDO)it.next(); 3161 if (type==1 && !o.oid_getState().equals(openRunningState)) continue; 3162 if (type==-1 && !_prClosedStatesBigDecimals.contains(o.oid_getState())) continue; 3163 if (lastStateTimeBoundary!=null && o.getLastStateTime()>lstb) continue; 3164 if (pkgId!=null) { 3165 ProcessDefinitionDO pDefDO=o.getProcessDefinition(); 3166 if (!pkgId.equals(pDefDO.getPackageId())) continue; 3167 if (pDefId!=null && !pDefId.equals(pDefDO.getProcessDefinitionId())) continue; 3168 } 3169 int index = list.indexOf(o); 3170 if (-1 != index) 3171 list.remove(o); 3172 } 3173 for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.ProcessDO"); 3174 it.hasNext();) { 3175 ProcessDO o = (ProcessDO)it.next(); 3176 if (type==1 && !o.oid_getState().equals(openRunningState)) continue; 3177 if (type==-1 && !_prClosedStatesBigDecimals.contains(o.oid_getState())) continue; 3178 if (lastStateTimeBoundary!=null && o.getLastStateTime()>lstb) continue; 3179 if (pkgId!=null) { 3180 ProcessDefinitionDO pDefDO=o.getProcessDefinition(); 3181 if (!pkgId.equals(pDefDO.getPackageId())) continue; 3182 if (pDefId!=null && !pDefId.equals(pDefDO.getProcessDefinitionId())) continue; 3183 } 3184 int index = list.indexOf(o); 3185 if (-1 == index) 3186 list.add(o); 3187 else { 3188 list.set(index, o); 3189 } 3190 } 3193 DOs = new ProcessDO[list.size()]; 3194 list.toArray(DOs); 3195 return DOs; 3196 } 3197 catch (Throwable t) { 3198 throw new PersistenceException(t); 3199 } 3200 } 3201 3202 protected ProcessDO getPersistedProcessObject (String procId,SharkTransaction ti) throws PersistenceException { 3203 ProcessDO DO=null; 3204 3205 ProcessQuery query = null; 3206 try { 3207 for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.ProcessDO"); 3208 it.hasNext();) { 3209 DO = (ProcessDO)it.next(); 3210 if (procId.equals(DO.getId())) 3211 return DO; 3212 } 3213 for (Iterator it = ((SharkDODSTransaction)ti).iterator4typeDeleted("class org.enhydra.shark.instancepersistence.data.ProcessDO"); 3214 it.hasNext();) { 3215 DO = (ProcessDO)it.next(); 3216 if (procId.equals(DO.getId())) 3217 return null; 3218 } 3219 query=new ProcessQuery(((SharkDODSTransaction)ti).getDODSTransaction()); 3220 query.setQueryId(procId); 3222 query.requireUniqueInstance(); 3224 DO = query.getNextDO(); 3225 ((SharkDODSTransaction)ti)._read(DO); 3226 return DO; 3227 } 3228 catch (Throwable t) { 3229 throw new PersistenceException(t); 3230 } 3231 } 3232 3233 protected ProcessRequesterDO getProcessRequester(String procId,SharkTransaction ti) throws PersistenceException { 3234 ProcessRequesterDO DO=getPersistedRequesterObject(procId,ti); 3235 try { 3236 if (null == DO) { 3237 DO=ProcessRequesterDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction()); 3238 } 3239 return DO; 3240 } catch (Throwable t) { 3241 throw new PersistenceException(t); 3242 } 3243 } 3244 3245 protected ProcessRequesterDO getPersistedRequesterObject (String procId,SharkTransaction ti) throws PersistenceException { 3246 ProcessRequesterDO DO=null; 3247 ProcessRequesterQuery query = null; 3248 try { 3249 for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.ProcessRequesterDO"); 3250 it.hasNext();) { 3251 DO = (ProcessRequesterDO)it.next(); 3252 if (procId.equals(DO.getId())) 3253 return DO; 3254 } 3255 for (Iterator it = ((SharkDODSTransaction)ti).iterator4typeDeleted("class org.enhydra.shark.instancepersistence.data.ProcessRequesterDO"); 3256 it.hasNext();) { 3257 DO = (ProcessRequesterDO)it.next(); 3258 if (procId.equals(DO.getId())) 3259 return null; 3260 } 3261 query=new ProcessRequesterQuery(((SharkDODSTransaction)ti).getDODSTransaction()); 3262 query.setQueryId(procId); 3264 query.requireUniqueInstance(); 3266 DO = query.getNextDO(); 3267 ((SharkDODSTransaction)ti)._read(DO); 3268 return DO; 3269 } 3270 catch (Throwable t) { 3271 throw new PersistenceException(t); 3272 } 3273 } 3274 3275 3292 3293 protected ActivityDO getPersistedObject (ActivityPersistenceInterface act,SharkTransaction ti) throws PersistenceException { 3294 ActivityDO DO=getPersistedActivityObject(act.getId(),ti); 3296 3298 try { 3299 if (DO==null) { 3300 DO=ActivityDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction()); 3301 } 3302 return DO; 3303 } 3304 catch (Throwable t) { 3305 throw new PersistenceException(t); 3306 } 3307 } 3308 3309 protected ActivityDO[] getPersistedActivities (SharkTransaction ti,int type,BigDecimal procOId, String sqlWhere) throws PersistenceException { 3314 3315 ActivityDO[] DOs=null; 3316 ActivityQuery query = null; 3317 try { 3318 query=new ActivityQuery(((SharkDODSTransaction)ti).getDODSTransaction()); 3319 QueryBuilder qb=qb=query.getQueryBuilder(); 3320 3321 if (procOId!=null) { 3322 qb.addWhere(ActivityDO.Process,procOId,QueryBuilder.EQUAL); 3323 } 3324 3325 if (sqlWhere!=null) { 3326 qb.addWhere(sqlWhere); 3327 } 3328 3329 if (type==1) { 3330 qb.addWhereOpenParen(); 3331 for (int i=0; i<_actOpenStatesBigDecimals.size(); i++) { 3332 qb.addWhere(ActivityDO.State, 3333 (BigDecimal )_actOpenStatesBigDecimals.get(i), 3334 QueryBuilder.EQUAL); 3335 if (i<_actOpenStatesBigDecimals.size()-1) { 3336 qb.addWhereOr(); 3337 } 3338 } 3339 qb.addWhereCloseParen(); 3340 } else if (type==-1) { 3341 qb.addWhereOpenParen(); 3342 for (int i=0; i<_actClosedStatesBigDecimals.size(); i++) { 3343 qb.addWhere(ActivityDO.State, 3344 (BigDecimal )_actClosedStatesBigDecimals.get(i), 3345 QueryBuilder.EQUAL); 3346 if (i<_actClosedStatesBigDecimals.size()-1) { 3347 qb.addWhereOr(); 3348 } 3349 } 3350 qb.addWhereCloseParen(); 3351 } 3352 DOs = query.getDOArray(); 3353 List list = new ArrayList(Arrays.asList(DOs)); 3354 for (Iterator it = ((SharkDODSTransaction)ti).iterator4typeDeleted("class org.enhydra.shark.instancepersistence.data.ActivityDO"); 3355 it.hasNext();) { 3356 ActivityDO o = (ActivityDO)it.next(); 3357 if (procOId!=null && !o.oid_getProcess().equals(procOId)) continue; 3358 if (type==1 && !_actOpenStatesBigDecimals.contains(o.oid_getState())) continue; 3359 if (type==-1 && !_actClosedStatesBigDecimals.contains(o.oid_getState())) continue; 3360 int index = list.indexOf(o); 3361 if (-1 != index) 3362 list.remove(o); 3363 } 3364 for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.ActivityDO"); 3365 it.hasNext();) { 3366 ActivityDO o = (ActivityDO)it.next(); 3367 if (procOId!=null && !o.oid_getProcess().equals(procOId)) continue; 3368 if (type==1 && !_actOpenStatesBigDecimals.contains(o.oid_getState())) { 3369 list.remove(o); 3370 continue; 3371 } 3372 if (type==-1 && !_actClosedStatesBigDecimals.contains(o.oid_getState())) continue; 3373 int index = list.indexOf(o); 3374 if (-1 == index) { 3375 list.add(o); 3376 } 3377 else { 3378 list.set(index, o); 3379 } 3380 } 3383 DOs = new ActivityDO[list.size()]; 3384 list.toArray(DOs); 3385 return DOs; 3386 } 3387 catch (Throwable t) { 3388 throw new PersistenceException(t); 3389 } 3390 } 3391 3392 protected ActivityDO getPersistedActivityObject (String actId,SharkTransaction ti) throws PersistenceException { 3393 if (null == actId) 3394 return null; 3395 3396 ActivityDO DO=null; 3397 ActivityQuery query = null; 3398 3399 try { 3400 for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.ActivityDO"); 3402 it.hasNext();) { 3403 DO = (ActivityDO)it.next(); 3404 if (actId.equals(DO.getId())) { 3406 return DO; 3408 } 3409 } 3410 for (Iterator it = ((SharkDODSTransaction)ti).iterator4typeDeleted("class org.enhydra.shark.instancepersistence.data.ActivityDO"); 3411 it.hasNext();) { 3412 DO = (ActivityDO)it.next(); 3413 if (actId.equals(DO.getId())) { 3415 return null; 3417 } 3418 } 3419 query=new ActivityQuery(((SharkDODSTransaction)ti).getDODSTransaction()); 3422 query.setQueryId(actId); 3425 query.requireUniqueInstance(); 3428 3430 DO = query.getNextDO(); 3431 ((SharkDODSTransaction)ti)._read(DO); 3433 return DO; 3434 } 3435 catch (Throwable t) { 3436 throw new PersistenceException(t); 3438 } 3439 } 3440 3441 protected ResourceDO getPersistedObject (ResourcePersistenceInterface res,SharkTransaction ti) throws PersistenceException { 3442 ResourceDO DO=getPersistedResourceObject(res.getUsername(),ti); 3443 3444 try { 3445 if (DO==null) { 3446 DO=ResourceDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction()); 3447 } 3448 return DO; 3449 } 3450 catch (Throwable t) { 3451 throw new PersistenceException(t); 3452 } 3453 } 3454 3455 protected ResourceDO getPersistedResourceObject (String username,SharkTransaction ti) throws PersistenceException { 3456 if (null == username) 3457 return null; 3458 ResourceDO DO=null; 3459 ResourceQuery query = null; 3460 try { 3461 for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.ResourceDO"); 3462 it.hasNext();) { 3463 DO = (ResourceDO)it.next(); 3464 if (username.equals(DO.getUsername())) 3465 return DO; 3466 } 3467 for (Iterator it = ((SharkDODSTransaction)ti).iterator4typeDeleted("class org.enhydra.shark.instancepersistence.data.ResourceDO"); 3468 it.hasNext();) { 3469 DO = (ResourceDO)it.next(); 3470 if (username.equals(DO.getUsername())) 3471 return null; 3472 } 3473 query=new ResourceQuery(((SharkDODSTransaction)ti).getDODSTransaction()); 3474 query.setQueryUsername(username); 3476 query.requireUniqueInstance(); 3478 DO = query.getNextDO(); 3479 ((SharkDODSTransaction)ti)._read(DO); 3480 3481 return DO; 3482 } 3483 catch (Throwable t) { 3484 throw new PersistenceException(t); 3485 } 3486 } 3487 3488 protected ResourceDO[] getAllPersistedResources (SharkTransaction ti, String sqlWhere) throws PersistenceException { 3489 ResourceDO[] DOs=null; 3490 3491 ResourceQuery query = null; 3492 try { 3493 query=new ResourceQuery(((SharkDODSTransaction)ti).getDODSTransaction()); 3494 if (null != sqlWhere) { 3495 query.getQueryBuilder().addWhere(sqlWhere); 3496 } 3497 DOs = query.getDOArray(); 3498 List list = new ArrayList(Arrays.asList(DOs)); 3499 for (Iterator it = ((SharkDODSTransaction)ti).iterator4typeDeleted("class org.enhydra.shark.instancepersistence.data.ResourceDO"); 3500 it.hasNext();) { 3501 Object o = it.next(); 3502 int index = list.indexOf(o); 3503 if (-1 != index) 3504 list.remove(o); 3505 } 3506 for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.ResourceDO"); 3507 it.hasNext();) { 3508 Object o = it.next(); 3509 int index = list.indexOf(o); 3510 if (-1 == index) 3511 list.add(o); 3512 else { 3513 list.set(index, o); 3514 } 3515 } 3518 DOs = new ResourceDO[list.size()]; 3519 list.toArray(DOs); 3520 return DOs; 3521 } 3522 catch (Throwable t) { 3523 throw new PersistenceException(t); 3524 } 3525 } 3526 3527 protected AssignmentDO getPersistedObject (AssignmentPersistenceInterface ass,SharkTransaction ti) throws PersistenceException { 3528 AssignmentDO DO=getPersistedAssignmentObject(ass.getActivityId(),ass.getResourceUsername(),ti); 3529 3530 try { 3531 if (DO==null) { 3532 DO=AssignmentDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction()); 3533 } 3534 return DO; 3535 } 3536 catch (Throwable t) { 3537 throw new PersistenceException(t); 3538 } 3539 } 3540 3541 protected AssignmentDO getPersistedAssignmentObject (String actId,String username,SharkTransaction ti) throws PersistenceException { 3542 AssignmentDO DO=null; 3543 3544 3546 AssignmentQuery query = null; 3547 try { 3548 for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.AssignmentDO"); 3551 it.hasNext();) { 3552 DO = (AssignmentDO)it.next(); 3553 if (username.equals(DO.getResourceId()) 3554 && actId.equals(DO.getActivity().getId())) { 3555 return DO; 3557 } 3558 } 3559 for (Iterator it = ((SharkDODSTransaction)ti).iterator4typeDeleted("class org.enhydra.shark.instancepersistence.data.AssignmentDO"); 3560 it.hasNext();) { 3561 DO = (AssignmentDO)it.next(); 3562 if (username.equals(DO.getResourceId()) 3563 && actId.equals(DO.getActivityId())) { 3564 return null; 3566 } 3567 } 3568 DBTransaction dbt = ((SharkDODSTransaction)ti).getDODSTransaction(); 3569 query=new AssignmentQuery(dbt); 3570 query.setQueryActivityId(actId); 3572 query.setQueryResourceId(username); 3573 query.requireUniqueInstance(); 3575 DO = query.getNextDO(); 3576 ((SharkDODSTransaction)ti)._read(DO); 3577 3578 return DO; 3580 } 3581 catch (Throwable t) { 3582 throw new PersistenceException(t); 3583 } 3584 } 3585 3586 protected AssignmentDO[] getAllPersistedAssignments (SharkTransaction ti, String sqlWhere) throws PersistenceException { 3587 AssignmentDO[] DOs=null; 3588 3589 AssignmentQuery query = null; 3590 try { 3591 query=new AssignmentQuery(((SharkDODSTransaction)ti).getDODSTransaction()); 3592 if (null != sqlWhere) { 3593 query.getQueryBuilder().addWhere(sqlWhere); 3594 } 3595 DOs = query.getDOArray(); 3596 List list = new ArrayList(Arrays.asList(DOs)); 3597 for (Iterator it = ((SharkDODSTransaction)ti).iterator4typeDeleted("class org.enhydra.shark.instancepersistence.data.AssignmentDO"); 3598 it.hasNext();) { 3599 Object o = it.next(); 3600 int index = list.indexOf(o); 3601 if (-1 != index) 3602 list.remove(o); 3603 } 3604 for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.AssignmentDO"); 3605 it.hasNext();) { 3606 Object o = it.next(); 3607 int index = list.indexOf(o); 3608 if (-1 == index) 3609 list.add(o); 3610 else { 3611 list.set(index, o); 3612 } 3613 } 3616 DOs = new AssignmentDO[list.size()]; 3617 list.toArray(DOs); 3618 return DOs; 3619 } 3620 catch (Throwable t) { 3621 throw new PersistenceException(t); 3622 } 3623 } 3624 3625 protected AndJoinEntryDO[] getPersistedAndJoinEntries (String procId, 3626 String asDefId, 3627 String aDefId, 3628 SharkTransaction ti) throws PersistenceException { 3629 AndJoinEntryDO[] DOs=null; 3630 3631 AndJoinEntryQuery query = null; 3632 try { 3633 query=new AndJoinEntryQuery(((SharkDODSTransaction)ti).getDODSTransaction()); 3634 query.setQueryProcess(getPersistedProcessObject(procId,ti)); 3635 query.setQueryActivitySetDefinitionId(asDefId); 3636 query.setQueryActivityDefinitionId(aDefId); 3637 DOs = query.getDOArray(); 3638 List list = new ArrayList(Arrays.asList(DOs)); 3639 for (Iterator it = ((SharkDODSTransaction)ti).iterator4typeDeleted("class org.enhydra.shark.instancepersistence.data.AndJoinEntryDO"); 3640 it.hasNext();) { 3641 AndJoinEntryDO ajedo = (AndJoinEntryDO)it.next(); 3642 int index = list.indexOf(ajedo); 3643 if (((asDefId==null && ajedo.getActivitySetDefinitionId()==null) || (asDefId!=null && asDefId.equals(ajedo.getActivitySetDefinitionId()))) 3644 && (aDefId.equals(ajedo.getActivityDefinitionId())) 3645 && procId.equals(ajedo.getProcess().getId())) { 3646 if (-1 != index) 3647 list.remove(ajedo); 3648 } 3649 } 3650 for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.AndJoinEntryDO"); 3651 it.hasNext();) { 3652 AndJoinEntryDO ajedo = (AndJoinEntryDO)it.next(); 3653 int index = list.indexOf(ajedo); 3654 if (((asDefId==null && ajedo.getActivitySetDefinitionId()==null) || (asDefId!=null && asDefId.equals(ajedo.getActivitySetDefinitionId()))) 3655 && (aDefId.equals(ajedo.getActivityDefinitionId())) 3656 && procId.equals(ajedo.getProcess().getId())) { 3657 if (-1 == index) 3658 list.add(ajedo); 3659 else { 3660 list.set(index, ajedo); 3661 } 3662 } 3663 } 3664 DOs = new AndJoinEntryDO[list.size()]; 3665 list.toArray(DOs); 3666 return DOs; 3667 } 3668 catch (Throwable t) { 3669 throw new PersistenceException(t); 3670 } 3671 } 3672 3673 protected DeadlineDO[] getPersistedDeadlines (String procId,long timeLimitBoundary,SharkTransaction ti) throws PersistenceException { 3674 DeadlineDO[] DOs=null; 3675 3676 DeadlineQuery query = null; 3677 try { 3678 query=new DeadlineQuery(((SharkDODSTransaction)ti).getDODSTransaction()); 3679 query.setQueryProcess(getPersistedProcessObject(procId,ti)); 3680 if (timeLimitBoundary>=0) { 3681 query.setQueryTimeLimit(timeLimitBoundary,QueryBuilder.LESS_THAN); 3682 } 3683 DOs = query.getDOArray(); 3684 List list = new ArrayList(Arrays.asList(DOs)); 3685 for (Iterator it = ((SharkDODSTransaction)ti).iterator4typeDeleted("class org.enhydra.shark.instancepersistence.data.DeadlineDO"); 3686 it.hasNext();) { 3687 DeadlineDO ddo = (DeadlineDO)it.next(); 3688 int index = list.indexOf(ddo); 3689 if (procId.equals(ddo.getProcess().getId())) { 3690 if (-1 != index) 3691 list.remove(ddo); 3692 } 3693 } 3694 for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.DeadlineDO"); 3695 it.hasNext();) { 3696 DeadlineDO ddo = (DeadlineDO)it.next(); 3697 int index = list.indexOf(ddo); 3698 if (procId.equals(ddo.getProcess().getId())) { 3699 if (-1 == index) 3700 list.add(ddo); 3701 else { 3702 list.set(index, ddo); 3703 } 3704 } 3705 } 3706 DOs = new DeadlineDO[list.size()]; 3707 list.toArray(DOs); 3708 return DOs; 3709 } 3710 catch (Throwable t) { 3711 throw new PersistenceException(t); 3712 } 3713 } 3714 3715 protected DeadlineDO[] getActivitiesPersistedDeadlines (String actId,long timeLimitBoundary,SharkTransaction ti) throws PersistenceException { 3716 DeadlineDO[] DOs=null; 3717 3718 DeadlineQuery query = null; 3719 try { 3720 query=new DeadlineQuery(((SharkDODSTransaction)ti).getDODSTransaction()); 3721 query.setQueryActivity(getPersistedActivityObject(actId,ti)); 3722 if (timeLimitBoundary>=0) { 3723 query.setQueryTimeLimit(timeLimitBoundary,QueryBuilder.LESS_THAN); 3724 } 3725 DOs = query.getDOArray(); 3726 List list = new ArrayList(Arrays.asList(DOs)); 3727 for (Iterator it = ((SharkDODSTransaction)ti).iterator4typeDeleted("class org.enhydra.shark.instancepersistence.data.DeadlineDO"); 3728 it.hasNext();) { 3729 DeadlineDO ddo = (DeadlineDO)it.next(); 3730 int index = list.indexOf(ddo); 3731 if (actId.equals(ddo.getActivity().getId())) { 3732 if (-1 != index) 3733 list.remove(ddo); 3734 } 3735 } 3736 for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.DeadlineDO"); 3737 it.hasNext();) { 3738 DeadlineDO ddo = (DeadlineDO)it.next(); 3739 int index = list.indexOf(ddo); 3740 if (actId.equals(ddo.getActivity().getId())) { 3741 if (-1 == index) 3742 list.add(ddo); 3743 else { 3744 list.set(index, ddo); 3745 } 3746 } 3747 } 3748 DOs = new DeadlineDO[list.size()]; 3749 list.toArray(DOs); 3750 return DOs; 3751 } 3752 catch (Throwable t) { 3753 throw new PersistenceException(t); 3754 } 3755 } 3756 3757 protected DeadlineDO getPersistedObject (DeadlinePersistenceInterface dpe,SharkTransaction ti) throws PersistenceException { 3758 DeadlineDO DO=getPersistedDeadlineObject(dpe.getUniqueId(),ti); 3759 3760 try { 3761 if (DO==null) { 3762 DO=DeadlineDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction()); 3763 } 3764 return DO; 3765 } 3766 catch (Throwable t) { 3767 throw new PersistenceException(t); 3768 } 3769 } 3770 3771 protected DeadlineDO getPersistedDeadlineObject (String uniqueId,SharkTransaction ti) throws PersistenceException { 3772 3773 if (uniqueId==null) return null; 3774 3775 DeadlineDO DO=null; 3776 DeadlineQuery query = null; 3777 try { 3778 for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.DeadlineDO"); 3779 it.hasNext();) { 3780 DO = (DeadlineDO)it.next(); 3781 if (uniqueId.equals(DO.getCNT())) 3782 return DO; 3783 } 3784 for (Iterator it = ((SharkDODSTransaction)ti).iterator4typeDeleted("class org.enhydra.shark.instancepersistence.data.DeadlineDO"); 3785 it.hasNext();) { 3786 DO = (DeadlineDO)it.next(); 3787 if (uniqueId.equals(DO.getCNT())) 3788 return null; 3789 } 3790 query=new DeadlineQuery(((SharkDODSTransaction)ti).getDODSTransaction()); 3791 query.setQueryCNT(new BigDecimal (uniqueId)); 3793 query.requireUniqueInstance(); 3795 DO = query.getNextDO(); 3796 ((SharkDODSTransaction)ti)._read(DO); 3797 3798 return DO; 3799 } 3800 catch (Throwable t) { 3801 throw new PersistenceException(t); 3802 } 3803 } 3804 3805 protected ProcessDataDO getPersistedObject (ProcessVariablePersistenceInterface var,SharkTransaction ti) throws PersistenceException { 3806 ProcessDataDO DO= 3807 getPersistedProcessVariableObject(var.getProcessId(),var.getDefinitionId(),ti); 3808 3809 try { 3810 if (DO==null) { 3811 DO=ProcessDataDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction()); 3812 } 3813 return DO; 3814 } 3815 catch (Throwable t) { 3816 throw new PersistenceException(t); 3817 } 3818 } 3819 3820 protected ProcessDataDO getPersistedProcessVariableObject (String procId, 3821 String defId,SharkTransaction ti) throws PersistenceException { 3822 ProcessDataDO DO=null; 3823 3824 ProcessDataQuery query = null; 3825 try { 3826 ProcessDO pDO=getPersistedProcessObject(procId,ti); 3827 if (null != pDO) { 3828 BigDecimal pOId = pDO.get_OId().toBigDecimal(); 3829 for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.ProcessDataDO"); 3830 it.hasNext();) { 3831 DO = (ProcessDataDO)it.next(); 3832 if (defId.equals(DO.getVariableDefinitionId()) 3833 && pOId.equals(DO.oid_getProcess())) 3834 return DO; 3835 } 3836 for (Iterator it = ((SharkDODSTransaction)ti).iterator4typeDeleted("class org.enhydra.shark.instancepersistence.data.ProcessDataDO"); 3837 it.hasNext();) { 3838 DO = (ProcessDataDO)it.next(); 3839 if (defId.equals(DO.getVariableDefinitionId()) 3840 && pOId.equals(DO.oid_getProcess())) 3841 return null; 3842 } 3843 } 3844 query=new ProcessDataQuery(((SharkDODSTransaction)ti).getDODSTransaction()); 3845 query.setQueryProcess(pDO); 3847 query.setQueryVariableDefinitionId(defId); 3848 query.requireUniqueInstance(); 3850 DO = query.getNextDO(); 3851 ((SharkDODSTransaction)ti)._read(DO); 3852 3853 return DO; 3854 } 3855 catch (Throwable t) { 3856 throw new PersistenceException(t); 3857 } 3858 } 3859 3860 protected ProcessDataWOBDO getPersistedObject2 (ProcessVariablePersistenceInterface var,SharkTransaction ti) throws PersistenceException { 3861 ProcessDataWOBDO DO= 3862 getPersistedProcessVariableObject2(var.getProcessId(),var.getDefinitionId(),ti); 3863 3864 try { 3865 if (DO==null) { 3866 DO=ProcessDataWOBDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction()); 3867 } 3868 return DO; 3869 } 3870 catch (Throwable t) { 3871 throw new PersistenceException(t); 3872 } 3873 } 3874 3875 protected ProcessDataWOBDO getPersistedProcessVariableObject2 (String procId, 3876 String defId,SharkTransaction ti) throws PersistenceException { 3877 ProcessDataWOBDO DO=null; 3878 3879 try { 3880 ProcessDO pDO=getPersistedProcessObject(procId,ti); 3881 if (null != pDO) { 3882 BigDecimal pOId = pDO.get_OId().toBigDecimal(); 3883 for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.ProcessDataWOBDO"); 3884 it.hasNext();) { 3885 DO = (ProcessDataWOBDO)it.next(); 3886 if (defId.equals(DO.getVariableDefinitionId()) 3887 && pOId.equals(DO.oid_getProcess())) 3888 return DO; 3889 } 3890 for (Iterator it = ((SharkDODSTransaction)ti).iterator4typeDeleted("class org.enhydra.shark.instancepersistence.data.ProcessDataDO"); 3891 it.hasNext();) { 3892 DO = (ProcessDataWOBDO)it.next(); 3893 if (defId.equals(DO.getVariableDefinitionId()) 3894 && pOId.equals(DO.oid_getProcess())) 3895 return null; 3896 } 3897 } 3898 ProcessDataWOBQuery query=new ProcessDataWOBQuery(((SharkDODSTransaction)ti).getDODSTransaction()); 3899 query.setQueryProcess(pDO); 3901 query.setQueryVariableDefinitionId(defId); 3902 query.requireUniqueInstance(); 3904 DO = query.getNextDO(); 3905 ((SharkDODSTransaction)ti)._read(DO); 3906 3907 return DO; 3908 } 3909 catch (Throwable t) { 3910 throw new PersistenceException(t); 3911 } 3912 } 3913 3914 protected ProcessDataBLOBDO getPersistedObject (ProcessDataWOBDO pdDO,SharkTransaction ti) throws PersistenceException { 3915 ProcessDataBLOBDO DO= 3916 getPersistedProcessVariableBLOBObject(pdDO,ti); 3917 3918 try { 3919 if (DO==null) { 3920 DO=ProcessDataBLOBDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction()); 3921 } 3922 return DO; 3923 } 3924 catch (Throwable t) { 3925 throw new PersistenceException(t); 3926 } 3927 } 3928 3929 protected ProcessDataBLOBDO getPersistedProcessVariableBLOBObject (ProcessDataWOBDO pdDO,SharkTransaction ti) throws PersistenceException { 3930 ProcessDataBLOBDO DO=null; 3931 3932 try { 3933 if (null != pdDO) { 3934 BigDecimal pdOId = pdDO.get_OId().toBigDecimal(); 3935 for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.ProcessDataBLOBDO"); 3936 it.hasNext();) { 3937 DO = (ProcessDataBLOBDO)it.next(); 3938 if (pdOId.equals(DO.oid_getProcessDataWOB())) 3939 return DO; 3940 } 3941 for (Iterator it = ((SharkDODSTransaction)ti).iterator4typeDeleted("class org.enhydra.shark.instancepersistence.data.ProcessDataBLOBDO"); 3942 it.hasNext();) { 3943 DO = (ProcessDataBLOBDO)it.next(); 3944 if (pdOId.equals(DO.oid_getProcessDataWOB())) 3945 return null; 3946 } 3947 } 3948 ProcessDataBLOBQuery query=new ProcessDataBLOBQuery(((SharkDODSTransaction)ti).getDODSTransaction()); 3949 query.setQueryProcessDataWOB(pdDO); 3951 query.requireUniqueInstance(); 3953 DO = query.getNextDO(); 3954 ((SharkDODSTransaction)ti)._read(DO); 3955 3956 return DO; 3957 } 3958 catch (Throwable t) { 3959 throw new PersistenceException(t); 3960 } 3961 } 3962 3963 protected ActivityDataDO getPersistedObject (ActivityVariablePersistenceInterface var,SharkTransaction ti) throws PersistenceException { 3964 ActivityDataDO DO= 3965 getPersistedActivityVariableObject(var.getActivityId(),var.getDefinitionId(),ti); 3966 3967 try { 3968 if (DO==null) { 3969 DO=ActivityDataDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction()); 3970 } 3971 return DO; 3972 } 3973 catch (Throwable t) { 3974 throw new PersistenceException(t); 3975 } 3976 } 3977 3978 protected ActivityDataDO getPersistedActivityVariableObject (String actId, 3979 String defId,SharkTransaction ti) throws PersistenceException { 3980 ActivityDataDO DO=null; 3981 3982 ActivityDataQuery query = null; 3983 try { 3984 ActivityDO aDO=getPersistedActivityObject(actId,ti); 3985 if (null != aDO) { 3986 BigDecimal aOId = aDO.get_OId().toBigDecimal(); 3987 for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.ActivityDataDO"); 3988 it.hasNext();) { 3989 DO = (ActivityDataDO)it.next(); 3990 if (defId.equals(DO.getVariableDefinitionId()) 3991 && aOId.equals(DO.oid_getActivity())) 3992 return DO; 3993 } 3994 for (Iterator it = ((SharkDODSTransaction)ti).iterator4typeDeleted("class org.enhydra.shark.instancepersistence.data.ActivityDataDO"); 3995 it.hasNext();) { 3996 DO = (ActivityDataDO)it.next(); 3997 if (defId.equals(DO.getVariableDefinitionId()) 3998 && aOId.equals(DO.oid_getActivity())) 3999 return null; 4000 } 4001 } 4002 query=new ActivityDataQuery(((SharkDODSTransaction)ti).getDODSTransaction()); 4003 4005 query.setQueryActivity(aDO); 4006 query.setQueryVariableDefinitionId(defId); 4007 query.requireUniqueInstance(); 4009 DO = query.getNextDO(); 4010 ((SharkDODSTransaction)ti)._read(DO); 4011 4012 return DO; 4013 } 4014 catch (Throwable t) { 4015 throw new PersistenceException(t); 4016 } 4017 } 4018 4019 protected ActivityDataWOBDO getPersistedObject2 (ActivityVariablePersistenceInterface var,SharkTransaction ti) throws PersistenceException { 4020 ActivityDataWOBDO DO= 4021 getPersistedActivityVariableObject2(var.getActivityId(),var.getDefinitionId(),ti); 4022 4023 try { 4024 if (DO==null) { 4025 DO=ActivityDataWOBDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction()); 4026 } 4027 return DO; 4028 } 4029 catch (Throwable t) { 4030 throw new PersistenceException(t); 4031 } 4032 } 4033 4034 protected ActivityDataWOBDO getPersistedActivityVariableObject2 (String actId, 4035 String defId,SharkTransaction ti) throws PersistenceException { 4036 ActivityDataWOBDO DO=null; 4037 4038 try { 4039 ActivityDO aDO=getPersistedActivityObject(actId,ti); 4040 if (null != aDO) { 4041 BigDecimal aOId = aDO.get_OId().toBigDecimal(); 4042 for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.ActivityDataWOBDO"); 4043 it.hasNext();) { 4044 DO = (ActivityDataWOBDO)it.next(); 4045 if (defId.equals(DO.getVariableDefinitionId()) 4046 && aOId.equals(DO.oid_getActivity())) 4047 return DO; 4048 } 4049 for (Iterator it = ((SharkDODSTransaction)ti).iterator4typeDeleted("class org.enhydra.shark.instancepersistence.data.ActivityDataWOBDO"); 4050 it.hasNext();) { 4051 DO = (ActivityDataWOBDO)it.next(); 4052 if (defId.equals(DO.getVariableDefinitionId()) 4053 && aOId.equals(DO.oid_getActivity())) 4054 return null; 4055 } 4056 } 4057 ActivityDataWOBQuery query = new ActivityDataWOBQuery(((SharkDODSTransaction)ti).getDODSTransaction()); 4058 4060 query.setQueryActivity(aDO); 4061 query.setQueryVariableDefinitionId(defId); 4062 query.requireUniqueInstance(); 4064 DO = query.getNextDO(); 4065 ((SharkDODSTransaction)ti)._read(DO); 4066 4067 return DO; 4068 } 4069 catch (Throwable t) { 4070 throw new PersistenceException(t); 4071 } 4072 } 4073 4074 protected ActivityDataBLOBDO getPersistedObject (ActivityDataWOBDO adDO,SharkTransaction ti) throws PersistenceException { 4075 ActivityDataBLOBDO DO= 4076 getPersistedActivityVariableBLOBObject(adDO,ti); 4077 4078 try { 4079 if (DO==null) { 4080 DO=ActivityDataBLOBDO.createVirgin(((SharkDODSTransaction)ti).getDODSTransaction()); 4081 } 4082 return DO; 4083 } 4084 catch (Throwable t) { 4085 throw new PersistenceException(t); 4086 } 4087 } 4088 4089 protected ActivityDataBLOBDO getPersistedActivityVariableBLOBObject (ActivityDataWOBDO adDO,SharkTransaction ti) throws PersistenceException { 4090 ActivityDataBLOBDO DO=null; 4091 4092 try { 4093 if (null != adDO) { 4094 BigDecimal pdOId = adDO.get_OId().toBigDecimal(); 4095 for (Iterator it = ((SharkDODSTransaction)ti).iterator4type("class org.enhydra.shark.instancepersistence.data.ActivityDataBLOBDO"); 4096 it.hasNext();) { 4097 DO = (ActivityDataBLOBDO)it.next(); 4098 if (pdOId.equals(DO.oid_getActivityDataWOB())) 4099 return DO; 4100 } 4101 for (Iterator it = ((SharkDODSTransaction)ti).iterator4typeDeleted("class org.enhydra.shark.instancepersistence.data.ActivityDataBLOBDO"); 4102 it.hasNext();) { 4103 DO = (ActivityDataBLOBDO)it.next(); 4104 if (pdOId.equals(DO.oid_getActivityDataWOB())) 4105 return null; 4106 } 4107 } 4108 ActivityDataBLOBQuery query=new ActivityDataBLOBQuery(((SharkDODSTransaction)ti).getDODSTransaction()); 4109 query.setQueryActivityDataWOB(adDO); 4111 query.requireUniqueInstance(); 4113 DO = query.getNextDO(); 4114 ((SharkDODSTransaction)ti)._read(DO); 4115 4116 return DO; 4117 } 4118 catch (Throwable t) { 4119 throw new PersistenceException(t); 4120 } 4121 } 4122 4123 protected ActivityStateDO getPersistedActivityStateObject ( 4124 String value,boolean searchByKeyValue,DBTransaction ti) throws PersistenceException { 4125 ActivityStateDO DO=null; 4126 4127 ActivityStateQuery query = null; 4128 try { 4129 query=new ActivityStateQuery(ti); 4130 if (searchByKeyValue) { 4132 query.setQueryKeyValue(value); 4133 } 4134 else { 4135 query.setQueryName(value); 4136 } 4137 query.requireUniqueInstance(); 4138 DO = query.getNextDO(); 4139 4140 if (DO==null) { 4141 DO=ActivityStateDO.createVirgin(ti); 4142 } 4143 return DO; 4144 } 4145 catch (Throwable t) { 4146 t.printStackTrace(); 4147 throw new PersistenceException(t); 4148 } 4149 } 4150 4151 protected ProcessStateDO getPersistedProcessStateObject ( 4152 String value,boolean searchByKeyValue,DBTransaction ti) throws PersistenceException { 4153 ProcessStateDO DO=null; 4154 4155 ProcessStateQuery query = null; 4156 try { 4157 query=new ProcessStateQuery(ti); 4158 if (searchByKeyValue) { 4160 query.setQueryKeyValue(value); 4161 } 4162 else { 4163 query.setQueryName(value); 4164 } 4165 query.requireUniqueInstance(); 4166 DO = query.getNextDO(); 4167 4168 if (DO==null) { 4169 DO=ProcessStateDO.createVirgin(ti); 4170 } 4171 return DO; 4172 } 4173 catch (Throwable t) { 4174 t.printStackTrace(); 4175 throw new PersistenceException(t); 4176 } 4177 } 4178 4179 public ActivityPersistenceInterface createActivity () { 4181 return new DODSActivity(); 4182 } 4183 4184 public ProcessPersistenceInterface createProcess () { 4185 return new DODSProcess(); 4186 } 4187 4188 public ProcessMgrPersistenceInterface createProcessMgr () { 4189 return new DODSProcessMgr(); 4190 } 4191 4192 public AssignmentPersistenceInterface createAssignment () { 4193 return new DODSAssignment(); 4194 } 4195 4196 public ResourcePersistenceInterface createResource () { 4197 return new DODSResource(); 4198 } 4199 4200 public ProcessVariablePersistenceInterface createProcessVariable () { 4201 return new DODSProcessVariable(); 4202 } 4203 4204 public ActivityVariablePersistenceInterface createActivityVariable () { 4205 return new DODSActivityVariable(); 4206 } 4207 4208 public AndJoinEntryInterface createAndJoinEntry () { 4209 return new DODSAndJoinEntry(); 4210 } 4211 4212 public DeadlinePersistenceInterface createDeadline() { 4213 return new DODSDeadline(); 4214 } 4215 4216 public BigDecimal getNextDecId(String idName) throws PersistenceException { 4217 try { 4218 return DODSUtilities.getNext(idName); 4219 } catch (Exception e) { 4220 throw new PersistenceException("Couldn't allocate id",e); 4221 } 4222 } 4223 4224 public String getNextId(String idName) throws PersistenceException { 4225 return getNextDecId(idName).toString(); 4226 } 4227 4228 public List getProcessMgrsWhere(SharkTransaction ti, String sqlWhere) throws PersistenceException { 4229 List ret = new ArrayList(); 4230 4231 ProcessDefinitionDO[] mgrs = getAllPersistedProcessMgrs(ti, 4232 null, 4233 null, 4234 null, 4235 sqlWhere); 4236 if (mgrs != null) { 4237 for (int i = 0; i < mgrs.length; i++) { 4238 ProcessMgrPersistenceInterface mgr = restore(mgrs[i]); 4239 ret.add(mgr); 4240 } 4241 } 4242 return ret; 4243 } 4244 4245 public List getResourcesWhere(SharkTransaction t, String sqlWhere) throws PersistenceException { 4246 List ret=new ArrayList(); 4247 if (null != sqlWhere && sqlWhere.trim().length() < 1) 4248 sqlWhere = null; 4249 ResourceDO[] ress=getAllPersistedResources(t, sqlWhere); 4250 if (ress!=null) { 4251 for (int i=0;i<ress.length; i++) { 4252 ResourcePersistenceInterface res=restore(ress[i]); 4253 ret.add(res); 4254 } 4255 } 4256 return ret; 4257 } 4258 4259 public List getAssignmentsWhere(SharkTransaction t, String sqlWhere) throws PersistenceException { 4260 List ret=new ArrayList(); 4261 4262 4265 AssignmentDO[] ass=getAllPersistedAssignments(t, sqlWhere); 4266 if (ass!=null) { 4268 for (int i=0;i<ass.length; i++) { 4269 try { 4270 if (ass[i].getIsValid()) { 4271 AssignmentPersistenceInterface as=restore(ass[i]); 4272 ret.add(as); 4273 } 4274 } catch (Throwable ex) { 4275 throw new PersistenceException(ex); 4276 } 4277 } 4278 } 4279 return ret; 4282 } 4283 4284 public List getProcessesWhere(SharkTransaction ti, String sqlWhere) throws PersistenceException { 4285 List ret=new ArrayList(); 4286 4289 ProcessDO[] procs=getPersistedProcesses(ti,0,null,null,null,null,sqlWhere); 4290 4291 try { 4292 if (procs!=null) { 4294 for (int i=0;i<procs.length; i++) { 4295 ProcessPersistenceInterface proc=restore(procs[i]); 4296 ret.add(proc); 4297 } 4298 } 4299 return ret; 4302 } catch (Exception e) { 4303 throw new PersistenceException(e); 4304 } 4305 } 4306 4307 public List getActivitiesWhere(SharkTransaction ti, String sqlWhere) throws PersistenceException { 4308 List ret=new ArrayList(); 4309 4312 ActivityDO[] acts=getPersistedActivities(ti,0,null,sqlWhere); 4313 if (acts!=null) { 4315 for (int i=0;i<acts.length; i++) { 4316 ActivityPersistenceInterface act=restore(acts[i]); 4317 ret.add(act); 4318 } 4319 } 4320 return ret; 4323 } 4324 4325 4326 5115} 5116 | Popular Tags |