OSDN Git Service

634324f9140a622521ba1242537d713947f662e4
[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 "
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                      + " c.constraint_name as r_constraint_name, "
202                      + " d.column_name as r_column_name, "
203                      + " d.position as r_position "
204                      + " from "
205                      + "   user_constraints a, "
206                      + "   user_cons_columns b,"
207                      + "   user_constraints c, "
208                      + "   user_cons_columns d "
209                      + " where "
210                      + "   a.constraint_type = 'R'"
211                      + "   and a.owner = b.owner"
212                      + "   and a.table_name = b.table_name"
213                      + "   and a.constraint_name = b.constraint_name"
214                      + "   and c.constraint_type in('P','U')"
215                      + "   and c.owner = b.owner"
216                      + "   and c.table_name = d.table_name"
217                      + "   and c.constraint_name = d.constraint_name"
218                      + "   and a.r_owner = c.owner"
219                      + "   and a.r_constraint_name = c.constraint_name"
220                      + " order by"
221                      + "   a.table_name,a.constraint_name,b.position,d.position"
222                 },
223                 {       //SQL SERVER
224                 "select "
225                      + "a.name    as table_name, "
226                      + "replace(replace(cast(b.value as varchar(4000)), char(13), ''), char(10), '') as table_comments, "
227                      + "c.name    as column_name, "
228                      + "replace(replace(cast(d.value as varchar(4000)), char(13), ''), char(10), '') as column_comments, "
229                      + "e.name as data_type, "
230                      + "c.max_length as data_length, "
231                      + "c.precision as data_precision, "
232                      + "c.scale as data_scale, "
233                      + "case c.is_nullable"
234                      + "  when '0' then '\81Z'"
235                      + "  else null "
236                      + "end as nullable,"
237                      + "g.definition as data_default "
238                      + "from "
239                      + "sys.tables as a "
240                      + "left outer join sys.extended_properties as b "
241                      + "on a.object_id = b.major_id and b.minor_id = 0 "
242                      + "inner join sys.columns as c "
243                      + "on a.object_id = c.object_id "
244                      + "left outer join sys.extended_properties as d "
245                      + "on a.object_id = d.major_id and c.column_id = d.minor_id "
246                      + "inner join sys.types as e "
247                      + "on c.system_type_id = e.system_type_id and c.user_type_id = e.user_type_id "
248                      + "left outer join sys.sysconstraints f "
249                      + "on c.object_id = f.id "
250                      + "and c.column_id = f.colid "
251                      + "and (f.status & 2069) = 2069 "
252                      + "left outer join sys.default_constraints g "
253                      + "on f.constid = g.object_id "
254                      + "and a.schema_id = g.schema_id "
255                      + "order by a.name,c.column_id ",
256                 "select "
257                      + "d.name as table_name, "
258                      + "a.name as index_name, "
259                      + "a.type as index_type, "
260                      + "case a.is_unique "
261                      + "  when 1 then "
262                      + "    case a.is_primary_key "
263                      + "      when 1 then 'P' "
264                      + "        else "
265                      + "            case a.is_unique_constraint "
266                      + "                when 1 then 'U' "
267                      + "                else '' "
268                      + "            end "
269                      + "    end "
270                      + "  else '' "
271                      + "end as constraint_type, "
272                      + "c.name as column_name, "
273                      + "b.key_ordinal as column_position "
274                      + "from "
275                      + "  sys.indexes as a "
276                      + "  inner join sys.index_columns as b "
277                      + "      on a.object_id = b.object_id and a.index_id = b.index_id "
278                      + "  inner join sys.columns as c "
279                      + "      on c.column_id = b.column_id "
280                      + "         and c.object_id = b.object_id "
281                      + "  inner join sys.objects as d "
282                      + "      on a.object_id = d.object_id and d.type = 'U' "
283                      + "order by d.name, a.name,b.key_ordinal",
284                 "select "
285                      + " a.name as view_name, "
286                      + " replace(replace(cast(b.value as varchar(4000)), char(13), ''), char(10), '') as comments "
287                      + "from "
288                      + " sys.views a "
289                      + " left outer join sys.extended_properties as b "
290                      + " on a.object_id = b.major_id and b.minor_id = 0 "
291                      + "order by "
292                      + " a.name",
293                 "select "
294                      + " name as object_name, 'PROCEDURE' as object_type from sys.procedures"
295                      + " union select "
296                      + " name as object_name, 'FUNCTION' as object_type from sys.objects where type in('FN', 'FS', 'FT', 'IF', 'TF') "
297                      + " union select "
298                      + " name as object_name, 'TRIGGER' as object_type from sys.triggers "
299                      + " order by object_name,object_type ",
300                 "select "
301                      + "  name as sequence_name,"
302                      + "  cast(minimum_value as varchar(20)) as min_value,"
303                      + "  cast(maximum_value as varchar(20)) as max_value,"
304                      + "  cast(increment as varchar(20)) as increment_by,"
305                      + "  is_cycling as cycle_flag,"
306                      + "  is_cached as order_flag,"
307                      + "  cast(cache_size as varchar(20)) as cache_size,"
308                      + "  cast(start_value as varchar(20)) as last_number "
309                      + " from sys.sequences "
310                      + " order by name",
311                 "select "
312                      + " name as synonym_name,"
313                      + " schema_id as table_owner,"
314                      + " base_object_name as table_name,"
315                      + " '' as db_link "
316                      + "from sys.synonyms "
317                      + "order by synonym_name,table_owner,table_name",
318                 "select "
319                      + " c.name as table_name, "
320                      + " b.index_id, "
321                      + " d.name as index_name , "
322                      + " a.type_desc as allocation_type, "
323                      + " a.data_pages, "
324                      + " partition_number "
325                      + "from "
326                      + " sys.allocation_units as a "
327                      + " inner join sys.partitions as b "
328                      + " on a.container_id = b.partition_id "
329                      + " inner join sys.objects as c "
330                      + " on b.object_id = c.object_id and c.type = 'U' "
331                      + " inner join sys.indexes as d "
332                      + " on b.index_id = d.index_id and d.object_id = b.object_id "
333                      + "order by c.name, b.index_id",
334                 "select "
335                      + " c.name as table_name, "
336                      + " a.name as constraint_name, "
337                      + " d.name as column_name, "
338                      + " b.constraint_column_id as position, "
339                      + " e.name as r_table_name, "
340                      + " g.name as r_constraint_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 + " CACHE " + cacheSz);
970                                 if (odFg.equals("N")){
971                                         pw[1].print(" NOORDER");
972                                 } else {
973                                         pw[1].print(" ORDER");
974                                 }
975                                 if (cycFg.equals("N")){
976                                         pw[1].print(" NOCYCLE");
977                                 } else {
978                                         pw[1].print(" CYCLE");
979                                 }
980                                 pw[1].println(cp.SQL_TERMINATOR[cp.dbType]);
981                                 pw[2].println("DROP SEQUENCE " + DB_SQL_QUOTED_S[cp.dbType]+ seqName + DB_SQL_QUOTED_E[cp.dbType]+ cp.SQL_TERMINATOR[cp.dbType]);
982                                 for(int i=0;i<strSplit[0].length;i++)CmnUtils.debugPrint("'" + strSplit[0][i] + "'");
983                         }
984                         for(int i=1;i<3;i++)pw[i].close();
985                         for(int i=1;i<3;i++)pw[i]=null;
986                         br[0].close();
987                         br[0] = null;
988                         // Sequence Contents end
989
990                         // Synonym Contents start
991                         br[0] = new BufferedReader(new FileReader(folder + "/" + FILE_NAME[TYPE_SYNONYM] + "_" + database + "." + cp.fileExtension));
992                         pw[1] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_SYNONYM]))));
993                         pw[2] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + cp.SQL_FILE_NAME[cp.DROP_SYNONYM]))));
994
995                         while((strLine=br[0].readLine()) != null){
996                                 strSplit[0] = CmnUtils.split(strLine, cp.delimiter);
997                                 synmName = strSplit[0][0];
998                                 tbOwner = strSplit[0][1];
999                                 tbName = strSplit[0][2];
1000                                 dbLnk = strSplit[0][3];
1001                                 
1002                                 pw[1].print("CREATE SYNONYM " + DB_SQL_QUOTED_S[cp.dbType]+ synmName + DB_SQL_QUOTED_E[cp.dbType]+ " FOR ");
1003                                 if(dbLnk.equals("")){
1004                                         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]);
1005                                 } else {
1006                                         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]);
1007                                 }
1008                                 pw[1].println(cp.SQL_TERMINATOR[cp.dbType]);
1009                                 pw[2].println("DROP SYNONYM " + DB_SQL_QUOTED_S[cp.dbType]+ synmName + DB_SQL_QUOTED_E[cp.dbType]+ cp.SQL_TERMINATOR[cp.dbType]);
1010                                 for(int i=0;i<strSplit[0].length;i++)CmnUtils.debugPrint("'" + strSplit[0][i] + "'");
1011                         }
1012                         for(int i=1;i<3;i++)pw[i].close();
1013                         for(int i=1;i<3;i++)pw[i]=null;
1014                         br[0].close();
1015                         br[0] = null;
1016                         // Synonym Contents end
1017
1018                         // Fk Contents start
1019                         File tsvFile = new File(folder + "/" + FILE_NAME[TYPE_FK] + "_" + database + "." + cp.fileExtension);
1020                         if (tsvFile.length() > 0) {
1021                                 br[0] = new BufferedReader(new FileReader(folder + "/" + FILE_NAME[TYPE_FK] + "_" + database + "." + cp.fileExtension));
1022                                 pw[1] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_FK]))));
1023                                 pw[2] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + cp.SQL_FILE_NAME[cp.DROP_FK]))));
1024                                 tbName = "";
1025                                 fkName = "";
1026                                 fkCol = "";
1027                                 fkColPos = "";
1028                                 rtbName = "";
1029                                 rfkName = "";
1030                                 rfkCol = "";
1031                                 rfkColPos = "";
1032                                 
1033                                 while((strLine=br[0].readLine()) != null){
1034                                         strSplit[0] = CmnUtils.split(strLine, cp.delimiter);
1035                                         if(!fkName.equals(strSplit[0][1]) && !fkName.equals("")){
1036                                                 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]);
1037                                                 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]);
1038                                                 for(int i=0;i<strSplit[0].length;i++)CmnUtils.debugPrint("'" + strSplit[0][i] + "'");
1039                                                 tbName = strSplit[0][0];
1040                                                 fkName = strSplit[0][1];
1041                                                 fkCol = strSplit[0][2];
1042                                                 fkColPos = strSplit[0][3];
1043                                                 rtbName = strSplit[0][4];
1044                                                 rfkName = strSplit[0][5];
1045                                                 rfkCol = strSplit[0][6];
1046                                                 rfkColPos = strSplit[0][7];
1047                                         } else {
1048                                                 if(fkName.equals("")){
1049                                                         tbName = strSplit[0][0];
1050                                                         fkName = strSplit[0][1];
1051                                                         fkCol = strSplit[0][2];
1052                                                         fkColPos = strSplit[0][3];
1053                                                         rtbName = strSplit[0][4];
1054                                                         rfkName = strSplit[0][5];
1055                                                         rfkCol = strSplit[0][6];
1056                                                         rfkColPos = strSplit[0][7];
1057                                                 } else {
1058                                                         if (strSplit[0][3].equals(strSplit[0][7])) {
1059                                                                 fkCol = fkCol + DB_SQL_QUOTED_E[cp.dbType]+ ", " + DB_SQL_QUOTED_S[cp.dbType]+ strSplit[0][2];
1060                                                                 rfkCol = rfkCol + DB_SQL_QUOTED_E[cp.dbType]+ ", " + DB_SQL_QUOTED_S[cp.dbType]+ strSplit[0][6];
1061                                                         }
1062                                                 }
1063                                         }
1064                                         
1065                                 }
1066                                 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]);
1067                                 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]);
1068                                 for(int i=1;i<3;i++)pw[i].close();
1069                                 for(int i=1;i<3;i++)pw[i]=null;
1070                                 br[0].close();
1071                                 br[0] = null;
1072                         }
1073                         // Fk Contents end
1074
1075                         // Rhysical Contents start
1076                         if(cp.isPhysical){
1077                                 // physical index setting
1078                                 br[0] = new BufferedReader(new FileReader(folder + "/" + FILE_NAME[TYPE_OBJ] + "_" + database + "." + cp.fileExtension));
1079                                 br[1] = new BufferedReader(new FileReader(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_PKEY]));
1080                                 br[2] = new BufferedReader(new FileReader(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_UKEY]));
1081                                 br[3] = new BufferedReader(new FileReader(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_INDEX]));
1082                                 pw[1] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_PKEY] + "." + phyfileExtension))));
1083                                 pw[2] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_UKEY] + "." + phyfileExtension))));
1084                                 pw[3] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_INDEX] + "." + phyfileExtension))));
1085                                 alData = new ArrayList<String>();
1086                                 int rowNo;
1087                                 String [] rowData;
1088                                 while((strLine=br[0].readLine()) != null){
1089                                         strSplit[0] = CmnUtils.split(strLine, cp.delimiter);
1090                                         for(int i=0;i<strSplit[0].length;i++)alData.add(strSplit[0][i]);
1091                                 }
1092                                 while((strLine=br[1].readLine()) != null){
1093                                         strSplit[0] = CmnUtils.splitSpace(strLine);
1094                                         rowNo = CmnUtils.getArrayRowNo(alData, 12, 1, strSplit[0][5].replaceAll("\"",""));
1095                                         if (rowNo != -1){
1096                                                 rowData = rowData = CmnUtils.getArrayRowData(alData, 12, rowNo);
1097                                                 CmnUtils.debugPrint(strSplit[0][5] + ":" + rowNo);
1098                                                 for(int i=0;i<rowData.length;i++)CmnUtils.debugPrint(rowData[i]);
1099                                                 tbName = rowData[0];
1100                                                 objName = rowData[1];
1101                                                 objTyp = rowData[2];
1102                                                 pctFree = rowData[3];
1103                                                 pctUsed = rowData[4];
1104                                                 iniTrns = rowData[5];
1105                                                 freeLst = rowData[6];
1106                                                 flstGrp = rowData[7];
1107                                                 bufPool = rowData[8];
1108                                                 tblSpace = rowData[9];
1109                                                 logging = rowData[10];
1110                                                 segByts = rowData[11];
1111                                                 pw[1].print(strLine.replace(';',' '));
1112                                                 pw[1].print("USING INDEX PCTFREE " + pctFree);
1113                                                 pw[1].print(" INITRANS " + iniTrns + " STORAGE(");
1114                                                 if(!freeLst.equals(""))pw[1].print(" FREELISTS " + freeLst);
1115                                                 if(!flstGrp.equals(""))pw[1].print(" FREELIST GROUPS " + flstGrp);
1116                                                 pw[1].print(" BUFFER_POOL " + bufPool + ")");
1117                                                 pw[1].print(" TABLESPACE " + DB_SQL_QUOTED_S[cp.dbType]+ tblSpace + DB_SQL_QUOTED_E[cp.dbType]);
1118                                                 if(logging.equals("NO")){
1119                                                         pw[1].println(" NOLOGGING" + cp.SQL_TERMINATOR[cp.dbType]);
1120                                                 } else {
1121                                                         pw[1].println(cp.SQL_TERMINATOR[cp.dbType]);
1122                                                 }
1123                                         } else {
1124                                                 pw[1].println(strLine);
1125                                                 CmnUtils.errorPrint(strSplit[0][5] + ",UNUSABLE INDEX");
1126                                         }
1127                                 }
1128                                 while((strLine=br[2].readLine()) != null){
1129                                         strSplit[0] = CmnUtils.splitSpace(strLine);
1130                                         rowNo = CmnUtils.getArrayRowNo(alData, 12, 1, strSplit[0][5].replaceAll("\"",""));
1131                                         if (rowNo != -1){
1132                                                 rowData = rowData = CmnUtils.getArrayRowData(alData, 12, rowNo);
1133                                                 CmnUtils.debugPrint(strSplit[0][5] + ":" + rowNo);
1134                                                 for(int i=0;i<rowData.length;i++)CmnUtils.debugPrint(rowData[i]);
1135                                                 tbName = rowData[0];
1136                                                 objName = rowData[1];
1137                                                 objTyp = rowData[2];
1138                                                 pctFree = rowData[3];
1139                                                 pctUsed = rowData[4];
1140                                                 iniTrns = rowData[5];
1141                                                 freeLst = rowData[6];
1142                                                 flstGrp = rowData[7];
1143                                                 bufPool = rowData[8];
1144                                                 tblSpace = rowData[9];
1145                                                 logging = rowData[10];
1146                                                 segByts = rowData[11];
1147                                                 pw[2].print(strLine.replace(';',' '));
1148                                                 pw[2].print("USING INDEX PCTFREE " + pctFree);
1149                                                 pw[2].print(" INITRANS " + iniTrns + " STORAGE(");
1150                                                 if(!freeLst.equals(""))pw[2].print(" FREELISTS " + freeLst);
1151                                                 if(!flstGrp.equals(""))pw[2].print(" FREELIST GROUPS " + flstGrp);
1152                                                 pw[2].print(" BUFFER_POOL " + bufPool + ")");
1153                                                 pw[2].print(" TABLESPACE " + DB_SQL_QUOTED_S[cp.dbType]+ tblSpace + DB_SQL_QUOTED_E[cp.dbType]);
1154                                                 if(logging.equals("NO")){
1155                                                         pw[2].println(" NOLOGGING" + cp.SQL_TERMINATOR[cp.dbType]);
1156                                                 } else {
1157                                                         pw[2].println(cp.SQL_TERMINATOR[cp.dbType]);
1158                                                 }
1159                                         } else {
1160                                                 pw[2].println(strLine);
1161                                                 CmnUtils.errorPrint(strSplit[0][5] + ",UNUSABLE INDEX");
1162                                         }
1163                                 }
1164                                 while((strLine=br[3].readLine()) != null){
1165                                         strSplit[0] = CmnUtils.splitSpace(strLine);
1166                                         rowNo = CmnUtils.getArrayRowNo(alData, 12, 1, strSplit[0][2].replaceAll("\"",""));
1167                                         CmnUtils.debugPrint("rowNo=" + rowNo);
1168                                         if (rowNo != -1){
1169                                                 rowData = CmnUtils.getArrayRowData(alData, 12, rowNo);
1170                                                 for(int i=0;i<rowData.length;i++)CmnUtils.debugPrint(rowData[i]);
1171                                                 tbName = rowData[0];
1172                                                 objName = rowData[1];
1173                                                 objTyp = rowData[2];
1174                                                 pctFree = rowData[3];
1175                                                 pctUsed = rowData[4];
1176                                                 iniTrns = rowData[5];
1177                                                 freeLst = rowData[6];
1178                                                 flstGrp = rowData[7];
1179                                                 bufPool = rowData[8];
1180                                                 tblSpace = rowData[9];
1181                                                 logging = rowData[10];
1182                                                 segByts = rowData[11];
1183                                                 pw[3].print(strLine.replace(';',' '));
1184                                                 pw[3].print("PCTFREE " + pctFree);
1185                                                 pw[3].print(" INITRANS " + iniTrns + " STORAGE(");
1186                                                 if(!freeLst.equals(""))pw[3].print(" FREELISTS " + freeLst);
1187                                                 if(!flstGrp.equals(""))pw[3].print(" FREELIST GROUPS " + flstGrp);
1188                                                 pw[3].print(" BUFFER_POOL " + bufPool + ")");
1189                                                 pw[3].print(" TABLESPACE " + DB_SQL_QUOTED_S[cp.dbType]+ tblSpace + DB_SQL_QUOTED_E[cp.dbType]);
1190                                                 if(logging.equals("NO")){
1191                                                         pw[3].println(" NOLOGGING" + cp.SQL_TERMINATOR[cp.dbType]);
1192                                                 } else {
1193                                                         pw[3].println(cp.SQL_TERMINATOR[cp.dbType]);
1194                                                 }
1195                                         } else {
1196                                                 pw[3].println(strLine);
1197                                                 CmnUtils.errorPrint(strSplit[0][2] + ",UNUSABLE INDEX");
1198                                         }
1199                                 }
1200                                 for(int i=1;i<4;i++)pw[i].close();
1201                                 for(int i=1;i<4;i++)pw[i]=null;
1202                                 for(int i=0;i<4;i++)br[i].close();
1203                                 for(int i=0;i<4;i++)br[i]=null;
1204                                 
1205                                 File [] fmFl = new File[6];
1206                                 File [] toFl = new File[6];
1207                                 
1208                                 fmFl[0] = new File(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_PKEY] + "." + phyfileExtension);
1209                                 fmFl[1] = new File(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_UKEY] + "." + phyfileExtension);
1210                                 fmFl[2] = new File(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_INDEX] + "." + phyfileExtension);
1211                                 toFl[0] = new File(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_PKEY]);
1212                                 toFl[1] = new File(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_UKEY]);
1213                                 toFl[2] = new File(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_INDEX]);
1214                                 for(int i=0;i<3;i++){
1215                                         CmnUtils.debugPrint(fmFl[i].toString() + ">" + toFl[i].toString());
1216                                         toFl[i].delete();
1217                                         fmFl[i].renameTo(toFl[i]);
1218                                 }
1219                                 
1220                                 // physical table setting
1221                                 File tbDir = new File(folder + "/TABLES");
1222                                 File [] tbFiles = tbDir.listFiles();
1223                                 File tb = null;
1224                                 File oTb = null;
1225                                 for(int i=0;i<tbFiles.length;i++){
1226                                         tb = tbFiles[i];
1227                                         tbName = tb.getName().replaceAll(".sql","");
1228                                         oTb = new File(tb + "." + phyfileExtension);
1229                                         CmnUtils.debugPrint(tbName);
1230                                         br[0] = new BufferedReader(new FileReader(tb));
1231                                         pw[0] = new PrintWriter(new BufferedWriter(new FileWriter(oTb)));
1232                                         while((strLine=br[0].readLine()) != null){
1233                                                 if(strLine.equals(")" + cp.SQL_TERMINATOR[cp.dbType])){
1234                                                         rowNo = CmnUtils.getArrayRowNo(alData, 12, 1, tbName);
1235                                                         if (rowNo != -1){
1236                                                                 rowData = CmnUtils.getArrayRowData(alData, 12, rowNo);
1237                                                                 CmnUtils.debugPrint(tbName + ":" + rowNo);
1238                                                                 //for(int j=0;j<rowData.length;i++)CmnUtils.debugPrint(rowData[j]);
1239                                                                 tbName = rowData[0];
1240                                                                 objName = rowData[1];
1241                                                                 objTyp = rowData[2];
1242                                                                 pctFree = rowData[3];
1243                                                                 pctUsed = rowData[4];
1244                                                                 iniTrns = rowData[5];
1245                                                                 freeLst = rowData[6];
1246                                                                 flstGrp = rowData[7];
1247                                                                 bufPool = rowData[8];
1248                                                                 tblSpace = rowData[9];
1249                                                                 logging = rowData[10];
1250                                                                 segByts = rowData[11];
1251                                                                 pw[0].print(") PCTFREE " + pctFree);
1252                                                                 if(!pctUsed.equals(""))pw[0].print(" PCTUSED " + pctUsed);
1253                                                                 pw[0].print(" INITRANS " + iniTrns + " STORAGE(");
1254                                                                 if(!freeLst.equals(""))pw[0].print(" FREELISTS " + freeLst);
1255                                                                 if(!flstGrp.equals(""))pw[0].print(" FREELIST GROUPS " + flstGrp);
1256                                                                 pw[0].print(" BUFFER_POOL " + bufPool + ")");
1257                                                                 pw[0].print(" TABLESPACE " + DB_SQL_QUOTED_S[cp.dbType]+ tblSpace + DB_SQL_QUOTED_E[cp.dbType]);
1258                                                                 if(logging.equals("NO")){
1259                                                                         pw[0].println(" NOLOGGING" + cp.SQL_TERMINATOR[cp.dbType]);
1260                                                                 } else {
1261                                                                         pw[0].println(cp.SQL_TERMINATOR[cp.dbType]);
1262                                                                 }
1263                                                         } else {
1264                                                                 pw[0].println(")" + cp.SQL_TERMINATOR[cp.dbType]);
1265                                                         }
1266                                                 } else {
1267                                                         pw[0].println(strLine);
1268                                                 }
1269                                         }
1270                                         pw[0].close();
1271                                         pw[0]=null;
1272                                         br[0].close();
1273                                         br[0]=null;
1274                                         tb.delete();
1275                                         oTb.renameTo(tb);
1276                                 }
1277                         }
1278                         // Rhysical Contents end
1279
1280                         // Remove work file
1281                         File fl= null;
1282                         for(int i=0;i<sql[cp.dbType].length;i++){
1283                                 fl= new File(folder + "/" + FILE_NAME[i] + "_" + database + "." + cp.fileExtension);
1284                                 CmnUtils.debugPrint(fl.toString());
1285                                 fl.delete();
1286                         }
1287
1288                         // disconnect database
1289                         dao.disconnect();
1290                         CmnUtils.infoPrint("\83\81\83^\83f\81[\83^\83A\83\93\83\8d\81[\83h\82ð\8fI\97¹\82µ\82Ü\82µ\82½\81B");
1291
1292                 } catch(SQLException se) {
1293                         try{
1294                                 CmnUtils.errorPrint(se.toString());
1295                                 se.printStackTrace();
1296                                 se = se.getNextException();
1297                                 if(se != null) {
1298                                         System.out.println(se.getMessage());
1299                                 }
1300                                 dao.rollback();
1301                         } catch (Exception see) {}
1302                 } catch (Exception e) {                 
1303                         try{
1304                                 CmnUtils.errorPrint(e.toString());
1305                                 e.printStackTrace();
1306                                 dao.rollback();
1307                         } catch (Exception ee) {}
1308                 } finally{
1309                         try{
1310                                 for(int i=0;i<6;i++){
1311                                         if(pw[i]!=null){
1312                                                 pw[i].close();
1313                                                 pw[i]=null;
1314                                         }
1315                                 }
1316                                 for(int i=0;i<4;i++){
1317                                         if(br[i]!=null){
1318                                                 br[i].close();
1319                                                 br[i]=null;
1320                                         }
1321                                 }
1322                         } catch (Exception e) {}
1323                 }
1324         }
1325         
1326         private String commentOnTable(CmnProps _cp, String _tableName, String _tableCmnt, int _type) throws Exception{
1327                 String retVal = "";
1328                 if(!_tableCmnt.equals("")){
1329                         switch (_cp.dbType) {
1330                           case DB_TYPE_ORACLE:
1331                                 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];
1332                             break;
1333                           case DB_TYPE_SQLSERVER:
1334                                 if(_type == TYPE_TABLE){
1335                                         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];
1336                                 } else if(_type == TYPE_VIEW){
1337                                         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];
1338                                 }
1339                                 break;
1340                           default :
1341                         }
1342                 }
1343                 return retVal;
1344         }
1345         private String commentOnColumn(CmnProps _cp, String _tableName, String _colName, String _colCmnt, int _type) throws Exception{
1346                 String retVal = "";
1347                 if(!_colCmnt.equals("")){
1348                         switch (_cp.dbType) {
1349                           case DB_TYPE_ORACLE:
1350                                 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];
1351                             break;
1352                           case DB_TYPE_SQLSERVER:
1353                                 if(_type == TYPE_TABLE){
1354                                         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];
1355                                 } else if(_type == TYPE_VIEW){
1356                                         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];
1357                                 }
1358                             break;
1359                           default :
1360                         }
1361                 }
1362                 return retVal;
1363         }
1364 }
1365