1 package com.rapide_act;
3 import java.io.BufferedInputStream;
4 import java.io.FileInputStream;
5 import java.io.IOException;
6 import java.io.InputStream;
8 import java.io.FileReader;
9 import java.io.FileWriter;
10 import java.io.BufferedWriter;
11 import java.io.BufferedReader;
12 import java.io.PrintWriter;
13 import java.io.PrintWriter;
14 import java.util.Date;
15 import java.util.ArrayList;
16 import java.util.Iterator;
17 import java.util.Properties;
18 import java.util.regex.Pattern;
19 import java.sql.Connection;
20 import java.sql.DriverManager;
21 import java.sql.ResultSet;
22 import java.sql.ResultSetMetaData;
23 import java.sql.SQLException;
24 import java.sql.PreparedStatement;
25 import java.sql.Timestamp;
29 public class RapideMetaUnloader{
31 private static final int DB_TYPE_ORACLE = 0;
32 private static final int DB_TYPE_SQLSERVER = 1;
33 private static final int DB_TYPE_MYSQL = 2;
34 private static final int DB_TYPE_DB2 = 3;
35 private static final int DB_TYPE_POSTGRESQL = 4;
36 private static final int DB_TYPE_HIRDB = 5;
37 private static final int DB_TYPE_UNKNOWN = -1;
38 private static final int TYPE_TABLE = 0;
39 private static final int TYPE_INDEX = 1;
40 private static final int TYPE_VIEW = 2;
41 private static final int TYPE_PROCEDURE = 3;
42 private static final int TYPE_SEQ = 4;
43 private static final int TYPE_SYNONYM = 5;
44 private static final int TYPE_OBJ = 6;
45 private static final int TYPE_FK = 7;
46 private static final String [] FILE_NAME = {
56 private static final String lineSeparator = System.getProperty("line.separator");
57 protected static final String [] DB_SQL_QUOTED_S = {"\"", "[", "`", "\"", "\"", "\""};
58 protected static final String [] DB_SQL_QUOTED_E = {"\"", "]", "`", "\"", "\"", "\""};
59 private static final String [] DROP_OPTION = {" CASCADE CONSTRAINT PURGE", "", "", "", "", ""};
60 // private static final String [] cp.SQL_TERMINATOR = {";", lineSeparator + "GO", ";", ";", ";", ";"};
61 // private static final String [] cp.SQL_PREFIX = {"@", ":r ", "", "", "", ""};
62 private static final String [][] sql = {
65 + "a.table_name as table_name,"
66 + "replace(replace(b.comments, chr(13), ''), chr(10), '') as table_comments,"
67 + "c.column_name as column_name, "
68 + "replace(replace(d.comments, chr(13), ''), chr(10), '') as column_comments, "
69 + "decode(c.data_type, 'TIMESTAMP(6)', 'TIMESTAMP',c.data_type) as data_type, "
70 + "c.data_length as data_length,"
71 + "c.data_precision as data_precision,"
72 + "c.data_scale as data_scale,"
73 + "decode(c.nullable, 'N', '
\81\9b', null) as nullable,"
74 + "c.data_default as data_default "
75 + "from user_tables a "
76 + "inner join user_tab_comments b "
77 + "on a.table_name = b.table_name "
78 + "inner join user_tab_columns c "
79 + "on a.table_name = c.table_name "
80 + "inner join user_col_comments d "
81 + "on c.table_name = d.table_name "
82 + " and c.column_name = d.column_name "
83 + "order by a.table_name,c.column_id",
88 + " c.constraint_type,"
90 + " b.column_position "
93 + " user_ind_columns b,"
94 + " user_constraints c "
96 + " a.table_name = b.table_name and"
97 + " a.index_name = b.index_name and"
98 + " a.table_name = c.table_name(+) and"
99 + " a.index_name = c.constraint_name(+) "
103 + " b.column_position",
106 + " replace(replace(c.comments, chr(13), ''), chr(10), '') as comments "
109 + " user_tab_comments c "
111 + " a.view_name = c.table_name(+) "
119 + " where object_type in('PACKAGE BODY','PROCEDURE','FUNCTION','TRIGGER','TYPE')"
120 + " group by object_name,object_type"
121 + " order by object_name,object_type",
124 + " to_char(min_value) as min_value,"
125 + " to_char(max_value) as max_value,"
126 + " to_char(increment_by) as increment_by,"
129 + " to_char(cache_size) as cache_size,"
130 + " to_char(last_number) as last_number "
131 + " from user_sequences "
132 + " order by sequence_name",
138 + "from user_synonyms "
139 + "order by synonym_name,table_owner,table_name",
148 + " a.freelist_groups,"
150 + " a.tablespace_name, "
156 + " table_name as object_name,"
157 + " 'TABLE' as object_type,"
162 + " freelist_groups,"
164 + " tablespace_name, "
170 + " index_name as object_name,"
171 + " 'INDEX' as object_type,"
173 + " null as pct_used,"
176 + " freelist_groups,"
178 + " tablespace_name, "
190 + " where a.object_name = b.segment_name "
191 + " and a.object_type = b.segment_type "
196 + " a.table_name as table_name, "
197 + " a.constraint_name as constraint_name, "
198 + " b.column_name as column_name, "
199 + " b.position as position,"
200 + " c.table_name as r_table_name, "
201 + " d.column_name as r_column_name, "
202 + " d.position as r_position "
204 + " user_constraints a, "
205 + " user_cons_columns b,"
206 + " user_constraints c, "
207 + " user_cons_columns d "
209 + " a.constraint_type = 'R'"
210 + " and a.owner = b.owner"
211 + " and a.table_name = b.table_name"
212 + " and a.constraint_name = b.constraint_name"
213 + " and c.constraint_type in('P','U')"
214 + " and c.owner = b.owner"
215 + " and c.table_name = d.table_name"
216 + " and c.constraint_name = d.constraint_name"
217 + " and a.r_owner = c.owner"
218 + " and a.r_constraint_name = c.constraint_name"
220 + " a.table_name,a.constraint_name,b.position,d.position"
224 + "a.name as table_name, "
225 + "replace(replace(cast(b.value as varchar(4000)), char(13), ''), char(10), '') as table_comments, "
226 + "c.name as column_name, "
227 + "replace(replace(cast(d.value as varchar(4000)), char(13), ''), char(10), '') as column_comments, "
228 + "e.name as data_type, "
229 + "c.max_length as data_length, "
230 + "c.precision as data_precision, "
231 + "c.scale as data_scale, "
232 + "case c.is_nullable"
233 + " when '0' then '
\81Z'"
236 + "g.definition as data_default "
239 + "left outer join sys.extended_properties as b "
240 + "on a.object_id = b.major_id and b.minor_id = 0 "
241 + "inner join sys.columns as c "
242 + "on a.object_id = c.object_id "
243 + "left outer join sys.extended_properties as d "
244 + "on a.object_id = d.major_id and c.column_id = d.minor_id "
245 + "inner join sys.types as e "
246 + "on c.system_type_id = e.system_type_id and c.user_type_id = e.user_type_id "
247 + "left outer join sys.sysconstraints f "
248 + "on c.object_id = f.id "
249 + "and c.column_id = f.colid "
250 + "and (f.status & 2069) = 2069 "
251 + "left outer join sys.default_constraints g "
252 + "on f.constid = g.object_id "
253 + "and a.schema_id = g.schema_id "
254 + "order by a.name,c.column_id ",
256 + "d.name as table_name, "
257 + "a.name as index_name, "
258 + "a.type as index_type, "
259 + "case a.is_unique "
261 + " case a.is_primary_key "
262 + " when 1 then 'P' "
264 + " case a.is_unique_constraint "
265 + " when 1 then 'U' "
270 + "end as constraint_type, "
271 + "c.name as column_name, "
272 + "b.key_ordinal as column_position "
274 + " sys.indexes as a "
275 + " inner join sys.index_columns as b "
276 + " on a.object_id = b.object_id and a.index_id = b.index_id "
277 + " inner join sys.columns as c "
278 + " on c.column_id = b.column_id "
279 + " and c.object_id = b.object_id "
280 + " inner join sys.objects as d "
281 + " on a.object_id = d.object_id and d.type = 'U' "
282 + "order by d.name, a.name,b.key_ordinal",
284 + " a.name as view_name, "
285 + " replace(replace(cast(b.value as varchar(4000)), char(13), ''), char(10), '') as comments "
288 + " left outer join sys.extended_properties as b "
289 + " on a.object_id = b.major_id and b.minor_id = 0 "
293 + " name as object_name, 'PROCEDURE' as object_type from sys.procedures"
295 + " name as object_name, 'FUNCTION' as object_type from sys.objects where type in('FN', 'FS', 'FT', 'IF', 'TF') "
297 + " name as object_name, 'TRIGGER' as object_type from sys.triggers "
298 + " order by object_name,object_type ",
300 + " name as sequence_name,"
301 + " cast(minimum_value as varchar(20)) as min_value,"
302 + " cast(maximum_value as varchar(20)) as max_value,"
303 + " cast(increment as varchar(20)) as increment_by,"
304 + " is_cycling as cycle_flag,"
305 + " is_cached as order_flag,"
306 + " cast(cache_size as varchar(20)) as cache_size,"
307 + " cast(start_value as varchar(20)) as last_number "
308 + " from sys.sequences "
311 + " a.name as synonym_name,"
312 + " b.name as table_owner,"
313 + " base_object_name as table_name,"
315 + "from sys.synonyms a "
316 + " inner join sys.schemas as b "
317 + " on a.schema_id = b.schema_id "
318 + "order by synonym_name,table_owner,table_name",
320 + " c.name as table_name, "
322 + " d.name as index_name , "
323 + " a.type_desc as allocation_type, "
325 + " partition_number "
327 + " sys.allocation_units as a "
328 + " inner join sys.partitions as b "
329 + " on a.container_id = b.partition_id "
330 + " inner join sys.objects as c "
331 + " on b.object_id = c.object_id and c.type = 'U' "
332 + " inner join sys.indexes as d "
333 + " on b.index_id = d.index_id and d.object_id = b.object_id "
334 + "order by c.name, b.index_id",
336 + " c.name as table_name, "
337 + " a.name as constraint_name, "
338 + " d.name as column_name, "
339 + " b.constraint_column_id as position, "
340 + " e.name as r_table_name, "
341 + " f.name as r_column_name ,"
342 + " f.column_id as r_position "
343 + "from sys.foreign_keys as a "
344 + " inner join sys.foreign_key_columns as b "
345 + " on a.object_id = b.constraint_object_id "
346 + " inner join sys.tables as c "
347 + " on b.parent_object_id = c.object_id "
348 + " inner join sys.columns as d "
349 + " on b.parent_object_id = d.object_id and "
350 + " b.parent_column_id = d.column_id "
351 + " inner join sys.tables as e "
352 + " on b.referenced_object_id = e.object_id "
353 + " inner join sys.columns as f "
354 + " on b.referenced_object_id = f.object_id and "
355 + " b.referenced_column_id = f.column_id "
356 + " inner join sys.key_constraints as g "
357 + " on a.referenced_object_id = g.parent_object_id "
358 + "order by table_name,constraint_name, position"
361 private static String sql_view_text[] = {
362 "select text from user_views where view_name = ?",
363 "select c.definition "
364 + "from sys.views a "
365 + "inner join sys.objects b "
366 + "on b.object_id = a.object_id "
367 + "inner join sys.sql_modules c "
368 + "on c.object_id = b.object_id "
371 private static String sql_view_column_and_comment[] = {
374 + " replace(replace(d.comments, chr(13), ''), chr(10), '') as comments "
376 + " user_tab_columns b,"
377 + " user_col_comments d "
379 + " b.table_name = ? and"
380 + " b.table_name = d.table_name(+) and"
381 + " b.column_name = d.column_name(+) "
385 + " b.name as column_name, "
389 + " inner join sys.columns b on a.object_id = b.object_id and a.name = ? "
390 + " inner join sys.types c on b.system_type_id = c.system_type_id "
391 + " where a.type = 'V' "
392 + " and c.user_type_id <> 256 "
393 + " order by b.column_id"
395 private static String sql_proc[] = {
396 "select text from user_source where type = ? and name = ? order by line",
397 "select d.definition "
399 + " (select a.name,'PROCEDURE' as type,c.definition "
400 + "from sys.procedures a "
401 + "inner join sys.objects b "
402 + "on b.object_id = a.object_id "
403 + "inner join sys.sql_modules c "
404 + "on c.object_id = b.object_id "
406 + " a.name,'FUNCTION' as type,c.definition "
407 + "from sys.objects a "
408 + "inner join sys.objects b "
409 + "on b.object_id = a.object_id "
410 + "inner join sys.sql_modules c "
411 + "on c.object_id = b.object_id and a.type in('FN', 'FS', 'FT', 'IF', 'TF') "
413 + "a.name,'TRIGGER' as type,c.definition "
414 + "from sys.triggers a "
415 + "inner join sys.objects b "
416 + "on b.object_id = a.object_id "
417 + "inner join sys.sql_modules c "
418 + "on c.object_id = b.object_id) d "
419 + "where d.type = ? and d.name = ?"
422 private String database = null;
423 private String phyfileExtension = "phy";
425 public static void main(String args[]){
427 if (args.length > 0){
428 RapideMetaUnloader RapideMetaUnloader = new RapideMetaUnloader(args[0]);
429 RapideMetaUnloader.metaUnload();
431 RapideMetaUnloader RapideMetaUnloader = new RapideMetaUnloader(null);
432 RapideMetaUnloader.metaUnload();
434 } catch (Exception e) {
439 RapideMetaUnloader(String _database) {
441 database = _database;
445 private void metaUnload(){
446 Connection conn = null;
447 PreparedStatement stmt = null;
448 BufferedReader [] br = new BufferedReader[4];
449 PrintWriter [] pw = new PrintWriter[6];
451 File subFolder = null;
452 String strLine = null;
453 String strLine2 = null;
454 String [][] strSplit = new String[4][];
455 String strContents = null;
456 ArrayList<String> alData = null;
457 ArrayList<String> alData2 = null;
459 String tableName = null;
460 String tableCmnt = null;
461 String colName = null;
462 String colCmnt = null;
463 String colType = null;
464 String colLen = null;
465 String colPrec = null;
466 String colScale = null;
467 String colNoN = null;
468 String colDflt = null;
469 String indexName = null;
470 String indexType = null;
471 String constraintType = null;
472 String colPos = null;
473 String seqName = null;
474 String minVal = null;
475 String maxVal = null;
479 String cacheSz = null;
481 String synmOwner = null;
482 String synmName = null;
483 String tbOwner = null;
484 String tbName = null;
486 String userName = null;
487 String passWord = null;
489 String created = null;
490 String acStat = null;
491 String defTbsp = null;
492 String tmpTbsp = null;
493 String grntee = null;
494 String grntor = null;
495 String grntrl = null;
497 String grntabl = null;
500 String objName = null;
501 String objTyp = null;
502 String pctFree = null;
503 String pctUsed = null;
504 String iniTrns = null;
505 String freeLst = null;
506 String flstGrp = null;
507 String bufPool = null;
508 String tblSpace = null;
509 String logging = null;
510 String segByts = null;
512 String fkName = null;
514 String fkColPos = null;
515 String rtbName = null;
516 String rfkName = null;
517 String rfkCol = null;
518 String rfkColPos = null;
521 CmnAccessObjects dao = null;
525 cp.setProperty(database);
527 if (cp.dbType > cp.DB_TYPE_SQLSERVER || cp.dbType <0){
528 throw new Exception("
\83f
\81[
\83^
\83x
\81[
\83X
\82ª
\91Î
\8fÛ
\8aO
\82Å
\82·
\81B[" + cp.DB_TYPE_NAME[cp.dbType] + "]");
530 if(cp.outFolder != null){
531 folder = new File(cp.outFolder);
533 if(database != null){
534 folder = new File(cp.DEFAULT_OUT_FOLDER + "/DDL_" + database.toUpperCase() + "_" + CmnUtils.getYmdhm());
536 folder = new File(cp.DEFAULT_OUT_FOLDER + "/DDL_" + cp.DB_TYPE_NAME[cp.dbType].toUpperCase() + "_" + CmnUtils.getYmdhm());
541 CmnUtils.infoPrint("-->
\8fo
\97Í
\90æ
\83t
\83H
\83\8b\83_='" + folder + "'");
542 CmnUtils.infoPrint("
\83\81\83^
\83f
\81[
\83^
\83A
\83\93\83\8d\81[
\83h
\82ð
\8aJ
\8en
\82µ
\82Ü
\82µ
\82½
\81B");
545 dao = new CmnAccessObjects(cp);
546 conn = dao.connect();
547 // Def tsv Writing start
548 for(int i=0;i<sql[cp.dbType].length;i++){
549 dao.select(sql[cp.dbType][i]);
550 CmnUtils.writeSeparator(folder + "/" + FILE_NAME[i] + "_" + database +"." + cp.fileExtension, dao.getColumnCount(), dao.getArrayList(), cp.delimiter);
552 // Def tsv Writing end
554 // Table Contents start
555 br[0] = new BufferedReader(new FileReader(folder + "/" + FILE_NAME[TYPE_TABLE] + "_" + database + "." + cp.fileExtension));
556 subFolder = new File(folder + "/TABLES");
558 pw[1] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_TABLE]))));
559 pw[2] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + cp.SQL_FILE_NAME[cp.DROP_TABLE]))));
560 pw[3] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + cp.SQL_FILE_NAME[cp.TRUNCATE_TABLE]))));
573 StringBuffer sbTbCnts = new StringBuffer();
574 StringBuffer sbTbCmnt = new StringBuffer();
575 while((strLine=br[0].readLine()) != null){
576 if(!strLine.equals("")){
577 strSplit[0] = CmnUtils.split(strLine, cp.delimiter);
578 if (!tableName.equals("")){
579 sbTbCnts.append(" " + DB_SQL_QUOTED_S[cp.dbType]+ colName + DB_SQL_QUOTED_E[cp.dbType]);
580 sbTbCnts.append(" " + colType);
581 if(!colCmnt.equals(""))sbTbCmnt.append(commentOnColumn(cp, tableName, colName, colCmnt, TYPE_TABLE));
582 if(!colCmnt.equals(""))sbTbCmnt.append(lineSeparator);
583 if(CmnUtils.isColPrec(colType, colPrec)){
584 sbTbCnts.append("(" + colPrec);
585 if (!colScale.equals("") && !colScale.equals("0"))sbTbCnts.append("," + colScale);
586 sbTbCnts.append(")");
587 } else if (CmnUtils.isColLength(colType)){
588 if(colLen.equals("-1")){
589 sbTbCnts.append("(max)");
591 sbTbCnts.append("(" + CmnUtils.getColLength(colType, colLen) + ")");
594 if (!colDflt.equals(""))sbTbCnts.append(" DEFAULT " + colDflt.trim());
595 if (!colNoN.equals("")){
596 sbTbCnts.append(" NOT NULL");
598 sbTbCnts.append(" NULL");
600 if (!strSplit[0][0].equals(tableName)){
601 pw[1].println(cp.SQL_PREFIX[cp.dbType] + "TABLES/" + tableName + ".sql");
602 pw[2].println("DROP TABLE " + DB_SQL_QUOTED_S[cp.dbType]+ tableName + DB_SQL_QUOTED_E[cp.dbType]+ DROP_OPTION[cp.dbType] + cp.SQL_TERMINATOR[cp.dbType]);
603 pw[3].println("TRUNCATE TABLE " + DB_SQL_QUOTED_S[cp.dbType]+ tableName + DB_SQL_QUOTED_E[cp.dbType]+ cp.SQL_TERMINATOR[cp.dbType]);
604 sbTbCnts.append(lineSeparator);
605 sbTbCnts.append(")" + cp.SQL_TERMINATOR[cp.dbType]);
606 sbTbCnts.append(lineSeparator);
607 pw[0] = new PrintWriter(new BufferedWriter(new FileWriter(new File(subFolder + "/" + tableName + ".sql"))));
608 strSplit[1] = CmnUtils.split(sbTbCnts.toString(), lineSeparator);
609 for(int i=0;i<strSplit[1].length;i++)if(!strSplit[1][i].trim().equals(""))pw[0].println(strSplit[1][i]);
610 strSplit[2] = CmnUtils.split(sbTbCmnt.toString(), lineSeparator);
611 for(int i=0;i<strSplit[2].length;i++)if(!strSplit[2][i].trim().equals(""))pw[0].println(strSplit[2][i]);
614 CmnUtils.infoPrint(String.format("%1$-30s",tableName) + "
\83\81\83^
\83f
\81[
\83^
\82ª
\83A
\83\93\83\8d\81[
\83h
\82³
\82ê
\82Ü
\82µ
\82½
\81B");
615 sbTbCnts = new StringBuffer();
616 sbTbCmnt = new StringBuffer();
617 sbTbCnts.append("CREATE TABLE " + DB_SQL_QUOTED_S[cp.dbType]+ strSplit[0][0] + DB_SQL_QUOTED_E[cp.dbType]);
618 sbTbCnts.append(lineSeparator);
619 sbTbCnts.append("(");
620 sbTbCnts.append(lineSeparator);
621 if(!strSplit[0][1].equals(""))sbTbCmnt.append(commentOnTable(cp, strSplit[0][0], strSplit[0][1], TYPE_TABLE));
622 if(!strSplit[0][1].equals(""))sbTbCmnt.append(lineSeparator);
624 sbTbCnts.append(",");
625 sbTbCnts.append(lineSeparator);
629 sbTbCnts.append("CREATE TABLE " + DB_SQL_QUOTED_S[cp.dbType]+ strSplit[0][0] + DB_SQL_QUOTED_E[cp.dbType]);
630 sbTbCnts.append(lineSeparator);
631 sbTbCnts.append("(");
632 sbTbCnts.append(lineSeparator);
633 if(!strSplit[0][1].equals(""))sbTbCmnt.append(commentOnTable(cp, strSplit[0][0], strSplit[0][1], TYPE_TABLE));
634 if(!strSplit[0][1].equals(""))sbTbCmnt.append(lineSeparator);
636 for(int i=0;i<strSplit[0].length;i++)CmnUtils.debugPrint("'" + strSplit[0][i] + "'");
638 tableName = strSplit[0][0];
639 tableCmnt = strSplit[0][1];
640 colName = strSplit[0][2];
641 colCmnt = strSplit[0][3];
642 colType = strSplit[0][4];
643 colLen = strSplit[0][5];
644 colPrec = strSplit[0][6];
645 colScale = strSplit[0][7];
646 colNoN = strSplit[0][8];
647 colDflt = strSplit[0][9];
651 if (!tableName.equals("")){
652 sbTbCnts.append(" " + DB_SQL_QUOTED_S[cp.dbType]+ colName + DB_SQL_QUOTED_E[cp.dbType]);
653 sbTbCnts.append(" " + colType);
654 if(!colCmnt.equals(""))sbTbCmnt.append(commentOnColumn(cp, tableName, colName, colCmnt, TYPE_TABLE));
655 if(!colCmnt.equals(""))sbTbCmnt.append(lineSeparator);
656 if(CmnUtils.isColPrec(colType, colPrec)){
657 sbTbCnts.append("(" + colPrec);
658 if (!colScale.equals("") && !colScale.equals("0"))sbTbCnts.append("," + colScale);
659 sbTbCnts.append(")");
660 } else if (CmnUtils.isColLength(colType)){
661 if(colLen.equals("-1")){
662 sbTbCnts.append("(max)");
664 sbTbCnts.append("(" + CmnUtils.getColLength(colType, colLen) + ")");
667 if (!colDflt.equals(""))sbTbCnts.append(" DEFAULT " + colDflt.trim());
668 if (!colNoN.equals("")){
669 sbTbCnts.append(" NOT NULL");
671 sbTbCnts.append(" NULL");
673 pw[1].println(cp.SQL_PREFIX[cp.dbType] + "TABLES/" + tableName + ".sql");
674 pw[2].println("DROP TABLE " + DB_SQL_QUOTED_S[cp.dbType]+ tableName + DB_SQL_QUOTED_E[cp.dbType]+ DROP_OPTION[cp.dbType] + cp.SQL_TERMINATOR[cp.dbType]);
675 pw[3].println("TRUNCATE TABLE " + DB_SQL_QUOTED_S[cp.dbType]+ tableName + DB_SQL_QUOTED_E[cp.dbType]+ cp.SQL_TERMINATOR[cp.dbType]);
676 sbTbCnts.append(lineSeparator);
677 sbTbCnts.append(")" + cp.SQL_TERMINATOR[cp.dbType]);
678 sbTbCnts.append(lineSeparator);
679 pw[0] = new PrintWriter(new BufferedWriter(new FileWriter(new File(subFolder + "/" + tableName + ".sql"))));
680 strSplit[1] = CmnUtils.split(sbTbCnts.toString(), lineSeparator);
681 for(int i=0;i<strSplit[1].length;i++)if(!strSplit[1][i].trim().equals(""))pw[0].println(strSplit[1][i]);
682 strSplit[2] = CmnUtils.split(sbTbCmnt.toString(), lineSeparator);
683 for(int i=0;i<strSplit[2].length;i++)if(!strSplit[2][i].trim().equals(""))pw[0].println(strSplit[2][i]);
686 CmnUtils.infoPrint(String.format("%1$-30s",tableName) + "
\83\81\83^
\83f
\81[
\83^
\82ª
\83A
\83\93\83\8d\81[
\83h
\82³
\82ê
\82Ü
\82µ
\82½
\81B");
688 for(int i=1;i<4;i++)pw[i].close();
689 for(int i=1;i<4;i++)pw[i]=null;
692 // Table Contents end
694 // Index Contents start
695 br[0] = new BufferedReader(new FileReader(folder + "/" + FILE_NAME[TYPE_INDEX] + "_" + database + "." + cp.fileExtension));
696 pw[0] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_PKEY]))));
697 pw[1] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_UKEY]))));
698 pw[2] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_INDEX]))));
699 pw[3] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + cp.SQL_FILE_NAME[cp.DROP_PKEY]))));
700 pw[4] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + cp.SQL_FILE_NAME[cp.DROP_UKEY]))));
701 pw[5] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + cp.SQL_FILE_NAME[cp.DROP_INDEX]))));
710 StringBuffer sbIxCnts = new StringBuffer();
711 StringBuffer sbIx2Cnts = new StringBuffer();
712 StringBuffer sbIx3Cnts = new StringBuffer();
715 while((strLine=br[0].readLine()) != null){
716 if(!strLine.equals("")){
717 strSplit[0] = CmnUtils.split(strLine, cp.delimiter);
718 //Not 1st Line Process
719 if (!indexName.equals("")){
720 if (!strSplit[0][1].equals(indexName)){
722 if (colPos.equals("1")){
723 sbIxCnts.append(DB_SQL_QUOTED_S[cp.dbType]+ colName + DB_SQL_QUOTED_E[cp.dbType]);
724 if (constraintType.equals("U"))sbIx2Cnts.append(DB_SQL_QUOTED_S[cp.dbType]+ colName + DB_SQL_QUOTED_E[cp.dbType]);
726 sbIxCnts.append(", " + DB_SQL_QUOTED_S[cp.dbType]+ colName + DB_SQL_QUOTED_E[cp.dbType]);
727 if (constraintType.equals("U"))sbIx2Cnts.append(", " + DB_SQL_QUOTED_S[cp.dbType]+ colName + DB_SQL_QUOTED_E[cp.dbType]);
729 sbIxCnts.append(")" + cp.SQL_TERMINATOR[cp.dbType]);
730 sbIxCnts.append(lineSeparator);
731 if (constraintType.equals("U"))sbIx2Cnts.append(")" + cp.SQL_TERMINATOR[cp.dbType]);
732 sbIx2Cnts.append(lineSeparator);
733 sbIx3Cnts.append(lineSeparator);
736 if (constraintType.equals("P")){
737 strSplit[1] = CmnUtils.split(sbIxCnts.toString(), lineSeparator);
738 for(int i=0;i<strSplit[1].length;i++)if(!strSplit[1][i].trim().equals(""))pw[0].println(strSplit[1][i]);
739 strSplit[2] = CmnUtils.split(sbIx2Cnts.toString(), lineSeparator);
740 for(int i=0;i<strSplit[2].length;i++)if(!strSplit[2][i].trim().equals(""))pw[3].println(strSplit[2][i]);
741 } else if (constraintType.equals("U")){
742 strSplit[1] = CmnUtils.split(sbIxCnts.toString(), lineSeparator);
743 for(int i=0;i<strSplit[1].length;i++)if(!strSplit[1][i].trim().equals(""))pw[1].println(strSplit[1][i]);
744 strSplit[2] = CmnUtils.split(sbIx2Cnts.toString(), lineSeparator);
745 for(int i=0;i<strSplit[2].length;i++)if(!strSplit[2][i].trim().equals(""))pw[4].println(strSplit[2][i]);
746 } else if (constraintType.equals("")){
747 strSplit[1] = CmnUtils.split(sbIxCnts.toString(), lineSeparator);
748 for(int i=0;i<strSplit[1].length;i++)if(!strSplit[1][i].trim().equals(""))pw[2].println(strSplit[1][i]);
750 strSplit[3] = CmnUtils.split(sbIx3Cnts.toString(), lineSeparator);
751 for(int i=0;i<strSplit[3].length;i++)if(!strSplit[3][i].trim().equals(""))pw[5].println(strSplit[3][i]);
754 sbIxCnts = new StringBuffer();
755 sbIx2Cnts = new StringBuffer();
756 sbIx3Cnts = new StringBuffer();
758 //Index Changed Process
759 if (strSplit[0][3].equals("P")){
760 sbIxCnts.append("ALTER TABLE " + DB_SQL_QUOTED_S[cp.dbType]+ strSplit[0][0] + DB_SQL_QUOTED_E[cp.dbType]+ " ADD CONSTRAINT " + DB_SQL_QUOTED_S[cp.dbType]+ strSplit[0][1] + DB_SQL_QUOTED_E[cp.dbType]+ " PRIMARY KEY(");
761 sbIx2Cnts.append("ALTER TABLE " + DB_SQL_QUOTED_S[cp.dbType]+ strSplit[0][0] + DB_SQL_QUOTED_E[cp.dbType]+ " DROP CONSTRAINT " + DB_SQL_QUOTED_S[cp.dbType]+ strSplit[0][1] + DB_SQL_QUOTED_E[cp.dbType]+ cp.SQL_TERMINATOR[cp.dbType]);
762 } else if (strSplit[0][3].equals("U")){
763 sbIxCnts.append("ALTER TABLE " + DB_SQL_QUOTED_S[cp.dbType]+ strSplit[0][0] + DB_SQL_QUOTED_E[cp.dbType]+ " ADD CONSTRAINT " + DB_SQL_QUOTED_S[cp.dbType]+ strSplit[0][1] + DB_SQL_QUOTED_E[cp.dbType]+ " UNIQUE(");
764 sbIx2Cnts.append("ALTER TABLE " + DB_SQL_QUOTED_S[cp.dbType]+ strSplit[0][0] + DB_SQL_QUOTED_E[cp.dbType]+ " DROP UNIQUE(");
765 } else if (strSplit[0][3].equals("")){
766 sbIxCnts.append("CREATE INDEX " + DB_SQL_QUOTED_S[cp.dbType]+ strSplit[0][1] + DB_SQL_QUOTED_E[cp.dbType]+ " ON " + strSplit[0][0] + "(");
768 sbIx3Cnts.append("DROP INDEX " + DB_SQL_QUOTED_S[cp.dbType]+ strSplit[0][1] + DB_SQL_QUOTED_E[cp.dbType]+ cp.SQL_TERMINATOR[cp.dbType]);
769 } else if (strSplit[0][1].equals(indexName)){
770 if (colPos.equals("1")){
771 sbIxCnts.append(DB_SQL_QUOTED_S[cp.dbType]+ colName + DB_SQL_QUOTED_E[cp.dbType]);
772 if (constraintType.equals("U"))sbIx2Cnts.append(DB_SQL_QUOTED_S[cp.dbType]+ colName + DB_SQL_QUOTED_E[cp.dbType]);
774 sbIxCnts.append(", " + DB_SQL_QUOTED_S[cp.dbType]+ colName + DB_SQL_QUOTED_E[cp.dbType]);
775 if (constraintType.equals("U"))sbIx2Cnts.append(", " + DB_SQL_QUOTED_S[cp.dbType]+ colName + DB_SQL_QUOTED_E[cp.dbType]);
782 if (strSplit[0][3].equals("P")){
783 sbIxCnts.append("ALTER TABLE " + DB_SQL_QUOTED_S[cp.dbType]+ strSplit[0][0] + DB_SQL_QUOTED_E[cp.dbType]+ " ADD CONSTRAINT " + DB_SQL_QUOTED_S[cp.dbType]+ strSplit[0][1] + DB_SQL_QUOTED_E[cp.dbType]+ " PRIMARY KEY(");
784 sbIx2Cnts.append("ALTER TABLE " + DB_SQL_QUOTED_S[cp.dbType]+ strSplit[0][0] + DB_SQL_QUOTED_E[cp.dbType]+ " DROP CONSTRAINT " + DB_SQL_QUOTED_S[cp.dbType]+ strSplit[0][1] + DB_SQL_QUOTED_E[cp.dbType]+ cp.SQL_TERMINATOR[cp.dbType]);
785 } else if (strSplit[0][3].equals("U")){
786 sbIxCnts.append("ALTER TABLE " + DB_SQL_QUOTED_S[cp.dbType]+ strSplit[0][0] + DB_SQL_QUOTED_E[cp.dbType]+ " ADD CONSTRAINT " + DB_SQL_QUOTED_S[cp.dbType]+ strSplit[0][1] + DB_SQL_QUOTED_E[cp.dbType]+ " UNIQUE(");
787 sbIx2Cnts.append("ALTER TABLE " + DB_SQL_QUOTED_S[cp.dbType]+ strSplit[0][0] + DB_SQL_QUOTED_E[cp.dbType]+ " DROP UNIQUE(");
788 } else if (strSplit[0][3].equals("")){
789 sbIxCnts.append("CREATE INDEX " + DB_SQL_QUOTED_S[cp.dbType]+ strSplit[0][1] + DB_SQL_QUOTED_E[cp.dbType]+ " ON " + DB_SQL_QUOTED_S[cp.dbType]+ strSplit[0][0] + DB_SQL_QUOTED_E[cp.dbType]+ "(");
791 sbIx3Cnts.append("DROP INDEX " + DB_SQL_QUOTED_S[cp.dbType]+ strSplit[0][1] + DB_SQL_QUOTED_E[cp.dbType]+ cp.SQL_TERMINATOR[cp.dbType]);
793 for(int i=0;i<strSplit[0].length;i++)CmnUtils.debugPrint("'" + strSplit[0][i] + "'");
795 tableName = strSplit[0][0];
796 indexName = strSplit[0][1];
797 indexType = strSplit[0][2];
798 constraintType = strSplit[0][3];
799 colName = strSplit[0][4];
800 colPos = strSplit[0][5];
803 if (!indexName.equals("")){
805 if (colPos.equals("1")){
806 sbIxCnts.append(DB_SQL_QUOTED_S[cp.dbType]+ colName + DB_SQL_QUOTED_E[cp.dbType]);
807 if (constraintType.equals("U"))sbIx2Cnts.append(DB_SQL_QUOTED_S[cp.dbType]+ colName + DB_SQL_QUOTED_E[cp.dbType]);
809 sbIxCnts.append(", " + DB_SQL_QUOTED_S[cp.dbType]+ colName + DB_SQL_QUOTED_E[cp.dbType]);
810 if (constraintType.equals("U"))sbIx2Cnts.append(", " + DB_SQL_QUOTED_S[cp.dbType]+ colName + DB_SQL_QUOTED_E[cp.dbType]);
812 sbIxCnts.append(")" + cp.SQL_TERMINATOR[cp.dbType]);
813 sbIxCnts.append(lineSeparator);
814 if (constraintType.equals("U"))sbIx2Cnts.append(")" + cp.SQL_TERMINATOR[cp.dbType]);
815 sbIx2Cnts.append(lineSeparator);
816 sbIx3Cnts.append(lineSeparator);
819 if (constraintType.equals("P")){
820 strSplit[1] = CmnUtils.split(sbIxCnts.toString(), lineSeparator);
821 for(int i=0;i<strSplit[1].length;i++)if(!strSplit[1][i].trim().equals(""))pw[0].println(strSplit[1][i]);
822 strSplit[2] = CmnUtils.split(sbIx2Cnts.toString(), lineSeparator);
823 for(int i=0;i<strSplit[2].length;i++)if(!strSplit[2][i].trim().equals(""))pw[3].println(strSplit[2][i]);
824 } else if (constraintType.equals("U")){
825 strSplit[1] = CmnUtils.split(sbIxCnts.toString(), lineSeparator);
826 for(int i=0;i<strSplit[1].length;i++)if(!strSplit[1][i].trim().equals(""))pw[1].println(strSplit[1][i]);
827 strSplit[2] = CmnUtils.split(sbIx2Cnts.toString(), lineSeparator);
828 for(int i=0;i<strSplit[2].length;i++)if(!strSplit[2][i].trim().equals(""))pw[4].println(strSplit[2][i]);
829 } else if (constraintType.equals("")){
830 strSplit[1] = CmnUtils.split(sbIxCnts.toString(), lineSeparator);
831 for(int i=0;i<strSplit[1].length;i++)if(!strSplit[1][i].trim().equals(""))pw[2].println(strSplit[1][i]);
833 strSplit[3] = CmnUtils.split(sbIx3Cnts.toString(), lineSeparator);
834 for(int i=0;i<strSplit[3].length;i++)if(!strSplit[3][i].trim().equals(""))pw[5].println(strSplit[3][i]);
838 for(int i=0;i<6;i++)pw[i].close();
839 for(int i=0;i<6;i++)pw[i]=null;
842 // Index Contents end
844 // View Contents start
845 br[0] = new BufferedReader(new FileReader(folder + "/" + FILE_NAME[TYPE_VIEW] + "_" + database + "." + cp.fileExtension));
846 subFolder = new File(folder + "/VIEWS");
848 pw[1] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_VIEW]))));
849 pw[2] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + cp.SQL_FILE_NAME[cp.DROP_VIEW]))));
850 while((strLine=br[0].readLine()) != null){
851 strSplit[0] = CmnUtils.split(strLine, cp.delimiter);
852 CmnUtils.debugPrint("'" + strSplit[0][0] + "'");
853 pw[1].println(cp.SQL_PREFIX[cp.dbType] + "VIEWS/" + strSplit[0][0] + ".sql");
854 pw[2].println("DROP VIEW " + DB_SQL_QUOTED_S[cp.dbType]+ strSplit[0][0] + DB_SQL_QUOTED_E[cp.dbType]+ cp.SQL_TERMINATOR[cp.dbType]);
855 if (strSplit[0].length>1)CmnUtils.debugPrint("'" + strSplit[0][1] + "'");
856 pw[0] = new PrintWriter(new BufferedWriter(new FileWriter(new File(subFolder + "/" + strSplit[0][0] + ".sql"))));
858 stmt = dao.prepareSql(sql_view_column_and_comment[cp.dbType]);
859 stmt.setString(1,strSplit[0][0]);
861 alData = dao.getArrayList();
862 columnCount = dao.getColumnCount();
863 if (cp.dbType == cp.DB_TYPE_ORACLE){
864 pw[0].println("/* " + strSplit[0][0] + " */");
865 pw[0].println("CREATE OR REPLACE VIEW " + DB_SQL_QUOTED_S[cp.dbType]+ strSplit[0][0] + DB_SQL_QUOTED_E[cp.dbType]);
867 for(int i=0;i<alData.size();i++){
868 if ((i+1) % columnCount == 1){
870 if (!alData.get(i+1).trim().equals("")){
871 pw[0].println(" " + DB_SQL_QUOTED_S[cp.dbType]+ alData.get(i) + DB_SQL_QUOTED_E[cp.dbType]+ " -- " + alData.get(i+1));
873 pw[0].println(" " + DB_SQL_QUOTED_S[cp.dbType]+ alData.get(i) + DB_SQL_QUOTED_E[cp.dbType]);
876 if (!alData.get(i+1).trim().equals("")){
877 pw[0].println(" ," + DB_SQL_QUOTED_S[cp.dbType]+ alData.get(i) + DB_SQL_QUOTED_E[cp.dbType]+ " -- " + alData.get(i+1));
879 pw[0].println(" ," + DB_SQL_QUOTED_S[cp.dbType]+ alData.get(i) + DB_SQL_QUOTED_E[cp.dbType]);
887 stmt = dao.prepareSql(sql_view_text[cp.dbType]);
888 stmt.setString(1,strSplit[0][0]);
890 alData2 = dao.getArrayList();
891 strContents = alData2.get(0).trim();
892 strSplit[1] = CmnUtils.split(strContents, lineSeparator);
893 for(int i=0;i<strSplit[1].length;i++)if(!strSplit[1][i].trim().equals(""))pw[0].println(strSplit[1][i].replaceAll("\"\"","\"").replaceAll(Pattern.quote(cp.user.toUpperCase() + "."),"").replaceAll(Pattern.quote(cp.user.toLowerCase() + "."),""));
894 pw[0].println(cp.SQL_TERMINATOR[cp.dbType]);
896 if (!strSplit[0][1].trim().equals(""))pw[0].println(commentOnTable(cp, strSplit[0][0], strSplit[0][1], TYPE_VIEW));
897 for(int i=0;i<alData.size();i++){
898 if ((i+1) % columnCount == 0){
899 if (!alData.get(i).trim().equals(""))pw[0].println(commentOnColumn(cp, strSplit[0][0], alData.get(i-1), alData.get(i), TYPE_VIEW));
904 CmnUtils.infoPrint(String.format("%1$-30s",strSplit[0][0]) + "
\83\81\83^
\83f
\81[
\83^
\82ª
\83A
\83\93\83\8d\81[
\83h
\82³
\82ê
\82Ü
\82µ
\82½
\81B");
906 for(int i=1;i<3;i++)pw[i].close();
907 for(int i=1;i<3;i++)pw[i]=null;
912 // Procedure Contents start
913 br[0] = new BufferedReader(new FileReader(folder + "/" + FILE_NAME[TYPE_PROCEDURE] + "_" + database + "." + cp.fileExtension));
914 subFolder = new File(folder + "/PROCEDURES");
916 pw[1] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_PROCEDURE]))));
917 pw[2] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + cp.SQL_FILE_NAME[cp.DROP_PROCEDURE]))));
918 while((strLine=br[0].readLine()) != null){
919 strSplit[0] = CmnUtils.split(strLine, cp.delimiter);
920 CmnUtils.debugPrint("'" + strSplit[0][0] + "'");
921 pw[1].println(cp.SQL_PREFIX[cp.dbType] + "PROCEDURES/" + strSplit[0][0] + ".sql");
922 pw[2].println("DROP " + strSplit[0][1] + " " + strSplit[0][0] + cp.SQL_TERMINATOR[cp.dbType]);
923 if (strSplit[0].length>1)CmnUtils.debugPrint("'" + strSplit[0][1] + "'");
924 pw[0] = new PrintWriter(new BufferedWriter(new FileWriter(new File(subFolder + "/" + strSplit[0][0] + ".sql"))));
925 if (cp.dbType == cp.DB_TYPE_ORACLE){
926 pw[0].println("/* " + strSplit[0][0] + " */");
927 pw[0].print("CREATE OR REPLACE ");
929 stmt = dao.prepareSql(sql_proc[cp.dbType]);
930 stmt.setString(1,strSplit[0][1]);
931 stmt.setString(2,strSplit[0][0]);
933 alData = dao.getArrayList();
934 for(int i=0;i<alData.size();i++){
935 strContents = alData.get(i);
936 if(!strContents.equals(""))pw[0].println(strContents.replaceAll("\"\"","\"").replaceAll(Pattern.quote(cp.user.toUpperCase() + "."),"").replaceAll(Pattern.quote(cp.user.toLowerCase() + "."),""));
939 if (cp.dbType == cp.DB_TYPE_SQLSERVER){
940 pw[0].println(cp.SQL_TERMINATOR[cp.dbType]);
941 //pw[0].println("/");
945 CmnUtils.infoPrint(String.format("%1$-30s",strSplit[0][0]) + "
\83\81\83^
\83f
\81[
\83^
\82ª
\83A
\83\93\83\8d\81[
\83h
\82³
\82ê
\82Ü
\82µ
\82½
\81B");
947 for(int i=1;i<3;i++)pw[i].close();
948 for(int i=1;i<3;i++)pw[i]=null;
951 // Procedure Contents end
953 // Sequence Contents start
954 br[0] = new BufferedReader(new FileReader(folder + "/" + FILE_NAME[TYPE_SEQ] + "_" + database + "." + cp.fileExtension));
955 pw[1] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_SEQUENCE]))));
956 pw[2] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + cp.SQL_FILE_NAME[cp.DROP_SEQUENCE]))));
958 while((strLine=br[0].readLine()) != null){
959 strSplit[0] = CmnUtils.split(strLine, cp.delimiter);
960 seqName = strSplit[0][0];
961 minVal = strSplit[0][1];
962 maxVal = strSplit[0][2];
963 incSz = strSplit[0][3];
964 cycFg = strSplit[0][4];
965 odFg = strSplit[0][5];
966 cacheSz = strSplit[0][6];
967 if(cacheSz.equals("0"))cacheSz="10";
968 lstNo = strSplit[0][7];
969 pw[1].print("CREATE SEQUENCE " + DB_SQL_QUOTED_S[cp.dbType]+ seqName + DB_SQL_QUOTED_E[cp.dbType]+ " MINVALUE " + minVal + " MAXVALUE " + maxVal + " INCREMENT BY " + incSz + " START WITH " + lstNo);
970 if (cp.dbType == cp.DB_TYPE_ORACLE){
971 pw[1].print(" CACHE " + cacheSz);
972 if (odFg.equals("N")){
973 pw[1].print(" NOORDER");
975 pw[1].print(" ORDER");
977 if (cycFg.equals("N")){
978 pw[1].print(" NOCYCLE");
980 pw[1].print(" CYCLE");
982 } else if (cp.dbType == cp.DB_TYPE_SQLSERVER){
983 if (cacheSz.equals("")){
984 pw[1].print(" NO CACHE");
986 pw[1].print(" CACHE " + cacheSz);
988 if (cycFg.equals("N")){
989 pw[1].print(" NO CYCLE");
991 pw[1].print(" CYCLE");
994 pw[1].println(cp.SQL_TERMINATOR[cp.dbType]);
995 pw[2].println("DROP SEQUENCE " + DB_SQL_QUOTED_S[cp.dbType]+ seqName + DB_SQL_QUOTED_E[cp.dbType]+ cp.SQL_TERMINATOR[cp.dbType]);
996 for(int i=0;i<strSplit[0].length;i++)CmnUtils.debugPrint("'" + strSplit[0][i] + "'");
998 for(int i=1;i<3;i++)pw[i].close();
999 for(int i=1;i<3;i++)pw[i]=null;
1002 // Sequence Contents end
1004 // Synonym Contents start
1005 br[0] = new BufferedReader(new FileReader(folder + "/" + FILE_NAME[TYPE_SYNONYM] + "_" + database + "." + cp.fileExtension));
1006 pw[1] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_SYNONYM]))));
1007 pw[2] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + cp.SQL_FILE_NAME[cp.DROP_SYNONYM]))));
1009 while((strLine=br[0].readLine()) != null){
1010 strSplit[0] = CmnUtils.split(strLine, cp.delimiter);
1011 synmName = strSplit[0][0];
1012 tbOwner = strSplit[0][1];
1013 tbName = strSplit[0][2];
1014 dbLnk = strSplit[0][3];
1016 pw[1].print("CREATE SYNONYM " + DB_SQL_QUOTED_S[cp.dbType]+ synmName + DB_SQL_QUOTED_E[cp.dbType]+ " FOR ");
1017 if(cp.dbType == cp.DB_TYPE_ORACLE){
1018 if(!dbLnk.equals("")){
1019 pw[1].print(DB_SQL_QUOTED_S[cp.dbType]+ tbName + DB_SQL_QUOTED_E[cp.dbType]+ "@" + DB_SQL_QUOTED_S[cp.dbType]+ dbLnk + DB_SQL_QUOTED_S[cp.dbType]);
1021 pw[1].print(DB_SQL_QUOTED_S[cp.dbType]+ tbOwner + DB_SQL_QUOTED_E[cp.dbType]+ "." + DB_SQL_QUOTED_S[cp.dbType]+ tbName + DB_SQL_QUOTED_E[cp.dbType]);
1023 } else if(cp.dbType == cp.DB_TYPE_SQLSERVER){
1024 pw[1].print(tbName);
1026 pw[1].println(cp.SQL_TERMINATOR[cp.dbType]);
1027 pw[2].println("DROP SYNONYM " + DB_SQL_QUOTED_S[cp.dbType]+ synmName + DB_SQL_QUOTED_E[cp.dbType]+ cp.SQL_TERMINATOR[cp.dbType]);
1028 for(int i=0;i<strSplit[0].length;i++)CmnUtils.debugPrint("'" + strSplit[0][i] + "'");
1030 for(int i=1;i<3;i++)pw[i].close();
1031 for(int i=1;i<3;i++)pw[i]=null;
1034 // Synonym Contents end
1036 // Fk Contents start
1037 File tsvFile = new File(folder + "/" + FILE_NAME[TYPE_FK] + "_" + database + "." + cp.fileExtension);
1038 if (tsvFile.length() > 0) {
1039 br[0] = new BufferedReader(new FileReader(folder + "/" + FILE_NAME[TYPE_FK] + "_" + database + "." + cp.fileExtension));
1040 pw[1] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_FK]))));
1041 pw[2] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + cp.SQL_FILE_NAME[cp.DROP_FK]))));
1050 while((strLine=br[0].readLine()) != null){
1051 strSplit[0] = CmnUtils.split(strLine, cp.delimiter);
1052 if(!fkName.equals(strSplit[0][1]) && !fkName.equals("")){
1053 pw[1].println("ALTER TABLE " + DB_SQL_QUOTED_S[cp.dbType]+ tbName + DB_SQL_QUOTED_E[cp.dbType]+ " ADD CONSTRAINT " + DB_SQL_QUOTED_S[cp.dbType]+ fkName + DB_SQL_QUOTED_E[cp.dbType]+ " FOREIGN KEY (" + DB_SQL_QUOTED_S[cp.dbType]+ fkCol + DB_SQL_QUOTED_E[cp.dbType]+ ") REFERENCES " + DB_SQL_QUOTED_S[cp.dbType]+ rtbName + DB_SQL_QUOTED_E[cp.dbType]+ " (" + DB_SQL_QUOTED_S[cp.dbType]+ rfkCol + DB_SQL_QUOTED_E[cp.dbType]+ ")" + cp.SQL_TERMINATOR[cp.dbType]);
1054 pw[2].println("ALTER TABLE " + DB_SQL_QUOTED_S[cp.dbType]+ tbName + DB_SQL_QUOTED_E[cp.dbType]+ " DROP CONSTRAINT " + DB_SQL_QUOTED_S[cp.dbType]+ fkName + DB_SQL_QUOTED_E[cp.dbType]+ cp.SQL_TERMINATOR[cp.dbType]);
1055 for(int i=0;i<strSplit[0].length;i++)CmnUtils.debugPrint("'" + strSplit[0][i] + "'");
1056 tbName = strSplit[0][0];
1057 fkName = strSplit[0][1];
1058 fkCol = strSplit[0][2];
1059 fkColPos = strSplit[0][3];
1060 rtbName = strSplit[0][4];
1061 rfkCol = strSplit[0][5];
1062 rfkColPos = strSplit[0][6];
1064 if(fkName.equals("")){
1065 tbName = strSplit[0][0];
1066 fkName = strSplit[0][1];
1067 fkCol = strSplit[0][2];
1068 fkColPos = strSplit[0][3];
1069 rtbName = strSplit[0][4];
1070 rfkCol = strSplit[0][5];
1071 rfkColPos = strSplit[0][6];
1074 (cp.dbType == cp.DB_TYPE_ORACLE && strSplit[0][3].equals(strSplit[0][6])) ||
1075 cp.dbType != cp.DB_TYPE_ORACLE
1077 fkCol = fkCol + DB_SQL_QUOTED_E[cp.dbType]+ ", " + DB_SQL_QUOTED_S[cp.dbType]+ strSplit[0][2];
1078 rfkCol = rfkCol + DB_SQL_QUOTED_E[cp.dbType]+ ", " + DB_SQL_QUOTED_S[cp.dbType]+ strSplit[0][5];
1084 pw[1].println("ALTER TABLE " + DB_SQL_QUOTED_S[cp.dbType]+ tbName + DB_SQL_QUOTED_E[cp.dbType]+ " ADD CONSTRAINT " + DB_SQL_QUOTED_S[cp.dbType]+ fkName + DB_SQL_QUOTED_E[cp.dbType]+ " FOREIGN KEY (" + DB_SQL_QUOTED_S[cp.dbType]+ fkCol + DB_SQL_QUOTED_E[cp.dbType]+ ") REFERENCES " + DB_SQL_QUOTED_S[cp.dbType]+ rtbName + DB_SQL_QUOTED_E[cp.dbType]+ " (" + DB_SQL_QUOTED_S[cp.dbType]+ rfkCol + DB_SQL_QUOTED_E[cp.dbType]+ ")" + cp.SQL_TERMINATOR[cp.dbType]);
1085 pw[2].println("ALTER TABLE " + DB_SQL_QUOTED_S[cp.dbType]+ tbName + DB_SQL_QUOTED_E[cp.dbType]+ " DROP CONSTRAINT " + DB_SQL_QUOTED_S[cp.dbType]+ fkName + DB_SQL_QUOTED_E[cp.dbType]+ cp.SQL_TERMINATOR[cp.dbType]);
1086 for(int i=1;i<3;i++)pw[i].close();
1087 for(int i=1;i<3;i++)pw[i]=null;
1093 // Rhysical Contents start
1094 if(cp.isPhysical && cp.dbType == cp.DB_TYPE_ORACLE){
1095 // physical index setting
1096 br[0] = new BufferedReader(new FileReader(folder + "/" + FILE_NAME[TYPE_OBJ] + "_" + database + "." + cp.fileExtension));
1097 br[1] = new BufferedReader(new FileReader(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_PKEY]));
1098 br[2] = new BufferedReader(new FileReader(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_UKEY]));
1099 br[3] = new BufferedReader(new FileReader(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_INDEX]));
1100 pw[1] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_PKEY] + "." + phyfileExtension))));
1101 pw[2] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_UKEY] + "." + phyfileExtension))));
1102 pw[3] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_INDEX] + "." + phyfileExtension))));
1103 alData = new ArrayList<String>();
1106 while((strLine=br[0].readLine()) != null){
1107 strSplit[0] = CmnUtils.split(strLine, cp.delimiter);
1108 for(int i=0;i<strSplit[0].length;i++)alData.add(strSplit[0][i]);
1110 while((strLine=br[1].readLine()) != null){
1111 strSplit[0] = CmnUtils.splitSpace(strLine);
1112 rowNo = CmnUtils.getArrayRowNo(alData, 12, 1, strSplit[0][5].replaceAll("\"",""));
1114 rowData = rowData = CmnUtils.getArrayRowData(alData, 12, rowNo);
1115 CmnUtils.debugPrint(strSplit[0][5] + ":" + rowNo);
1116 for(int i=0;i<rowData.length;i++)CmnUtils.debugPrint(rowData[i]);
1117 tbName = rowData[0];
1118 objName = rowData[1];
1119 objTyp = rowData[2];
1120 pctFree = rowData[3];
1121 pctUsed = rowData[4];
1122 iniTrns = rowData[5];
1123 freeLst = rowData[6];
1124 flstGrp = rowData[7];
1125 bufPool = rowData[8];
1126 tblSpace = rowData[9];
1127 logging = rowData[10];
1128 segByts = rowData[11];
1129 pw[1].print(strLine.replace(';',' '));
1130 pw[1].print("USING INDEX PCTFREE " + pctFree);
1131 pw[1].print(" INITRANS " + iniTrns + " STORAGE(");
1132 if(!freeLst.equals(""))pw[1].print(" FREELISTS " + freeLst);
1133 if(!flstGrp.equals(""))pw[1].print(" FREELIST GROUPS " + flstGrp);
1134 pw[1].print(" BUFFER_POOL " + bufPool + ")");
1135 pw[1].print(" TABLESPACE " + DB_SQL_QUOTED_S[cp.dbType]+ tblSpace + DB_SQL_QUOTED_E[cp.dbType]);
1136 if(logging.equals("NO")){
1137 pw[1].println(" NOLOGGING" + cp.SQL_TERMINATOR[cp.dbType]);
1139 pw[1].println(cp.SQL_TERMINATOR[cp.dbType]);
1142 pw[1].println(strLine);
1143 CmnUtils.errorPrint(strSplit[0][5] + ",UNUSABLE INDEX");
1146 while((strLine=br[2].readLine()) != null){
1147 strSplit[0] = CmnUtils.splitSpace(strLine);
1148 rowNo = CmnUtils.getArrayRowNo(alData, 12, 1, strSplit[0][5].replaceAll("\"",""));
1150 rowData = rowData = CmnUtils.getArrayRowData(alData, 12, rowNo);
1151 CmnUtils.debugPrint(strSplit[0][5] + ":" + rowNo);
1152 for(int i=0;i<rowData.length;i++)CmnUtils.debugPrint(rowData[i]);
1153 tbName = rowData[0];
1154 objName = rowData[1];
1155 objTyp = rowData[2];
1156 pctFree = rowData[3];
1157 pctUsed = rowData[4];
1158 iniTrns = rowData[5];
1159 freeLst = rowData[6];
1160 flstGrp = rowData[7];
1161 bufPool = rowData[8];
1162 tblSpace = rowData[9];
1163 logging = rowData[10];
1164 segByts = rowData[11];
1165 pw[2].print(strLine.replace(';',' '));
1166 pw[2].print("USING INDEX PCTFREE " + pctFree);
1167 pw[2].print(" INITRANS " + iniTrns + " STORAGE(");
1168 if(!freeLst.equals(""))pw[2].print(" FREELISTS " + freeLst);
1169 if(!flstGrp.equals(""))pw[2].print(" FREELIST GROUPS " + flstGrp);
1170 pw[2].print(" BUFFER_POOL " + bufPool + ")");
1171 pw[2].print(" TABLESPACE " + DB_SQL_QUOTED_S[cp.dbType]+ tblSpace + DB_SQL_QUOTED_E[cp.dbType]);
1172 if(logging.equals("NO")){
1173 pw[2].println(" NOLOGGING" + cp.SQL_TERMINATOR[cp.dbType]);
1175 pw[2].println(cp.SQL_TERMINATOR[cp.dbType]);
1178 pw[2].println(strLine);
1179 CmnUtils.errorPrint(strSplit[0][5] + ",UNUSABLE INDEX");
1182 while((strLine=br[3].readLine()) != null){
1183 strSplit[0] = CmnUtils.splitSpace(strLine);
1184 rowNo = CmnUtils.getArrayRowNo(alData, 12, 1, strSplit[0][2].replaceAll("\"",""));
1185 CmnUtils.debugPrint("rowNo=" + rowNo);
1187 rowData = CmnUtils.getArrayRowData(alData, 12, rowNo);
1188 for(int i=0;i<rowData.length;i++)CmnUtils.debugPrint(rowData[i]);
1189 tbName = rowData[0];
1190 objName = rowData[1];
1191 objTyp = rowData[2];
1192 pctFree = rowData[3];
1193 pctUsed = rowData[4];
1194 iniTrns = rowData[5];
1195 freeLst = rowData[6];
1196 flstGrp = rowData[7];
1197 bufPool = rowData[8];
1198 tblSpace = rowData[9];
1199 logging = rowData[10];
1200 segByts = rowData[11];
1201 pw[3].print(strLine.replace(';',' '));
1202 pw[3].print("PCTFREE " + pctFree);
1203 pw[3].print(" INITRANS " + iniTrns + " STORAGE(");
1204 if(!freeLst.equals(""))pw[3].print(" FREELISTS " + freeLst);
1205 if(!flstGrp.equals(""))pw[3].print(" FREELIST GROUPS " + flstGrp);
1206 pw[3].print(" BUFFER_POOL " + bufPool + ")");
1207 pw[3].print(" TABLESPACE " + DB_SQL_QUOTED_S[cp.dbType]+ tblSpace + DB_SQL_QUOTED_E[cp.dbType]);
1208 if(logging.equals("NO")){
1209 pw[3].println(" NOLOGGING" + cp.SQL_TERMINATOR[cp.dbType]);
1211 pw[3].println(cp.SQL_TERMINATOR[cp.dbType]);
1214 pw[3].println(strLine);
1215 CmnUtils.errorPrint(strSplit[0][2] + ",UNUSABLE INDEX");
1218 for(int i=1;i<4;i++)pw[i].close();
1219 for(int i=1;i<4;i++)pw[i]=null;
1220 for(int i=0;i<4;i++)br[i].close();
1221 for(int i=0;i<4;i++)br[i]=null;
1223 File [] fmFl = new File[6];
1224 File [] toFl = new File[6];
1226 fmFl[0] = new File(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_PKEY] + "." + phyfileExtension);
1227 fmFl[1] = new File(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_UKEY] + "." + phyfileExtension);
1228 fmFl[2] = new File(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_INDEX] + "." + phyfileExtension);
1229 toFl[0] = new File(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_PKEY]);
1230 toFl[1] = new File(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_UKEY]);
1231 toFl[2] = new File(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_INDEX]);
1232 for(int i=0;i<3;i++){
1233 CmnUtils.debugPrint(fmFl[i].toString() + ">" + toFl[i].toString());
1235 fmFl[i].renameTo(toFl[i]);
1238 // physical table setting
1239 File tbDir = new File(folder + "/TABLES");
1240 File [] tbFiles = tbDir.listFiles();
1243 for(int i=0;i<tbFiles.length;i++){
1245 tbName = tb.getName().replaceAll(".sql","");
1246 oTb = new File(tb + "." + phyfileExtension);
1247 CmnUtils.debugPrint(tbName);
1248 br[0] = new BufferedReader(new FileReader(tb));
1249 pw[0] = new PrintWriter(new BufferedWriter(new FileWriter(oTb)));
1250 while((strLine=br[0].readLine()) != null){
1251 if(strLine.equals(")" + cp.SQL_TERMINATOR[cp.dbType])){
1252 rowNo = CmnUtils.getArrayRowNo(alData, 12, 1, tbName);
1254 rowData = CmnUtils.getArrayRowData(alData, 12, rowNo);
1255 CmnUtils.debugPrint(tbName + ":" + rowNo);
1256 //for(int j=0;j<rowData.length;i++)CmnUtils.debugPrint(rowData[j]);
1257 tbName = rowData[0];
1258 objName = rowData[1];
1259 objTyp = rowData[2];
1260 pctFree = rowData[3];
1261 pctUsed = rowData[4];
1262 iniTrns = rowData[5];
1263 freeLst = rowData[6];
1264 flstGrp = rowData[7];
1265 bufPool = rowData[8];
1266 tblSpace = rowData[9];
1267 logging = rowData[10];
1268 segByts = rowData[11];
1269 pw[0].print(") PCTFREE " + pctFree);
1270 if(!pctUsed.equals(""))pw[0].print(" PCTUSED " + pctUsed);
1271 pw[0].print(" INITRANS " + iniTrns + " STORAGE(");
1272 if(!freeLst.equals(""))pw[0].print(" FREELISTS " + freeLst);
1273 if(!flstGrp.equals(""))pw[0].print(" FREELIST GROUPS " + flstGrp);
1274 pw[0].print(" BUFFER_POOL " + bufPool + ")");
1275 pw[0].print(" TABLESPACE " + DB_SQL_QUOTED_S[cp.dbType]+ tblSpace + DB_SQL_QUOTED_E[cp.dbType]);
1276 if(logging.equals("NO")){
1277 pw[0].println(" NOLOGGING" + cp.SQL_TERMINATOR[cp.dbType]);
1279 pw[0].println(cp.SQL_TERMINATOR[cp.dbType]);
1282 pw[0].println(")" + cp.SQL_TERMINATOR[cp.dbType]);
1285 pw[0].println(strLine);
1296 // Rhysical Contents end
1300 for(int i=0;i<sql[cp.dbType].length;i++){
1301 fl= new File(folder + "/" + FILE_NAME[i] + "_" + database + "." + cp.fileExtension);
1302 CmnUtils.debugPrint(fl.toString());
1306 // disconnect database
1308 CmnUtils.infoPrint("
\83\81\83^
\83f
\81[
\83^
\83A
\83\93\83\8d\81[
\83h
\82ð
\8fI
\97¹
\82µ
\82Ü
\82µ
\82½
\81B");
1310 } catch(SQLException se) {
1312 CmnUtils.errorPrint(se.toString());
1313 se.printStackTrace();
1314 se = se.getNextException();
1316 System.out.println(se.getMessage());
1319 } catch (Exception see) {}
1320 } catch (Exception e) {
1322 CmnUtils.errorPrint(e.toString());
1323 e.printStackTrace();
1325 } catch (Exception ee) {}
1328 for(int i=0;i<6;i++){
1334 for(int i=0;i<4;i++){
1340 } catch (Exception e) {}
1344 private String commentOnTable(CmnProps _cp, String _tableName, String _tableCmnt, int _type) throws Exception{
1346 if(!_tableCmnt.equals("")){
1347 switch (_cp.dbType) {
1348 case DB_TYPE_ORACLE:
1349 retVal = "COMMENT ON TABLE " + DB_SQL_QUOTED_S[_cp.dbType]+ _tableName + DB_SQL_QUOTED_E[_cp.dbType]+ " IS '" + _tableCmnt.replaceAll("'","''") + "'" + _cp.SQL_TERMINATOR[_cp.dbType];
1351 case DB_TYPE_SQLSERVER:
1352 if(_type == TYPE_TABLE){
1353 retVal = "exec sys.sp_addextendedproperty @name=N'MS_Description',@value=N'" + _tableCmnt.replaceAll("'","''") + "',@level0type=N'schema',@level0name=N'dbo',@level1type=N'table',@level1name=N'" + _tableName + "'" + _cp.SQL_TERMINATOR[_cp.dbType];
1354 } else if(_type == TYPE_VIEW){
1355 retVal = "exec sys.sp_addextendedproperty @name=N'MS_Description',@value=N'" + _tableCmnt.replaceAll("'","''") + "',@level0type=N'schema',@level0name=N'dbo',@level1type=N'view',@level1name=N'" + _tableName + "'" + _cp.SQL_TERMINATOR[_cp.dbType];
1363 private String commentOnColumn(CmnProps _cp, String _tableName, String _colName, String _colCmnt, int _type) throws Exception{
1365 if(!_colCmnt.equals("")){
1366 switch (_cp.dbType) {
1367 case DB_TYPE_ORACLE:
1368 retVal = "COMMENT ON COLUMN " + DB_SQL_QUOTED_S[_cp.dbType]+ _tableName + DB_SQL_QUOTED_E[_cp.dbType]+ "." + DB_SQL_QUOTED_S[_cp.dbType]+ _colName + DB_SQL_QUOTED_E[_cp.dbType]+ " IS '" + _colCmnt.replaceAll("'","''") + "'" + _cp.SQL_TERMINATOR[_cp.dbType];
1370 case DB_TYPE_SQLSERVER:
1371 if(_type == TYPE_TABLE){
1372 retVal = "exec sys.sp_addextendedproperty @name=N'MS_Description',@value=N'" + _colCmnt.replaceAll("'","''") + "',@level0type=N'schema',@level0name=N'dbo',@level1type=N'table',@level1name=N'" + _tableName + "',@level2type=N'column',@level2name=N'" + _colName + "'" + _cp.SQL_TERMINATOR[_cp.dbType];
1373 } else if(_type == TYPE_VIEW){
1374 retVal = "exec sys.sp_addextendedproperty @name=N'MS_Description',@value=N'" + _colCmnt.replaceAll("'","''") + "',@level0type=N'schema',@level0name=N'dbo',@level1type=N'view',@level1name=N'" + _tableName + "',@level2type=N'column',@level2name=N'" + _colName + "'" + _cp.SQL_TERMINATOR[_cp.dbType];