• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Revisiónc5ac56eaf49b9af216f9d532789b18e7cd356df0 (tree)
Tiempo2017-01-28 08:54:40
Autorkuboryu <kuboryu@yaho...>
Commiterkuboryu

Log Message

20170128

Cambiar Resumen

Diferencia incremental

--- a/com/rapide_act/CmnProperty.java
+++ b/com/rapide_act/CmnProperty.java
@@ -73,7 +73,8 @@ public class CmnProperty{
7373 protected String [] prop_val = new String[KEYS];
7474 protected static final String [] MASK_PTN = {"ALL", "ALT", "EDGE"};
7575 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";
7778 protected static String [] tSqlArray = {
7879 "select "
7980 + " table_name "
@@ -162,7 +163,7 @@ public class CmnProperty{
162163 Properties prop = null;
163164 try {
164165 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"));
166167 prop.load(br);
167168 for(int i=0;i<KEYS;i++){
168169 prop_val[i] = prop.getProperty(database + "." +PROP_KEY[i]);
@@ -170,7 +171,7 @@ public class CmnProperty{
170171 br.close();
171172 br = null;
172173 } catch (NullPointerException e) {
173- throw new Exception("Property File (" + _propFile +") Not Found");
174+ throw new Exception("プロパティファイルが見つかりません。[" + _propFile +"]");
174175 } catch (IOException e) {
175176 throw e;
176177 }
@@ -222,7 +223,7 @@ public class CmnProperty{
222223 if(!CmnUtils.isEmpty(prop_val[D_TBLKEYSQL]))tkSql = prop_val[D_TBLKEYSQL];
223224 if(!CmnUtils.isEmpty(prop_val[D_ORDER]) && prop_val[D_ORDER].toUpperCase().equals("Y"))isOrder = true;
224225 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]);
226227 if(!CmnUtils.isEmpty(prop_val[D_INCLTAB]))isInclTables = true;
227228 if(!CmnUtils.isEmpty(prop_val[D_EXCLTAB]))isExclTables = true;
228229 if(!CmnUtils.isEmpty(prop_val[D_INCLCOL]))isInclCols = true;
@@ -246,14 +247,14 @@ public class CmnProperty{
246247 if(!CmnUtils.isEmpty(prop_val[D_DBYTEMASKCHR]))doubleByteMaskChar = prop_val[D_DBYTEMASKCHR].charAt(0);
247248 if(!CmnUtils.isEmpty(prop_val[D_MASKPTN]))maskPattern = prop_val[D_MASKPTN];
248249
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(ドライバ)が未指定です。");
257258 }
258259
259260 for(int i = 0;i<DB_TYPE_NAME.length;i++){
@@ -266,21 +267,13 @@ public class CmnProperty{
266267 if (dbType != DB_TYPE_UNKNOWN){
267268 if(!CmnUtils.isEmpty(prop_val[D_TBLSQL])){
268269 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])){
278270 tkSql = prop_val[D_TBLKEYSQL];
279271 } else {
272+ tSql = tSqlArray[dbType];
280273 tkSql = tkSqlArray[dbType];
281274 }
282275 } else {
283- throw new Exception("dbtype unknown");
276+ throw new Exception("データベース製品が識別できません。[" + url + "]");
284277 }
285278
286279 if(database!=null)CmnUtils.infoPrint("-->対象データベース='" + database.toUpperCase() + "'");
--- a/com/rapide_act/CmnUtils.java
+++ b/com/rapide_act/CmnUtils.java
@@ -431,6 +431,16 @@ public class CmnUtils{
431431 }
432432 }
433433
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+
434444 public static String[] getSystemProperty(String _str) throws Exception{
435445 String [] retValue = null;
436446 if(System.getProperty(_str)!=null){
--- a/com/rapide_act/DataAccessObjects.java
+++ b/com/rapide_act/DataAccessObjects.java
@@ -61,57 +61,10 @@ public class DataAccessObjects{
6161 private byte [] colBytes = null;
6262 private Blob colBlob = null;
6363 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;
7364 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+
11568 DataAccessObjects(String _user, String _pass, String _url, String _driver){
11669 user = _user;
11770 pass = _pass;
@@ -119,6 +72,14 @@ public class DataAccessObjects{
11972 driver = _driver;
12073 }
12174
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+
12283 public Connection connect() throws Exception{
12384
12485 try {
@@ -298,20 +259,6 @@ public class DataAccessObjects{
298259 tbName = _tbName;
299260 }
300261
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-
315262 public ResultSet getResultSet() throws Exception{
316263 return rst;
317264 }
@@ -353,31 +300,31 @@ public class DataAccessObjects{
353300
354301 if (colString != null) {
355302 if (i == _firstCol){
356- if(isQuotation){
303+ if(cp.isQuotation){
357304 if (_firstCol == _lastCol){
358- _pw.print("\"" + colString + "\"" + lnSprtr);
305+ _pw.print("\"" + colString + "\"" + cp.lineSeparator);
359306 } else {
360307 _pw.print("\"" + colString);
361308 }
362309 } else {
363310 if (_firstCol == _lastCol){
364- _pw.print(colString + lnSprtr);
311+ _pw.print(colString + cp.lineSeparator);
365312 } else {
366313 _pw.print(colString);
367314 }
368315 }
369316
370317 } 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);
373320 } else {
374- _pw.print(delimiter + colString + lnSprtr);
321+ _pw.print(cp.delimiter + colString + cp.lineSeparator);
375322 }
376323 } else {
377- if(isQuotation){
378- _pw.print("\"" + delimiter + "\"" + colString);
324+ if(cp.isQuotation){
325+ _pw.print("\"" + cp.delimiter + "\"" + colString);
379326 } else {
380- _pw.print(delimiter + colString);
327+ _pw.print(cp.delimiter + colString);
381328 }
382329 }
383330
@@ -385,30 +332,30 @@ public class DataAccessObjects{
385332
386333 } else {
387334 if (i == _firstCol){
388- if(isQuotation){
335+ if(cp.isQuotation){
389336 if (_firstCol == _lastCol){
390- _pw.print("\"" + nullMark + "\"" + lnSprtr);
337+ _pw.print("\"" + cp.nullMark + "\"" + cp.lineSeparator);
391338 } else {
392- _pw.print("\"" + nullMark);
339+ _pw.print("\"" + cp.nullMark);
393340 }
394341 } else {
395342 if (_firstCol == _lastCol){
396- _pw.print(nullMark + lnSprtr);
343+ _pw.print(cp.nullMark + cp.lineSeparator);
397344 } else {
398- _pw.print(nullMark);
345+ _pw.print(cp.nullMark);
399346 }
400347 }
401348 } 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);
404351 } else {
405- _pw.print(delimiter + nullMark + lnSprtr);
352+ _pw.print(cp.delimiter + cp.nullMark + cp.lineSeparator);
406353 }
407354 } else {
408- if(isQuotation){
409- _pw.print("\"" + delimiter + "\"" + nullMark);
355+ if(cp.isQuotation){
356+ _pw.print("\"" + cp.delimiter + "\"" + cp.nullMark);
410357 } else {
411- _pw.print(delimiter + nullMark);
358+ _pw.print(cp.delimiter + cp.nullMark);
412359 }
413360 }
414361 }
@@ -445,26 +392,26 @@ public class DataAccessObjects{
445392 if (CmnUtils.isColString(_colTypeName)) {
446393 colString = _rst.getString(_rec_cnt);
447394 if (colString != null) {
448- if(isQuotation){
395+ if(cp.isQuotation){
449396 colString =colString.trim().replaceAll("\0","").replaceAll("\"","\"\"");
450397 } else {
451398 colString =colString.trim().replaceAll("\0","");
452399 }
453- if(isMask){
400+ if(cp.isMask){
454401 if(_colMask==true){
455402 StringBuffer sb = new StringBuffer();
456403 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]) &&
458405 (j % 2) == 1) ||
459- (maskPtn.toUpperCase().equals(MASK_PTN[MASK_PTN_EDGE]) &&
406+ (cp.maskPattern.toUpperCase().equals(cp.MASK_PTN[cp.MASK_PTN_EDGE]) &&
460407 !(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]))
462409 )
463410 ){
464411 if(CmnUtils.isHankaku(colString.charAt(j))){
465- sb.append(singleByteChr);
412+ sb.append(cp.singleByteMaskChar);
466413 } else {
467- sb.append(doubleByteChr);
414+ sb.append(cp.doubleByteMaskChar);
468415 }
469416 } else {
470417 sb.append(colString.charAt(j));
--- a/com/rapide_act/RapideLoader.java
+++ b/com/rapide_act/RapideLoader.java
@@ -50,12 +50,12 @@ public class RapideLoader{
5050 }
5151
5252
53- RapideLoader(String _database) throws Exception{
53+ RapideLoader(String _database) {
5454 super();
5555 database = _database;
5656 }
5757
58- private void load() throws Exception{
58+ private void load(){
5959 Connection conn = null;
6060 PreparedStatement stmt = null;
6161 PreparedStatement stmt_ins = null;
@@ -85,14 +85,12 @@ public class RapideLoader{
8585 int fl_col_count = 0;
8686 boolean isLob = false;
8787 boolean isContinue = false;
88+ CmnProperty cp = null;
89+ DataAccessObjects dao = null;
8890
89- CmnProperty cp = new CmnProperty();
90- cp.setProperty(database);
91-
92- DataAccessObjects dao = new DataAccessObjects(cp.user, cp.pass, cp.url, cp.driver);
9391 try {
94- conn = dao.connect();
95- conn.setAutoCommit(false);
92+ cp = new CmnProperty();
93+ cp.setProperty(database);
9694
9795 if(cp.inFolder != null){
9896 folder = new File(cp.inFolder);
@@ -103,9 +101,11 @@ public class RapideLoader{
103101 folder = new File(cp.DEFAULT_IN_FOLDER + "/" + cp.DB_TYPE_NAME[cp.dbType].toUpperCase());
104102 }
105103 }
106- CmnUtils.infoPrint("-->入力元='" + folder + "'");
104+ CmnUtils.infoPrint("-->入力元フォルダ='" + folder + "'");
107105 CmnUtils.infoPrint("データロードを開始しました。");
108-
106+ dao = new DataAccessObjects(cp);
107+ conn = dao.connect();
108+ conn.setAutoCommit(false);
109109 dao.select(cp.tSql);
110110 alData = dao.getArrayList();
111111 tb_count = dao.getColumnCount();
@@ -202,7 +202,6 @@ public class RapideLoader{
202202 }
203203
204204 colIncl = (Boolean[])alColIncl.toArray(new Boolean[0]);
205-
206205 sql_insert = "INSERT INTO " + tbName + "(";
207206 for(int j=0;j<colData.length;j++){
208207 for(int l=0;l<tb_col_count;l++){
@@ -237,7 +236,7 @@ public class RapideLoader{
237236 CmnUtils.infoPrinting(String.format("%1$-30s",tbName));
238237 } else {
239238 dao.rollback();
240- CmnUtils.debugPrint("column count is zero");
239+ CmnUtils.debugPrint("指定した区切り文字でのカラム数が0です。");
241240 if(br != null){
242241 br.close();
243242 br=null;
@@ -257,7 +256,7 @@ public class RapideLoader{
257256 if(colData.length == fl_col_count){
258257 if(!strMltLine.equals("")){
259258 dao.rollback();
260- System.out.println(String.format("%1$10d",tb_rec_count) + " ERROR:column count is unmatch");
259+ CmnUtils.errorPrint("該当レコードのカラム数がアンマッチです。[" + tb_rec_count + "]");
261260 CmnUtils.debugPrint("************Record End");
262261 if(br != null){
263262 br.close();
@@ -286,7 +285,7 @@ public class RapideLoader{
286285 isContinue = false;
287286 } else if(colData.length >fl_col_count){
288287 dao.rollback();
289- CmnUtils.errorPrint(String.format("%1$10d",tb_rec_count) + "column count is unmatch");
288+ CmnUtils.errorPrint("該当レコードのカラム数がアンマッチです。[" + tb_rec_count + "]");
290289 CmnUtils.debugPrint("************Record End");
291290 if(br != null){
292291 br.close();
@@ -432,7 +431,7 @@ public class RapideLoader{
432431 stmt_ins.setClob(j+1,null,0);
433432 }
434433 } else {
435- CmnUtils.errorPrint("unmatch column type=" + colTypeName[tb_col_seq[j]]);
434+ CmnUtils.errorPrint("カラムのデータ型が対象外です。[" + colTypeName[tb_col_seq[j]] + "]");
436435 break TABLE_LOOP;
437436 }
438437 }
@@ -453,7 +452,7 @@ public class RapideLoader{
453452 }
454453 if(!isLob)stmt_ins.executeBatch();
455454 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) + " 行 ロードされました。");
457456 CmnUtils.debugPrint("************Record End");
458457 if(br != null){
459458 br.close();
@@ -468,31 +467,33 @@ public class RapideLoader{
468467 }
469468 }
470469 } else {
471- throw new Exception("Folder Not Found(" + folder + ")");
470+ CmnUtils.errorPrint("入力元フォルダが見つかりません。[" + folder + "]");
472471 }
473472
474- dao.disconnect();
473+ CmnUtils.infoPrint("データロードを終了しました。");
475474
476475 } 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) {}
479481 } 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) {}
492497 }
493- CmnUtils.infoPrint("データロードを終了しました。");
494498 }
495-
496-
497499 }
498-
--- a/com/rapide_act/RapideUnloader.java
+++ b/com/rapide_act/RapideUnloader.java
@@ -30,121 +30,6 @@ import java.sql.Timestamp;
3030 public class RapideUnloader{
3131
3232 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- };
14833
14934 public static void main(String args[]){
15035 try {
@@ -160,43 +45,14 @@ public class RapideUnloader{
16045 }
16146 }
16247
163- RapideUnloader(String _database) throws Exception{
48+ RapideUnloader(String _database) {
16449 super();
16550 database = _database;
16651
16752 }
16853
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- }
19854
199- private void unload() throws Exception{
55+ private void unload() {
20056 Connection conn = null;
20157 PreparedStatement stmt = null;
20258 ResultSet rst = null;
@@ -204,10 +60,9 @@ public class RapideUnloader{
20460 String sql_insert = null;
20561 String order_columns = "";
20662 int orders = 0;
207- int dbType = DB_TYPE_UNKNOWN;
20863
20964 PrintWriter pw = null;
210- File fldr = null;
65+ File folder = null;
21166 ArrayList<String> alColName = null;
21267 ArrayList<String> alColTypeName = null;
21368 ArrayList<Integer> alIsNullable = null;
@@ -216,120 +71,29 @@ public class RapideUnloader{
21671 ArrayList<String> alData = null;
21772 int tb_count = 0;
21873 int tb_col_count = 0;
74+ CmnProperty cp = null;
75+ DataAccessObjects dao = null;
21976
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);
29777 try {
298- conn = dao.connect();
78+ cp = new CmnProperty();
79+ cp.setProperty(database);
29980
300- if(outFolder != null){
301- fldr = new File(outFolder);
81+ if(cp.outFolder != null){
82+ folder = new File(cp.outFolder);
30283 } else {
30384 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());
30586 } 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());
30788 }
308- fldr.mkdir();
89+ folder.mkdir();
30990 }
31091
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);
33397 alData = dao.getArrayList();
33498 tb_count = dao.getColumnCount();
33599 orders = 0;
@@ -338,22 +102,22 @@ public class RapideUnloader{
338102 for(int i=0;i<alData.size();i++){
339103 if ((i+1) % tb_count == 1){
340104 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()));
344108 orders = 0;
345109 order_columns = "";
346110 continue;
347111 }
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()));
351115 orders = 0;
352116 order_columns = "";
353117 continue;
354118 }
355119 if (!alData.get(i+1).equals("")){
356- if(isOrder){
120+ if(cp.isOrder){
357121 if (orders == 0){
358122 if (!alData.get(i+1).equals(""))order_columns = alData.get(i+1);
359123 } else {
@@ -362,7 +126,7 @@ public class RapideUnloader{
362126 orders++;
363127 }
364128 }
365- if(isOrder){
129+ if(cp.isOrder){
366130 if(!order_columns.equals("")){
367131 sql_unload = "select * from " + alData.get(i) + " order by " + order_columns;
368132 } else {
@@ -382,20 +146,20 @@ public class RapideUnloader{
382146 tb_col_count = dao.getColumnCount();
383147 for(int j=0;j<alColName.size();j++){
384148 if(CmnUtils.isColString(alColTypeName.get(j))){
385- if(isMask){
149+ if(cp.isMask){
386150 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())
390154 ) ||
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())
395159 ) ||
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())
399163 )
400164 ){
401165 CmnUtils.debugPrint("Mask Column=" + alColName.get(j).toUpperCase());
@@ -409,20 +173,20 @@ public class RapideUnloader{
409173 } else {
410174 alColMask.add(false);
411175 }
412- if(isInclCols || isExclCols){
176+ if(cp.isInclCols || cp.isExclCols){
413177 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())
417181 ) ||
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())
422186 ) ||
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())
426190 )
427191 ){
428192 CmnUtils.debugPrint("column=" + alColName.get(j).toUpperCase());
@@ -455,12 +219,12 @@ public class RapideUnloader{
455219 dao.setArrayColumnMaskList(alColMask);
456220
457221 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)));
459223 CmnUtils.infoPrinting(String.format("%1$-30s",alData.get(i)));
460224
461225 for(int j=0;j<alColName.size();j++){
462226 if(j==firstCol){
463- if(isQuotation){
227+ if(cp.isQuotation){
464228 pw.print("\"" + alColName.get(j));
465229 } else {
466230 pw.print(alColName.get(j));
@@ -469,24 +233,24 @@ public class RapideUnloader{
469233 if(colIncl[j])pw.print(alColName.get(j));
470234 }
471235 if (firstCol == lastCol){
472- if(isQuotation){
473- pw.print("\"" + lineSeparator);
236+ if(cp.isQuotation){
237+ pw.print("\"" + cp.lineSeparator);
474238 } else {
475- pw.print("" + lineSeparator);
239+ pw.print("" + cp.lineSeparator);
476240 }
477241 } else {
478242 if (j==lastCol){
479- if(isQuotation){
480- pw.print("\"" + lineSeparator);
243+ if(cp.isQuotation){
244+ pw.print("\"" + cp.lineSeparator);
481245 } else {
482- pw.print("" + lineSeparator);
246+ pw.print("" + cp.lineSeparator);
483247 }
484248 } else {
485249 if(colIncl[j]){
486- if(isQuotation){
487- pw.print("\"" + delimiter + "\"");
250+ if(cp.isQuotation){
251+ pw.print("\"" + cp.delimiter + "\"");
488252 } else {
489- pw.print(delimiter);
253+ pw.print(cp.delimiter);
490254 }
491255 }
492256 }
@@ -496,13 +260,13 @@ public class RapideUnloader{
496260 dao.closeRecordSet();
497261 pw.close();
498262 pw = null;
499- System.out.println(String.format("%1$10d",dao.getRecCount()) + " rows exported");
263+ System.out.println(String.format("%1$10d",dao.getRecCount()) + " 行 アンロードされました。");
500264 }
501265 orders = 0;
502266 order_columns = "";
503267 } else {
504268 if (!alData.get(i+1).equals("")){
505- if(isOrder){
269+ if(cp.isOrder){
506270 if (orders == 0){
507271 if (!alData.get(i+1).equals(""))order_columns = alData.get(i+1);
508272 } else {
@@ -517,17 +281,27 @@ public class RapideUnloader{
517281 }
518282 }
519283
520- dao.disconnect();
284+ CmnUtils.infoPrint("データアンロードを終了しました。");
521285
522286 } catch (Exception e) {
523- throw e;
287+ try{
288+ CmnUtils.errorPrint(e.toString());
289+ e.printStackTrace();
290+ dao.rollback();
291+ } catch (Exception ee) {}
524292 } 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) {}
529304 }
530- CmnUtils.infoPrint("End DataUnload -----------------------------------------------");
531305 }
532306
533307