1 package org.codehaus.mojo.sql;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.BufferedOutputStream;
23 import java.io.BufferedReader;
24 import java.io.File;
25 import java.io.FileInputStream;
26 import java.io.FileOutputStream;
27 import java.io.FileReader;
28 import java.io.IOException;
29 import java.io.InputStream;
30 import java.io.InputStreamReader;
31 import java.io.OutputStream;
32 import java.io.PrintStream;
33 import java.io.Reader;
34 import java.io.StringReader;
35 import java.sql.Connection;
36 import java.sql.Driver;
37 import java.sql.ResultSet;
38 import java.sql.ResultSetMetaData;
39 import java.sql.SQLException;
40 import java.sql.SQLWarning;
41 import java.sql.Statement;
42 import java.util.ArrayList;
43 import java.util.Collections;
44 import java.util.Enumeration;
45 import java.util.List;
46 import java.util.Properties;
47 import java.util.StringTokenizer;
48 import java.util.Vector;
49
50 import org.apache.commons.io.IOUtils;
51 import org.apache.commons.lang.StringEscapeUtils;
52 import org.apache.maven.execution.MavenSession;
53 import org.apache.maven.plugin.AbstractMojo;
54 import org.apache.maven.plugin.MojoExecutionException;
55 import org.apache.maven.project.MavenProject;
56 import org.apache.maven.settings.Server;
57 import org.apache.maven.settings.Settings;
58 import org.apache.maven.shared.filtering.MavenFileFilter;
59 import org.apache.maven.shared.filtering.MavenFileFilterRequest;
60 import org.apache.maven.shared.filtering.MavenFilteringException;
61 import org.codehaus.plexus.util.FileUtils;
62 import org.codehaus.plexus.util.IOUtil;
63 import org.codehaus.plexus.util.StringUtils;
64 import org.springframework.core.io.DefaultResourceLoader;
65 import org.springframework.core.io.Resource;
66 import org.springframework.core.io.ResourceLoader;
67
68
69
70
71
72
73 public class SqlExecMojo extends AbstractMojo {
74
75
76
77
78
79 public static final String ON_ERROR_ABORT = "abort";
80
81
82
83
84
85
86 public static final String ON_ERROR_ABORT_AFTER = "abortAfter";
87
88
89
90
91
92 public static final String ON_ERROR_CONTINUE = "continue";
93
94
95
96
97
98 public static final String FILE_SORTING_ASC = "ascending";
99
100
101
102
103
104 public static final String FILE_SORTING_DSC = "descending";
105
106
107
108
109
110
111
112
113
114
115
116 private String username;
117
118
119
120
121
122
123
124
125
126 private String password;
127
128
129
130
131
132
133
134
135
136 private boolean enableAnonymousPassword;
137
138
139
140
141
142
143
144
145 private String driverProperties;
146
147
148
149
150
151
152
153 private Settings settings;
154
155
156
157
158
159
160
161
162 private String settingsKey;
163
164
165
166
167
168
169
170
171
172 private boolean skipOnConnectionError;
173
174
175
176
177
178
179
180
181 private boolean forceMojoExecution;
182
183
184
185
186
187
188
189
190 protected MavenProject project;
191
192
193
194
195
196
197 private MavenSession mavenSession;
198
199
200
201
202
203
204
205
206
207 private String sqlCommand = "";
208
209
210
211
212
213
214
215 private File[] srcFiles;
216
217
218
219
220
221
222
223 private String[] resourceLocations;
224
225
226
227
228
229
230
231 private Fileset fileset;
232
233
234
235
236
237
238
239 private boolean skip;
240
241
242
243
244
245
246
247
248
249 private String url;
250
251
252
253
254
255
256
257
258 private String driver;
259
260
261
262
263
264
265
266
267 private boolean autocommit;
268
269
270
271
272
273
274
275
276 private String onError = ON_ERROR_ABORT;
277
278
279
280
281
282
283
284
285
286 private String delimiter = ";";
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303 private String delimiterType = DelimiterType.NORMAL;
304
305
306
307
308
309
310
311
312
313 private String orderFile = null;
314
315
316
317
318
319
320
321
322
323
324
325
326 private boolean enableBlockMode = false;
327
328
329
330
331
332
333
334 private boolean keepFormat = false;
335
336
337
338
339
340
341
342
343 private boolean printResultSet = false;
344
345
346
347
348 private boolean showheaders = true;
349
350
351
352
353
354
355
356 private File outputFile;
357
358
359
360
361
362 private String outputDelimiter;
363
364
365
366
367
368
369
370
371 private String encoding = "";
372
373
374
375
376 private boolean append = false;
377
378
379
380
381
382
383
384
385 private boolean escapeProcessing = true;
386
387
388
389
390
391
392
393 private int successfulStatements = 0;
394
395
396
397
398 private int totalStatements = 0;
399
400
401
402
403 private Connection conn = null;
404
405
406
407
408 private Statement statement = null;
409
410
411
412
413 private Vector<Transaction> transactions = new Vector<Transaction>();
414
415
416
417
418
419 private MavenFileFilter fileFilter;
420
421
422
423
424
425
426
427
428 private boolean enableFiltering;
429
430
431
432
433
434
435
436
437
438
439
440
441 public Transaction createTransaction() {
442 Transaction t = new Transaction();
443 transactions.addElement(t);
444 return t;
445 }
446
447
448
449
450
451
452
453
454 public void addText(String sql) {
455 this.sqlCommand += sql;
456 }
457
458
459
460
461
462
463
464 public void setEncoding(String encoding) {
465 this.encoding = encoding;
466 }
467
468
469
470
471
472
473
474
475 public void setDelimiter(String delimiter) {
476 this.delimiter = delimiter;
477 }
478
479
480
481
482
483
484
485 public void setDelimiterType(String delimiterType) {
486 this.delimiterType = delimiterType;
487 }
488
489
490
491
492
493
494
495
496
497 public void setPrintResutlSet(boolean print) {
498 setPrintResultSet(print);
499 }
500
501
502
503
504
505
506
507
508 public void setPrintResultSet(boolean print) {
509 this.printResultSet = print;
510 }
511
512
513
514
515
516
517
518
519
520 public void setShowheaders(boolean showheaders) {
521 this.showheaders = showheaders;
522 }
523
524
525
526
527
528
529
530 public void setOutputFile(File output) {
531 this.outputFile = output;
532 }
533
534
535
536
537
538
539
540
541
542 public void setAppend(boolean append) {
543 this.append = append;
544 }
545
546
547
548
549
550
551
552 public void setKeepFormat(boolean keepformat) {
553 this.keepFormat = keepformat;
554 }
555
556
557
558
559
560
561
562 public void setEscapeProcessing(boolean enable) {
563 escapeProcessing = enable;
564 }
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579 protected boolean skipMojo() {
580 if (skip) {
581 getLog().info("Skip sql execution");
582 return true;
583 }
584
585 if (!forceMojoExecution && project != null && "pom".equals(project.getPackaging())) {
586 getLog().info("Skipping sql execution for project with packaging type 'pom'");
587 return true;
588 }
589
590 return false;
591 }
592
593
594
595
596
597
598 public void execute() throws MojoExecutionException {
599
600 if (skipMojo()) {
601 return;
602 }
603
604 successfulStatements = 0;
605
606 totalStatements = 0;
607
608 loadUserInfoFromSettings();
609
610 addCommandToTransactions();
611
612 addFilesToTransactions();
613
614 addFileSetToTransactions();
615
616 addResourcesToTransactions();
617
618 sortTransactions();
619
620 try {
621 conn = getConnection();
622 } catch (SQLException e) {
623 if (!this.skipOnConnectionError) {
624 throw new MojoExecutionException(e.getMessage(), e);
625 } else {
626
627 return;
628 }
629 }
630
631 try {
632 statement = conn.createStatement();
633 statement.setEscapeProcessing(escapeProcessing);
634
635 PrintStream out = System.out;
636 try {
637 if (outputFile != null) {
638 getLog().debug("Opening PrintStream to output file " + outputFile);
639 out = new PrintStream(new BufferedOutputStream(new FileOutputStream(outputFile.getAbsolutePath(),
640 append)));
641 }
642
643
644 for (Enumeration<Transaction> e = transactions.elements(); e.hasMoreElements();) {
645 Transaction t = e.nextElement();
646
647 t.runTransaction(out);
648
649 if (!autocommit) {
650 getLog().debug("Committing transaction");
651 conn.commit();
652 }
653 }
654 } finally {
655 if (out != null && out != System.out) {
656 out.close();
657 }
658 }
659 } catch (IOException e) {
660 throw new MojoExecutionException(e.getMessage(), e);
661 } catch (SQLException e) {
662 if (!autocommit && conn != null && ON_ERROR_ABORT.equalsIgnoreCase(getOnError())) {
663 try {
664 conn.rollback();
665 } catch (SQLException ex) {
666
667 }
668 }
669 throw new MojoExecutionException(e.getMessage(), e);
670 } finally {
671 try {
672 if (statement != null) {
673 statement.close();
674 }
675 if (conn != null) {
676 conn.close();
677 }
678 } catch (SQLException ex) {
679
680 }
681 }
682
683 getLog().info(
684 getSuccessfulStatements() + " of " + getTotalStatements() + " SQL statements executed successfully");
685
686 if (ON_ERROR_ABORT_AFTER.equalsIgnoreCase(getOnError()) && totalStatements != successfulStatements) {
687 throw new MojoExecutionException("Some SQL statements failed to execute");
688 }
689
690 }
691
692
693
694
695
696 private void addCommandToTransactions() {
697 createTransaction().addText(sqlCommand.trim());
698 }
699
700
701
702
703
704 private void addFileSetToTransactions() {
705 String[] includedFiles;
706 if (fileset != null) {
707 fileset.scan();
708 includedFiles = fileset.getIncludedFiles();
709 } else {
710 includedFiles = new String[0];
711 }
712
713 for (int j = 0; j < includedFiles.length; j++) {
714 createTransaction().setSrc(new File(fileset.getBasedir(), includedFiles[j]));
715 }
716 }
717
718 protected Resource[] getResources(String[] locations) throws MojoExecutionException {
719 if (locations == null || locations.length == 0) {
720 return new Resource[] {};
721 }
722 ResourceLoader loader = new DefaultResourceLoader();
723 List<Resource> resources = new ArrayList<Resource>();
724 for (int i = 0; i < locations.length; i++) {
725 String location = locations[i];
726
727 if (StringUtils.isEmpty(location)) {
728 continue;
729 }
730 Resource resource = loader.getResource(location);
731 if (!resource.exists()) {
732
733 throw new MojoExecutionException("Resource " + location + " was not found");
734 }
735 resources.add(resource);
736 }
737 return resources.toArray(new Resource[resources.size()]);
738 }
739
740 protected void copy(Resource resource, File file) throws IOException {
741 InputStream in = resource.getInputStream();
742 OutputStream out = new FileOutputStream(file);
743 IOUtils.copyLarge(in, out);
744 }
745
746
747
748
749
750
751 private void addResourcesToTransactions() throws MojoExecutionException {
752 String[] locations = getResourceLocations();
753 Resource[] resources = getResources(locations);
754
755 MavenFileFilterRequest request = new MavenFileFilterRequest();
756 request.setEncoding(encoding);
757 request.setMavenSession(mavenSession);
758 request.setMavenProject(project);
759 request.setFiltering(enableFiltering);
760 for (int i = 0; i < resources.length; i++) {
761 Resource resource = resources[i];
762 String filename = resource.getFilename();
763 String basename = FileUtils.basename(filename);
764 String extension = FileUtils.extension(filename);
765 File sourceFile = FileUtils.createTempFile(basename, extension, null);
766
767 try {
768 copy(resource, sourceFile);
769 } catch (IOException e) {
770 throw new MojoExecutionException("Error copying resource " + resource + "to a temp file", e);
771 }
772
773 File targetFile = FileUtils.createTempFile(basename, extension, null);
774 if (!getLog().isDebugEnabled()) {
775 targetFile.deleteOnExit();
776 sourceFile.deleteOnExit();
777 }
778
779 request.setFrom(sourceFile);
780 request.setTo(targetFile);
781
782 try {
783 fileFilter.copyFile(request);
784 } catch (MavenFilteringException e) {
785 throw new MojoExecutionException(e.getMessage());
786 }
787
788 createTransaction().setSrc(targetFile);
789 }
790 }
791
792
793
794
795
796
797 private void addFilesToTransactions() throws MojoExecutionException {
798 File[] files = getSrcFiles();
799
800 MavenFileFilterRequest request = new MavenFileFilterRequest();
801 request.setEncoding(encoding);
802 request.setMavenSession(mavenSession);
803 request.setMavenProject(project);
804 request.setFiltering(enableFiltering);
805 for (int i = 0; files != null && i < files.length; ++i) {
806 if (files[i] != null && !files[i].exists()) {
807 throw new MojoExecutionException(files[i].getPath() + " not found.");
808 }
809
810 File sourceFile = files[i];
811 String basename = FileUtils.basename(sourceFile.getName());
812 String extension = FileUtils.extension(sourceFile.getName());
813 File targetFile = FileUtils.createTempFile(basename, extension, null);
814 if (!getLog().isDebugEnabled()) {
815 targetFile.deleteOnExit();
816 }
817
818 request.setFrom(sourceFile);
819 request.setTo(targetFile);
820
821 try {
822 fileFilter.copyFile(request);
823 } catch (MavenFilteringException e) {
824 throw new MojoExecutionException(e.getMessage());
825 }
826
827 createTransaction().setSrc(targetFile);
828 }
829 }
830
831
832
833
834 private void sortTransactions() {
835 if (FILE_SORTING_ASC.equalsIgnoreCase(this.orderFile)) {
836 Collections.sort(transactions);
837 } else if (FILE_SORTING_DSC.equalsIgnoreCase(this.orderFile)) {
838 Collections.sort(transactions, Collections.reverseOrder());
839 }
840 }
841
842
843
844
845
846
847
848 private void loadUserInfoFromSettings() throws MojoExecutionException {
849 if (this.settingsKey == null) {
850 this.settingsKey = getUrl();
851 }
852
853 if ((getUsername() == null || getPassword() == null) && (settings != null)) {
854 Server server = this.settings.getServer(this.settingsKey);
855
856 if (server != null) {
857 if (getUsername() == null) {
858 setUsername(server.getUsername());
859 }
860
861 if (getPassword() == null) {
862 setPassword(server.getPassword());
863 }
864 }
865 }
866
867 if (getUsername() == null) {
868
869 setUsername("");
870 }
871
872 if (getPassword() == null) {
873
874 setPassword("");
875 }
876 }
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892 private Connection getConnection() throws MojoExecutionException, SQLException {
893 getLog().debug("connecting to " + getUrl());
894 Properties info = new Properties();
895 info.put("user", getUsername());
896
897 if (!enableAnonymousPassword) {
898 info.put("password", getPassword());
899 }
900
901 info.putAll(this.getDriverProperties());
902
903 Driver driverInstance = null;
904
905 try {
906 Class<?> dc = Class.forName(getDriver());
907 driverInstance = (Driver) dc.newInstance();
908 } catch (ClassNotFoundException e) {
909 throw new MojoExecutionException("Driver class not found: " + getDriver(), e);
910 } catch (Exception e) {
911 throw new MojoExecutionException("Failure loading driver: " + getDriver(), e);
912 }
913
914 Connection conn = driverInstance.connect(getUrl(), info);
915
916 if (conn == null) {
917
918 throw new SQLException("No suitable Driver for " + getUrl());
919 }
920
921 conn.setAutoCommit(autocommit);
922 return conn;
923 }
924
925
926
927
928
929
930
931 protected Properties getDriverProperties() throws MojoExecutionException {
932 Properties properties = new Properties();
933
934 if (!StringUtils.isEmpty(this.driverProperties)) {
935 String[] tokens = StringUtils.split(this.driverProperties, ",");
936 for (int i = 0; i < tokens.length; ++i) {
937 String[] keyValueTokens = StringUtils.split(tokens[i].trim(), "=");
938 if (keyValueTokens.length != 2) {
939 throw new MojoExecutionException("Invalid JDBC Driver properties: " + this.driverProperties);
940 }
941
942 properties.setProperty(keyValueTokens[0], keyValueTokens[1]);
943
944 }
945 }
946
947 return properties;
948 }
949
950
951
952
953
954
955
956
957
958
959
960 private void runStatements(Reader reader, PrintStream out) throws SQLException, IOException {
961 String line;
962
963 if (enableBlockMode) {
964
965
966 line = IOUtil.toString(reader);
967 execSQL(line, out);
968 return;
969 }
970
971 StringBuffer sql = new StringBuffer();
972
973 BufferedReader in = new BufferedReader(reader);
974
975 while ((line = in.readLine()) != null) {
976 if (!keepFormat) {
977 line = line.trim();
978 }
979
980 if (!keepFormat) {
981 if (line.startsWith("//")) {
982 continue;
983 }
984 if (line.startsWith("--")) {
985 continue;
986 }
987 StringTokenizer st = new StringTokenizer(line);
988 if (st.hasMoreTokens()) {
989 String token = st.nextToken();
990 if ("REM".equalsIgnoreCase(token)) {
991 continue;
992 }
993 }
994 }
995
996 if (!keepFormat) {
997 sql.append(" ").append(line);
998 } else {
999 sql.append("\n").append(line);
1000 }
1001
1002
1003
1004
1005 if (!keepFormat) {
1006 if (SqlSplitter.containsSqlEnd(line, delimiter) == SqlSplitter.NO_END) {
1007 sql.append("\n");
1008 }
1009 }
1010
1011 if ((delimiterType.equals(DelimiterType.NORMAL) && SqlSplitter.containsSqlEnd(line, delimiter) > 0)
1012 || (delimiterType.equals(DelimiterType.ROW) && line.trim().equals(delimiter))) {
1013 execSQL(sql.substring(0, sql.length() - delimiter.length()), out);
1014 sql.setLength(0);
1015 }
1016 }
1017
1018
1019 if (!sql.toString().equals("")) {
1020 execSQL(sql.toString(), out);
1021 }
1022 }
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032 private void execSQL(String sql, PrintStream out) throws SQLException {
1033
1034 if ("".equals(sql.trim())) {
1035 return;
1036 }
1037
1038 ResultSet resultSet = null;
1039 try {
1040 totalStatements++;
1041 getLog().debug("SQL: " + sql);
1042
1043 boolean ret;
1044 int updateCountTotal = 0;
1045
1046 ret = statement.execute(sql);
1047 do {
1048 if (!ret) {
1049 int updateCount = statement.getUpdateCount();
1050 if (updateCount != -1) {
1051 updateCountTotal += updateCount;
1052 }
1053 } else {
1054 resultSet = statement.getResultSet();
1055 if (printResultSet) {
1056 printResultSet(resultSet, out);
1057 }
1058 }
1059 ret = statement.getMoreResults();
1060 } while (ret);
1061
1062 getLog().debug(updateCountTotal + " rows affected");
1063
1064 if (printResultSet) {
1065 StringBuffer line = new StringBuffer();
1066 line.append(updateCountTotal).append(" rows affected");
1067 out.println(line);
1068 }
1069
1070 SQLWarning warning = conn.getWarnings();
1071 while (warning != null) {
1072 getLog().debug(warning + " sql warning");
1073 warning = warning.getNextWarning();
1074 }
1075 conn.clearWarnings();
1076 successfulStatements++;
1077 } catch (SQLException e) {
1078 getLog().error("Failed to execute: " + sql);
1079 if (ON_ERROR_ABORT.equalsIgnoreCase(getOnError())) {
1080 throw e;
1081 }
1082 getLog().error(e.toString());
1083 } finally {
1084 if (resultSet != null) {
1085 resultSet.close();
1086 }
1087 }
1088 }
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100 private void printResultSet(ResultSet rs, PrintStream out) throws SQLException {
1101 if (rs != null) {
1102 getLog().debug("Processing new result set.");
1103 ResultSetMetaData md = rs.getMetaData();
1104 int columnCount = md.getColumnCount();
1105 StringBuffer line = new StringBuffer();
1106 if (showheaders) {
1107 boolean first = true;
1108 for (int col = 1; col <= columnCount; col++) {
1109 String columnValue = md.getColumnName(col);
1110
1111 if (columnValue != null) {
1112 columnValue = columnValue.trim();
1113
1114 if (",".equals(outputDelimiter)) {
1115 columnValue = StringEscapeUtils.escapeCsv(columnValue);
1116 }
1117 }
1118
1119 if (first) {
1120 first = false;
1121 } else {
1122 line.append(outputDelimiter);
1123 }
1124 line.append(columnValue);
1125 }
1126 out.println(line);
1127 line = new StringBuffer();
1128 }
1129 while (rs.next()) {
1130 boolean first = true;
1131 for (int col = 1; col <= columnCount; col++) {
1132 String columnValue = rs.getString(col);
1133 if (columnValue != null) {
1134 columnValue = columnValue.trim();
1135
1136 if (",".equals(outputDelimiter)) {
1137 columnValue = StringEscapeUtils.escapeCsv(columnValue);
1138 }
1139 }
1140
1141 if (first) {
1142 first = false;
1143 } else {
1144 line.append(outputDelimiter);
1145 }
1146 line.append(columnValue);
1147 }
1148 out.println(line);
1149 line = new StringBuffer();
1150 }
1151 }
1152 out.println();
1153 }
1154
1155
1156
1157
1158
1159
1160 private class Transaction implements Comparable<Transaction> {
1161 private File tSrcFile = null;
1162
1163 private String tSqlCommand = "";
1164
1165
1166
1167
1168 public void setSrc(File src) {
1169 this.tSrcFile = src;
1170 }
1171
1172
1173
1174
1175 public void addText(String sql) {
1176 this.tSqlCommand += sql;
1177 }
1178
1179
1180
1181
1182 private void runTransaction(PrintStream out) throws IOException, SQLException {
1183 if (tSqlCommand.length() != 0) {
1184 getLog().info("Executing commands");
1185
1186 runStatements(new StringReader(tSqlCommand), out);
1187 }
1188
1189 if (tSrcFile != null) {
1190 getLog().info("Executing file: " + tSrcFile.getAbsolutePath());
1191
1192 Reader reader = null;
1193
1194 if (StringUtils.isEmpty(encoding)) {
1195 reader = new FileReader(tSrcFile);
1196 } else {
1197 reader = new InputStreamReader(new FileInputStream(tSrcFile), encoding);
1198 }
1199
1200 try {
1201 runStatements(reader, out);
1202 } finally {
1203 reader.close();
1204 }
1205 }
1206 }
1207
1208 public int compareTo(Transaction transaction) {
1209
1210 if (transaction.tSrcFile == null) {
1211 if (this.tSrcFile == null) {
1212 return 0;
1213 } else {
1214 return Integer.MAX_VALUE;
1215 }
1216 } else {
1217 if (this.tSrcFile == null) {
1218 return Integer.MIN_VALUE;
1219 } else {
1220 return this.tSrcFile.compareTo(transaction.tSrcFile);
1221 }
1222 }
1223 }
1224 }
1225
1226
1227
1228
1229
1230 public String getUsername() {
1231 return this.username;
1232 }
1233
1234 public void setUsername(String username) {
1235 this.username = username;
1236 }
1237
1238 public String getPassword() {
1239 return this.password;
1240 }
1241
1242 public void setPassword(String password) {
1243 this.password = password;
1244 }
1245
1246 public String getUrl() {
1247 return this.url;
1248 }
1249
1250 public void setUrl(String url) {
1251 this.url = url;
1252 }
1253
1254 public String getDriver() {
1255 return this.driver;
1256 }
1257
1258 public void setDriver(String driver) {
1259 this.driver = driver;
1260 }
1261
1262 void setAutocommit(boolean autocommit) {
1263 this.autocommit = autocommit;
1264 }
1265
1266 void setFileset(Fileset fileset) {
1267 this.fileset = fileset;
1268 }
1269
1270 public File[] getSrcFiles() {
1271 return this.srcFiles;
1272 }
1273
1274 public void setSrcFiles(File[] files) {
1275 this.srcFiles = files;
1276 }
1277
1278 public String getOrderFile() {
1279 return this.orderFile;
1280 }
1281
1282 public void setOrderFile(String orderFile) {
1283 if (FILE_SORTING_ASC.equalsIgnoreCase(orderFile)) {
1284 this.orderFile = FILE_SORTING_ASC;
1285 } else if (FILE_SORTING_DSC.equalsIgnoreCase(orderFile)) {
1286 this.orderFile = FILE_SORTING_DSC;
1287 } else {
1288 throw new IllegalArgumentException(orderFile + " is not a valid value for orderFile, only '"
1289 + FILE_SORTING_ASC + "' or '" + FILE_SORTING_DSC + "'.");
1290 }
1291 }
1292
1293
1294
1295
1296 int getGoodSqls() {
1297 return this.getSuccessfulStatements();
1298 }
1299
1300
1301
1302
1303
1304
1305 public int getSuccessfulStatements() {
1306 return successfulStatements;
1307 }
1308
1309
1310
1311
1312
1313
1314
1315 public int getTotalStatements() {
1316 return totalStatements;
1317 }
1318
1319 public String getOnError() {
1320 return this.onError;
1321 }
1322
1323 public void setOnError(String action) {
1324 if (ON_ERROR_ABORT.equalsIgnoreCase(action)) {
1325 this.onError = ON_ERROR_ABORT;
1326 } else if (ON_ERROR_CONTINUE.equalsIgnoreCase(action)) {
1327 this.onError = ON_ERROR_CONTINUE;
1328 } else if (ON_ERROR_ABORT_AFTER.equalsIgnoreCase(action)) {
1329 this.onError = ON_ERROR_ABORT_AFTER;
1330 } else {
1331 throw new IllegalArgumentException(action + " is not a valid value for onError, only '" + ON_ERROR_ABORT
1332 + "', '" + ON_ERROR_ABORT_AFTER + "', or '" + ON_ERROR_CONTINUE + "'.");
1333 }
1334 }
1335
1336 void setSettings(Settings settings) {
1337 this.settings = settings;
1338 }
1339
1340 void setSettingsKey(String key) {
1341 this.settingsKey = key;
1342 }
1343
1344 void setSkip(boolean skip) {
1345 this.skip = skip;
1346 }
1347
1348 public void setDriverProperties(String driverProperties) {
1349 this.driverProperties = driverProperties;
1350 }
1351
1352 public boolean isEnableBlockMode() {
1353 return enableBlockMode;
1354 }
1355
1356 public void setEnableBlockMode(boolean enableBlockMode) {
1357 this.enableBlockMode = enableBlockMode;
1358 }
1359
1360 public String getSqlCommand() {
1361 return sqlCommand;
1362 }
1363
1364 public void setSqlCommand(String sqlCommand) {
1365 this.sqlCommand = sqlCommand;
1366 }
1367
1368 public Vector<Transaction> getTransactions() {
1369 return transactions;
1370 }
1371
1372 public void setTransactions(Vector<Transaction> transactions) {
1373 this.transactions = transactions;
1374 }
1375
1376 public void setFileFilter(MavenFileFilter filter) {
1377 this.fileFilter = filter;
1378 }
1379
1380 public String[] getResourceLocations() {
1381 return resourceLocations;
1382 }
1383
1384 public void setResourceLocations(String[] resourceLocations) {
1385 this.resourceLocations = resourceLocations;
1386 }
1387 }