Produced by Araxis Merge on 11/14/2017 6:57:19 AM Central Standard Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.
| # | Location | File | Last Modified |
|---|---|---|---|
| 1 | cbs.zip\cbs\cbs\src\main\java\gov\va\cpss\job\cbs | CbsDelegateMultiItemWriter.java | Thu Nov 9 14:19:54 2017 UTC |
| 2 | cbs.zip\cbs\cbs\src\main\java\gov\va\cpss\job\cbs | CbsDelegateMultiItemWriter.java | Tue Nov 14 12:26:13 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 2 | 722 |
| Changed | 1 | 2 |
| Inserted | 0 | 0 |
| Removed | 0 | 0 |
| Whitespace | |
|---|---|
| Character case | Differences in character case are significant |
| Line endings | Differences in line endings (CR and LF characters) are ignored |
| CR/LF characters | Not shown in the comparison detail |
No regular expressions were active.
| 1 | package go v.va.cpss. job.cbs; | |
| 2 | ||
| 3 | import sta tic gov.va .cpss.job. CbssJobPro cessingCon stants.JOB _FAILURE_K EY; | |
| 4 | import sta tic gov.va .cpss.job. CbssJobPro cessingCon stants.JOB _FAILURE_M ESSAGE_KEY ; | |
| 5 | import sta tic gov.va .cpss.job. CbssJobPro cessingCon stants.WRI TE_FAILURE _STATUS; | |
| 6 | import sta tic gov.va .cpss.job. cbs.CbsPro cessingCon stants.CBS _TOTAL_INI TIAL_STATE MENT_COUNT _KEY; | |
| 7 | import sta tic gov.va .cpss.job. cbs.CbsPro cessingCon stants.CBS _TOTAL_REP LACED_STAT EMENT_COUN T_KEY; | |
| 8 | ||
| 9 | import sta tic java.u til.stream .Collector s.toList; | |
| 10 | ||
| 11 | import jav a.util.Arr ayList; | |
| 12 | import jav a.util.Lis t; | |
| 13 | ||
| 14 | import org .apache.lo g4j.Logger ; | |
| 15 | import org .springfra mework.bat ch.core.Ex itStatus; | |
| 16 | import org .springfra mework.bat ch.core.It emWriteLis tener; | |
| 17 | import org .springfra mework.bat ch.core.Jo bExecution ; | |
| 18 | import org .springfra mework.bat ch.core.St epExecutio n; | |
| 19 | import org .springfra mework.bat ch.core.St epExecutio nListener; | |
| 20 | import org .springfra mework.bat ch.item.It emWriter; | |
| 21 | ||
| 22 | import gov .va.cpss.m odel.cbs.C BSSitePati ent; | |
| 23 | import gov .va.cpss.m odel.cbs.C BSSiteStmt ; | |
| 24 | import gov .va.cpss.m odel.cbs.C BSSiteTran s; | |
| 25 | import gov .va.cpss.m odel.cbs.C BSStmt; | |
| 26 | import gov .va.cpss.s ervice.Cbs Service; | |
| 27 | ||
| 28 | /** | |
| 29 | * Impleme ntation of ItemWrite r used to handle wri ting of co nsolidated | |
| 30 | * stateme nts when p rocessing. | |
| 31 | * | |
| 32 | * @author DN S BROWNL | |
| 33 | */ | |
| 34 | public cla ss CbsDele gateMultiI temWriter | |
| 35 | impl ements Ite mWriter<CB SStmt>, It emWriteLis tener<CBSS tmt>, Step ExecutionL istener { | |
| 36 | ||
| 37 | pr ivate fina l Logger w riterLogge r = Logger .getLogger (CbsDelega teMultiIte mWriter.cl ass.getCan onicalName ()); | |
| 38 | ||
| 39 | /* | |
| 40 | * Flag to i ndicate th at the job has been forcefully stopped a nd should no | |
| 41 | * longer at tempt writ es. | |
| 42 | * / | |
| 43 | pr ivate bool ean forceS top = fals e; | |
| 44 | ||
| 45 | /* | |
| 46 | * Count of statements written s uccessfull y. | |
| 47 | * / | |
| 48 | pr ivate long initialSt atementCou nt = 0; | |
| 49 | ||
| 50 | /* | |
| 51 | * Count of replaced s tatements updated su ccessfully . | |
| 52 | * / | |
| 53 | pr ivate long replacedS tatementCo unt = 0; | |
| 54 | ||
| 55 | pr ivate JobE xecution j obExecutio n; | |
| 56 | ||
| 57 | pr ivate CbsS ervice cbs Service; | |
| 58 | ||
| 59 | /* | |
| 60 | * Delegate writer use d to take advantage of batch u pdating re placed | |
| 61 | * statement s. | |
| 62 | * / | |
| 63 | pr ivate Item Writer<Lon g> cbsStmt DatabaseIt emUpdater; | |
| 64 | ||
| 65 | /* | |
| 66 | * Delegate writer use d to take advantage of batch w riting sit e transact ion | |
| 67 | * records. | |
| 68 | * / | |
| 69 | pr ivate Item Writer<CBS SiteTrans> cbsSiteTr ansDatabas eItemWrite r; | |
| 70 | ||
| 71 | pu blic CbsSe rvice getC bsService( ) { | |
| 72 | retu rn cbsServ ice; | |
| 73 | } | |
| 74 | ||
| 75 | pu blic void setCbsServ ice(CbsSer vice cbsSe rvice) { | |
| 76 | this .cbsServic e = cbsSer vice; | |
| 77 | } | |
| 78 | ||
| 79 | pu blic ItemW riter<Long > getCbsSt mtDatabase ItemUpdate r() { | |
| 80 | retu rn cbsStmt DatabaseIt emUpdater; | |
| 81 | } | |
| 82 | ||
| 83 | pu blic void setCbsStmt DatabaseIt emUpdater( ItemWriter <Long> cbs StmtDataba seItemUpda ter) { | |
| 84 | this .cbsStmtDa tabaseItem Updater = cbsStmtDat abaseItemU pdater; | |
| 85 | } | |
| 86 | ||
| 87 | pu blic ItemW riter<CBSS iteTrans> getCbsSite TransDatab aseItemWri ter() { | |
| 88 | retu rn cbsSite TransDatab aseItemWri ter; | |
| 89 | } | |
| 90 | ||
| 91 | pu blic void setCbsSite TransDatab aseItemWri ter(ItemWr iter<CBSSi teTrans> c bsSiteTran sDatabaseI temWriter) { | |
| 92 | this .cbsSiteTr ansDatabas eItemWrite r = cbsSit eTransData baseItemWr iter; | |
| 93 | } | |
| 94 | ||
| 95 | @S uppressWar nings({ "u nused", "u nchecked" }) | |
| 96 | @O verride | |
| 97 | pu blic void write(List <? extends CBSStmt> items) thr ows Except ion { | |
| 98 | ||
| 99 | writ erLogger.d ebug("Begi n Write"); | |
| 100 | ||
| 101 | // D o not atte mpt to wri te if forc ed stop. | |
| 102 | if ( forceStop) { | |
| 103 | return ; | |
| 104 | } | |
| 105 | ||
| 106 | try { | |
| 107 | // Tra ck list of replaced statements . | |
| 108 | List<L ong> repla cedStateme ntL = new ArrayList< >(); | |
| 109 | ||
| 110 | if (tr ue) { | |
| 111 | // NEW W AY - using batch ins erts but w e don't ha ve | |
| 112 | // acces s to the n ew primary key id fi elds | |
| 113 | cbsServi ce.batchSa veStatemen ts((List<C BSStmt>) i tems); | |
| 114 | ||
| 115 | initialS tatementCo unt += ite ms.size(); | |
| 116 | ||
| 117 | replaced StatementL = items.s tream().ma p(cbsStmt -> cbsStmt .getReplac edStmtId() ) | |
| 118 | .f ilter(repl acedStmtId -> replac edStmtId ! = 0).colle ct(toList( )); | |
| 119 | } else { | |
| 120 | // OLD W AY | |
| 121 | ||
| 122 | // Loop through al l of the s tatements to write. | |
| 123 | for (Obj ect item : items) { | |
| 124 | ||
| 125 | CBSStmt st atement = (CBSStmt) item; | |
| 126 | ||
| 127 | // Batch w on't retur n generate d keys so use DAO. | |
| 128 | writerLogg er.debug(" Saving CBS Stmt: " + statement. toString() ); | |
| 129 | cbsService .saveState ment(state ment); | |
| 130 | ||
| 131 | // Increme nt the wri te count f or tabulat ing expect ed totals | |
| 132 | // during final comp letion tas k. | |
| 133 | ++initialS tatementCo unt; | |
| 134 | ||
| 135 | // Loop th rough all of the Sit eStmt. | |
| 136 | for (CBSSi teStmt sit eStatement : stateme nt.getSite StmtL()) { | |
| 137 | ||
| 138 | // Save the database a uto-genera ted statem ent ID in the | |
| 139 | // site | |
| 140 | // statement . | |
| 141 | si teStatemen t.setStmtI d(statemen t.getId()) ; | |
| 142 | ||
| 143 | // Batch won 't return generated keys so us e service. | |
| 144 | wr iterLogger .debug("Sa ving CBSSi teStmt"); | |
| 145 | cb sService.s aveSiteSta tement(sit eStatement ); | |
| 146 | ||
| 147 | // Update th e site pat ient with the associ ated site | |
| 148 | // statement ID. | |
| 149 | wr iterLogger .debug("Sa ving CBSSi tePatient" ); | |
| 150 | CB SSitePatie nt sitePat ient = sit eStatement .getSitePa tient(); | |
| 151 | si tePatient. setSiteStm tId(siteSt atement.ge tId()); | |
| 152 | ||
| 153 | // Since one to one ra tio to sit e statemen t just use the | |
| 154 | // service t o save. | |
| 155 | cb sService.s avePatient (sitePatie nt); | |
| 156 | ||
| 157 | // Update th e list of site trans with the associated | |
| 158 | // site | |
| 159 | // statement ID. | |
| 160 | Li st<CBSSite Trans> sit eTransL = siteStatem ent.getSit eTransL(); | |
| 161 | si teTransL.s tream().fo rEach(u -> u.setSite StmtId(sit eStatement .getId())) ; | |
| 162 | ||
| 163 | // We don't need gener ated keys so we can use the ba tch | |
| 164 | // for | |
| 165 | // this inse rt. | |
| 166 | wr iterLogger .debug("Sa ving list of CBSSite Trans"); | |
| 167 | cb sSiteTrans DatabaseIt emWriter.w rite(siteT ransL); | |
| 168 | ||
| 169 | } | |
| 170 | ||
| 171 | // Append to replace d statemen t list if necessary. | |
| 172 | if (statem ent.getRep lacedStmtI d() != 0) { | |
| 173 | re placedStat ementL.add (statement .getReplac edStmtId() ); | |
| 174 | } | |
| 175 | ||
| 176 | } | |
| 177 | ||
| 178 | } | |
| 179 | ||
| 180 | // We can use ba tch to upd ate replac ed stateme nts. | |
| 181 | if (!r eplacedSta tementL.is Empty()) { | |
| 182 | writerLo gger.debug ("Updating Replaced Statements "); | |
| 183 | cbsStmtD atabaseIte mUpdater.w rite(repla cedStateme ntL); | |
| 184 | // Save the count for tabula ting expec ted totals during fi nal | |
| 185 | // compl etion task . | |
| 186 | replaced StatementC ount = rep lacedState mentL.size (); | |
| 187 | } | |
| 188 | ||
| 189 | } ca tch (Excep tion e) { | |
| 190 | ||
| 191 | String Builder er ror = new StringBuil der(); | |
| 192 | error. append("Er ror during write bec ause of ") ; | |
| 193 | error. append(e.g etClass(). getSimpleN ame()); | |
| 194 | error. append("\n Cause: "); | |
| 195 | error. append(e.g etCause(). getMessage ().trim()) ; | |
| 196 | ||
| 197 | // Unr ecoverable error so stop the j ob. | |
| 198 | stopJo b(WRITE_FA ILURE_STAT US, error. toString() ); | |
| 199 | } | |
| 200 | ||
| 201 | writ erLogger.d ebug("End Write"); | |
| 202 | } | |
| 203 | ||
| 204 | @O verride | |
| 205 | pu blic void beforeWrit e(List<? e xtends CBS Stmt> item s) { | |
| 206 | // R eset the w rite count . | |
| 207 | init ialStateme ntCount = 0; | |
| 208 | repl acedStatem entCount = 0; | |
| 209 | ||
| 210 | forc eStop = fa lse; | |
| 211 | if ( jobExecuti on.getExec utionConte xt().conta insKey(JOB _FAILURE_K EY)) { | |
| 212 | writer Logger.err or("System failure d etected.") ; | |
| 213 | forceS top = true ; | |
| 214 | } | |
| 215 | } | |
| 216 | ||
| 217 | @O verride | |
| 218 | pu blic void afterWrite (List<? ex tends CBSS tmt> items ) { | |
| 219 | ||
| 220 | // S aving runn ing total of the wri tten count s in the j ob executi on | |
| 221 | // c ontext for completio n task ref erence. | |
| 222 | if ( (items != null) && ! items.isEm pty()) { | |
| 223 | ||
| 224 | if (!u pdateIniti alStatemen tCount()) { | |
| 225 | // Set f ailure and message. | |
| 226 | stopJob( WRITE_FAIL URE_STATUS , "Unable to update running to tal initia l statemen t count"); | |
| 227 | } else if (!upda teReplaced StatementC ount()) { | |
| 228 | // Set f ailure and message. | |
| 229 | stopJob( WRITE_FAIL URE_STATUS , "Unable to update running to tal replac ed stateme nt count") ; | |
| 230 | } | |
| 231 | } | |
| 232 | } | |
| 233 | ||
| 234 | /* * | |
| 235 | * Update th e running total of i nitial sta tements wr itten in t he job | |
| 236 | * execution context. | |
| 237 | * | |
| 238 | * @return B oolean fla g indicati ng if succ essful or not. | |
| 239 | * / | |
| 240 | pr ivate bool ean update InitialSta tementCoun t() { | |
| 241 | ||
| 242 | bool ean succes sful = fal se; | |
| 243 | ||
| 244 | if ( jobExecuti on.getExec utionConte xt().conta insKey(CBS _TOTAL_INI TIAL_STATE MENT_COUNT _KEY)) { | |
| 245 | jobExe cution.get ExecutionC ontext().p utLong(CBS _TOTAL_INI TIAL_STATE MENT_COUNT _KEY, | |
| 246 | jobExecuti on.getExec utionConte xt().getLo ng(CBS_TOT AL_INITIAL _STATEMENT _COUNT_KEY ) | |
| 247 | + in itialState mentCount) ; | |
| 248 | succes sful = tru e; | |
| 249 | } | |
| 250 | ||
| 251 | retu rn success ful; | |
| 252 | } | |
| 253 | ||
| 254 | /* * | |
| 255 | * Update th e running total of r eplaced st atements u pdated in the job | |
| 256 | * execution context. | |
| 257 | * | |
| 258 | * @return B oolean fla g indicati ng if succ essful or not. | |
| 259 | * / | |
| 260 | pr ivate bool ean update ReplacedSt atementCou nt() { | |
| 261 | ||
| 262 | bool ean succes sful = fal se; | |
| 263 | ||
| 264 | if ( jobExecuti on.getExec utionConte xt().conta insKey(CBS _TOTAL_REP LACED_STAT EMENT_COUN T_KEY)) { | |
| 265 | jobExe cution.get ExecutionC ontext().p utLong(CBS _TOTAL_REP LACED_STAT EMENT_COUN T_KEY, | |
| 266 | jobExecuti on.getExec utionConte xt().getLo ng(CBS_TOT AL_REPLACE D_STATEMEN T_COUNT_KE Y) | |
| 267 | + re placedStat ementCount ); | |
| 268 | succes sful = tru e; | |
| 269 | } | |
| 270 | ||
| 271 | retu rn success ful; | |
| 272 | } | |
| 273 | ||
| 274 | @O verride | |
| 275 | pu blic void onWriteErr or(Excepti on e, List <? extends CBSStmt> items) { | |
| 276 | ||
| 277 | writ erLogger.e rror("Writ er encount ered syste m error an d forced s top"); | |
| 278 | ||
| 279 | Stri ngBuilder error = ne w StringBu ilder(); | |
| 280 | erro r.append(" Unable to write item because o f "); | |
| 281 | erro r.append(e .getClass( ).getSimpl eName()); | |
| 282 | erro r.append(" \nMessage: "); | |
| 283 | erro r.append(e .getMessag e()); | |
| 284 | if ( (e.getCaus e() != nul l) && (e.g etCause(). getMessage () != null )) { | |
| 285 | error. append("\n Cause: "); | |
| 286 | error. append(e.g etCause(). getMessage ().trim()) ; | |
| 287 | } | |
| 288 | ||
| 289 | // S et failure and messa ge. | |
| 290 | stop Job(WRITE_ FAILURE_ST ATUS, "Unr ecoverable writer er ror"); | |
| 291 | } | |
| 292 | ||
| 293 | @O verride | |
| 294 | pu blic void beforeStep (StepExecu tion stepE xecution) { | |
| 295 | writ erLogger.i nfo("Befor e Step Exe cution"); | |
| 296 | // S ave the jo b executio n at the b eginning o f the step . | |
| 297 | // T he executi on context will be u sed to set key value s as data is | |
| 298 | // p rocessed. | |
| 299 | jobE xecution = stepExecu tion.getJo bExecution (); | |
| 300 | } | |
| 301 | ||
| 302 | @O verride | |
| 303 | pu blic ExitS tatus afte rStep(Step Execution stepExecut ion) { | |
| 304 | writ erLogger.i nfo("After Step Exec ution"); | |
| 305 | // D o not need to do any thing afte r step. | |
| 306 | retu rn null; | |
| 307 | } | |
| 308 | ||
| 309 | /* * | |
| 310 | * Forcefull y stop the job proce ssing beca use a fail ure was de tected. | |
| 311 | * | |
| 312 | * @param st atus | |
| 313 | * The stat us for the failure. | |
| 314 | * @param me ssage | |
| 315 | * The mess age associ ated with the status failure. | |
| 316 | * / | |
| 317 | pr ivate void stopJob(f inal Strin g status, final Stri ng message ) { | |
| 318 | ||
| 319 | // S et the fla g to indic ate the jo b has been forcefull y stopped. | |
| 320 | forc eStop = tr ue; | |
| 321 | ||
| 322 | // L og message . | |
| 323 | writ erLogger.e rror("Writ er executi on encount ered unrec overable e rror and f orced stop "); | |
| 324 | ||
| 325 | // S et failure and messa ge. | |
| 326 | setF ailureStat us(status) ; | |
| 327 | ||
| 328 | // S et failure message. | |
| 329 | setF ailureMess age(messag e); | |
| 330 | } | |
| 331 | ||
| 332 | /* * | |
| 333 | * Set the f ailure in the job ex ecution co ntext. | |
| 334 | * | |
| 335 | * @param st atus | |
| 336 | * The fail ure status . | |
| 337 | * / | |
| 338 | pr ivate void setFailur eStatus(fi nal String status) { | |
| 339 | ||
| 340 | // L og job fai lure statu s. | |
| 341 | writ erLogger.e rror("Job failed wit h status: " + status ); | |
| 342 | ||
| 343 | // S et job fai lure. | |
| 344 | jobE xecution.g etExecutio nContext() .putString (JOB_FAILU RE_KEY, st atus); | |
| 345 | } | |
| 346 | ||
| 347 | /* * | |
| 348 | * Set the f ailure mes sage in th e job exec ution cont ext. | |
| 349 | * | |
| 350 | * @param me ssage | |
| 351 | * The mess age to ass ociate wit h the erro r status. | |
| 352 | * / | |
| 353 | pr ivate void setFailur eMessage(f inal Strin g message) { | |
| 354 | ||
| 355 | // L og job fai lure messa ge. | |
| 356 | writ erLogger.e rror("Job failure me ssage: " + message); | |
| 357 | ||
| 358 | // S et job fai lure messa ge. | |
| 359 | jobE xecution.g etExecutio nContext() .putString (JOB_FAILU RE_MESSAGE _KEY, mess age); | |
| 360 | } | |
| 361 | ||
| 362 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.