OSDN Git Service

20170514
[rapideact/rapideact.git] / com / rapide_act / RapideMetaUnloader.java
1 package com.rapide_act;
2
3 import java.io.BufferedInputStream;
4 import java.io.FileInputStream;
5 import java.io.IOException;
6 import java.io.InputStream;
7 import java.io.File;
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;
26 import java.sql.Blob;
27 import java.sql.Clob;
28
29 public class RapideMetaUnloader{
30
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 = {
47                 "TABLEDEF",
48                 "INDEXDEF",
49                 "VIEWDEF",
50                 "PROCDEF",
51                 "SEQDEF",
52                 "SYNMDEF",
53                 "OBJDEF",
54                 "FKDEF"
55         };
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 =  {
63                 {       //ORACLE
64                 "select "
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",
84                 "select "
85                      + " a.table_name,"
86                      + " a.index_name,"
87                      + " a.index_type,"
88                      + " c.constraint_type,"
89                      + " b.column_name,"
90                      + " b.column_position "
91                      + " from"
92                      + " user_indexes a,"
93                      + " user_ind_columns b,"
94                      + " user_constraints c "
95                      + " where"
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(+) "
100                      + " order by"
101                      + " a.table_name,"
102                      + " a.index_name,"
103                      + " b.column_position",
104                 "select "
105                      + " a.view_name, "
106                      + " replace(replace(c.comments, chr(13), ''), chr(10), '') as comments "
107                      + " from"
108                      + " user_views a, "
109                      + " user_tab_comments c "
110                      + " where"
111                         + "  a.view_name = c.table_name(+) "
112                      + " order by"
113                      + " a.view_name",
114                 "select "
115                      + " object_name, "
116                      + " object_type "
117                      + "from"
118                      + " user_objects"
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",
122                 "select "
123                      + "  sequence_name,"
124                      + "  to_char(min_value) as min_value,"
125                      + "  to_char(max_value) as max_value,"
126                      + "  to_char(increment_by) as increment_by,"
127                      + "  cycle_flag,"
128                      + "  order_flag,"
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",
133                 "select "
134                      + "  synonym_name,"
135                      + "  table_owner,"
136                      + "  table_name,"
137                      + "  db_link "
138                      + "from user_synonyms "
139                      + "order by synonym_name,table_owner,table_name",
140                 "select "
141                      + " a.table_name,"
142                      + " a.object_name,"
143                      + " a.object_type,"
144                      + " a.pct_free,"
145                      + " a.pct_used,"
146                      + " a.ini_trans,"
147                      + " a.freelists,"
148                      + " a.freelist_groups,"
149                      + " a.buffer_pool,"
150                      + " a.tablespace_name, "
151                      + " a.logging, "
152                      + " b.bytes "
153                      + "from "
154                      + "(select "
155                      + " table_name,"
156                      + " table_name as object_name,"
157                      + " 'TABLE' as object_type,"
158                      + " pct_free,"
159                      + " pct_used,"
160                      + " ini_trans,"
161                      + " freelists,"
162                      + " freelist_groups,"
163                      + " buffer_pool,"
164                      + " tablespace_name, "
165                      + " logging "
166                      + "from "
167                      + " user_tables "
168                      + " union select "
169                      + " table_name,"
170                      + " index_name as object_name,"
171                      + " 'INDEX' as object_type,"
172                      + " pct_free,"
173                      + " null as pct_used,"
174                      + " ini_trans,"
175                      + " freelists,"
176                      + " freelist_groups,"
177                      + " buffer_pool,"
178                      + " tablespace_name, "
179                      + " logging "
180                      + " from "
181                      + " user_indexes "
182                      + ") a, "
183                      + "(select "
184                      + " segment_name,"
185                      + " segment_type,"
186                      + " bytes "
187                      + " from "
188                      + " user_segments "
189                      + ") b "
190                      + " where a.object_name = b.segment_name "
191                      + " and a.object_type = b.segment_type "
192                      + " order by"
193                      + " a.table_name,"
194                      + " a.object_name",
195                 "select distinct "
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 "
203                      + " from "
204                      + "   user_constraints a, "
205                      + "   user_cons_columns b,"
206                      + "   user_constraints c, "
207                      + "   user_cons_columns d "
208                      + " where "
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"
219                      + " order by"
220                      + "   a.table_name,a.constraint_name,b.position,d.position"
221                 },
222                 {       //SQL SERVER
223                 "select "
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'"
234                      + "  else null "
235                      + "end as nullable,"
236                      + "g.definition as data_default "
237                      + "from "
238                      + "sys.tables as a "
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 ",
255                 "select "
256                      + "d.name as table_name, "
257                      + "a.name as index_name, "
258                      + "a.type as index_type, "
259                      + "case a.is_unique "
260                      + "  when 1 then "
261                      + "    case a.is_primary_key "
262                      + "      when 1 then 'P' "
263                      + "        else "
264                      + "            case a.is_unique_constraint "
265                      + "                when 1 then 'U' "
266                      + "                else '' "
267                      + "            end "
268                      + "    end "
269                      + "  else '' "
270                      + "end as constraint_type, "
271                      + "c.name as column_name, "
272                      + "b.key_ordinal as column_position "
273                      + "from "
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",
283                 "select "
284                      + " a.name as view_name, "
285                      + " replace(replace(cast(b.value as varchar(4000)), char(13), ''), char(10), '') as comments "
286                      + "from "
287                      + " sys.views a "
288                      + " left outer join sys.extended_properties as b "
289                      + " on a.object_id = b.major_id and b.minor_id = 0 "
290                      + "order by "
291                      + " a.name",
292                 "select "
293                      + " name as object_name, 'PROCEDURE' as object_type from sys.procedures"
294                      + " union select "
295                      + " name as object_name, 'FUNCTION' as object_type from sys.objects where type in('FN', 'FS', 'FT', 'IF', 'TF') "
296                      + " union select "
297                      + " name as object_name, 'TRIGGER' as object_type from sys.triggers "
298                      + " order by object_name,object_type ",
299                 "select "
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 "
309                      + " order by name",
310                 "select "
311                      + " a.name as synonym_name,"
312                      + " b.name as table_owner,"
313                      + " base_object_name as table_name,"
314                      + " '' as db_link "
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",
319                 "select "
320                      + " c.name as table_name, "
321                      + " b.index_id, "
322                      + " d.name as index_name , "
323                      + " a.type_desc as allocation_type, "
324                      + " a.data_pages, "
325                      + " partition_number "
326                      + "from "
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",
335                 "select distinct "
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"
359                 }
360         };
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 "
369                      + "where a.name = ?"
370         };
371         private static String sql_view_column_and_comment[] = {
372                 "select "
373              + " b.column_name,"
374              + " replace(replace(d.comments, chr(13), ''), chr(10), '') as comments "
375              + " from"
376              + " user_tab_columns b,"
377              + " user_col_comments d "
378              + " where"
379              + "  b.table_name = ? and"
380              + "  b.table_name = d.table_name(+) and"
381              + "  b.column_name = d.column_name(+) "
382              + " order by"
383              + " b.column_id",
384             " select "
385              + " b.name as column_name, "
386              + " '' as comments "
387              + " from "
388              + " sys.objects a "
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"
394         };
395         private static String sql_proc[] = {
396                 "select text from user_source where type = ? and name = ? order by line",
397                 "select d.definition "
398                      + "from "
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 "
405                      + "union select "
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') "
412                      + "union select "
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 = ?"
420         };
421
422         private String database = null;
423         private String phyfileExtension = "phy";
424
425         public static void main(String args[]){
426                 try {
427                         if (args.length > 0){
428                                 RapideMetaUnloader RapideMetaUnloader = new RapideMetaUnloader(args[0]);
429                                 RapideMetaUnloader.metaUnload();
430                         } else {
431                                 RapideMetaUnloader RapideMetaUnloader = new RapideMetaUnloader(null);
432                                 RapideMetaUnloader.metaUnload();
433                         }
434                 } catch (Exception e) {
435                         e.printStackTrace();
436                 }
437         }
438
439         RapideMetaUnloader(String _database) {
440                 super();
441                 database = _database;
442         }
443
444
445         private void metaUnload(){
446                 Connection conn = null;
447                 PreparedStatement stmt = null;
448                 BufferedReader [] br = new BufferedReader[4];
449                 PrintWriter [] pw = new PrintWriter[6];
450                 File folder = null;
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;
458                 int columnCount = 0;
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;
476                 String incSz = null;
477                 String cycFg = null;
478                 String odFg = null;
479                 String cacheSz = null;
480                 String lstNo = null;
481                 String synmOwner = null;
482                 String synmName = null;
483                 String tbOwner = null;
484                 String tbName = null;
485                 String dbLnk = null;
486                 String userName = null;
487                 String passWord = null;
488                 String host = 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;
496                 String prvs = null;
497                 String grntabl = null;
498                 String hrchy = null;
499
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;
511
512                 String fkName = null;
513                 String fkCol = null;
514                 String fkColPos = null;
515                 String rtbName = null;
516                 String rfkName = null;
517                 String rfkCol = null;
518                 String rfkColPos = null;
519
520                 CmnProps cp = null;
521                 CmnAccessObjects dao = null;
522                 
523                 try {
524                         cp = new CmnProps();
525                         cp.setProperty(database);
526                         
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] + "]");
529                         }
530                         if(cp.outFolder != null){
531                                 folder = new File(cp.outFolder);
532                         } else {
533                                 if(database != null){
534                                         folder = new File(cp.DEFAULT_OUT_FOLDER + "/DDL_" + database.toUpperCase() + "_" + CmnUtils.getYmdhm());
535                                 } else {
536                                         folder = new File(cp.DEFAULT_OUT_FOLDER + "/DDL_" + cp.DB_TYPE_NAME[cp.dbType].toUpperCase() + "_" + CmnUtils.getYmdhm());
537                                 }
538                                 folder.mkdir();
539                         }
540
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");
543
544                         // Connect
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);
551                         }
552                         // Def tsv Writing end
553
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");
557                         subFolder.mkdir();
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]))));
561
562                         tableName = "";
563                         tableCmnt = "";
564                         colName = "";
565                         colCmnt = "";
566                         colType = "";
567                         colLen = "";
568                         colPrec = "";
569                         colScale = "";
570                         colNoN = "";
571                         colDflt = "";
572
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)");
590                                                         } else {
591                                                                 sbTbCnts.append("(" + CmnUtils.getColLength(colType, colLen) + ")");
592                                                         }
593                                                 }
594                                                 if (!colDflt.equals(""))sbTbCnts.append(" DEFAULT " + colDflt.trim());
595                                                 if (!colNoN.equals("")){
596                                                         sbTbCnts.append(" NOT NULL");
597                                                 } else {
598                                                         sbTbCnts.append(" NULL");
599                                                 }
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]);
612                                                         pw[0].close();
613                                                         pw[0] = null;
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);
623                                                 } else {
624                                                         sbTbCnts.append(",");
625                                                         sbTbCnts.append(lineSeparator);
626                                                 }
627                                         }
628                                         else {
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);
635                                         }
636                                         for(int i=0;i<strSplit[0].length;i++)CmnUtils.debugPrint("'" + strSplit[0][i] + "'");
637
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];
648                                 }
649                         }
650
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)");
663                                         } else {
664                                                 sbTbCnts.append("(" + CmnUtils.getColLength(colType, colLen) + ")");
665                                         }
666                                 }
667                                 if (!colDflt.equals(""))sbTbCnts.append(" DEFAULT " + colDflt.trim());
668                                 if (!colNoN.equals("")){
669                                         sbTbCnts.append(" NOT NULL");
670                                 } else {
671                                         sbTbCnts.append(" NULL");
672                                 }
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]);
684                                 pw[0].close();
685                                 pw[0] = null;
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");
687                         }
688                         for(int i=1;i<4;i++)pw[i].close();
689                         for(int i=1;i<4;i++)pw[i]=null;
690                         br[0].close();
691                         br[0] = null;
692                         // Table Contents end
693
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]))));
702
703                         //Initial Process
704                         tableName = "";
705                         indexName = "";
706                         indexType = "";
707                         constraintType = "";
708                         colName = "";
709                         colPos = "";
710                         StringBuffer sbIxCnts = new StringBuffer();
711                         StringBuffer sbIx2Cnts = new StringBuffer();
712                         StringBuffer sbIx3Cnts = new StringBuffer();
713
714                         //Loop Process
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)){
721                                                         //Post Process
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]);
725                                                         } else {
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]);
728                                                         }
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);
734
735                                                         //Write Buffer
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]);
749                                                         }
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]);
752
753                                                         //Initial Process
754                                                         sbIxCnts = new StringBuffer();
755                                                         sbIx2Cnts = new StringBuffer();
756                                                         sbIx3Cnts = new StringBuffer();
757
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] + "(");
767                                                         }
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]);
773                                                         } else {
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]);
776                                                         }
777                                                 }
778                                         }
779
780                                         //1st Line Process
781                                         else {
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]+ "(");
790                                                 }
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]);
792                                         }
793                                         for(int i=0;i<strSplit[0].length;i++)CmnUtils.debugPrint("'" + strSplit[0][i] + "'");
794
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];
801                                 }
802                         }
803                         if (!indexName.equals("")){
804                                 //Post Process
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]);
808                                 } else {
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]);
811                                 }
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);
817
818                                 //Write Buffer
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]);
832                                 }
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]);
835                         }
836
837                         //Close Buffer
838                         for(int i=0;i<6;i++)pw[i].close();
839                         for(int i=0;i<6;i++)pw[i]=null;
840                         br[0].close();
841                         br[0] = null;
842                         // Index Contents end
843
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");
847                         subFolder.mkdir();
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"))));
857                                 
858                                 stmt = dao.prepareSql(sql_view_column_and_comment[cp.dbType]);
859                                 stmt.setString(1,strSplit[0][0]);
860                                 dao.executeSql();
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]);
866                                         pw[0].println("(");
867                                         for(int i=0;i<alData.size();i++){
868                                                 if ((i+1) % columnCount == 1){
869                                                         if (i == 0){
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));
872                                                                 } else {
873                                                                         pw[0].println("    " + DB_SQL_QUOTED_S[cp.dbType]+ alData.get(i) + DB_SQL_QUOTED_E[cp.dbType]);
874                                                                 }
875                                                         } else {
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));
878                                                                 } else {
879                                                                         pw[0].println("    ," + DB_SQL_QUOTED_S[cp.dbType]+ alData.get(i) + DB_SQL_QUOTED_E[cp.dbType]);
880                                                                 }
881                                                         }
882                                                 }
883                                         }
884                                         pw[0].println(")");
885                                         pw[0].println("AS");
886                                 }
887                                 stmt = dao.prepareSql(sql_view_text[cp.dbType]);
888                                 stmt.setString(1,strSplit[0][0]);
889                                 dao.executeSql();
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]);
895
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));
900                                         }
901                                 }
902                                 pw[0].close();
903                                 pw[0] = null;
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");
905                         }
906                         for(int i=1;i<3;i++)pw[i].close();
907                         for(int i=1;i<3;i++)pw[i]=null;
908                         br[0].close();
909                         br[0] = null;
910                         // View Contents end
911
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");
915                         subFolder.mkdir();
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 ");
928                                 }
929                                 stmt = dao.prepareSql(sql_proc[cp.dbType]);
930                                 stmt.setString(1,strSplit[0][1]);
931                                 stmt.setString(2,strSplit[0][0]);
932                                 dao.executeSql();
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() + "."),""));
937                                 }
938                                 
939                                 if (cp.dbType == cp.DB_TYPE_SQLSERVER){
940                                         pw[0].println(cp.SQL_TERMINATOR[cp.dbType]);
941                                         //pw[0].println("/");
942                                 }
943                                 pw[0].close();
944                                 pw[0] = null;
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");
946                         }
947                         for(int i=1;i<3;i++)pw[i].close();
948                         for(int i=1;i<3;i++)pw[i]=null;
949                         br[0].close();
950                         br[0] = null;
951                         // Procedure Contents end
952
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]))));
957
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");
974                                         } else {
975                                                 pw[1].print(" ORDER");
976                                         }
977                                         if (cycFg.equals("N")){
978                                                 pw[1].print(" NOCYCLE");
979                                         } else {
980                                                 pw[1].print(" CYCLE");
981                                         }
982                                 } else if (cp.dbType == cp.DB_TYPE_SQLSERVER){
983                                         if (cacheSz.equals("")){
984                                                 pw[1].print(" NO CACHE");
985                                         } else {
986                                                 pw[1].print(" CACHE " + cacheSz);
987                                         }
988                                         if (cycFg.equals("N")){
989                                                 pw[1].print(" NO CYCLE");
990                                         } else {
991                                                 pw[1].print(" CYCLE");
992                                         }
993                                 }
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] + "'");
997                         }
998                         for(int i=1;i<3;i++)pw[i].close();
999                         for(int i=1;i<3;i++)pw[i]=null;
1000                         br[0].close();
1001                         br[0] = null;
1002                         // Sequence Contents end
1003
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]))));
1008
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];
1015                                 
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]);
1020                                         } else {
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]);
1022                                         }
1023                                 } else if(cp.dbType == cp.DB_TYPE_SQLSERVER){
1024                                         pw[1].print(tbName);
1025                                 }
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] + "'");
1029                         }
1030                         for(int i=1;i<3;i++)pw[i].close();
1031                         for(int i=1;i<3;i++)pw[i]=null;
1032                         br[0].close();
1033                         br[0] = null;
1034                         // Synonym Contents end
1035
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]))));
1042                                 tbName = "";
1043                                 fkName = "";
1044                                 fkCol = "";
1045                                 fkColPos = "";
1046                                 rtbName = "";
1047                                 rfkCol = "";
1048                                 rfkColPos = "";
1049                                 
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];
1063                                         } else {
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];
1072                                                 } else {
1073                                                         if (
1074                                                                 (cp.dbType == cp.DB_TYPE_ORACLE && strSplit[0][3].equals(strSplit[0][6])) ||
1075                                                                  cp.dbType != cp.DB_TYPE_ORACLE
1076                                                         ) {
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];
1079                                                         }
1080                                                 }
1081                                         }
1082                                         
1083                                 }
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;
1088                                 br[0].close();
1089                                 br[0] = null;
1090                         }
1091                         // Fk Contents end
1092
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>();
1104                                 int rowNo;
1105                                 String [] rowData;
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]);
1109                                 }
1110                                 while((strLine=br[1].readLine()) != null){
1111                                         strSplit[0] = CmnUtils.splitSpace(strLine);
1112                                         rowNo = CmnUtils.getArrayRowNo(alData, 12, 1, strSplit[0][5].replaceAll("\"",""));
1113                                         if (rowNo != -1){
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]);
1138                                                 } else {
1139                                                         pw[1].println(cp.SQL_TERMINATOR[cp.dbType]);
1140                                                 }
1141                                         } else {
1142                                                 pw[1].println(strLine);
1143                                                 CmnUtils.errorPrint(strSplit[0][5] + ",UNUSABLE INDEX");
1144                                         }
1145                                 }
1146                                 while((strLine=br[2].readLine()) != null){
1147                                         strSplit[0] = CmnUtils.splitSpace(strLine);
1148                                         rowNo = CmnUtils.getArrayRowNo(alData, 12, 1, strSplit[0][5].replaceAll("\"",""));
1149                                         if (rowNo != -1){
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]);
1174                                                 } else {
1175                                                         pw[2].println(cp.SQL_TERMINATOR[cp.dbType]);
1176                                                 }
1177                                         } else {
1178                                                 pw[2].println(strLine);
1179                                                 CmnUtils.errorPrint(strSplit[0][5] + ",UNUSABLE INDEX");
1180                                         }
1181                                 }
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);
1186                                         if (rowNo != -1){
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]);
1210                                                 } else {
1211                                                         pw[3].println(cp.SQL_TERMINATOR[cp.dbType]);
1212                                                 }
1213                                         } else {
1214                                                 pw[3].println(strLine);
1215                                                 CmnUtils.errorPrint(strSplit[0][2] + ",UNUSABLE INDEX");
1216                                         }
1217                                 }
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;
1222                                 
1223                                 File [] fmFl = new File[6];
1224                                 File [] toFl = new File[6];
1225                                 
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());
1234                                         toFl[i].delete();
1235                                         fmFl[i].renameTo(toFl[i]);
1236                                 }
1237                                 
1238                                 // physical table setting
1239                                 File tbDir = new File(folder + "/TABLES");
1240                                 File [] tbFiles = tbDir.listFiles();
1241                                 File tb = null;
1242                                 File oTb = null;
1243                                 for(int i=0;i<tbFiles.length;i++){
1244                                         tb = tbFiles[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);
1253                                                         if (rowNo != -1){
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]);
1278                                                                 } else {
1279                                                                         pw[0].println(cp.SQL_TERMINATOR[cp.dbType]);
1280                                                                 }
1281                                                         } else {
1282                                                                 pw[0].println(")" + cp.SQL_TERMINATOR[cp.dbType]);
1283                                                         }
1284                                                 } else {
1285                                                         pw[0].println(strLine);
1286                                                 }
1287                                         }
1288                                         pw[0].close();
1289                                         pw[0]=null;
1290                                         br[0].close();
1291                                         br[0]=null;
1292                                         tb.delete();
1293                                         oTb.renameTo(tb);
1294                                 }
1295                         }
1296                         // Rhysical Contents end
1297
1298                         // Remove work file
1299                         File fl= null;
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());
1303                                 fl.delete();
1304                         }
1305
1306                         // disconnect database
1307                         dao.disconnect();
1308                         CmnUtils.infoPrint("\83\81\83^\83f\81[\83^\83A\83\93\83\8d\81[\83h\82ð\8fI\97¹\82µ\82Ü\82µ\82½\81B");
1309
1310                 } catch(SQLException se) {
1311                         try{
1312                                 CmnUtils.errorPrint(se.toString());
1313                                 se.printStackTrace();
1314                                 se = se.getNextException();
1315                                 if(se != null) {
1316                                         System.out.println(se.getMessage());
1317                                 }
1318                                 dao.rollback();
1319                         } catch (Exception see) {}
1320                 } catch (Exception e) {                 
1321                         try{
1322                                 CmnUtils.errorPrint(e.toString());
1323                                 e.printStackTrace();
1324                                 dao.rollback();
1325                         } catch (Exception ee) {}
1326                 } finally{
1327                         try{
1328                                 for(int i=0;i<6;i++){
1329                                         if(pw[i]!=null){
1330                                                 pw[i].close();
1331                                                 pw[i]=null;
1332                                         }
1333                                 }
1334                                 for(int i=0;i<4;i++){
1335                                         if(br[i]!=null){
1336                                                 br[i].close();
1337                                                 br[i]=null;
1338                                         }
1339                                 }
1340                         } catch (Exception e) {}
1341                 }
1342         }
1343         
1344         private String commentOnTable(CmnProps _cp, String _tableName, String _tableCmnt, int _type) throws Exception{
1345                 String retVal = "";
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];
1350                             break;
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];
1356                                 }
1357                                 break;
1358                           default :
1359                         }
1360                 }
1361                 return retVal;
1362         }
1363         private String commentOnColumn(CmnProps _cp, String _tableName, String _colName, String _colCmnt, int _type) throws Exception{
1364                 String retVal = "";
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];
1369                             break;
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];
1375                                 }
1376                             break;
1377                           default :
1378                         }
1379                 }
1380                 return retVal;
1381         }
1382 }
1383