1 package com.rapide_act;
3 import java.io.BufferedInputStream;
4 import java.io.BufferedReader;
5 import java.io.BufferedWriter;
6 import java.io.FileInputStream;
7 import java.io.InputStream;
8 import java.io.InputStreamReader;
9 import java.io.IOException;
11 import java.io.FileReader;
12 import java.io.FileWriter;
13 import java.io.PrintWriter;
14 import java.io.PrintWriter;
15 import java.util.Date;
16 import java.util.ArrayList;
17 import java.util.Iterator;
18 import java.util.Properties;
21 import java.sql.Connection;
22 import java.sql.DriverManager;
23 import java.sql.PreparedStatement;
24 import java.sql.ResultSet;
25 import java.sql.ResultSetMetaData;
26 import java.sql.SQLException;
27 import java.sql.Timestamp;
28 import java.math.BigDecimal;
30 public class CmnProperty{
31 protected String database = null;
32 protected static final int DB_TYPE_ORACLE = 0;
33 protected static final int DB_TYPE_SQLSERVER = 1;
34 protected static final int DB_TYPE_MYSQL = 2;
35 protected static final int DB_TYPE_DB2 = 3;
36 protected static final int DB_TYPE_POSTGRESQL = 4;
37 protected static final int DB_TYPE_HIRDB = 5;
38 protected static final int DB_TYPE_UNKNOWN = -1;
39 protected static final String [] DB_TYPE_NAME = {"ORACLE", "SQLSERVER", "MYSQL", "DB2", "POSTGRESQL", "HIRDB"};
40 protected static final String [] DB_SQL_QUOTED = {"\"", "\"", "`", "\"", "\"", "\""};
41 protected static final int MASK_PTN_ALL = 0;
42 protected static final int MASK_PTN_ALT = 1;
43 protected static final int MASK_PTN_EDGE = 2;
44 protected static final int D_USER = 0;
45 protected static final int D_PASS = 1;
46 protected static final int D_URL = 2;
47 protected static final int D_DRIVER = 3;
48 protected static final int D_OUTPUT = 4;
49 protected static final int D_INPUT = 5;
50 protected static final int D_LINESEP = 6;
51 protected static final int D_INLINESEP = 7;
52 protected static final int D_FILENCODE = 8;
53 protected static final int D_NULLMARK = 9;
54 protected static final int D_DELIMITER = 10;
55 protected static final int D_TBLSQL = 11;
56 protected static final int D_TBLKEYSQL = 12;
57 protected static final int D_ORDER = 13;
58 protected static final int D_QUOTATION = 14;
59 protected static final int D_BATCOUNT = 15;
60 protected static final int D_INCLTAB = 16;
61 protected static final int D_EXCLTAB = 17;
62 protected static final int D_INCLCOL = 18;
63 protected static final int D_EXCLCOL = 19;
64 protected static final int D_INCLCOLMASK = 20;
65 protected static final int D_EXCLCOLMASK = 21;
66 protected static final int D_SBYTEMASKCHR = 22;
67 protected static final int D_DBYTEMASKCHR = 23;
68 protected static final int D_MASKPTN = 24;
69 protected static final int D_PROPFILE = 25;
70 protected static final int D_SPCPADDING = 26;
71 protected static final int D_FILEEXT = 27;
72 protected static final int D_SQLQUOTED = 28;
73 protected static final int D_PHYSICAL = 29;
74 protected static final int D_DROP = 30;
75 protected static final int KEYS = 31;
76 protected 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","sp","ext","sq", "ph", "dp"};
80 protected String [] prop_val = new String[KEYS];
81 protected static final String [] MASK_PTN = {"ALL", "ALT", "EDGE"};
82 protected static final String DEFAULT_IN_FOLDER = "input";
83 protected static final String DEFAULT_OUT_FOLDER = "output";
84 protected static final String DEFAULT_PROP_FILE = "RapideAct.properties";
86 protected static final int CREATE_TABLE = 0;
87 protected static final int DROP_TABLE = 1;
88 protected static final int TRUNCATE_TABLE = 2;
89 protected static final int CREATE_PKEY = 3;
90 protected static final int DROP_PKEY = 4;
91 protected static final int CREATE_UKEY = 5;
92 protected static final int DROP_UKEY = 6;
93 protected static final int CREATE_INDEX = 7;
94 protected static final int DROP_INDEX = 8;
95 protected static final int CREATE_VIEW = 9;
96 protected static final int DROP_VIEW = 10;
97 protected static final int CREATE_PROCEDURE = 11;
98 protected static final int DROP_PROCEDURE = 12;
99 protected static final int CREATE_SYNONYM = 13;
100 protected static final int DROP_SYNONYM = 14;
101 protected static final int CREATE_SEQUENCE = 15;
102 protected static final int DROP_SEQUENCE = 16;
103 protected static final int CREATE_FK = 17;
104 protected static final int DROP_FK = 18;
106 protected static final String [] SQL_FILE_NAME = {
110 "createPrimaryKey.sql",
111 "dropPrimaryKey.sql",
112 "createUniqueKey.sql",
118 "createProcedure.sql",
122 "createSequence.sql",
128 protected static final String [] T_SQL_ARRAY = {
131 + " from user_tables "
132 + " order by table_name",
134 + " name as table_name "
135 + " from sys.tables "
139 + " from information_schema.tables "
140 + " where table_type = 'BASE TABLE' and table_schema = database() "
141 + " order by table_name",
144 + " from syscat.tables "
145 + " where tabschema = current_schema and ownertype = 'U' and type = 'T' "
146 + " order by tabname",
149 + " from information_schema.tables "
150 + " where table_type = 'BASE TABLE' and table_schema = current_schema() "
151 + " order by table_name",
154 + " from master.sql_tables "
155 + " where table_type = 'BASE TABLE' and table_schema=current_user "
156 + " order by table_name"
158 protected static final String [] TK_SQL_ARRAY = {
162 + " from user_tables a,"
163 + " (select b.table_name, "
166 + " from user_constraints b, "
167 + " user_cons_columns c "
168 + " where b.constraint_type = 'P' and "
169 + " b.table_name = c.table_name and "
170 + " b.constraint_name = c.constraint_name "
172 + "where a.table_name = d.table_name(+) "
173 + "order by a.table_name, d.position",
175 + " a.name as table_name, "
176 + " d.name as col_name "
177 + "from sys.tables as a "
178 + "left outer join sys.key_constraints as b "
179 + "on a.object_id = b.parent_object_id "
180 + " and b.type = 'PK' "
181 + "left outer join sys.index_columns as c "
182 + "on b.parent_object_id = c.object_id "
183 + " and b.unique_index_id = c.index_id "
184 + "left outer join sys.columns as d "
185 + "on c.object_id = d.object_id "
186 + " and c.column_id = d.column_id "
187 + "order by a.name,c.key_ordinal",
197 + " information_schema.tables "
198 + " where table_type = 'BASE TABLE' and table_schema = database()"
200 + " left outer join information_schema.key_column_usage b "
201 + " on a.table_schema = b.table_schema "
202 + " and a.table_name = b.table_name "
203 + " and b.constraint_name = 'PRIMARY' "
205 + " a.table_name,b.ordinal_position",
217 + " tabschema = current_schema"
218 + " and ownertype = 'U'"
221 + " left outer join "
229 + " syscat.keycoluse c,"
230 + " syscat.tabconst d"
232 + " c.tabschema = current_schema"
233 + " and c.tabschema = d.tabschema"
234 + " and c.constname = d.constname"
235 + " and d.type = 'P'"
236 + " group by c.tabschema,c.tabname,c.colname,c.colseq"
238 + " on a.tabschema = b.tabschema and a.tabname = b.tabname"
239 + " order by a.tabname,b.colseq",
249 + " information_schema.tables a"
250 + " where table_type = 'BASE TABLE' and table_schema = current_schema()"
252 + " left outer join "
255 + " b1.table_schema,"
258 + " b2.ordinal_position"
260 + " information_schema.table_constraints b1,"
261 + " information_schema.key_column_usage b2"
263 + " b1.table_schema = current_schema() and"
264 + " b1.table_catalog = current_database() and"
265 + " b1.constraint_type = 'PRIMARY KEY' and"
266 + " b1.table_catalog = b2.table_catalog and"
267 + " b1.table_schema = b2.table_schema and"
268 + " b1.table_name = b2.table_name and"
269 + " b1.constraint_name = b2.constraint_name"
271 + " on a.table_schema = b.table_schema "
272 + " and a.table_name = b.table_name "
274 + " a.table_name,b.ordinal_position",
283 + " master.sql_tables a1 "
285 + " a1.table_schema=current_user and "
286 + " a1.table_type='BASE TABLE' "
295 + " master.sql_tables c, "
296 + " master.sql_columns d "
298 + " c.table_schema=current_user and "
299 + " c.table_type='BASE TABLE' and "
300 + " c.table_schema=d.table_schema and "
301 + " c.table_name=d.table_name and "
302 + " d.cluster_key = 'Y' "
309 + " a.table_name=b.table_name "
315 protected String user = null;
316 protected String pass = null;
317 protected String url = null;
318 protected String driver = null;
319 protected String outFolder = null;
320 protected String inFolder = null;
321 protected String lineSeparator = System.getProperty("line.separator");
322 protected String inColLineSeparator = System.getProperty("line.separator");
323 protected String fileEncoding = System.getProperty("file.encoding");
324 protected String nullMark = "";
325 protected String delimiter = "\t";
326 protected String fileExtension = "tsv";
327 protected boolean isSpcPadding = false;
328 protected String sqlQuoted = null;
329 protected String tSql = null;
330 protected String tkSql = null;
331 protected boolean isOrder = false;
332 protected boolean isQuotation = true;
333 protected boolean isPhysical = false;
334 protected boolean isDrop = false;
335 protected int batchCount = 1000;
336 protected String inclTables = null;
337 protected String exclTables = null;
338 protected String inclCols = null;
339 protected String exclCols = null;
340 protected String inclColsMask = null;
341 protected String exclColsMask = null;
342 protected char singleByteMaskChar = '*';
343 protected char doubleByteMaskChar = '\u25A0';
344 protected String maskPattern = "ALT";
346 protected String [] inclTablesArray = null;
347 protected String [] exclTablesArray = null;
348 protected String [] inclColsArray = null;
349 protected String [] exclColsArray = null;
350 protected String [] inclColsMaskArray = null;
351 protected String [] exclColsMaskArray = null;
352 protected boolean isInclTables = false;
353 protected boolean isExclTables = false;
354 protected boolean isInclCols = false;
355 protected boolean isExclCols = false;
356 protected boolean isMask = false;
357 protected boolean isInclColsMask = false;
358 protected boolean isExclColsMask = false;
359 protected int dbType = DB_TYPE_UNKNOWN;
361 protected void getProperties(String _propFile) throws Exception{
362 BufferedReader br = null;
363 Properties prop = null;
365 prop = new Properties();
366 br = new BufferedReader(new InputStreamReader(CmnProperty.class.getClassLoader().getResourceAsStream(_propFile), "UTF-8"));
368 for(int i=0;i<KEYS;i++){
369 prop_val[i] = prop.getProperty(database + "." +PROP_KEY[i]);
373 } catch (NullPointerException e) {
374 throw new Exception("
\83v
\83\8d\83p
\83e
\83B
\83t
\83@
\83C
\83\8b\82ª
\8c©
\82Â
\82©
\82è
\82Ü
\82¹
\82ñ
\81B[" + _propFile +"]");
375 } catch (IOException e) {
385 catch (IOException e) {
396 protected void setProperty(String _database) throws Exception{
397 database = _database;
398 if(database != null){
399 if(!CmnUtils.isEmpty(prop_val[D_PROPFILE])){
400 getProperties(System.getProperty(prop_val[D_PROPFILE]));
402 getProperties(DEFAULT_PROP_FILE);
406 for(int i=0;i<KEYS;i++){
407 if(System.getProperty(PROP_KEY[i])!=null)prop_val[i] = System.getProperty(PROP_KEY[i]);
408 CmnUtils.debugPrint(PROP_KEY[i] + "=" + prop_val[i]);
411 if(!CmnUtils.isEmpty(prop_val[D_USER]))user = prop_val[D_USER];
412 if(!CmnUtils.isEmpty(prop_val[D_PASS]))pass = prop_val[D_PASS];
413 if(!CmnUtils.isEmpty(prop_val[D_URL]))url = prop_val[D_URL];
414 if(!CmnUtils.isEmpty(prop_val[D_DRIVER]))driver = prop_val[D_DRIVER];
415 if(!CmnUtils.isEmpty(prop_val[D_OUTPUT]))outFolder = prop_val[D_OUTPUT];
416 if(!CmnUtils.isEmpty(prop_val[D_INPUT]))inFolder = prop_val[D_INPUT];
417 if(!CmnUtils.isEmpty(prop_val[D_LINESEP]))lineSeparator = CmnUtils.getLineSeparator(prop_val[D_LINESEP]);
418 if(!CmnUtils.isEmpty(prop_val[D_INLINESEP]))inColLineSeparator = CmnUtils.getLineSeparator(prop_val[D_INLINESEP]);
419 if(!CmnUtils.isEmpty(prop_val[D_FILENCODE]))fileEncoding = prop_val[D_FILENCODE];
420 if(!CmnUtils.isEmpty(prop_val[D_NULLMARK]))nullMark = prop_val[D_NULLMARK];
421 if(!CmnUtils.isEmpty(prop_val[D_DELIMITER]))delimiter = CmnUtils.getDelimiter(prop_val[D_DELIMITER]);
422 if(!CmnUtils.isEmpty(prop_val[D_TBLSQL]))tSql = prop_val[D_TBLSQL];
423 if(!CmnUtils.isEmpty(prop_val[D_TBLKEYSQL]))tkSql = prop_val[D_TBLKEYSQL];
424 if(!CmnUtils.isEmpty(prop_val[D_ORDER]) && prop_val[D_ORDER].toUpperCase().equals("Y"))isOrder = true;
425 if(!CmnUtils.isEmpty(prop_val[D_QUOTATION]) && prop_val[D_QUOTATION].toUpperCase().equals("N"))isQuotation = false;
426 if(!CmnUtils.isEmpty(prop_val[D_PHYSICAL]) && prop_val[D_PHYSICAL].toUpperCase().equals("Y"))isPhysical = true;
427 if(!CmnUtils.isEmpty(prop_val[D_DROP]) && prop_val[D_DROP].toUpperCase().equals("Y"))isDrop = true;
428 if(!CmnUtils.isEmpty(prop_val[D_BATCOUNT]) && CmnUtils.isNumeric(prop_val[D_BATCOUNT]))batchCount = Integer.parseInt(prop_val[D_BATCOUNT]);
429 if(!CmnUtils.isEmpty(prop_val[D_INCLTAB]))isInclTables = true;
430 if(!CmnUtils.isEmpty(prop_val[D_EXCLTAB]))isExclTables = true;
431 if(!CmnUtils.isEmpty(prop_val[D_INCLCOL]))isInclCols = true;
432 if(!CmnUtils.isEmpty(prop_val[D_EXCLCOL]))isExclCols = true;
433 if(!CmnUtils.isEmpty(prop_val[D_INCLCOLMASK]))isInclColsMask = true;
434 if(!CmnUtils.isEmpty(prop_val[D_EXCLCOLMASK]))isExclColsMask = true;
435 if(isInclColsMask || isExclColsMask)isMask = true;
436 if(!CmnUtils.isEmpty(prop_val[D_INCLTAB]))inclTables = prop_val[D_INCLTAB].toUpperCase();
437 if(!CmnUtils.isEmpty(prop_val[D_EXCLTAB]))exclTables = prop_val[D_EXCLTAB].toUpperCase();
438 if(!CmnUtils.isEmpty(prop_val[D_INCLCOL]))inclCols = prop_val[D_INCLCOL].toUpperCase();
439 if(!CmnUtils.isEmpty(prop_val[D_EXCLCOL]))exclCols = prop_val[D_EXCLCOL].toUpperCase();
440 if(!CmnUtils.isEmpty(prop_val[D_INCLCOLMASK]))inclColsMask = prop_val[D_INCLCOLMASK].toUpperCase();
441 if(!CmnUtils.isEmpty(prop_val[D_EXCLCOLMASK]))exclColsMask = prop_val[D_EXCLCOLMASK].toUpperCase();
442 if(!CmnUtils.isEmpty(prop_val[D_INCLTAB]))inclTablesArray = CmnUtils.splitCsv(prop_val[D_INCLTAB].toUpperCase());
443 if(!CmnUtils.isEmpty(prop_val[D_EXCLTAB]))exclTablesArray = CmnUtils.splitCsv(prop_val[D_EXCLTAB].toUpperCase());
444 if(!CmnUtils.isEmpty(prop_val[D_INCLCOL]))inclColsArray = CmnUtils.splitCsv(prop_val[D_INCLCOL].toUpperCase());
445 if(!CmnUtils.isEmpty(prop_val[D_EXCLCOL]))exclColsArray = CmnUtils.splitCsv(prop_val[D_EXCLCOL].toUpperCase());
446 if(!CmnUtils.isEmpty(prop_val[D_INCLCOLMASK]))inclColsMaskArray = CmnUtils.splitCsv(prop_val[D_INCLCOLMASK].toUpperCase());
447 if(!CmnUtils.isEmpty(prop_val[D_EXCLCOLMASK]))exclColsMaskArray = CmnUtils.splitCsv(prop_val[D_EXCLCOLMASK].toUpperCase());
448 if(!CmnUtils.isEmpty(prop_val[D_SBYTEMASKCHR]))singleByteMaskChar = prop_val[D_SBYTEMASKCHR].charAt(0);
449 if(!CmnUtils.isEmpty(prop_val[D_DBYTEMASKCHR]))doubleByteMaskChar = prop_val[D_DBYTEMASKCHR].charAt(0);
450 if(!CmnUtils.isEmpty(prop_val[D_MASKPTN]))maskPattern = prop_val[D_MASKPTN];
451 if(!CmnUtils.isEmpty(prop_val[D_SPCPADDING]) && prop_val[D_SPCPADDING].toUpperCase().equals("Y"))isSpcPadding = true;
452 if(!CmnUtils.isEmpty(prop_val[D_FILEEXT]))fileExtension = prop_val[D_FILEEXT];
454 if(CmnUtils.isEmpty(user)){
455 throw new Exception("us(
\83\86\81[
\83UID)
\82ª
\96¢
\8ew
\92è
\82Å
\82·
\81B");
456 } else if (CmnUtils.isEmpty(pass)){
457 throw new Exception("pw(
\83p
\83X
\83\8f\81[
\83h)
\82ª
\96¢
\8ew
\92è
\82Å
\82·
\81B");
458 } else if (CmnUtils.isEmpty(url)){
459 throw new Exception("url(
\90Ú
\91±
\8fî
\95ñ)
\82ª
\96¢
\8ew
\92è
\82Å
\82·
\81B");
460 } else if (CmnUtils.isEmpty(driver)){
461 throw new Exception("dr(
\83h
\83\89\83C
\83o)
\82ª
\96¢
\8ew
\92è
\82Å
\82·
\81B");
464 for(int i = 0;i<DB_TYPE_NAME.length;i++){
465 if (url.toUpperCase().contains(DB_TYPE_NAME[i])){
471 if (dbType != DB_TYPE_UNKNOWN){
472 if(!CmnUtils.isEmpty(prop_val[D_TBLSQL])){
473 tSql = prop_val[D_TBLSQL];
475 tSql = T_SQL_ARRAY[dbType];
477 if(!CmnUtils.isEmpty(prop_val[D_TBLKEYSQL])){
478 tkSql = prop_val[D_TBLKEYSQL];
480 tkSql = TK_SQL_ARRAY[dbType];
482 if(!CmnUtils.isEmpty(prop_val[D_SQLQUOTED])){
483 sqlQuoted = prop_val[D_SQLQUOTED];
485 sqlQuoted = DB_SQL_QUOTED[dbType];
488 throw new Exception("
\83f
\81[
\83^
\83x
\81[
\83X
\90»
\95i
\82ª
\8e¯
\95Ê
\82Å
\82«
\82Ü
\82¹
\82ñ
\81B[" + url + "]");
491 if(database!=null)CmnUtils.infoPrint("-->
\91Î
\8fÛ
\83f
\81[
\83^
\83x
\81[
\83X='" + database.toUpperCase() + "'");
492 if(!CmnUtils.isEmpty(prop_val[D_FILEEXT]))CmnUtils.infoPrint("-->
\83t
\83@
\83C
\83\8b\8ag
\92£
\8eq='" + prop_val[D_FILEEXT] + "'");
493 if(!CmnUtils.isEmpty(prop_val[D_DELIMITER]))CmnUtils.infoPrint("-->
\8bæ
\90Ø
\82è
\95¶
\8e\9a='" + prop_val[D_DELIMITER] + "'");
494 if(!CmnUtils.isEmpty(prop_val[D_LINESEP]))CmnUtils.infoPrint("-->
\89ü
\8ds
\83R
\81[
\83h='" + prop_val[D_LINESEP] + "'");
495 if(!CmnUtils.isEmpty(prop_val[D_INLINESEP]))CmnUtils.infoPrint("-->
\83J
\83\89\83\80\93à
\89ü
\8ds
\83R
\81[
\83h='" + prop_val[D_INLINESEP] + "'");
496 if(!CmnUtils.isEmpty(prop_val[D_FILENCODE]))CmnUtils.infoPrint("-->
\95¶
\8e\9a\83R
\81[
\83h='" + prop_val[D_FILENCODE] + "'");
497 if(!CmnUtils.isEmpty(prop_val[D_QUOTATION]))CmnUtils.infoPrint("-->
\88ø
\97p
\8bå=" + CmnUtils.getYesNo(isQuotation));
498 if(!CmnUtils.isEmpty(prop_val[D_SQLQUOTED]))CmnUtils.infoPrint("-->SQL
\88ø
\97p
\95\84=" + "'" + sqlQuoted + "'");
499 if(!CmnUtils.isEmpty(prop_val[D_ORDER]))CmnUtils.infoPrint("-->
\83\
\81[
\83g=" + CmnUtils.getYesNo(isOrder));
500 if(!CmnUtils.isEmpty(prop_val[D_BATCOUNT]))CmnUtils.infoPrint("-->
\83o
\83b
\83`
\8f\88\97\9d\90\94=" + batchCount);
501 if(isSpcPadding)CmnUtils.infoPrint("-->
\8bó
\94\92\96\84\82ß=" + CmnUtils.getYesNo(isSpcPadding));
502 if(isInclTables)CmnUtils.infoPrint("-->
\91Î
\8fÛ
\83e
\81[
\83u
\83\8b='" + inclTables.toUpperCase() + "'");
503 if(isExclTables)CmnUtils.infoPrint("-->
\8f\9c\8aO
\83e
\81[
\83u
\83\8b='" + exclTables.toUpperCase() + "'");
504 if(isInclCols)CmnUtils.infoPrint("-->
\91Î
\8fÛ
\83J
\83\89\83\80='" + inclCols.toUpperCase() + "'");
505 if(isExclCols)CmnUtils.infoPrint("-->
\8f\9c\8aO
\83J
\83\89\83\80='" + exclCols.toUpperCase() + "'");
507 CmnUtils.infoPrint("-->
\83}
\83X
\83L
\83\93\83O=" + CmnUtils.getYesNo(isMask));
508 CmnUtils.infoPrint("-->
\83}
\83X
\83N
\83L
\83\93\83O
\83p
\83^
\81[
\83\93=" + maskPattern.toUpperCase());
509 CmnUtils.infoPrint("-->
\94¼
\8ap
\83}
\83X
\83N
\95¶
\8e\9a='" + singleByteMaskChar + "'");
510 CmnUtils.infoPrint("-->
\91S
\8ap
\83}
\83X
\83N
\95¶
\8e\9a='" + doubleByteMaskChar + "'");
511 if(isInclColsMask)CmnUtils.infoPrint("-->
\83}
\83X
\83N
\91Î
\8fÛ
\83J
\83\89\83\80='" + inclColsMask.toUpperCase() + "'");
512 if(isExclColsMask)CmnUtils.infoPrint("-->
\83}
\83X
\83N
\8f\9c\8aO
\83J
\83\89\83\80='" + exclColsMask.toUpperCase() + "'");