Revision | c5ac56eaf49b9af216f9d532789b18e7cd356df0 (tree) |
---|---|
Zeit | 2017-01-28 08:54:40 |
Autor | kuboryu <kuboryu@yaho...> |
Commiter | kuboryu |
20170128
@@ -73,7 +73,8 @@ public class CmnProperty{ | ||
73 | 73 | protected String [] prop_val = new String[KEYS]; |
74 | 74 | protected static final String [] MASK_PTN = {"ALL", "ALT", "EDGE"}; |
75 | 75 | protected static final String DEFAULT_IN_FOLDER = "input"; |
76 | - protected static final String DEFAULT_PROP_FILE = "RapideLoader.properties"; | |
76 | + protected static final String DEFAULT_OUT_FOLDER = "output"; | |
77 | + protected static final String DEFAULT_PROP_FILE = "RapideAct.properties"; | |
77 | 78 | protected static String [] tSqlArray = { |
78 | 79 | "select " |
79 | 80 | + " table_name " |
@@ -162,7 +163,7 @@ public class CmnProperty{ | ||
162 | 163 | Properties prop = null; |
163 | 164 | try { |
164 | 165 | prop = new Properties(); |
165 | - br = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream(_propFile), "UTF-8")); | |
166 | + br = new BufferedReader(new InputStreamReader(CmnProperty.class.getClassLoader().getResourceAsStream(_propFile), "UTF-8")); | |
166 | 167 | prop.load(br); |
167 | 168 | for(int i=0;i<KEYS;i++){ |
168 | 169 | prop_val[i] = prop.getProperty(database + "." +PROP_KEY[i]); |
@@ -170,7 +171,7 @@ public class CmnProperty{ | ||
170 | 171 | br.close(); |
171 | 172 | br = null; |
172 | 173 | } catch (NullPointerException e) { |
173 | - throw new Exception("Property File (" + _propFile +") Not Found"); | |
174 | + throw new Exception("プロパティファイルが見つかりません。[" + _propFile +"]"); | |
174 | 175 | } catch (IOException e) { |
175 | 176 | throw e; |
176 | 177 | } |
@@ -222,7 +223,7 @@ public class CmnProperty{ | ||
222 | 223 | if(!CmnUtils.isEmpty(prop_val[D_TBLKEYSQL]))tkSql = prop_val[D_TBLKEYSQL]; |
223 | 224 | if(!CmnUtils.isEmpty(prop_val[D_ORDER]) && prop_val[D_ORDER].toUpperCase().equals("Y"))isOrder = true; |
224 | 225 | if(!CmnUtils.isEmpty(prop_val[D_QUOTATION]) && prop_val[D_QUOTATION].toUpperCase().equals("N"))isQuotation = false; |
225 | - if(!CmnUtils.isEmpty(prop_val[D_BATCOUNT]))batchCount = Integer.parseInt(prop_val[D_BATCOUNT]); | |
226 | + if(!CmnUtils.isEmpty(prop_val[D_BATCOUNT]) && CmnUtils.isNumeric(prop_val[D_BATCOUNT]))batchCount = Integer.parseInt(prop_val[D_BATCOUNT]); | |
226 | 227 | if(!CmnUtils.isEmpty(prop_val[D_INCLTAB]))isInclTables = true; |
227 | 228 | if(!CmnUtils.isEmpty(prop_val[D_EXCLTAB]))isExclTables = true; |
228 | 229 | if(!CmnUtils.isEmpty(prop_val[D_INCLCOL]))isInclCols = true; |
@@ -246,14 +247,14 @@ public class CmnProperty{ | ||
246 | 247 | if(!CmnUtils.isEmpty(prop_val[D_DBYTEMASKCHR]))doubleByteMaskChar = prop_val[D_DBYTEMASKCHR].charAt(0); |
247 | 248 | if(!CmnUtils.isEmpty(prop_val[D_MASKPTN]))maskPattern = prop_val[D_MASKPTN]; |
248 | 249 | |
249 | - if(user == null){ | |
250 | - throw new Exception("user is null"); | |
251 | - } else if (pass == null){ | |
252 | - throw new Exception("pass is null"); | |
253 | - } else if (url == null){ | |
254 | - throw new Exception("url is null"); | |
255 | - } else if (driver == null){ | |
256 | - throw new Exception("driver is null"); | |
250 | + if(CmnUtils.isEmpty(user)){ | |
251 | + throw new Exception("us(ユーザID)が未指定です。"); | |
252 | + } else if (CmnUtils.isEmpty(pass)){ | |
253 | + throw new Exception("pw(パスワード)が未指定です。"); | |
254 | + } else if (CmnUtils.isEmpty(url)){ | |
255 | + throw new Exception("url(接続情報)が未指定です。"); | |
256 | + } else if (CmnUtils.isEmpty(driver)){ | |
257 | + throw new Exception("dr(ドライバ)が未指定です。"); | |
257 | 258 | } |
258 | 259 | |
259 | 260 | for(int i = 0;i<DB_TYPE_NAME.length;i++){ |
@@ -266,21 +267,13 @@ public class CmnProperty{ | ||
266 | 267 | if (dbType != DB_TYPE_UNKNOWN){ |
267 | 268 | if(!CmnUtils.isEmpty(prop_val[D_TBLSQL])){ |
268 | 269 | tSql = prop_val[D_TBLSQL]; |
269 | - } else { | |
270 | - tSql = tSqlArray[dbType]; | |
271 | - } | |
272 | - } else { | |
273 | - throw new Exception("dbtype unknown"); | |
274 | - } | |
275 | - | |
276 | - if (dbType != DB_TYPE_UNKNOWN){ | |
277 | - if(!CmnUtils.isEmpty(prop_val[D_TBLKEYSQL])){ | |
278 | 270 | tkSql = prop_val[D_TBLKEYSQL]; |
279 | 271 | } else { |
272 | + tSql = tSqlArray[dbType]; | |
280 | 273 | tkSql = tkSqlArray[dbType]; |
281 | 274 | } |
282 | 275 | } else { |
283 | - throw new Exception("dbtype unknown"); | |
276 | + throw new Exception("データベース製品が識別できません。[" + url + "]"); | |
284 | 277 | } |
285 | 278 | |
286 | 279 | if(database!=null)CmnUtils.infoPrint("-->対象データベース='" + database.toUpperCase() + "'"); |
@@ -431,6 +431,16 @@ public class CmnUtils{ | ||
431 | 431 | } |
432 | 432 | } |
433 | 433 | |
434 | + public static boolean isNumeric(String _str) { | |
435 | + boolean retVal = true; | |
436 | + try { | |
437 | + int val = Integer.parseInt(_str); | |
438 | + } catch (Exception e){ | |
439 | + retVal = false; | |
440 | + } | |
441 | + return retVal; | |
442 | + } | |
443 | + | |
434 | 444 | public static String[] getSystemProperty(String _str) throws Exception{ |
435 | 445 | String [] retValue = null; |
436 | 446 | if(System.getProperty(_str)!=null){ |
@@ -61,57 +61,10 @@ public class DataAccessObjects{ | ||
61 | 61 | private byte [] colBytes = null; |
62 | 62 | private Blob colBlob = null; |
63 | 63 | private Clob colClob = null; |
64 | - private int recCount = 0; | |
65 | - private InputStream is = null; | |
66 | - private ByteArrayOutputStream baos = null; | |
67 | - private boolean isQuotation = true; | |
68 | - private boolean isMask = false; | |
69 | - private boolean isInclMaskCols = false; | |
70 | - private boolean isExclMaskCols = false; | |
71 | - private String inclMaskCols = null; | |
72 | - private String exclMaskCols = null; | |
73 | 64 | private String tbName = null; |
74 | - private String nullMark = ""; | |
75 | - private String lnSprtr = System.getProperty("line.separator"); | |
76 | - private String delimiter = "\t"; | |
77 | - private char singleByteChr = '*'; | |
78 | - private char doubleByteChr = '*'; | |
79 | - private String maskPtn = "ALT"; | |
80 | - private static final int MASK_PTN_ALL = 0; | |
81 | - private static final int MASK_PTN_ALT = 1; | |
82 | - private static final int MASK_PTN_EDGE = 2; | |
83 | - private static final String [] MASK_PTN = {"ALL", "ALT", "EDGE"}; | |
84 | - private static final int USER = 0; | |
85 | - private static final int PASS = 1; | |
86 | - private static final int URL = 2; | |
87 | - private static final int DRIVER = 3; | |
88 | - private static final int OUTPUT = 4; | |
89 | - private static final int INPUT = 5; | |
90 | - private static final int LINESEP = 6; | |
91 | - private static final int INLINESEP = 7; | |
92 | - private static final int FILENCODE = 8; | |
93 | - private static final int NULLMARK = 9; | |
94 | - private static final int DELIMITER = 10; | |
95 | - private static final int TBLSQL = 11; | |
96 | - private static final int TBLKEYSQL = 12; | |
97 | - private static final int ORDER = 13; | |
98 | - private static final int QUOTATION = 14; | |
99 | - private static final int BATCOUNT = 15; | |
100 | - private static final int INCLTAB = 16; | |
101 | - private static final int EXCLTAB = 17; | |
102 | - private static final int INCLCOL = 18; | |
103 | - private static final int EXCLCOL = 19; | |
104 | - private static final int INCLCOLMASK = 20; | |
105 | - private static final int EXCLCOLMASK = 21; | |
106 | - private static final int SBYTEMASKCHR = 22; | |
107 | - private static final int DBYTEMASKCHR = 23; | |
108 | - private static final int MASKPTN = 24; | |
109 | - private static final int PROPFILE = 25; | |
110 | - private static final String [] PROP_KEY = { "us","pw","url","dr","out","in","ls","ils","fe","nm", | |
111 | - "dm","ts","tks","od","qt","bc","it","et","ic","ec", | |
112 | - "icm","ecm","smc","dmc","mp","pf"}; | |
113 | - private static final int KEYS = 26; | |
114 | - private String [] prop_val = null; | |
65 | + private int recCount = 0; | |
66 | + private CmnProperty cp = null; | |
67 | + | |
115 | 68 | DataAccessObjects(String _user, String _pass, String _url, String _driver){ |
116 | 69 | user = _user; |
117 | 70 | pass = _pass; |
@@ -119,6 +72,14 @@ public class DataAccessObjects{ | ||
119 | 72 | driver = _driver; |
120 | 73 | } |
121 | 74 | |
75 | + DataAccessObjects(CmnProperty _cp){ | |
76 | + cp = _cp; | |
77 | + user = cp.user; | |
78 | + pass = cp.pass; | |
79 | + url = cp.url; | |
80 | + driver = cp.driver; | |
81 | + } | |
82 | + | |
122 | 83 | public Connection connect() throws Exception{ |
123 | 84 | |
124 | 85 | try { |
@@ -298,20 +259,6 @@ public class DataAccessObjects{ | ||
298 | 259 | tbName = _tbName; |
299 | 260 | } |
300 | 261 | |
301 | - public void setPropVal(String[] _prop_val) throws Exception{ | |
302 | - prop_val = _prop_val; | |
303 | - if(!CmnUtils.isEmpty(prop_val[LINESEP]))lnSprtr = CmnUtils.getLineSeparator(prop_val[LINESEP]); | |
304 | - if(!CmnUtils.isEmpty(prop_val[NULLMARK]))nullMark = prop_val[NULLMARK]; | |
305 | - if(!CmnUtils.isEmpty(prop_val[QUOTATION]) && prop_val[QUOTATION].toUpperCase().equals("N"))isQuotation = false; | |
306 | - if(!CmnUtils.isEmpty(prop_val[INCLCOLMASK]))isInclMaskCols = true; | |
307 | - if(!CmnUtils.isEmpty(prop_val[EXCLCOLMASK]))isExclMaskCols = true; | |
308 | - if(isInclMaskCols || isExclMaskCols)isMask = true; | |
309 | - if(!CmnUtils.isEmpty(prop_val[SBYTEMASKCHR]))singleByteChr = prop_val[SBYTEMASKCHR].charAt(0); | |
310 | - if(!CmnUtils.isEmpty(prop_val[DBYTEMASKCHR]))doubleByteChr = prop_val[DBYTEMASKCHR].charAt(0); | |
311 | - if(!CmnUtils.isEmpty(prop_val[MASKPTN]))maskPtn = prop_val[MASKPTN]; | |
312 | - if(!CmnUtils.isEmpty(prop_val[DELIMITER]))delimiter = CmnUtils.getDelimiter(prop_val[DELIMITER]); | |
313 | - } | |
314 | - | |
315 | 262 | public ResultSet getResultSet() throws Exception{ |
316 | 263 | return rst; |
317 | 264 | } |
@@ -353,31 +300,31 @@ public class DataAccessObjects{ | ||
353 | 300 | |
354 | 301 | if (colString != null) { |
355 | 302 | if (i == _firstCol){ |
356 | - if(isQuotation){ | |
303 | + if(cp.isQuotation){ | |
357 | 304 | if (_firstCol == _lastCol){ |
358 | - _pw.print("\"" + colString + "\"" + lnSprtr); | |
305 | + _pw.print("\"" + colString + "\"" + cp.lineSeparator); | |
359 | 306 | } else { |
360 | 307 | _pw.print("\"" + colString); |
361 | 308 | } |
362 | 309 | } else { |
363 | 310 | if (_firstCol == _lastCol){ |
364 | - _pw.print(colString + lnSprtr); | |
311 | + _pw.print(colString + cp.lineSeparator); | |
365 | 312 | } else { |
366 | 313 | _pw.print(colString); |
367 | 314 | } |
368 | 315 | } |
369 | 316 | |
370 | 317 | } else if (i == _lastCol){ |
371 | - if(isQuotation){ | |
372 | - _pw.print("\"" + delimiter + "\"" + colString + "\"" + lnSprtr); | |
318 | + if(cp.isQuotation){ | |
319 | + _pw.print("\"" + cp.delimiter + "\"" + colString + "\"" + cp.lineSeparator); | |
373 | 320 | } else { |
374 | - _pw.print(delimiter + colString + lnSprtr); | |
321 | + _pw.print(cp.delimiter + colString + cp.lineSeparator); | |
375 | 322 | } |
376 | 323 | } else { |
377 | - if(isQuotation){ | |
378 | - _pw.print("\"" + delimiter + "\"" + colString); | |
324 | + if(cp.isQuotation){ | |
325 | + _pw.print("\"" + cp.delimiter + "\"" + colString); | |
379 | 326 | } else { |
380 | - _pw.print(delimiter + colString); | |
327 | + _pw.print(cp.delimiter + colString); | |
381 | 328 | } |
382 | 329 | } |
383 | 330 |
@@ -385,30 +332,30 @@ public class DataAccessObjects{ | ||
385 | 332 | |
386 | 333 | } else { |
387 | 334 | if (i == _firstCol){ |
388 | - if(isQuotation){ | |
335 | + if(cp.isQuotation){ | |
389 | 336 | if (_firstCol == _lastCol){ |
390 | - _pw.print("\"" + nullMark + "\"" + lnSprtr); | |
337 | + _pw.print("\"" + cp.nullMark + "\"" + cp.lineSeparator); | |
391 | 338 | } else { |
392 | - _pw.print("\"" + nullMark); | |
339 | + _pw.print("\"" + cp.nullMark); | |
393 | 340 | } |
394 | 341 | } else { |
395 | 342 | if (_firstCol == _lastCol){ |
396 | - _pw.print(nullMark + lnSprtr); | |
343 | + _pw.print(cp.nullMark + cp.lineSeparator); | |
397 | 344 | } else { |
398 | - _pw.print(nullMark); | |
345 | + _pw.print(cp.nullMark); | |
399 | 346 | } |
400 | 347 | } |
401 | 348 | } else if (i == _lastCol){ |
402 | - if(isQuotation){ | |
403 | - _pw.print("\"" + delimiter + "\"" + nullMark + "\"" + lnSprtr); | |
349 | + if(cp.isQuotation){ | |
350 | + _pw.print("\"" + cp.delimiter + "\"" + cp.nullMark + "\"" + cp.lineSeparator); | |
404 | 351 | } else { |
405 | - _pw.print(delimiter + nullMark + lnSprtr); | |
352 | + _pw.print(cp.delimiter + cp.nullMark + cp.lineSeparator); | |
406 | 353 | } |
407 | 354 | } else { |
408 | - if(isQuotation){ | |
409 | - _pw.print("\"" + delimiter + "\"" + nullMark); | |
355 | + if(cp.isQuotation){ | |
356 | + _pw.print("\"" + cp.delimiter + "\"" + cp.nullMark); | |
410 | 357 | } else { |
411 | - _pw.print(delimiter + nullMark); | |
358 | + _pw.print(cp.delimiter + cp.nullMark); | |
412 | 359 | } |
413 | 360 | } |
414 | 361 | } |
@@ -445,26 +392,26 @@ public class DataAccessObjects{ | ||
445 | 392 | if (CmnUtils.isColString(_colTypeName)) { |
446 | 393 | colString = _rst.getString(_rec_cnt); |
447 | 394 | if (colString != null) { |
448 | - if(isQuotation){ | |
395 | + if(cp.isQuotation){ | |
449 | 396 | colString =colString.trim().replaceAll("\0","").replaceAll("\"","\"\""); |
450 | 397 | } else { |
451 | 398 | colString =colString.trim().replaceAll("\0",""); |
452 | 399 | } |
453 | - if(isMask){ | |
400 | + if(cp.isMask){ | |
454 | 401 | if(_colMask==true){ |
455 | 402 | StringBuffer sb = new StringBuffer(); |
456 | 403 | for(int j=0;j<colString.length();j++){ |
457 | - if((maskPtn.toUpperCase().equals(MASK_PTN[MASK_PTN_ALT]) && | |
404 | + if((cp.maskPattern.toUpperCase().equals(cp.MASK_PTN[cp.MASK_PTN_ALT]) && | |
458 | 405 | (j % 2) == 1) || |
459 | - (maskPtn.toUpperCase().equals(MASK_PTN[MASK_PTN_EDGE]) && | |
406 | + (cp.maskPattern.toUpperCase().equals(cp.MASK_PTN[cp.MASK_PTN_EDGE]) && | |
460 | 407 | !(j == 0 || j == colString.length() - 1) || |
461 | - (maskPtn.toUpperCase().equals(MASK_PTN[MASK_PTN_ALL])) | |
408 | + (cp.maskPattern.toUpperCase().equals(cp.MASK_PTN[cp.MASK_PTN_ALL])) | |
462 | 409 | ) |
463 | 410 | ){ |
464 | 411 | if(CmnUtils.isHankaku(colString.charAt(j))){ |
465 | - sb.append(singleByteChr); | |
412 | + sb.append(cp.singleByteMaskChar); | |
466 | 413 | } else { |
467 | - sb.append(doubleByteChr); | |
414 | + sb.append(cp.doubleByteMaskChar); | |
468 | 415 | } |
469 | 416 | } else { |
470 | 417 | sb.append(colString.charAt(j)); |
@@ -50,12 +50,12 @@ public class RapideLoader{ | ||
50 | 50 | } |
51 | 51 | |
52 | 52 | |
53 | - RapideLoader(String _database) throws Exception{ | |
53 | + RapideLoader(String _database) { | |
54 | 54 | super(); |
55 | 55 | database = _database; |
56 | 56 | } |
57 | 57 | |
58 | - private void load() throws Exception{ | |
58 | + private void load(){ | |
59 | 59 | Connection conn = null; |
60 | 60 | PreparedStatement stmt = null; |
61 | 61 | PreparedStatement stmt_ins = null; |
@@ -85,14 +85,12 @@ public class RapideLoader{ | ||
85 | 85 | int fl_col_count = 0; |
86 | 86 | boolean isLob = false; |
87 | 87 | boolean isContinue = false; |
88 | + CmnProperty cp = null; | |
89 | + DataAccessObjects dao = null; | |
88 | 90 | |
89 | - CmnProperty cp = new CmnProperty(); | |
90 | - cp.setProperty(database); | |
91 | - | |
92 | - DataAccessObjects dao = new DataAccessObjects(cp.user, cp.pass, cp.url, cp.driver); | |
93 | 91 | try { |
94 | - conn = dao.connect(); | |
95 | - conn.setAutoCommit(false); | |
92 | + cp = new CmnProperty(); | |
93 | + cp.setProperty(database); | |
96 | 94 | |
97 | 95 | if(cp.inFolder != null){ |
98 | 96 | folder = new File(cp.inFolder); |
@@ -103,9 +101,11 @@ public class RapideLoader{ | ||
103 | 101 | folder = new File(cp.DEFAULT_IN_FOLDER + "/" + cp.DB_TYPE_NAME[cp.dbType].toUpperCase()); |
104 | 102 | } |
105 | 103 | } |
106 | - CmnUtils.infoPrint("-->入力元='" + folder + "'"); | |
104 | + CmnUtils.infoPrint("-->入力元フォルダ='" + folder + "'"); | |
107 | 105 | CmnUtils.infoPrint("データロードを開始しました。"); |
108 | - | |
106 | + dao = new DataAccessObjects(cp); | |
107 | + conn = dao.connect(); | |
108 | + conn.setAutoCommit(false); | |
109 | 109 | dao.select(cp.tSql); |
110 | 110 | alData = dao.getArrayList(); |
111 | 111 | tb_count = dao.getColumnCount(); |
@@ -202,7 +202,6 @@ public class RapideLoader{ | ||
202 | 202 | } |
203 | 203 | |
204 | 204 | colIncl = (Boolean[])alColIncl.toArray(new Boolean[0]); |
205 | - | |
206 | 205 | sql_insert = "INSERT INTO " + tbName + "("; |
207 | 206 | for(int j=0;j<colData.length;j++){ |
208 | 207 | for(int l=0;l<tb_col_count;l++){ |
@@ -237,7 +236,7 @@ public class RapideLoader{ | ||
237 | 236 | CmnUtils.infoPrinting(String.format("%1$-30s",tbName)); |
238 | 237 | } else { |
239 | 238 | dao.rollback(); |
240 | - CmnUtils.debugPrint("column count is zero"); | |
239 | + CmnUtils.debugPrint("指定した区切り文字でのカラム数が0です。"); | |
241 | 240 | if(br != null){ |
242 | 241 | br.close(); |
243 | 242 | br=null; |
@@ -257,7 +256,7 @@ public class RapideLoader{ | ||
257 | 256 | if(colData.length == fl_col_count){ |
258 | 257 | if(!strMltLine.equals("")){ |
259 | 258 | dao.rollback(); |
260 | - System.out.println(String.format("%1$10d",tb_rec_count) + " ERROR:column count is unmatch"); | |
259 | + CmnUtils.errorPrint("該当レコードのカラム数がアンマッチです。[" + tb_rec_count + "]"); | |
261 | 260 | CmnUtils.debugPrint("************Record End"); |
262 | 261 | if(br != null){ |
263 | 262 | br.close(); |
@@ -286,7 +285,7 @@ public class RapideLoader{ | ||
286 | 285 | isContinue = false; |
287 | 286 | } else if(colData.length >fl_col_count){ |
288 | 287 | dao.rollback(); |
289 | - CmnUtils.errorPrint(String.format("%1$10d",tb_rec_count) + "column count is unmatch"); | |
288 | + CmnUtils.errorPrint("該当レコードのカラム数がアンマッチです。[" + tb_rec_count + "]"); | |
290 | 289 | CmnUtils.debugPrint("************Record End"); |
291 | 290 | if(br != null){ |
292 | 291 | br.close(); |
@@ -432,7 +431,7 @@ public class RapideLoader{ | ||
432 | 431 | stmt_ins.setClob(j+1,null,0); |
433 | 432 | } |
434 | 433 | } else { |
435 | - CmnUtils.errorPrint("unmatch column type=" + colTypeName[tb_col_seq[j]]); | |
434 | + CmnUtils.errorPrint("カラムのデータ型が対象外です。[" + colTypeName[tb_col_seq[j]] + "]"); | |
436 | 435 | break TABLE_LOOP; |
437 | 436 | } |
438 | 437 | } |
@@ -453,7 +452,7 @@ public class RapideLoader{ | ||
453 | 452 | } |
454 | 453 | if(!isLob)stmt_ins.executeBatch(); |
455 | 454 | dao.commit(); |
456 | - System.out.println(String.format("%1$10d",tb_rec_count) + " rows imported"); | |
455 | + System.out.println(String.format("%1$10d",tb_rec_count) + " 行 ロードされました。"); | |
457 | 456 | CmnUtils.debugPrint("************Record End"); |
458 | 457 | if(br != null){ |
459 | 458 | br.close(); |
@@ -468,31 +467,33 @@ public class RapideLoader{ | ||
468 | 467 | } |
469 | 468 | } |
470 | 469 | } else { |
471 | - throw new Exception("Folder Not Found(" + folder + ")"); | |
470 | + CmnUtils.errorPrint("入力元フォルダが見つかりません。[" + folder + "]"); | |
472 | 471 | } |
473 | 472 | |
474 | - dao.disconnect(); | |
473 | + CmnUtils.infoPrint("データロードを終了しました。"); | |
475 | 474 | |
476 | 475 | } catch (Exception e) { |
477 | - dao.rollback(); | |
478 | - throw e; | |
476 | + try{ | |
477 | + CmnUtils.errorPrint(e.toString()); | |
478 | + e.printStackTrace(); | |
479 | + dao.rollback(); | |
480 | + } catch (Exception ee) {} | |
479 | 481 | } finally{ |
480 | - if(stmt != null){ | |
481 | - stmt.close(); | |
482 | - stmt=null; | |
483 | - } | |
484 | - if(stmt_ins != null){ | |
485 | - stmt_ins.close(); | |
486 | - stmt_ins=null; | |
487 | - } | |
488 | - if(br!=null){ | |
489 | - br.close(); | |
490 | - br=null; | |
491 | - } | |
482 | + try{ | |
483 | + dao.disconnect(); | |
484 | + if(stmt != null){ | |
485 | + stmt.close(); | |
486 | + stmt=null; | |
487 | + } | |
488 | + if(stmt_ins != null){ | |
489 | + stmt_ins.close(); | |
490 | + stmt_ins=null; | |
491 | + } | |
492 | + if(br!=null){ | |
493 | + br.close(); | |
494 | + br=null; | |
495 | + } | |
496 | + } catch (Exception e) {} | |
492 | 497 | } |
493 | - CmnUtils.infoPrint("データロードを終了しました。"); | |
494 | 498 | } |
495 | - | |
496 | - | |
497 | 499 | } |
498 | - |
@@ -30,121 +30,6 @@ import java.sql.Timestamp; | ||
30 | 30 | public class RapideUnloader{ |
31 | 31 | |
32 | 32 | private String database = null; |
33 | - private String driver = null; | |
34 | - private String user = null; | |
35 | - private String pass = null; | |
36 | - private String url = null; | |
37 | - private String tkSql; | |
38 | - private static final int DB_TYPE_ORACLE = 0; | |
39 | - private static final int DB_TYPE_SQLSERVER = 1; | |
40 | - private static final int DB_TYPE_DB2 = 2; | |
41 | - private static final int DB_TYPE_MYSQL = 3; | |
42 | - private static final int DB_TYPE_POSTGRESQL = 4; | |
43 | - private static final int DB_TYPE_UNKNOWN = -1; | |
44 | - private static final int MASK_PTN_ALL = 0; | |
45 | - private static final int MASK_PTN_ALT = 1; | |
46 | - private static final int MASK_PTN_EDGE = 2; | |
47 | - private static final int D_USER = 0; | |
48 | - private static final int D_PASS = 1; | |
49 | - private static final int D_URL = 2; | |
50 | - private static final int D_DRIVER = 3; | |
51 | - private static final int D_OUTPUT = 4; | |
52 | - private static final int D_INPUT = 5; | |
53 | - private static final int D_LINESEP = 6; | |
54 | - private static final int D_INLINESEP = 7; | |
55 | - private static final int D_FILENCODE = 8; | |
56 | - private static final int D_NULLMARK = 9; | |
57 | - private static final int D_DELIMITER = 10; | |
58 | - private static final int D_TBLSQL = 11; | |
59 | - private static final int D_TBLKEYSQL = 12; | |
60 | - private static final int D_ORDER = 13; | |
61 | - private static final int D_QUOTATION = 14; | |
62 | - private static final int D_BATCOUNT = 15; | |
63 | - private static final int D_INCLTAB = 16; | |
64 | - private static final int D_EXCLTAB = 17; | |
65 | - private static final int D_INCLCOL = 18; | |
66 | - private static final int D_EXCLCOL = 19; | |
67 | - private static final int D_INCLCOLMASK = 20; | |
68 | - private static final int D_EXCLCOLMASK = 21; | |
69 | - private static final int D_SBYTEMASKCHR = 22; | |
70 | - private static final int D_DBYTEMASKCHR = 23; | |
71 | - private static final int D_MASKPTN = 24; | |
72 | - private static final int D_PROPFILE = 25; | |
73 | - private static final int KEYS = 26; | |
74 | - private static final String [] DB_TYPE_NAME = {"ORACLE", "SQLSERVER", "DB2", "MYSQL", "POSTGRESQL"}; | |
75 | - private static final String [] MASK_PTN = {"ALL", "ALT", "EDGE"}; | |
76 | - private static final String [] PROP_KEY = { "us","pw","url","dr","out","in","ls","ils","fe","nm", | |
77 | - "dm","ts","tks","od","qt","bc","it","et","ic","ec", | |
78 | - "icm","ecm","smc","dmc","mp","pf"}; | |
79 | - private static final String DEFAULT_FOLDER = "output"; | |
80 | - private static final String DEFAULT_PROP_FILE = "RapideLoader.properties"; | |
81 | - | |
82 | - private String nullMark = ""; | |
83 | - private boolean isOrder = false; | |
84 | - private boolean isQuotation = true; | |
85 | - private boolean isInclTables = false; | |
86 | - private boolean isExclTables = false; | |
87 | - private boolean isInclCols = false; | |
88 | - private boolean isExclCols = false; | |
89 | - private boolean isMask = false; | |
90 | - private boolean isInclColsMask = false; | |
91 | - private boolean isExclColsMask = false; | |
92 | - private String delimiter = "\t"; | |
93 | - private String lineSeparator = System.getProperty("line.separator"); | |
94 | - private String inColLineSeparator = System.getProperty("line.separator"); | |
95 | - private String outFolder = null; | |
96 | - private String inFolder = null; | |
97 | - private String inclTables = null; | |
98 | - private String exclTables = null; | |
99 | - private String inclCols = null; | |
100 | - private String exclCols = null; | |
101 | - private String inclMaskCols = null; | |
102 | - private String exclMaskCols = null; | |
103 | - private String [] inclTablesArray = null; | |
104 | - private String [] exclTablesArray = null; | |
105 | - private String [] inclColsArray = null; | |
106 | - private String [] exclColsArray = null; | |
107 | - private String [] inclColsMaskArray = null; | |
108 | - private String [] exclColsMaskArray = null; | |
109 | - private char singleByteMaskChar = '*'; | |
110 | - private char doubleByteMaskChar = '\u25A0'; | |
111 | - private String maskPattern = "ALT"; | |
112 | - private String fileEncoding = System.getProperty("file.encoding"); | |
113 | - | |
114 | - private String [] prop_val = new String[KEYS]; | |
115 | - | |
116 | - | |
117 | - private static String [] tkSqlArray = { | |
118 | - "select " | |
119 | - + "a.table_name," | |
120 | - + "d.column_name " | |
121 | - + " from user_tables a," | |
122 | - + " (select b.table_name, " | |
123 | - + " c.column_name, " | |
124 | - + " c.position " | |
125 | - + " from user_constraints b, " | |
126 | - + " user_cons_columns c " | |
127 | - + " where b.CONSTRAINT_TYPE = 'P' and " | |
128 | - + " b.TABLE_NAME = c.TABLE_NAME and " | |
129 | - + " b.CONSTRAINT_NAME = c.CONSTRAINT_NAME " | |
130 | - + " ) d " | |
131 | - + "where a.table_name = d.table_name(+) " | |
132 | - + "order by a.table_name, d.position", | |
133 | - "SELECT " | |
134 | - + " A.name AS table_name, " | |
135 | - + " D.name AS col_name " | |
136 | - + "FROM sys.tables AS A " | |
137 | - + "LEFT OUTER JOIN sys.key_constraints AS B " | |
138 | - + "ON A.object_id = B.parent_object_id " | |
139 | - + " AND B.type = 'PK' " | |
140 | - + "LEFT OUTER JOIN sys.index_columns AS C " | |
141 | - + "ON B.parent_object_id = C.object_id " | |
142 | - + " AND B.unique_index_id = C.index_id " | |
143 | - + "LEFT OUTER JOIN sys.columns AS D " | |
144 | - + "ON C.object_id = D.object_id " | |
145 | - + " AND C.column_id = D.column_id " | |
146 | - + "order by A.name,C.key_ordinal" | |
147 | - }; | |
148 | 33 | |
149 | 34 | public static void main(String args[]){ |
150 | 35 | try { |
@@ -160,43 +45,14 @@ public class RapideUnloader{ | ||
160 | 45 | } |
161 | 46 | } |
162 | 47 | |
163 | - RapideUnloader(String _database) throws Exception{ | |
48 | + RapideUnloader(String _database) { | |
164 | 49 | super(); |
165 | 50 | database = _database; |
166 | 51 | |
167 | 52 | } |
168 | 53 | |
169 | - private void getProperties(String _propFile) throws Exception{ | |
170 | - BufferedReader br = null; | |
171 | - Properties prop = null; | |
172 | - try { | |
173 | - prop = new Properties(); | |
174 | - br = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream(_propFile), "UTF-8")); | |
175 | - prop.load(br); | |
176 | - for(int i=0;i<KEYS;i++){ | |
177 | - prop_val[i] = prop.getProperty(database + "." +PROP_KEY[i]); | |
178 | - } | |
179 | - br.close(); | |
180 | - br = null; | |
181 | - } catch (NullPointerException e) { | |
182 | - throw new Exception("Property File (" + _propFile +") Not Found"); | |
183 | - } catch (IOException e) { | |
184 | - throw e; | |
185 | - } | |
186 | - finally{ | |
187 | - try { | |
188 | - if (br != null) { | |
189 | - br.close(); | |
190 | - br = null; | |
191 | - } | |
192 | - } | |
193 | - catch (IOException e) { | |
194 | - throw e; | |
195 | - } | |
196 | - } | |
197 | - } | |
198 | 54 | |
199 | - private void unload() throws Exception{ | |
55 | + private void unload() { | |
200 | 56 | Connection conn = null; |
201 | 57 | PreparedStatement stmt = null; |
202 | 58 | ResultSet rst = null; |
@@ -204,10 +60,9 @@ public class RapideUnloader{ | ||
204 | 60 | String sql_insert = null; |
205 | 61 | String order_columns = ""; |
206 | 62 | int orders = 0; |
207 | - int dbType = DB_TYPE_UNKNOWN; | |
208 | 63 | |
209 | 64 | PrintWriter pw = null; |
210 | - File fldr = null; | |
65 | + File folder = null; | |
211 | 66 | ArrayList<String> alColName = null; |
212 | 67 | ArrayList<String> alColTypeName = null; |
213 | 68 | ArrayList<Integer> alIsNullable = null; |
@@ -216,120 +71,29 @@ public class RapideUnloader{ | ||
216 | 71 | ArrayList<String> alData = null; |
217 | 72 | int tb_count = 0; |
218 | 73 | int tb_col_count = 0; |
74 | + CmnProperty cp = null; | |
75 | + DataAccessObjects dao = null; | |
219 | 76 | |
220 | - | |
221 | - | |
222 | - if(database != null){ | |
223 | - if(!CmnUtils.isEmpty(prop_val[D_PROPFILE])){ | |
224 | - getProperties(System.getProperty(prop_val[D_PROPFILE])); | |
225 | - } else { | |
226 | - getProperties(DEFAULT_PROP_FILE); | |
227 | - } | |
228 | - } | |
229 | - | |
230 | - for(int i=0;i<KEYS;i++){ | |
231 | - if(System.getProperty(PROP_KEY[i])!=null)prop_val[i] = System.getProperty(PROP_KEY[i]); | |
232 | - CmnUtils.debugPrint(PROP_KEY[i] + "=" + prop_val[i]); | |
233 | - } | |
234 | - | |
235 | - if(!CmnUtils.isEmpty(prop_val[D_USER]))user = prop_val[D_USER]; | |
236 | - if(!CmnUtils.isEmpty(prop_val[D_PASS]))pass = prop_val[D_PASS]; | |
237 | - if(!CmnUtils.isEmpty(prop_val[D_URL]))url = prop_val[D_URL]; | |
238 | - if(!CmnUtils.isEmpty(prop_val[D_DRIVER]))driver = prop_val[D_DRIVER]; | |
239 | - if(!CmnUtils.isEmpty(prop_val[D_ORDER]) && prop_val[D_ORDER].toUpperCase().equals("Y"))isOrder = true; | |
240 | - if(!CmnUtils.isEmpty(prop_val[D_QUOTATION]) && prop_val[D_QUOTATION].toUpperCase().equals("N"))isQuotation = false; | |
241 | - if(!CmnUtils.isEmpty(prop_val[D_INCLTAB]))isInclTables = true; | |
242 | - if(!CmnUtils.isEmpty(prop_val[D_EXCLTAB]))isExclTables = true; | |
243 | - if(!CmnUtils.isEmpty(prop_val[D_INCLCOL]))isInclCols = true; | |
244 | - if(!CmnUtils.isEmpty(prop_val[D_EXCLCOL]))isExclCols = true; | |
245 | - if(!CmnUtils.isEmpty(prop_val[D_INCLCOLMASK]))isInclColsMask = true; | |
246 | - if(!CmnUtils.isEmpty(prop_val[D_EXCLCOLMASK]))isExclColsMask = true; | |
247 | - if(isInclColsMask || isExclColsMask)isMask = true; | |
248 | - if(!CmnUtils.isEmpty(prop_val[D_DELIMITER]))delimiter = CmnUtils.getDelimiter(prop_val[D_DELIMITER]); | |
249 | - if(!CmnUtils.isEmpty(prop_val[D_LINESEP]))lineSeparator = CmnUtils.getLineSeparator(prop_val[D_LINESEP]); | |
250 | - if(!CmnUtils.isEmpty(prop_val[D_OUTPUT]))outFolder = prop_val[D_OUTPUT]; | |
251 | - if(!CmnUtils.isEmpty(prop_val[D_INCLTAB]))inclTables = prop_val[D_INCLTAB].toUpperCase(); | |
252 | - if(!CmnUtils.isEmpty(prop_val[D_EXCLTAB]))exclTables = prop_val[D_EXCLTAB].toUpperCase(); | |
253 | - if(!CmnUtils.isEmpty(prop_val[D_INCLCOL]))inclCols = prop_val[D_INCLCOL].toUpperCase(); | |
254 | - if(!CmnUtils.isEmpty(prop_val[D_EXCLCOL]))exclCols = prop_val[D_EXCLCOL].toUpperCase(); | |
255 | - if(!CmnUtils.isEmpty(prop_val[D_INCLCOLMASK]))inclMaskCols = prop_val[D_INCLCOLMASK].toUpperCase(); | |
256 | - if(!CmnUtils.isEmpty(prop_val[D_EXCLCOLMASK]))exclMaskCols = prop_val[D_EXCLCOLMASK].toUpperCase(); | |
257 | - if(!CmnUtils.isEmpty(prop_val[D_INCLTAB]))inclTablesArray = CmnUtils.splitCsv(prop_val[D_INCLTAB].toUpperCase()); | |
258 | - if(!CmnUtils.isEmpty(prop_val[D_EXCLTAB]))exclTablesArray = CmnUtils.splitCsv(prop_val[D_EXCLTAB].toUpperCase()); | |
259 | - if(!CmnUtils.isEmpty(prop_val[D_INCLCOL]))inclColsArray = CmnUtils.splitCsv(prop_val[D_INCLCOL].toUpperCase()); | |
260 | - if(!CmnUtils.isEmpty(prop_val[D_EXCLCOL]))exclColsArray = CmnUtils.splitCsv(prop_val[D_EXCLCOL].toUpperCase()); | |
261 | - if(!CmnUtils.isEmpty(prop_val[D_INCLCOLMASK]))inclColsMaskArray = CmnUtils.splitCsv(prop_val[D_INCLCOLMASK].toUpperCase()); | |
262 | - if(!CmnUtils.isEmpty(prop_val[D_EXCLCOLMASK]))exclColsMaskArray = CmnUtils.splitCsv(prop_val[D_EXCLCOLMASK].toUpperCase()); | |
263 | - if(!CmnUtils.isEmpty(prop_val[D_SBYTEMASKCHR]))singleByteMaskChar = prop_val[D_SBYTEMASKCHR].charAt(0); | |
264 | - if(!CmnUtils.isEmpty(prop_val[D_DBYTEMASKCHR]))doubleByteMaskChar = prop_val[D_DBYTEMASKCHR].charAt(0); | |
265 | - if(!CmnUtils.isEmpty(prop_val[D_MASKPTN]))maskPattern = prop_val[D_MASKPTN]; | |
266 | - if(!CmnUtils.isEmpty(prop_val[D_FILENCODE]))fileEncoding = prop_val[D_FILENCODE]; | |
267 | - | |
268 | - if(user == null){ | |
269 | - throw new Exception("user is null"); | |
270 | - } else if (pass == null){ | |
271 | - throw new Exception("password is null"); | |
272 | - } else if (url == null){ | |
273 | - throw new Exception("url is null"); | |
274 | - } else if (driver == null){ | |
275 | - throw new Exception("driver is null"); | |
276 | - } | |
277 | - | |
278 | - for(int i = 0;i<DB_TYPE_NAME.length;i++){ | |
279 | - if (url.toUpperCase().contains(DB_TYPE_NAME[i])){ | |
280 | - dbType = i; | |
281 | - break; | |
282 | - } | |
283 | - } | |
284 | - | |
285 | - if (dbType != DB_TYPE_UNKNOWN){ | |
286 | - if(!CmnUtils.isEmpty(prop_val[D_TBLKEYSQL])){ | |
287 | - tkSql = prop_val[D_TBLKEYSQL]; | |
288 | - } else { | |
289 | - tkSql = tkSqlArray[dbType]; | |
290 | - } | |
291 | - } else { | |
292 | - throw new Exception("dbtype unknown"); | |
293 | - } | |
294 | - | |
295 | - DataAccessObjects dao = new DataAccessObjects(user, pass, url, driver); | |
296 | - dao.setPropVal(prop_val); | |
297 | 77 | try { |
298 | - conn = dao.connect(); | |
78 | + cp = new CmnProperty(); | |
79 | + cp.setProperty(database); | |
299 | 80 | |
300 | - if(outFolder != null){ | |
301 | - fldr = new File(outFolder); | |
81 | + if(cp.outFolder != null){ | |
82 | + folder = new File(cp.outFolder); | |
302 | 83 | } else { |
303 | 84 | if(database != null){ |
304 | - fldr = new File(DEFAULT_FOLDER + "/" + database.toUpperCase() + "_" + CmnUtils.getYmdhm()); | |
85 | + folder = new File(cp.DEFAULT_OUT_FOLDER + "/" + database.toUpperCase() + "_" + CmnUtils.getYmdhm()); | |
305 | 86 | } else { |
306 | - fldr = new File(DEFAULT_FOLDER + "/" + DB_TYPE_NAME[dbType].toUpperCase() + "_" + CmnUtils.getYmdhm()); | |
87 | + folder = new File(cp.DEFAULT_OUT_FOLDER + "/" + cp.DB_TYPE_NAME[cp.dbType].toUpperCase() + "_" + CmnUtils.getYmdhm()); | |
307 | 88 | } |
308 | - fldr.mkdir(); | |
89 | + folder.mkdir(); | |
309 | 90 | } |
310 | 91 | |
311 | - if(database!=null)CmnUtils.infoPrint("-->Database='" + database.toUpperCase() + "'"); | |
312 | - CmnUtils.infoPrint("-->Output='" + fldr + "'"); | |
313 | - if(!CmnUtils.isEmpty(prop_val[D_DELIMITER]))CmnUtils.infoPrint("-->Delimiter='" + prop_val[D_DELIMITER] + "'"); | |
314 | - if(!CmnUtils.isEmpty(prop_val[D_LINESEP]))CmnUtils.infoPrint("-->LineSeparator='" + prop_val[D_LINESEP] + "'"); | |
315 | - if(!CmnUtils.isEmpty(prop_val[D_FILENCODE]))CmnUtils.infoPrint("-->FileEncoding='" + prop_val[D_FILENCODE] + "'"); | |
316 | - if(!CmnUtils.isEmpty(prop_val[D_QUOTATION]))CmnUtils.infoPrint("-->Quotation=" + CmnUtils.getYesNo(isQuotation)); | |
317 | - if(!CmnUtils.isEmpty(prop_val[D_ORDER]))CmnUtils.infoPrint("-->Sort=" + CmnUtils.getYesNo(isOrder)); | |
318 | - if(isInclTables)CmnUtils.infoPrint("-->Include Tables='" + inclTables.toUpperCase() + "'"); | |
319 | - if(isExclTables)CmnUtils.infoPrint("-->Exclude Tables='" + exclTables.toUpperCase() + "'"); | |
320 | - if(isInclCols)CmnUtils.infoPrint("-->Include Columns='" + inclCols.toUpperCase() + "'"); | |
321 | - if(isExclCols)CmnUtils.infoPrint("-->Exclude Columns='" + exclCols.toUpperCase() + "'"); | |
322 | - if(isMask){ | |
323 | - CmnUtils.infoPrint("-->Masking=" + CmnUtils.getYesNo(isMask)); | |
324 | - CmnUtils.infoPrint("-->Masking Pattern=" + maskPattern.toUpperCase()); | |
325 | - if(isInclColsMask)CmnUtils.infoPrint("-->Masking Columns='" + inclMaskCols.toUpperCase() + "'"); | |
326 | - if(isExclColsMask)CmnUtils.infoPrint("-->Exclude Masking Columns='" + exclMaskCols.toUpperCase() + "'"); | |
327 | - CmnUtils.infoPrint("-->Single Byte Mask Char='" + singleByteMaskChar + "'"); | |
328 | - CmnUtils.infoPrint("-->Double Byte Mask Char='" + doubleByteMaskChar + "'"); | |
329 | - } | |
330 | - CmnUtils.infoPrint("Start DataUnload ---------------------------------------------"); | |
331 | - | |
332 | - dao.select(tkSql); | |
92 | + CmnUtils.infoPrint("-->出力先フォルダ='" + folder + "'"); | |
93 | + CmnUtils.infoPrint("データアンロードを開始しました。"); | |
94 | + dao = new DataAccessObjects(cp); | |
95 | + conn = dao.connect(); | |
96 | + dao.select(cp.tkSql); | |
333 | 97 | alData = dao.getArrayList(); |
334 | 98 | tb_count = dao.getColumnCount(); |
335 | 99 | orders = 0; |
@@ -338,22 +102,22 @@ public class RapideUnloader{ | ||
338 | 102 | for(int i=0;i<alData.size();i++){ |
339 | 103 | if ((i+1) % tb_count == 1){ |
340 | 104 | if ((i + 2 <alData.size()) && (!alData.get(i).equals(alData.get(i+2))) || (i + 2 == alData.size())) { |
341 | - if(isInclTables && !CmnUtils.isMatch(inclTablesArray,alData.get(i).toUpperCase())){ | |
342 | - CmnUtils.debugPrint("inclTables=" + inclTables); | |
343 | - CmnUtils.debugPrint("table=" + alData.get(i) + "," +CmnUtils.isMatch(inclTablesArray,alData.get(i).toUpperCase())); | |
105 | + if(cp.isInclTables && !CmnUtils.isMatch(cp.inclTablesArray,alData.get(i).toUpperCase())){ | |
106 | + CmnUtils.debugPrint("cp.inclTables=" + cp.inclTables); | |
107 | + CmnUtils.debugPrint("table=" + alData.get(i) + "," +CmnUtils.isMatch(cp.inclTablesArray,alData.get(i).toUpperCase())); | |
344 | 108 | orders = 0; |
345 | 109 | order_columns = ""; |
346 | 110 | continue; |
347 | 111 | } |
348 | - if(isExclTables && CmnUtils.isMatch(exclTablesArray,alData.get(i).toUpperCase())){ | |
349 | - CmnUtils.debugPrint("exclTables=" + exclTables); | |
350 | - CmnUtils.debugPrint("table=" + alData.get(i) + "," +CmnUtils.isMatch(exclTablesArray,alData.get(i).toUpperCase())); | |
112 | + if(cp.isExclTables && CmnUtils.isMatch(cp.exclTablesArray,alData.get(i).toUpperCase())){ | |
113 | + CmnUtils.debugPrint("cp.exclTables=" + cp.exclTables); | |
114 | + CmnUtils.debugPrint("table=" + alData.get(i) + "," +CmnUtils.isMatch(cp.exclTablesArray,alData.get(i).toUpperCase())); | |
351 | 115 | orders = 0; |
352 | 116 | order_columns = ""; |
353 | 117 | continue; |
354 | 118 | } |
355 | 119 | if (!alData.get(i+1).equals("")){ |
356 | - if(isOrder){ | |
120 | + if(cp.isOrder){ | |
357 | 121 | if (orders == 0){ |
358 | 122 | if (!alData.get(i+1).equals(""))order_columns = alData.get(i+1); |
359 | 123 | } else { |
@@ -362,7 +126,7 @@ public class RapideUnloader{ | ||
362 | 126 | orders++; |
363 | 127 | } |
364 | 128 | } |
365 | - if(isOrder){ | |
129 | + if(cp.isOrder){ | |
366 | 130 | if(!order_columns.equals("")){ |
367 | 131 | sql_unload = "select * from " + alData.get(i) + " order by " + order_columns; |
368 | 132 | } else { |
@@ -382,20 +146,20 @@ public class RapideUnloader{ | ||
382 | 146 | tb_col_count = dao.getColumnCount(); |
383 | 147 | for(int j=0;j<alColName.size();j++){ |
384 | 148 | if(CmnUtils.isColString(alColTypeName.get(j))){ |
385 | - if(isMask){ | |
149 | + if(cp.isMask){ | |
386 | 150 | if( |
387 | - (isInclColsMask && | |
388 | - !isExclColsMask && | |
389 | - CmnUtils.isMatch(inclColsMaskArray,alData.get(i).toUpperCase(),alColName.get(j).toUpperCase()) | |
151 | + (cp.isInclColsMask && | |
152 | + !cp.isExclColsMask && | |
153 | + CmnUtils.isMatch(cp.inclColsMaskArray,alData.get(i).toUpperCase(),alColName.get(j).toUpperCase()) | |
390 | 154 | ) || |
391 | - (isInclColsMask && | |
392 | - isExclColsMask && | |
393 | - CmnUtils.isMatch(inclColsMaskArray,alData.get(i).toUpperCase(),alColName.get(j).toUpperCase()) && | |
394 | - !CmnUtils.isMatch(exclColsMaskArray,alData.get(i).toUpperCase(),alColName.get(j).toUpperCase()) | |
155 | + (cp.isInclColsMask && | |
156 | + cp.isExclColsMask && | |
157 | + CmnUtils.isMatch(cp.inclColsMaskArray,alData.get(i).toUpperCase(),alColName.get(j).toUpperCase()) && | |
158 | + !CmnUtils.isMatch(cp.exclColsMaskArray,alData.get(i).toUpperCase(),alColName.get(j).toUpperCase()) | |
395 | 159 | ) || |
396 | - (!isInclColsMask && | |
397 | - isExclColsMask && | |
398 | - !CmnUtils.isMatch(exclColsMaskArray,alData.get(i).toUpperCase(),alColName.get(j).toUpperCase()) | |
160 | + (!cp.isInclColsMask && | |
161 | + cp.isExclColsMask && | |
162 | + !CmnUtils.isMatch(cp.exclColsMaskArray,alData.get(i).toUpperCase(),alColName.get(j).toUpperCase()) | |
399 | 163 | ) |
400 | 164 | ){ |
401 | 165 | CmnUtils.debugPrint("Mask Column=" + alColName.get(j).toUpperCase()); |
@@ -409,20 +173,20 @@ public class RapideUnloader{ | ||
409 | 173 | } else { |
410 | 174 | alColMask.add(false); |
411 | 175 | } |
412 | - if(isInclCols || isExclCols){ | |
176 | + if(cp.isInclCols || cp.isExclCols){ | |
413 | 177 | if( |
414 | - (isInclCols && | |
415 | - !isExclCols && | |
416 | - CmnUtils.isMatch(inclColsArray,alData.get(i).toUpperCase(), alColName.get(j).toUpperCase()) | |
178 | + (cp.isInclCols && | |
179 | + !cp.isExclCols && | |
180 | + CmnUtils.isMatch(cp.inclColsArray,alData.get(i).toUpperCase(), alColName.get(j).toUpperCase()) | |
417 | 181 | ) || |
418 | - (isInclCols && | |
419 | - isExclCols && | |
420 | - CmnUtils.isMatch(inclColsArray,alData.get(i).toUpperCase(), alColName.get(j).toUpperCase()) && | |
421 | - !CmnUtils.isMatch(exclColsArray,alData.get(i).toUpperCase(),alColName.get(j).toUpperCase()) | |
182 | + (cp.isInclCols && | |
183 | + cp.isExclCols && | |
184 | + CmnUtils.isMatch(cp.inclColsArray,alData.get(i).toUpperCase(), alColName.get(j).toUpperCase()) && | |
185 | + !CmnUtils.isMatch(cp.exclColsArray,alData.get(i).toUpperCase(),alColName.get(j).toUpperCase()) | |
422 | 186 | ) || |
423 | - (!isInclCols && | |
424 | - isExclCols && | |
425 | - !CmnUtils.isMatch(exclColsArray,alData.get(i).toUpperCase(),alColName.get(j).toUpperCase()) | |
187 | + (!cp.isInclCols && | |
188 | + cp.isExclCols && | |
189 | + !CmnUtils.isMatch(cp.exclColsArray,alData.get(i).toUpperCase(),alColName.get(j).toUpperCase()) | |
426 | 190 | ) |
427 | 191 | ){ |
428 | 192 | CmnUtils.debugPrint("column=" + alColName.get(j).toUpperCase()); |
@@ -455,12 +219,12 @@ public class RapideUnloader{ | ||
455 | 219 | dao.setArrayColumnMaskList(alColMask); |
456 | 220 | |
457 | 221 | if (lastCol >= 0){ |
458 | - pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fldr + "/" + alData.get(i) + ".csv"), fileEncoding))); | |
222 | + pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(folder + "/" + alData.get(i) + ".csv"), cp.fileEncoding))); | |
459 | 223 | CmnUtils.infoPrinting(String.format("%1$-30s",alData.get(i))); |
460 | 224 | |
461 | 225 | for(int j=0;j<alColName.size();j++){ |
462 | 226 | if(j==firstCol){ |
463 | - if(isQuotation){ | |
227 | + if(cp.isQuotation){ | |
464 | 228 | pw.print("\"" + alColName.get(j)); |
465 | 229 | } else { |
466 | 230 | pw.print(alColName.get(j)); |
@@ -469,24 +233,24 @@ public class RapideUnloader{ | ||
469 | 233 | if(colIncl[j])pw.print(alColName.get(j)); |
470 | 234 | } |
471 | 235 | if (firstCol == lastCol){ |
472 | - if(isQuotation){ | |
473 | - pw.print("\"" + lineSeparator); | |
236 | + if(cp.isQuotation){ | |
237 | + pw.print("\"" + cp.lineSeparator); | |
474 | 238 | } else { |
475 | - pw.print("" + lineSeparator); | |
239 | + pw.print("" + cp.lineSeparator); | |
476 | 240 | } |
477 | 241 | } else { |
478 | 242 | if (j==lastCol){ |
479 | - if(isQuotation){ | |
480 | - pw.print("\"" + lineSeparator); | |
243 | + if(cp.isQuotation){ | |
244 | + pw.print("\"" + cp.lineSeparator); | |
481 | 245 | } else { |
482 | - pw.print("" + lineSeparator); | |
246 | + pw.print("" + cp.lineSeparator); | |
483 | 247 | } |
484 | 248 | } else { |
485 | 249 | if(colIncl[j]){ |
486 | - if(isQuotation){ | |
487 | - pw.print("\"" + delimiter + "\""); | |
250 | + if(cp.isQuotation){ | |
251 | + pw.print("\"" + cp.delimiter + "\""); | |
488 | 252 | } else { |
489 | - pw.print(delimiter); | |
253 | + pw.print(cp.delimiter); | |
490 | 254 | } |
491 | 255 | } |
492 | 256 | } |
@@ -496,13 +260,13 @@ public class RapideUnloader{ | ||
496 | 260 | dao.closeRecordSet(); |
497 | 261 | pw.close(); |
498 | 262 | pw = null; |
499 | - System.out.println(String.format("%1$10d",dao.getRecCount()) + " rows exported"); | |
263 | + System.out.println(String.format("%1$10d",dao.getRecCount()) + " 行 アンロードされました。"); | |
500 | 264 | } |
501 | 265 | orders = 0; |
502 | 266 | order_columns = ""; |
503 | 267 | } else { |
504 | 268 | if (!alData.get(i+1).equals("")){ |
505 | - if(isOrder){ | |
269 | + if(cp.isOrder){ | |
506 | 270 | if (orders == 0){ |
507 | 271 | if (!alData.get(i+1).equals(""))order_columns = alData.get(i+1); |
508 | 272 | } else { |
@@ -517,17 +281,27 @@ public class RapideUnloader{ | ||
517 | 281 | } |
518 | 282 | } |
519 | 283 | |
520 | - dao.disconnect(); | |
284 | + CmnUtils.infoPrint("データアンロードを終了しました。"); | |
521 | 285 | |
522 | 286 | } catch (Exception e) { |
523 | - throw e; | |
287 | + try{ | |
288 | + CmnUtils.errorPrint(e.toString()); | |
289 | + e.printStackTrace(); | |
290 | + dao.rollback(); | |
291 | + } catch (Exception ee) {} | |
524 | 292 | } finally{ |
525 | - if(pw!=null){ | |
526 | - pw.close(); | |
527 | - pw=null; | |
528 | - } | |
293 | + try{ | |
294 | + dao.disconnect(); | |
295 | + if(stmt != null){ | |
296 | + stmt.close(); | |
297 | + stmt=null; | |
298 | + } | |
299 | + if(pw!=null){ | |
300 | + pw.close(); | |
301 | + pw=null; | |
302 | + } | |
303 | + } catch (Exception e) {} | |
529 | 304 | } |
530 | - CmnUtils.infoPrint("End DataUnload -----------------------------------------------"); | |
531 | 305 | } |
532 | 306 | |
533 | 307 |