Produced by Araxis Merge on 7/6/2017 8:32:13 AM Central Daylight 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 | HC 837 Compliance 05122017.zip\HC 837 Compliance 05122017\EDI_CodeConversion\EDI_CodeConversion\src\test\gov\va\med\hac\edi\utils\jpa | ScriptRunner.java | Thu May 12 19:17:56 2016 UTC |
2 | HC 837 Compliance 05122017.zip\HC 837 Compliance 05122017\EDI_CodeConversion\EDI_CodeConversion\src\test\gov\va\med\hac\edi\utils\jpa | ScriptRunner.java | Wed Jul 5 13:05:59 2017 UTC |
Description | Between Files 1 and 2 |
|
---|---|---|
Text Blocks | Lines | |
Unchanged | 2 | 514 |
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.med.h ac.edi.uti ls.jpa; | |
2 | ||
3 | import jav a.io.Buffe redReader; | |
4 | import jav a.io.Print Writer; | |
5 | import jav a.io.Reade r; | |
6 | import jav a.sql.*; | |
7 | ||
8 | /** | |
9 | * Adapted from a co py of ibat is.apache. org | |
10 | * @author DNS PENNET | |
11 | * | |
12 | */ | |
13 | public cla ss ScriptR unner { | |
14 | ||
15 | private static fin al String DEFAULT_DE LIMITER = ";"; | |
16 | ||
17 | private Connection connectio n; | |
18 | ||
19 | private boolean st opOnError; | |
20 | private boolean au toCommit; | |
21 | private boolean se ndFullScri pt; | |
22 | ||
23 | private PrintWrite r logWrite r = new Pr intWriter( System.out ); | |
24 | private PrintWrite r errorLog Writer = n ew PrintWr iter(Syste m.err); | |
25 | ||
26 | private String del imiter = D EFAULT_DEL IMITER; | |
27 | private boolean fu llLineDeli miter = fa lse; | |
28 | ||
29 | public S criptRunne r(Connecti on connect ion) { | |
30 | this.c onnection = connecti on; | |
31 | } | |
32 | ||
33 | public v oid setSto pOnError(b oolean sto pOnError) { | |
34 | this.s topOnError = stopOnE rror; | |
35 | } | |
36 | ||
37 | public v oid setAut oCommit(bo olean auto Commit) { | |
38 | this.a utoCommit = autoComm it; | |
39 | } | |
40 | ||
41 | public v oid setSen dFullScrip t(boolean sendFullSc ript) { | |
42 | this.s endFullScr ipt = send FullScript ; | |
43 | } | |
44 | ||
45 | public v oid setLog Writer(Pri ntWriter l ogWriter) { | |
46 | this.l ogWriter = logWriter ; | |
47 | } | |
48 | ||
49 | public v oid setErr orLogWrite r(PrintWri ter errorL ogWriter) { | |
50 | this.e rrorLogWri ter = erro rLogWriter ; | |
51 | } | |
52 | ||
53 | public v oid setDel imiter(Str ing delimi ter) { | |
54 | this.d elimiter = delimiter ; | |
55 | } | |
56 | ||
57 | public v oid setFul lLineDelim iter(boole an fullLin eDelimiter ) { | |
58 | this.f ullLineDel imiter = f ullLineDel imiter; | |
59 | } | |
60 | ||
61 | public v oid runScr ipt(Reader reader) { | |
62 | setAut oCommit(); | |
63 | ||
64 | try { | |
65 | if ( sendFullSc ript) { | |
66 | ex ecuteFullS cript(read er); | |
67 | } el se { | |
68 | ex ecuteLineB yLine(read er); | |
69 | } | |
70 | } fina lly { | |
71 | roll backConnec tion(); | |
72 | flus h(); | |
73 | } | |
74 | } | |
75 | ||
76 | private void execu teFullScri pt(Reader reader) { | |
77 | final String lin eseparator = System. getPropert y("line.se parator"); | |
78 | String Buffer scr ipt = new StringBuff er(); | |
79 | try { | |
80 | Buff eredReader lineReade r = new Bu fferedRead er(reader) ; | |
81 | Stri ng line; | |
82 | whil e ((line = lineReade r.readLine ()) != nul l) { | |
83 | sc ript.appen d(line); | |
84 | sc ript.appen d(linesepa rator); | |
85 | } | |
86 | Syst em.out.pri ntln(scrip t); | |
87 | exec uteStateme nt(script. toString() ); | |
88 | comm itConnecti on(); | |
89 | } catc h (Excepti on e) { | |
90 | Stri ng message = "Error executing: " + scrip t + ". Ca use: " + e ; | |
91 | prin tlnError(m essage); | |
92 | thro w new Runt imeExcepti on(message , e); | |
93 | } | |
94 | } | |
95 | ||
96 | private void execu teLineByLi ne(Reader reader) { | |
97 | String Buffer com mand = new StringBuf fer(); | |
98 | try { | |
99 | Buff eredReader lineReade r = new Bu fferedRead er(reader) ; | |
100 | Stri ng line; | |
101 | whil e ((line = lineReade r.readLine ()) != nul l) { | |
102 | co mmand = ha ndleLine(c ommand, li ne); | |
103 | } | |
104 | comm itConnecti on(); | |
105 | chec kForMissin gLineTermi nator(comm and); | |
106 | } catc h (Excepti on e) { | |
107 | Stri ng message = "Error executing: " + comma nd + ". C ause: " + e; | |
108 | prin tlnError(m essage); | |
109 | thro w new Runt imeExcepti on(message , e); | |
110 | } | |
111 | } | |
112 | ||
113 | public v oid closeC onnection( ) { | |
114 | try { | |
115 | conn ection.clo se(); | |
116 | } catc h (Excepti on e) { | |
117 | // i gnore | |
118 | } | |
119 | } | |
120 | ||
121 | private void setAu toCommit() { | |
122 | try { | |
123 | if ( autoCommit != connec tion.getAu toCommit() ) { | |
124 | co nnection.s etAutoComm it(autoCom mit); | |
125 | } | |
126 | } catc h (Throwab le t) { | |
127 | thro w new Runt imeExcepti on("Could not set Au toCommit t o " + auto Commit + " . Cause: " + t, t); | |
128 | } | |
129 | } | |
130 | ||
131 | private void commi tConnectio n() { | |
132 | try { | |
133 | if ( !connectio n.getAutoC ommit()) { | |
134 | co nnection.c ommit(); | |
135 | } | |
136 | } catc h (Throwab le t) { | |
137 | thro w new Runt imeExcepti on("Could not commit transacti on. Cause: " + t, t) ; | |
138 | } | |
139 | } | |
140 | ||
141 | private void rollb ackConnect ion() { | |
142 | try { | |
143 | if ( !connectio n.getAutoC ommit()) { | |
144 | co nnection.r ollback(); | |
145 | } | |
146 | } catc h (Throwab le t) { | |
147 | // i gnore | |
148 | } | |
149 | } | |
150 | ||
151 | private void check ForMissing LineTermin ator(Strin gBuffer co mmand) { | |
152 | if (co mmand != n ull && com mand.toStr ing().trim ().length( ) > 0) { | |
153 | thro w new Runt imeExcepti on("Line m issing end -of-line t erminator (" + delim iter + ") => " + com mand); | |
154 | } | |
155 | } | |
156 | ||
157 | private StringBuff er handleL ine(String Buffer com mand, Stri ng line) t hrows SQLE xception { | |
158 | String trimmedLi ne = line. trim(); | |
159 | if (li neIsCommen t(trimmedL ine)) { | |
160 | prin tln(trimme dLine); | |
161 | } else if (comma ndReadyToE xecute(tri mmedLine)) { | |
162 | comm and.append (line.subs tring(0, l ine.lastIn dexOf(deli miter))); | |
163 | comm and.append (" "); | |
164 | prin tln(comman d); | |
165 | exec uteStateme nt(command .toString( )); | |
166 | comm and.setLen gth(0); | |
167 | } else if (trimm edLine.len gth() > 0) { | |
168 | comm and.append (line); | |
169 | comm and.append (" "); | |
170 | } | |
171 | return command; | |
172 | } | |
173 | ||
174 | private boolean li neIsCommen t(String t rimmedLine ) { | |
175 | return trimmedLi ne.startsW ith("//") || trimmed Line.start sWith("--" ); | |
176 | } | |
177 | ||
178 | private boolean co mmandReady ToExecute( String tri mmedLine) { | |
179 | return !fullLine Delimiter && trimmed Line.endsW ith(delimi ter) | |
180 | || fullLineD elimiter & & trimmedL ine.equals (delimiter ); | |
181 | } | |
182 | ||
183 | private void execu teStatemen t(String c ommand) th rows SQLEx ception { | |
184 | boolea n hasResul ts = false ; | |
185 | Statem ent statem ent = conn ection.cre ateStateme nt(); | |
186 | if (st opOnError) { | |
187 | hasR esults = s tatement.e xecute(com mand); | |
188 | } else { | |
189 | try { | |
190 | ha sResults = statement .execute(c ommand); | |
191 | } ca tch (SQLEx ception e) { | |
192 | St ring messa ge = "Erro r executin g: " + com mand + ". Cause: " + e; | |
193 | pr intlnError (message); | |
194 | } | |
195 | } | |
196 | printR esults(sta tement, ha sResults); | |
197 | try { | |
198 | stat ement.clos e(); | |
199 | } catc h (Excepti on e) { | |
200 | // I gnore to w orkaround a bug in s ome connec tion pools | |
201 | } | |
202 | commit Connection (); | |
203 | } | |
204 | ||
205 | private void print Results(St atement st atement, b oolean has Results) { | |
206 | try { | |
207 | if ( hasResults ) { | |
208 | Re sultSet rs = stateme nt.getResu ltSet(); | |
209 | if (rs != nu ll) { | |
210 | ResultSetM etaData md = rs.getM etaData(); | |
211 | int cols = md.getCol umnCount() ; | |
212 | for (int i = 0; i < cols; i++) { | |
213 | String n ame = md.g etColumnLa bel(i + 1) ; | |
214 | print(na me + "\t") ; | |
215 | } | |
216 | println("" ); | |
217 | while (rs. next()) { | |
218 | for (int i = 0; i < cols; i+ +) { | |
219 | String value = r s.getStrin g(i + 1); | |
220 | print( value + "\ t"); | |
221 | } | |
222 | println( ""); | |
223 | } | |
224 | } | |
225 | } | |
226 | } catc h (SQLExce ption e) { | |
227 | prin tlnError(" Error prin ting resul ts: " + e. getMessage ()); | |
228 | } | |
229 | } | |
230 | ||
231 | private void print (Object o) { | |
232 | if (lo gWriter != null) { | |
233 | logW riter.prin t(o); | |
234 | } | |
235 | } | |
236 | ||
237 | private void print ln(Object o) { | |
238 | if (lo gWriter != null) { | |
239 | logW riter.prin tln(o); | |
240 | } | |
241 | } | |
242 | ||
243 | private void print lnError(Ob ject o) { | |
244 | if (er rorLogWrit er != null ) { | |
245 | erro rLogWriter .println(o ); | |
246 | } | |
247 | } | |
248 | ||
249 | private void flush () { | |
250 | if (lo gWriter != null) { | |
251 | logW riter.flus h(); | |
252 | } | |
253 | if (er rorLogWrit er != null ) { | |
254 | erro rLogWriter .flush(); | |
255 | } | |
256 | } | |
257 | ||
258 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.