OSDN Git Service

20170503_2
[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 FL_TABLE = 0;
32         private static final int FL_INDEX = 1;
33         private static final int FL_VIEW = 2;
34         private static final int FL_PROCEDURE = 3;
35         private static final int FL_SEQ = 4;
36         private static final int FL_SYNONYM = 5;
37         private static final int FL_OBJ = 6;
38         private static final int FL_FK = 7;
39         private static final String [] FILE_NAME = {
40                 "TABLEDEF",
41                 "INDEXDEF",
42                 "VIEWDEF",
43                 "PROCDEF",
44                 "SEQDEF",
45                 "SYNMDEF",
46                 "OBJDEF",
47                 "FKDEF"
48         };
49         private static final String [][] sql =  {
50                 {
51                 "select "
52                      + "a.table_name as table_name,"
53                      + "replace(replace(b.comments, chr(13), ''), chr(10), '') as table_comments,"
54                      + "c.column_name as column_name, "
55                      + "replace(replace(d.comments, chr(13), ''), chr(10), '') as column_comments, "
56                      + "decode(c.data_type, 'TIMESTAMP(6)', 'TIMESTAMP',c.data_type) as data_type, "
57                      + "c.data_length as data_length,"
58                      + "c.data_precision as data_precision,"
59                      + "c.data_scale as data_scale,"
60                      + "decode(c.nullable, 'N', '\81\9b', null) as nullable,"
61                      + "c.data_default as data_default "
62                      + "from user_tables a "
63                      + "inner join user_tab_comments b "
64                      + "on a.table_name = b.table_name "
65                      + "inner join user_tab_columns c "
66                      + "on a.table_name = c.table_name "
67                      + "inner join user_col_comments d "
68                      + "on c.table_name = d.table_name "
69                      + " and c.column_name = d.column_name "
70                      + "order by a.table_name,c.column_id",
71                 "select "
72                      + " a.table_name,"
73                      + " a.index_name,"
74                      + " a.index_type,"
75                      + " c.constraint_type,"
76                      + " b.column_name,"
77                      + " b.column_position "
78                      + " from"
79                      + " user_indexes a,"
80                      + " user_ind_columns b,"
81                      + " user_constraints c "
82                      + " where"
83                      + "  a.table_name = b.table_name and"
84                      + "  a.index_name = b.index_name and"
85                      + "  a.table_name = c.table_name(+) and"
86                      + "  a.index_name = c.constraint_name(+) "
87                      + " order by"
88                      + " a.table_name,"
89                      + " a.index_name,"
90                      + " b.column_position",
91                 "select "
92                      + " a.view_name, "
93                      + " replace(replace(c.comments, chr(13), ''), chr(10), '') as comments "
94                      + " from"
95                      + " user_views a, "
96                      + " user_tab_comments c "
97                      + " where"
98                         + "  a.view_name = c.table_name(+) "
99                      + " order by"
100                      + " a.view_name",
101                 "select "
102                      + " object_name, "
103                      + " object_type "
104                      + "from"
105                      + " user_objects"
106                      + " where object_type in('PACKAGE','PROCEDURE','FUNCTION','TRIGGER','TYPE')"
107                      + " group by object_name,object_type"
108                      + " order by object_name,object_type",
109                 "select "
110                      + "  sequence_name,"
111                      + "  to_char(min_value) as min_value,"
112                      + "  to_char(max_value) as max_value,"
113                      + "  to_char(increment_by) as increment_by,"
114                      + "  cycle_flag,"
115                      + "  order_flag,"
116                      + "  to_char(cache_size) as cache_size,"
117                      + "  to_char(last_number) as last_number "
118                      + " from user_sequences "
119                      + " order by sequence_name",
120                 "select "
121                      + "  synonym_name,"
122                      + "  table_owner,"
123                      + "  table_name,"
124                      + "  db_link "
125                      + "from user_synonyms "
126                      + "order by synonym_name,table_owner,table_name",
127                 "select "
128                      + " a.table_name,"
129                      + " a.object_name,"
130                      + " a.object_type,"
131                      + " a.pct_free,"
132                      + " a.pct_used,"
133                      + " a.ini_trans,"
134                      + " a.freelists,"
135                      + " a.freelist_groups,"
136                      + " a.buffer_pool,"
137                      + " a.tablespace_name, "
138                      + " a.logging, "
139                      + " b.bytes "
140                      + "from "
141                      + "(select "
142                      + " table_name,"
143                      + " table_name as object_name,"
144                      + " 'TABLE' as object_type,"
145                      + " pct_free,"
146                      + " pct_used,"
147                      + " ini_trans,"
148                      + " freelists,"
149                      + " freelist_groups,"
150                      + " buffer_pool,"
151                      + " tablespace_name, "
152                      + " logging "
153                      + "from "
154                      + " user_tables "
155                      + " union select "
156                      + " table_name,"
157                      + " index_name as object_name,"
158                      + " 'INDEX' as object_type,"
159                      + " pct_free,"
160                      + " null as pct_used,"
161                      + " ini_trans,"
162                      + " freelists,"
163                      + " freelist_groups,"
164                      + " buffer_pool,"
165                      + " tablespace_name, "
166                      + " logging "
167                      + " from "
168                      + " user_indexes "
169                      + ") a, "
170                      + "(select "
171                      + " segment_name,"
172                      + " segment_type,"
173                      + " bytes "
174                      + " from "
175                      + " user_segments "
176                      + ") b "
177                      + " where a.object_name = b.segment_name "
178                      + " and a.object_type = b.segment_type "
179                      + " order by"
180                      + " a.table_name,"
181                      + " a.object_name",
182                 "select "
183                      + " a.table_name as table_name, "
184                      + " a.constraint_name as constraint_name, "
185                      + " b.column_name as column_name, "
186                      + " b.position as position,"
187                      + " c.table_name as r_table_name, "
188                      + " c.constraint_name as r_constraint_name, "
189                      + " d.column_name as r_column_name, "
190                      + " d.position as r_position "
191                      + " from "
192                      + "   user_constraints a, "
193                      + "   user_cons_columns b,"
194                      + "   user_constraints c, "
195                      + "   user_cons_columns d "
196                      + " where "
197                      + "   a.constraint_type = 'R'"
198                      + "   and a.owner = b.owner"
199                      + "   and a.table_name = b.table_name"
200                      + "   and a.constraint_name = b.constraint_name"
201                      + "   and c.constraint_type in('P','U')"
202                      + "   and c.owner = b.owner"
203                      + "   and c.table_name = d.table_name"
204                      + "   and c.constraint_name = d.constraint_name"
205                      + "   and a.r_owner = c.owner"
206                      + "   and a.r_constraint_name = c.constraint_name"
207                      + " order by"
208                      + "   a.table_name,a.constraint_name,b.position,d.position"
209                 }
210         };
211         private static String sql_view_text = "select text from user_views where view_name = ?";
212         private static String sql_view_column_and_comment = "select "
213              + " b.column_name,"
214              + " replace(replace(d.comments, chr(13), ''), chr(10), '') as comments "
215              + " from"
216              + " user_tab_columns b,"
217              + " user_col_comments d "
218              + " where"
219              + "  b.table_name = ? and"
220              + "  b.table_name = d.table_name(+) and"
221              + "  b.column_name = d.column_name(+) "
222              + " order by"
223              + " b.column_id";
224         private static String sql_proc = "select text from user_source where name = ? order by line";
225
226         private String database = null;
227
228         public static void main(String args[]){
229                 try {
230                         if (args.length > 0){
231                                 RapideMetaUnloader RapideMetaUnloader = new RapideMetaUnloader(args[0]);
232                                 RapideMetaUnloader.metaUnload();
233                         } else {
234                                 RapideMetaUnloader RapideMetaUnloader = new RapideMetaUnloader(null);
235                                 RapideMetaUnloader.metaUnload();
236                         }
237                 } catch (Exception e) {
238                         e.printStackTrace();
239                 }
240         }
241
242         RapideMetaUnloader(String _database) {
243                 super();
244                 database = _database;
245         }
246
247
248         private void metaUnload(){
249                 Connection conn = null;
250                 PreparedStatement stmt = null;
251                 BufferedReader [] br = new BufferedReader[4];
252                 PrintWriter [] pw = new PrintWriter[6];
253                 File folder = null;
254                 File subFolder = null;
255                 String strLine = null;
256                 String strLine2 = null;
257                 String [][] strSplit = new String[4][];
258                 String strContents = null;
259                 ArrayList<String> alData = null;
260                 ArrayList<String> alData2 = null;
261                 int columnCount = 0;
262                 String tableName = null;
263                 String tableCmnt = null;
264                 String colName = null;
265                 String colCmnt = null;
266                 String colType = null;
267                 String colLen = null;
268                 String colPrec = null;
269                 String colScale = null;
270                 String colNoN = null;
271                 String colDflt = null;
272                 String indexName = null;
273                 String indexType = null;
274                 String constraintType = null;
275                 String colPos = null;
276                 String seqName = null;
277                 String minVal = null;
278                 String maxVal = null;
279                 String incSz = null;
280                 String cycFg = null;
281                 String odFg = null;
282                 String cacheSz = null;
283                 String lstNo = null;
284                 String synmOwner = null;
285                 String synmName = null;
286                 String tbOwner = null;
287                 String tbName = null;
288                 String dbLnk = null;
289                 String userName = null;
290                 String passWord = null;
291                 String host = null;
292                 String created = null;
293                 String acStat = null;
294                 String defTbsp = null;
295                 String tmpTbsp = null;
296                 String grntee = null;
297                 String grntor = null;
298                 String grntrl = null;
299                 String prvs = null;
300                 String grntabl = null;
301                 String hrchy = null;
302
303                 String objName = null;
304                 String objTyp = null;
305                 String pctFree = null;
306                 String pctUsed = null;
307                 String iniTrns = null;
308                 String freeLst = null;
309                 String flstGrp = null;
310                 String bufPool = null;
311                 String tblSpace = null;
312                 String logging = null;
313                 String segByts = null;
314
315                 String fkName = null;
316                 String fkCol = null;
317                 String fkColPos = null;
318                 String rtbName = null;
319                 String rfkName = null;
320                 String rfkCol = null;
321                 String rfkColPos = null;
322
323                 CmnProps cp = null;
324                 CmnAccessObjects dao = null;
325                 
326                 try {
327                         cp = new CmnProps();
328                         cp.setProperty(database);
329                         
330                         if (cp.dbType != cp.DB_TYPE_ORACLE){
331                                 throw new Exception("\83f\81[\83^\83x\81[\83X\82ª\91Î\8fÛ\8aO\82Å\82·\81B[" + cp.DB_TYPE_NAME[cp.dbType] + "]");
332                         }
333                         if(cp.outFolder != null){
334                                 folder = new File(cp.outFolder);
335                         } else {
336                                 if(database != null){
337                                         folder = new File(cp.DEFAULT_OUT_FOLDER + "/DDL_" + database.toUpperCase() + "_" + CmnUtils.getYmdhm());
338                                 } else {
339                                         folder = new File(cp.DEFAULT_OUT_FOLDER + "/DDL_" + cp.DB_TYPE_NAME[cp.dbType].toUpperCase() + "_" + CmnUtils.getYmdhm());
340                                 }
341                                 folder.mkdir();
342                         }
343
344                         CmnUtils.infoPrint("-->\8fo\97Í\90æ\83t\83H\83\8b\83_='" + folder + "'");
345                         CmnUtils.infoPrint("\83\81\83^\83f\81[\83^\83A\83\93\83\8d\81[\83h\82ð\8aJ\8en\82µ\82Ü\82µ\82½\81B");
346
347                         // Connect
348                         dao = new CmnAccessObjects(cp);
349                         conn = dao.connect();
350                         // Def tsv Writing start
351                         for(int i=0;i<sql[cp.dbType].length;i++){
352                                 dao.select(sql[cp.dbType][i]);
353                                 CmnUtils.writeSeparator(folder + "/" + FILE_NAME[i] + "_" + database +"." + cp.fileExtension, dao.getColumnCount(), dao.getArrayList(), cp.delimiter);
354                         }
355                         // Def tsv Writing end
356
357                         // Table Contents start
358                         br[0] = new BufferedReader(new FileReader(folder + "/" + FILE_NAME[FL_TABLE] + "_" + database + "." + cp.fileExtension));
359                         subFolder = new File(folder + "/TABLES");
360                         subFolder.mkdir();
361                         pw[1] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_TABLE]))));
362                         pw[2] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + cp.SQL_FILE_NAME[cp.DROP_TABLE]))));
363                         pw[3] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + cp.SQL_FILE_NAME[cp.TRUNCATE_TABLE]))));
364
365                         tableName = "";
366                         tableCmnt = "";
367                         colName = "";
368                         colCmnt = "";
369                         colType = "";
370                         colLen = "";
371                         colPrec = "";
372                         colScale = "";
373                         colNoN = "";
374                         colDflt = "";
375
376                         StringBuffer sbTbCnts = new StringBuffer();
377                         StringBuffer sbTbCmnt = new StringBuffer();
378                         while((strLine=br[0].readLine()) != null){
379                                 if(!strLine.equals("")){
380                                         strSplit[0] = CmnUtils.split(strLine, cp.delimiter);
381                                         if (!tableName.equals("")){
382                                                 sbTbCnts.append("    " + cp.sqlQuoted + colName + cp.sqlQuoted);
383                                                 sbTbCnts.append(" " + colType);
384                                                 if(!colCmnt.equals(""))sbTbCmnt.append("COMMENT ON COLUMN " + cp.sqlQuoted + tableName + cp.sqlQuoted + "." + cp.sqlQuoted + colName + cp.sqlQuoted + " IS '" + colCmnt.replaceAll("'","''") + "';");
385                                                 if(!colCmnt.equals(""))sbTbCmnt.append(cp.lineSeparator);
386                                                 if(CmnUtils.isColPrec(colType, colPrec)){
387                                                         sbTbCnts.append("(" + colPrec);
388                                                         if (!colScale.equals(""))sbTbCnts.append("," + colScale);
389                                                         sbTbCnts.append(")");
390                                                 } else if (CmnUtils.isColLength(colType, colLen)){
391                                                         sbTbCnts.append("(" + CmnUtils.getColLength(colType, colLen) + ")");
392                                                 }
393                                                 if (!colDflt.equals(""))sbTbCnts.append(" DEFAULT " + colDflt.trim());
394                                                 if (colNoN.equals("\81\9b"))sbTbCnts.append(" NOT NULL");
395                                                 if (!strSplit[0][0].equals(tableName)){
396                                                         pw[1].println("@TABLES/" + tableName + ".sql");
397                                                         pw[2].println("DROP TABLE " + cp.sqlQuoted + tableName + cp.sqlQuoted + " CASCADE CONSTRAINT PURGE;");
398                                                         pw[3].println("TRUNCATE TABLE " + cp.sqlQuoted + tableName + cp.sqlQuoted + ";");
399                                                         sbTbCnts.append(cp.lineSeparator);
400                                                         sbTbCnts.append(");");
401                                                         sbTbCnts.append(cp.lineSeparator);
402                                                         pw[0] = new PrintWriter(new BufferedWriter(new FileWriter(new File(subFolder + "/" + tableName + ".sql"))));
403                                                         strSplit[1] = CmnUtils.splitCrLf(sbTbCnts.toString());
404                                                         for(int i=0;i<strSplit[1].length;i++)if(!strSplit[1][i].trim().equals(""))pw[0].println(strSplit[1][i]);
405                                                         strSplit[2] = CmnUtils.splitCrLf(sbTbCmnt.toString());
406                                                         for(int i=0;i<strSplit[2].length;i++)if(!strSplit[2][i].trim().equals(""))pw[0].println(strSplit[2][i]);
407                                                         pw[0].close();
408                                                         pw[0] = null;
409                                                         sbTbCnts = new StringBuffer();
410                                                         sbTbCmnt = new StringBuffer();
411                                                         sbTbCnts.append("CREATE TABLE " + cp.sqlQuoted + strSplit[0][0] + cp.sqlQuoted);
412                                                         sbTbCnts.append(cp.lineSeparator);
413                                                         sbTbCnts.append("(");
414                                                         sbTbCnts.append(cp.lineSeparator);
415                                                         if(!strSplit[0][1].equals(""))sbTbCmnt.append("COMMENT ON TABLE " + cp.sqlQuoted + strSplit[0][0] + cp.sqlQuoted + " IS '" + strSplit[0][1].replaceAll("'","''") +"';");
416                                                         if(!strSplit[0][1].equals(""))sbTbCmnt.append(cp.lineSeparator);
417                                                 } else {
418                                                         sbTbCnts.append(",");
419                                                         sbTbCnts.append(cp.lineSeparator);
420                                                 }
421                                         }
422                                         else {
423                                                 sbTbCnts.append("CREATE TABLE " + cp.sqlQuoted + strSplit[0][0] + cp.sqlQuoted);
424                                                 sbTbCnts.append(cp.lineSeparator);
425                                                 sbTbCnts.append("(");
426                                                 sbTbCnts.append(cp.lineSeparator);
427                                                 if(!strSplit[0][1].equals(""))sbTbCmnt.append("COMMENT ON TABLE " + cp.sqlQuoted + strSplit[0][0] + cp.sqlQuoted + " IS '" + strSplit[0][1].replaceAll("'","''") +"';");
428                                                 if(!strSplit[0][1].equals(""))sbTbCmnt.append(cp.lineSeparator);
429                                         }
430                                         for(int i=0;i<strSplit[0].length;i++)CmnUtils.debugPrint("'" + strSplit[0][i] + "'");
431
432                                         tableName = strSplit[0][0];
433                                         tableCmnt = strSplit[0][1];
434                                         colName = strSplit[0][2];
435                                         colCmnt = strSplit[0][3];
436                                         colType = strSplit[0][4];
437                                         colLen = strSplit[0][5];
438                                         colPrec = strSplit[0][6];
439                                         colScale = strSplit[0][7];
440                                         colNoN = strSplit[0][8];
441                                         colDflt = strSplit[0][9];
442                                 }
443                         }
444
445                         if (!tableName.equals("")){
446                                 sbTbCnts.append("    " + cp.sqlQuoted + colName + cp.sqlQuoted);
447                                 sbTbCnts.append(" " + colType);
448                                 if(!colCmnt.equals(""))sbTbCmnt.append("COMMENT ON COLUMN " + cp.sqlQuoted + tableName + cp.sqlQuoted + "." + cp.sqlQuoted + colName + cp.sqlQuoted + " IS '" + colCmnt.replaceAll("'","''") + "';");
449                                 if(!colCmnt.equals(""))sbTbCmnt.append(cp.lineSeparator);
450                                 if(CmnUtils.isColPrec(colType, colPrec)){
451                                         sbTbCnts.append("(" + colPrec);
452                                         if (!colScale.equals(""))sbTbCnts.append("," + colScale);
453                                         sbTbCnts.append(")");
454                                 } else if (CmnUtils.isColLength(colType, colLen)){
455                                         sbTbCnts.append("(" + CmnUtils.getColLength(colType, colLen) + ")");
456                                 }
457                                 if (!colDflt.equals(""))sbTbCnts.append(" DEFAULT " + colDflt.trim());
458                                 if (colNoN.equals("\81\9b"))sbTbCnts.append(" NOT NULL");
459                                 pw[1].println("@TABLES/" + tableName + ".sql");
460                                 pw[2].println("DROP TABLE " + cp.sqlQuoted + tableName + cp.sqlQuoted + " CASCADE CONSTRAINT PURGE;");
461                                 pw[3].println("TRUNCATE TABLE " + cp.sqlQuoted + tableName + cp.sqlQuoted + ";");
462                                 sbTbCnts.append(cp.lineSeparator);
463                                 sbTbCnts.append(");");
464                                 sbTbCnts.append(cp.lineSeparator);
465                                 pw[0] = new PrintWriter(new BufferedWriter(new FileWriter(new File(subFolder + "/" + tableName + ".sql"))));
466                                 strSplit[1] = CmnUtils.splitCrLf(sbTbCnts.toString());
467                                 for(int i=0;i<strSplit[1].length;i++)if(!strSplit[1][i].trim().equals(""))pw[0].println(strSplit[1][i]);
468                                 strSplit[2] = CmnUtils.splitCrLf(sbTbCmnt.toString());
469                                 for(int i=0;i<strSplit[2].length;i++)if(!strSplit[2][i].trim().equals(""))pw[0].println(strSplit[2][i]);
470                                 pw[0].close();
471                                 pw[0] = null;
472                         }
473                         for(int i=1;i<4;i++)pw[i].close();
474                         for(int i=1;i<4;i++)pw[i]=null;
475                         br[0].close();
476                         br[0] = null;
477                         // Table Contents end
478
479                         // Index Contents start
480                         br[0] = new BufferedReader(new FileReader(folder + "/" + FILE_NAME[FL_INDEX] + "_" + database + "." + cp.fileExtension));
481                         pw[0] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_PKEY]))));
482                         pw[1] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_UKEY]))));
483                         pw[2] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_INDEX]))));
484                         pw[3] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + cp.SQL_FILE_NAME[cp.DROP_PKEY]))));
485                         pw[4] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + cp.SQL_FILE_NAME[cp.DROP_UKEY]))));
486                         pw[5] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + cp.SQL_FILE_NAME[cp.DROP_INDEX]))));
487
488                         //Initial Process
489                         tableName = "";
490                         indexName = "";
491                         indexType = "";
492                         constraintType = "";
493                         colName = "";
494                         colPos = "";
495                         StringBuffer sbIxCnts = new StringBuffer();
496                         StringBuffer sbIx2Cnts = new StringBuffer();
497                         StringBuffer sbIx3Cnts = new StringBuffer();
498
499                         //Loop Process
500                         while((strLine=br[0].readLine()) != null){
501                                 if(!strLine.equals("")){
502                                         strSplit[0] = CmnUtils.split(strLine, cp.delimiter);
503                                         //Not 1st Line Process
504                                         if (!indexName.equals("")){
505                                                 if (!strSplit[0][1].equals(indexName)){
506                                                         //Post Process
507                                                         if (colPos.equals("1")){
508                                                                 sbIxCnts.append(cp.sqlQuoted + colName + cp.sqlQuoted);
509                                                                 if (constraintType.equals("U"))sbIx2Cnts.append(cp.sqlQuoted + colName + cp.sqlQuoted);
510                                                         } else {
511                                                                 sbIxCnts.append(", " + cp.sqlQuoted + colName + cp.sqlQuoted);
512                                                                 if (constraintType.equals("U"))sbIx2Cnts.append(", " + cp.sqlQuoted + colName + cp.sqlQuoted);
513                                                         }
514                                                         sbIxCnts.append(");");
515                                                         sbIxCnts.append(cp.lineSeparator);
516                                                         if (constraintType.equals("U"))sbIx2Cnts.append(");");
517                                                         sbIx2Cnts.append(cp.lineSeparator);
518                                                         sbIx3Cnts.append(cp.lineSeparator);
519
520                                                         //Write Buffer
521                                                         if (constraintType.equals("P")){
522                                                                 strSplit[1] = CmnUtils.splitCrLf(sbIxCnts.toString());
523                                                                 for(int i=0;i<strSplit[1].length;i++)if(!strSplit[1][i].trim().equals(""))pw[0].println(strSplit[1][i]);
524                                                                 strSplit[2] = CmnUtils.splitCrLf(sbIx2Cnts.toString());
525                                                                 for(int i=0;i<strSplit[2].length;i++)if(!strSplit[2][i].trim().equals(""))pw[3].println(strSplit[2][i]);
526                                                         } else if (constraintType.equals("U")){
527                                                                 strSplit[1] = CmnUtils.splitCrLf(sbIxCnts.toString());
528                                                                 for(int i=0;i<strSplit[1].length;i++)if(!strSplit[1][i].trim().equals(""))pw[1].println(strSplit[1][i]);
529                                                                 strSplit[2] = CmnUtils.splitCrLf(sbIx2Cnts.toString());
530                                                                 for(int i=0;i<strSplit[2].length;i++)if(!strSplit[2][i].trim().equals(""))pw[4].println(strSplit[2][i]);
531                                                         } else if (constraintType.equals("")){
532                                                                 strSplit[1] = CmnUtils.splitCrLf(sbIxCnts.toString());
533                                                                 for(int i=0;i<strSplit[1].length;i++)if(!strSplit[1][i].trim().equals(""))pw[2].println(strSplit[1][i]);
534                                                         }
535                                                         strSplit[3] = CmnUtils.splitCrLf(sbIx3Cnts.toString());
536                                                         for(int i=0;i<strSplit[3].length;i++)if(!strSplit[3][i].trim().equals(""))pw[5].println(strSplit[3][i]);
537
538                                                         //Initial Process
539                                                         sbIxCnts = new StringBuffer();
540                                                         sbIx2Cnts = new StringBuffer();
541                                                         sbIx3Cnts = new StringBuffer();
542
543                                                         //Index Changed Process
544                                                         if (strSplit[0][3].equals("P")){
545                                                                 sbIxCnts.append("ALTER TABLE " + cp.sqlQuoted + strSplit[0][0] + cp.sqlQuoted + " ADD CONSTRAINT " + cp.sqlQuoted + strSplit[0][1] + cp.sqlQuoted + " PRIMARY KEY(");
546                                                                 sbIx2Cnts.append("ALTER TABLE " + cp.sqlQuoted + strSplit[0][0] + cp.sqlQuoted + " DROP CONSTRAINT " + cp.sqlQuoted + strSplit[0][1] + cp.sqlQuoted + ";");
547                                                         } else if (strSplit[0][3].equals("U")){
548                                                                 sbIxCnts.append("ALTER TABLE " + cp.sqlQuoted + strSplit[0][0] + cp.sqlQuoted + " ADD CONSTRAINT " + cp.sqlQuoted + strSplit[0][1] + cp.sqlQuoted + " UNIQUE(");
549                                                                 sbIx2Cnts.append("ALTER TABLE " + cp.sqlQuoted + strSplit[0][0] + cp.sqlQuoted + " DROP UNIQUE(");
550                                                         } else if (strSplit[0][3].equals("")){
551                                                                 sbIxCnts.append("CREATE INDEX " + cp.sqlQuoted + strSplit[0][1] + cp.sqlQuoted + " ON " + strSplit[0][0] + "(");
552                                                         }
553                                                         sbIx3Cnts.append("DROP INDEX " + cp.sqlQuoted + strSplit[0][1] + cp.sqlQuoted + ";");
554                                                 } else if (strSplit[0][1].equals(indexName)){
555                                                         if (colPos.equals("1")){
556                                                                 sbIxCnts.append(cp.sqlQuoted + colName + cp.sqlQuoted);
557                                                                 if (constraintType.equals("U"))sbIx2Cnts.append(cp.sqlQuoted + colName + cp.sqlQuoted);
558                                                         } else {
559                                                                 sbIxCnts.append(", " + cp.sqlQuoted + colName + cp.sqlQuoted);
560                                                                 if (constraintType.equals("U"))sbIx2Cnts.append(", " + cp.sqlQuoted + colName + cp.sqlQuoted);
561                                                         }
562                                                 }
563                                         }
564
565                                         //1st Line Process
566                                         else {
567                                                 if (strSplit[0][3].equals("P")){
568                                                         sbIxCnts.append("ALTER TABLE " + cp.sqlQuoted + strSplit[0][0] + cp.sqlQuoted + " ADD CONSTRAINT " + cp.sqlQuoted + strSplit[0][1] + cp.sqlQuoted + " PRIMARY KEY(");
569                                                         sbIx2Cnts.append("ALTER TABLE " + cp.sqlQuoted + strSplit[0][0] + cp.sqlQuoted + " DROP CONSTRAINT " + cp.sqlQuoted + strSplit[0][1] + cp.sqlQuoted + ";");
570                                                 } else if (strSplit[0][3].equals("U")){
571                                                         sbIxCnts.append("ALTER TABLE " + cp.sqlQuoted + strSplit[0][0] + cp.sqlQuoted + " ADD CONSTRAINT " + cp.sqlQuoted + strSplit[0][1] + cp.sqlQuoted + " UNIQUE(");
572                                                         sbIx2Cnts.append("ALTER TABLE " + cp.sqlQuoted + strSplit[0][0] + cp.sqlQuoted + " DROP UNIQUE(");
573                                                 } else if (strSplit[0][3].equals("")){
574                                                         sbIxCnts.append("CREATE INDEX " + cp.sqlQuoted + strSplit[0][1] + cp.sqlQuoted + " ON " + cp.sqlQuoted + strSplit[0][0] + cp.sqlQuoted + "(");
575                                                 }
576                                                 sbIx3Cnts.append("DROP INDEX " + cp.sqlQuoted + strSplit[0][1] + cp.sqlQuoted + ";");
577                                         }
578                                         for(int i=0;i<strSplit[0].length;i++)CmnUtils.debugPrint("'" + strSplit[0][i] + "'");
579
580                                         tableName = strSplit[0][0];
581                                         indexName = strSplit[0][1];
582                                         indexType = strSplit[0][2];
583                                         constraintType = strSplit[0][3];
584                                         colName = strSplit[0][4];
585                                         colPos = strSplit[0][5];
586                                 }
587                         }
588                         if (!indexName.equals("")){
589                                 //Post Process
590                                 if (colPos.equals("1")){
591                                         sbIxCnts.append(cp.sqlQuoted + colName + cp.sqlQuoted);
592                                         if (constraintType.equals("U"))sbIx2Cnts.append(cp.sqlQuoted + colName + cp.sqlQuoted);
593                                 } else {
594                                         sbIxCnts.append(", " + cp.sqlQuoted + colName + cp.sqlQuoted);
595                                         if (constraintType.equals("U"))sbIx2Cnts.append(", " + cp.sqlQuoted + colName + cp.sqlQuoted);
596                                 }
597                                 sbIxCnts.append(");");
598                                 sbIxCnts.append(cp.lineSeparator);
599                                 if (constraintType.equals("U"))sbIx2Cnts.append(");");
600                                 sbIx2Cnts.append(cp.lineSeparator);
601                                 sbIx3Cnts.append(cp.lineSeparator);
602
603                                 //Write Buffer
604                                 if (constraintType.equals("P")){
605                                         strSplit[1] = CmnUtils.splitCrLf(sbIxCnts.toString());
606                                         for(int i=0;i<strSplit[1].length;i++)if(!strSplit[1][i].trim().equals(""))pw[0].println(strSplit[1][i]);
607                                         strSplit[2] = CmnUtils.splitCrLf(sbIx2Cnts.toString());
608                                         for(int i=0;i<strSplit[2].length;i++)if(!strSplit[2][i].trim().equals(""))pw[3].println(strSplit[2][i]);
609                                 } else if (constraintType.equals("U")){
610                                         strSplit[1] = CmnUtils.splitCrLf(sbIxCnts.toString());
611                                         for(int i=0;i<strSplit[1].length;i++)if(!strSplit[1][i].trim().equals(""))pw[1].println(strSplit[1][i]);
612                                         strSplit[2] = CmnUtils.splitCrLf(sbIx2Cnts.toString());
613                                         for(int i=0;i<strSplit[2].length;i++)if(!strSplit[2][i].trim().equals(""))pw[4].println(strSplit[2][i]);
614                                 } else if (constraintType.equals("")){
615                                         strSplit[1] = CmnUtils.splitCrLf(sbIxCnts.toString());
616                                         for(int i=0;i<strSplit[1].length;i++)if(!strSplit[1][i].trim().equals(""))pw[2].println(strSplit[1][i]);
617                                 }
618                                 strSplit[3] = CmnUtils.splitCrLf(sbIx3Cnts.toString());
619                                 for(int i=0;i<strSplit[3].length;i++)if(!strSplit[3][i].trim().equals(""))pw[5].println(strSplit[3][i]);
620                         }
621
622                         //Close Buffer
623                         for(int i=0;i<6;i++)pw[i].close();
624                         for(int i=0;i<6;i++)pw[i]=null;
625                         br[0].close();
626                         br[0] = null;
627                         // Index Contents end
628
629                         // View Contents start
630                         br[0] = new BufferedReader(new FileReader(folder + "/" + FILE_NAME[FL_VIEW] + "_" + database + "." + cp.fileExtension));
631                         subFolder = new File(folder + "/VIEWS");
632                         subFolder.mkdir();
633                         pw[1] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_VIEW]))));
634                         pw[2] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + cp.SQL_FILE_NAME[cp.DROP_VIEW]))));
635                         while((strLine=br[0].readLine()) != null){
636                                 strSplit[0] = CmnUtils.split(strLine, cp.delimiter);
637                                 CmnUtils.debugPrint("'" + strSplit[0][0] + "'");
638                                 pw[1].println("@VIEWS/" + strSplit[0][0] + ".sql");
639                                 pw[2].println("DROP VIEW " + cp.sqlQuoted + strSplit[0][0] + cp.sqlQuoted + ";");
640                                 if (strSplit[0].length>1)CmnUtils.debugPrint("'" + strSplit[0][1] + "'");
641                                 pw[0] = new PrintWriter(new BufferedWriter(new FileWriter(new File(subFolder + "/" + strSplit[0][0] + ".sql"))));
642                                 stmt = dao.prepareSql(sql_view_column_and_comment);
643                                 stmt.setString(1,strSplit[0][0]);
644                                 dao.executeSql();
645                                 alData = dao.getArrayList();
646                                 columnCount = dao.getColumnCount();
647                                 pw[0].println("/* " + strSplit[0][0] + " */");
648                                 pw[0].println("CREATE OR REPLACE VIEW " + cp.sqlQuoted + strSplit[0][0] + cp.sqlQuoted);
649                                 pw[0].println("(");
650                                 for(int i=0;i<alData.size();i++){
651                                         if ((i+1) % columnCount == 1){
652                                                 if (i == 0){
653                                                         if (!alData.get(i+1).equals("")){
654                                                                 pw[0].println("    " + alData.get(i) + "    -- " + alData.get(i+1));
655                                                         } else {
656                                                                 pw[0].println("    " + alData.get(i));
657                                                         }
658                                                 } else {
659                                                         if (!alData.get(i+1).equals("")){
660                                                                 pw[0].println("    ," + alData.get(i) + "    -- " + alData.get(i+1));
661                                                         } else {
662                                                                 pw[0].println("    ," + alData.get(i));
663                                                         }
664                                                 }
665                                         }
666                                 }
667                                 pw[0].println(")");
668                                 pw[0].println("AS");
669                                 stmt = dao.prepareSql(sql_view_text);
670                                 stmt.setString(1,strSplit[0][0]);
671                                 dao.executeSql();
672                                 alData2 = dao.getArrayList();
673                                 strContents = alData2.get(0).trim();
674                                 strSplit[1] = CmnUtils.splitCrLf(strContents);
675                                 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() + "."),""));
676                                 pw[0].println(";");
677                                 if (!strSplit[0][1].equals(""))pw[0].println("COMMENT ON TABLE " + cp.sqlQuoted + strSplit[0][0] + cp.sqlQuoted + " IS '" + strSplit[0][1].replaceAll("'","''") + "';");
678                                 for(int i=0;i<alData.size();i++){
679                                         if ((i+1) % columnCount == 0){
680                                                 if (!alData.get(i).equals(""))pw[0].println("COMMENT ON COLUMN " + cp.sqlQuoted + strSplit[0][0] + cp.sqlQuoted + "." + alData.get(i-1) + " IS '" + alData.get(i).replaceAll("'","''") + "';");
681                                         }
682                                 }
683                                 pw[0].close();
684                                 pw[0] = null;
685                         }
686                         for(int i=1;i<3;i++)pw[i].close();
687                         for(int i=1;i<3;i++)pw[i]=null;
688                         br[0].close();
689                         br[0] = null;
690                         // View Contents end
691
692                         // Procedure Contents start
693                         br[0] = new BufferedReader(new FileReader(folder + "/" + FILE_NAME[FL_PROCEDURE] + "_" + database + "." + cp.fileExtension));
694                         subFolder = new File(folder + "/PROCEDURES");
695                         subFolder.mkdir();
696                         pw[1] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_PROCEDURE]))));
697                         pw[2] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + cp.SQL_FILE_NAME[cp.DROP_PROCEDURE]))));
698                         while((strLine=br[0].readLine()) != null){
699                                 strSplit[0] = CmnUtils.split(strLine, cp.delimiter);
700                                 CmnUtils.debugPrint("'" + strSplit[0][0] + "'");
701                                 pw[1].println("@PROCEDURES/" + strSplit[0][0] + ".sql");
702                                 pw[2].println("DROP " + strSplit[0][1] + " " + strSplit[0][0] + ";");
703                                 if (strSplit[0].length>1)CmnUtils.debugPrint("'" + strSplit[0][1] + "'");
704                                 pw[0] = new PrintWriter(new BufferedWriter(new FileWriter(new File(subFolder + "/" + strSplit[0][0] + ".sql"))));
705                                 pw[0].println("/* " + strSplit[0][0] + " */");
706                                 pw[0].print("CREATE OR REPLACE ");
707                                 stmt = dao.prepareSql(sql_proc);
708                                 stmt.setString(1,strSplit[0][0]);
709                                 dao.executeSql();
710                                 alData = dao.getArrayList();
711                                 for(int i=0;i<alData.size();i++){
712                                         strContents = alData.get(i);
713                                         if(!strContents.equals(""))pw[0].println(strContents.replaceAll(Pattern.quote(cp.user.toUpperCase() + "."),"").replaceAll(Pattern.quote(cp.user.toLowerCase() + "."),""));
714                                 }
715                                 //pw[0].println("/");
716                                 pw[0].close();
717                                 pw[0] = null;
718                         }
719                         for(int i=1;i<3;i++)pw[i].close();
720                         for(int i=1;i<3;i++)pw[i]=null;
721                         br[0].close();
722                         br[0] = null;
723                         // Procedure Contents end
724
725                         // Sequence Contents start
726                         br[0] = new BufferedReader(new FileReader(folder + "/" + FILE_NAME[FL_SEQ] + "_" + database + "." + cp.fileExtension));
727                         pw[1] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_SEQUENCE]))));
728                         pw[2] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + cp.SQL_FILE_NAME[cp.DROP_SEQUENCE]))));
729
730                         while((strLine=br[0].readLine()) != null){
731                                 strSplit[0] = CmnUtils.split(strLine, cp.delimiter);
732                                 seqName = strSplit[0][0];
733                                 minVal = strSplit[0][1];
734                                 maxVal = strSplit[0][2];
735                                 incSz = strSplit[0][3];
736                                 cycFg = strSplit[0][4];
737                                 odFg = strSplit[0][5];
738                                 cacheSz = strSplit[0][6];
739                                 if(cacheSz.equals("0"))cacheSz="10";
740                                 lstNo = strSplit[0][7];
741                                 pw[1].print("CREATE SEQUENCE " + cp.sqlQuoted + seqName + cp.sqlQuoted + " MINVALUE " + minVal + " MAXVALUE " + maxVal + " INCREMENT BY " + incSz + " START WITH " + lstNo + " CACHE " + cacheSz);
742                                 if (odFg.equals("N")){
743                                         pw[1].print(" NOORDER");
744                                 } else {
745                                         pw[1].print(" ORDER");
746                                 }
747                                 if (cycFg.equals("N")){
748                                         pw[1].print(" NOCYCLE");
749                                 } else {
750                                         pw[1].print(" CYCLE");
751                                 }
752                                 pw[1].println(";");
753                                 pw[2].println("DROP SEQUENCE " + cp.sqlQuoted + seqName + cp.sqlQuoted + ";");
754                                 for(int i=0;i<strSplit[0].length;i++)CmnUtils.debugPrint("'" + strSplit[0][i] + "'");
755                         }
756                         for(int i=1;i<3;i++)pw[i].close();
757                         for(int i=1;i<3;i++)pw[i]=null;
758                         br[0].close();
759                         br[0] = null;
760                         // Sequence Contents end
761
762                         // Synonym Contents start
763                         br[0] = new BufferedReader(new FileReader(folder + "/" + FILE_NAME[FL_SYNONYM] + "_" + database + "." + cp.fileExtension));
764                         pw[1] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_SYNONYM]))));
765                         pw[2] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + cp.SQL_FILE_NAME[cp.DROP_SYNONYM]))));
766
767                         while((strLine=br[0].readLine()) != null){
768                                 strSplit[0] = CmnUtils.split(strLine, cp.delimiter);
769                                 synmName = strSplit[0][0];
770                                 tbOwner = strSplit[0][1];
771                                 tbName = strSplit[0][2];
772                                 dbLnk = strSplit[0][3];
773                                 
774                                 pw[1].print("CREATE SYNONYM " + cp.sqlQuoted + synmName + cp.sqlQuoted + " FOR ");
775                                 if(dbLnk.equals("")){
776                                         pw[1].print(cp.sqlQuoted + tbOwner + cp.sqlQuoted + "." + cp.sqlQuoted + tbName + cp.sqlQuoted );
777                                 } else {
778                                         pw[1].print(cp.sqlQuoted + tbName + cp.sqlQuoted + "@" + cp.sqlQuoted + dbLnk + cp.sqlQuoted );
779                                 }
780                                 pw[1].println(";");
781                                 pw[2].println("DROP SYNONYM " + cp.sqlQuoted + synmName + cp.sqlQuoted + ";");
782                                 for(int i=0;i<strSplit[0].length;i++)CmnUtils.debugPrint("'" + strSplit[0][i] + "'");
783                         }
784                         for(int i=1;i<3;i++)pw[i].close();
785                         for(int i=1;i<3;i++)pw[i]=null;
786                         br[0].close();
787                         br[0] = null;
788                         // Synonym Contents end
789
790                         // Fk Contents start
791                         File tsvFile = new File(folder + "/" + FILE_NAME[FL_FK] + "_" + database + "." + cp.fileExtension);
792                         if (tsvFile.length() > 0) {
793                                 br[0] = new BufferedReader(new FileReader(folder + "/" + FILE_NAME[FL_FK] + "_" + database + "." + cp.fileExtension));
794                                 pw[1] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_FK]))));
795                                 pw[2] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + cp.SQL_FILE_NAME[cp.DROP_FK]))));
796                                 tbName = "";
797                                 fkName = "";
798                                 fkCol = "";
799                                 fkColPos = "";
800                                 rtbName = "";
801                                 rfkName = "";
802                                 rfkCol = "";
803                                 rfkColPos = "";
804                                 
805                                 while((strLine=br[0].readLine()) != null){
806                                         strSplit[0] = CmnUtils.split(strLine, cp.delimiter);
807                                         if(!fkName.equals(strSplit[0][1]) && !fkName.equals("")){
808                                                 pw[1].println("ALTER TABLE " + cp.sqlQuoted + tbName + cp.sqlQuoted + " ADD CONSTRAINT " + cp.sqlQuoted + fkName + cp.sqlQuoted + " FOREIGN KEY (" + cp.sqlQuoted + fkCol + cp.sqlQuoted + ") REFERENCES " + cp.sqlQuoted + rtbName + cp.sqlQuoted + " (" + cp.sqlQuoted + rfkCol + cp.sqlQuoted + ");");
809                                                 pw[2].println("ALTER TABLE " + cp.sqlQuoted + tbName + cp.sqlQuoted + " DROP CONSTRAINT " + cp.sqlQuoted + fkName + cp.sqlQuoted + ";");
810                                                 for(int i=0;i<strSplit[0].length;i++)CmnUtils.debugPrint("'" + strSplit[0][i] + "'");
811                                                 tbName = strSplit[0][0];
812                                                 fkName = strSplit[0][1];
813                                                 fkCol = strSplit[0][2];
814                                                 fkColPos = strSplit[0][3];
815                                                 rtbName = strSplit[0][4];
816                                                 rfkName = strSplit[0][5];
817                                                 rfkCol = strSplit[0][6];
818                                                 rfkColPos = strSplit[0][7];
819                                         } else {
820                                                 if(fkName.equals("")){
821                                                         tbName = strSplit[0][0];
822                                                         fkName = strSplit[0][1];
823                                                         fkCol = strSplit[0][2];
824                                                         fkColPos = strSplit[0][3];
825                                                         rtbName = strSplit[0][4];
826                                                         rfkName = strSplit[0][5];
827                                                         rfkCol = strSplit[0][6];
828                                                         rfkColPos = strSplit[0][7];
829                                                 } else {
830                                                         if (strSplit[0][3].equals(strSplit[0][7])) {
831                                                                 fkCol = fkCol + cp.sqlQuoted + ", " + cp.sqlQuoted + strSplit[0][2];
832                                                                 rfkCol = rfkCol + cp.sqlQuoted + ", " + cp.sqlQuoted + strSplit[0][6];
833                                                         }
834                                                 }
835                                         }
836                                         
837                                 }
838                                 pw[1].println("ALTER TABLE " + cp.sqlQuoted + tbName + cp.sqlQuoted + " ADD CONSTRAINT " + cp.sqlQuoted + fkName + cp.sqlQuoted + " FOREIGN KEY (" + cp.sqlQuoted + fkCol + cp.sqlQuoted + ") REFERENCES " + cp.sqlQuoted + rtbName + cp.sqlQuoted + " (" + cp.sqlQuoted + rfkCol + cp.sqlQuoted + ");");
839                                 pw[2].println("ALTER TABLE " + cp.sqlQuoted + tbName + cp.sqlQuoted + " DROP CONSTRAINT " + cp.sqlQuoted + fkName + cp.sqlQuoted + ";");
840                                 for(int i=1;i<3;i++)pw[i].close();
841                                 for(int i=1;i<3;i++)pw[i]=null;
842                                 br[0].close();
843                                 br[0] = null;
844                         }
845                         // Fk Contents end
846
847                         // Rhysical Contents start
848                         if(cp.isPhysical){
849                                 // physical index setting
850                                 br[0] = new BufferedReader(new FileReader(folder + "/" + FILE_NAME[FL_OBJ] + "_" + database + "." + cp.fileExtension));
851                                 br[1] = new BufferedReader(new FileReader(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_PKEY]));
852                                 br[2] = new BufferedReader(new FileReader(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_UKEY]));
853                                 br[3] = new BufferedReader(new FileReader(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_INDEX]));
854                                 pw[1] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_PKEY] + ".phy"))));
855                                 pw[2] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_UKEY] + ".phy"))));
856                                 pw[3] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_INDEX] + ".phy"))));
857                                 alData = new ArrayList<String>();
858                                 int rowNo;
859                                 String [] rowData;
860                                 while((strLine=br[0].readLine()) != null){
861                                         strSplit[0] = CmnUtils.split(strLine, cp.delimiter);
862                                         for(int i=0;i<strSplit[0].length;i++)alData.add(strSplit[0][i]);
863                                 }
864                                 while((strLine=br[1].readLine()) != null){
865                                         strSplit[0] = CmnUtils.splitSpace(strLine);
866                                         rowNo = CmnUtils.getArrayRowNo(alData, 12, 1, strSplit[0][5].replaceAll(cp.sqlQuoted,""));
867                                         if (rowNo != -1){
868                                                 rowData = rowData = CmnUtils.getArrayRowData(alData, 12, rowNo);
869                                                 CmnUtils.debugPrint(strSplit[0][5] + ":" + rowNo);
870                                                 for(int i=0;i<rowData.length;i++)CmnUtils.debugPrint(rowData[i]);
871                                                 tbName = rowData[0];
872                                                 objName = rowData[1];
873                                                 objTyp = rowData[2];
874                                                 pctFree = rowData[3];
875                                                 pctUsed = rowData[4];
876                                                 iniTrns = rowData[5];
877                                                 freeLst = rowData[6];
878                                                 flstGrp = rowData[7];
879                                                 bufPool = rowData[8];
880                                                 tblSpace = rowData[9];
881                                                 logging = rowData[10];
882                                                 segByts = rowData[11];
883                                                 pw[1].print(strLine.replace(';',' '));
884                                                 pw[1].print("USING INDEX PCTFREE " + pctFree);
885                                                 pw[1].print(" INITRANS " + iniTrns + " STORAGE(");
886                                                 if(!freeLst.equals(""))pw[1].print(" FREELISTS " + freeLst);
887                                                 if(!flstGrp.equals(""))pw[1].print(" FREELIST GROUPS " + flstGrp);
888                                                 pw[1].print(" BUFFER_POOL " + bufPool + ")");
889                                                 pw[1].print(" TABLESPACE " + cp.sqlQuoted + tblSpace + cp.sqlQuoted);
890                                                 if(logging.equals("NO")){
891                                                         pw[1].println(" NOLOGGING;");
892                                                 } else {
893                                                         pw[1].println(";");
894                                                 }
895                                         } else {
896                                                 pw[1].println(strLine);
897                                                 CmnUtils.errorPrint(strSplit[0][5] + ",UNUSABLE INDEX");
898                                         }
899                                 }
900                                 while((strLine=br[2].readLine()) != null){
901                                         strSplit[0] = CmnUtils.splitSpace(strLine);
902                                         rowNo = CmnUtils.getArrayRowNo(alData, 12, 1, strSplit[0][5].replaceAll(cp.sqlQuoted,""));
903                                         if (rowNo != -1){
904                                                 rowData = rowData = CmnUtils.getArrayRowData(alData, 12, rowNo);
905                                                 CmnUtils.debugPrint(strSplit[0][5] + ":" + rowNo);
906                                                 for(int i=0;i<rowData.length;i++)CmnUtils.debugPrint(rowData[i]);
907                                                 tbName = rowData[0];
908                                                 objName = rowData[1];
909                                                 objTyp = rowData[2];
910                                                 pctFree = rowData[3];
911                                                 pctUsed = rowData[4];
912                                                 iniTrns = rowData[5];
913                                                 freeLst = rowData[6];
914                                                 flstGrp = rowData[7];
915                                                 bufPool = rowData[8];
916                                                 tblSpace = rowData[9];
917                                                 logging = rowData[10];
918                                                 segByts = rowData[11];
919                                                 pw[2].print(strLine.replace(';',' '));
920                                                 pw[2].print("USING INDEX PCTFREE " + pctFree);
921                                                 pw[2].print(" INITRANS " + iniTrns + " STORAGE(");
922                                                 if(!freeLst.equals(""))pw[2].print(" FREELISTS " + freeLst);
923                                                 if(!flstGrp.equals(""))pw[2].print(" FREELIST GROUPS " + flstGrp);
924                                                 pw[2].print(" BUFFER_POOL " + bufPool + ")");
925                                                 pw[2].print(" TABLESPACE " + cp.sqlQuoted + tblSpace + cp.sqlQuoted);
926                                                 if(logging.equals("NO")){
927                                                         pw[2].println(" NOLOGGING;");
928                                                 } else {
929                                                         pw[2].println(";");
930                                                 }
931                                         } else {
932                                                 pw[2].println(strLine);
933                                                 CmnUtils.errorPrint(strSplit[0][5] + ",UNUSABLE INDEX");
934                                         }
935                                 }
936                                 while((strLine=br[3].readLine()) != null){
937                                         strSplit[0] = CmnUtils.splitSpace(strLine);
938                                         rowNo = CmnUtils.getArrayRowNo(alData, 12, 1, strSplit[0][2].replaceAll(cp.sqlQuoted,""));
939                                         CmnUtils.debugPrint("rowNo=" + rowNo);
940                                         if (rowNo != -1){
941                                                 rowData = CmnUtils.getArrayRowData(alData, 12, rowNo);
942                                                 for(int i=0;i<rowData.length;i++)CmnUtils.debugPrint(rowData[i]);
943                                                 tbName = rowData[0];
944                                                 objName = rowData[1];
945                                                 objTyp = rowData[2];
946                                                 pctFree = rowData[3];
947                                                 pctUsed = rowData[4];
948                                                 iniTrns = rowData[5];
949                                                 freeLst = rowData[6];
950                                                 flstGrp = rowData[7];
951                                                 bufPool = rowData[8];
952                                                 tblSpace = rowData[9];
953                                                 logging = rowData[10];
954                                                 segByts = rowData[11];
955                                                 pw[3].print(strLine.replace(';',' '));
956                                                 pw[3].print("PCTFREE " + pctFree);
957                                                 pw[3].print(" INITRANS " + iniTrns + " STORAGE(");
958                                                 if(!freeLst.equals(""))pw[3].print(" FREELISTS " + freeLst);
959                                                 if(!flstGrp.equals(""))pw[3].print(" FREELIST GROUPS " + flstGrp);
960                                                 pw[3].print(" BUFFER_POOL " + bufPool + ")");
961                                                 pw[3].print(" TABLESPACE " + cp.sqlQuoted + tblSpace + cp.sqlQuoted);
962                                                 if(logging.equals("NO")){
963                                                         pw[3].println(" NOLOGGING;");
964                                                 } else {
965                                                         pw[3].println(";");
966                                                 }
967                                         } else {
968                                                 pw[3].println(strLine);
969                                                 CmnUtils.errorPrint(strSplit[0][2] + ",UNUSABLE INDEX");
970                                         }
971                                 }
972                                 for(int i=1;i<4;i++)pw[i].close();
973                                 for(int i=1;i<4;i++)pw[i]=null;
974                                 for(int i=0;i<4;i++)br[i].close();
975                                 for(int i=0;i<4;i++)br[i]=null;
976                                 
977                                 File [] fmFl = new File[6];
978                                 File [] toFl = new File[6];
979                                 
980                                 fmFl[0] = new File(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_PKEY] + ".phy");
981                                 fmFl[1] = new File(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_UKEY] + ".phy");
982                                 fmFl[2] = new File(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_INDEX] + ".phy");
983                                 toFl[0] = new File(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_PKEY]);
984                                 toFl[1] = new File(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_UKEY]);
985                                 toFl[2] = new File(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_INDEX]);
986                                 for(int i=0;i<3;i++){
987                                         CmnUtils.debugPrint(fmFl[i].toString() + ">" + toFl[i].toString());
988                                         toFl[i].delete();
989                                         fmFl[i].renameTo(toFl[i]);
990                                 }
991                                 
992                                 // physical table setting
993                                 File tbDir = new File(folder + "/TABLES");
994                                 File [] tbFiles = tbDir.listFiles();
995                                 File tb = null;
996                                 File oTb = null;
997                                 for(int i=0;i<tbFiles.length;i++){
998                                         tb = tbFiles[i];
999                                         tbName = tb.getName().replaceAll(".sql","");
1000                                         oTb = new File(tb + ".phy");
1001                                         CmnUtils.debugPrint(tbName);
1002                                         br[0] = new BufferedReader(new FileReader(tb));
1003                                         pw[0] = new PrintWriter(new BufferedWriter(new FileWriter(oTb)));
1004                                         while((strLine=br[0].readLine()) != null){
1005                                                 if(strLine.equals(");")){
1006                                                         rowNo = CmnUtils.getArrayRowNo(alData, 12, 1, tbName);
1007                                                         if (rowNo != -1){
1008                                                                 rowData = CmnUtils.getArrayRowData(alData, 12, rowNo);
1009                                                                 CmnUtils.debugPrint(tbName + ":" + rowNo);
1010                                                                 //for(int j=0;j<rowData.length;i++)CmnUtils.debugPrint(rowData[j]);
1011                                                                 tbName = rowData[0];
1012                                                                 objName = rowData[1];
1013                                                                 objTyp = rowData[2];
1014                                                                 pctFree = rowData[3];
1015                                                                 pctUsed = rowData[4];
1016                                                                 iniTrns = rowData[5];
1017                                                                 freeLst = rowData[6];
1018                                                                 flstGrp = rowData[7];
1019                                                                 bufPool = rowData[8];
1020                                                                 tblSpace = rowData[9];
1021                                                                 logging = rowData[10];
1022                                                                 segByts = rowData[11];
1023                                                                 pw[0].print(") PCTFREE " + pctFree);
1024                                                                 if(!pctUsed.equals(""))pw[0].print(" PCTUSED " + pctUsed);
1025                                                                 pw[0].print(" INITRANS " + iniTrns + " STORAGE(");
1026                                                                 if(!freeLst.equals(""))pw[0].print(" FREELISTS " + freeLst);
1027                                                                 if(!flstGrp.equals(""))pw[0].print(" FREELIST GROUPS " + flstGrp);
1028                                                                 pw[0].print(" BUFFER_POOL " + bufPool + ")");
1029                                                                 pw[0].print(" TABLESPACE " + cp.sqlQuoted + tblSpace + cp.sqlQuoted);
1030                                                                 if(logging.equals("NO")){
1031                                                                         pw[0].println(" NOLOGGING;");
1032                                                                 } else {
1033                                                                         pw[0].println(";");
1034                                                                 }
1035                                                         } else {
1036                                                                 pw[0].println(");");
1037                                                         }
1038                                                 } else {
1039                                                         pw[0].println(strLine);
1040                                                 }
1041                                         }
1042                                         pw[0].close();
1043                                         pw[0]=null;
1044                                         br[0].close();
1045                                         br[0]=null;
1046                                         tb.delete();
1047                                         oTb.renameTo(tb);
1048                                 }
1049                         }
1050                         // Rhysical Contents end
1051
1052                         // Remove work file
1053                         File fl= null;
1054                         for(int i=0;i<sql[cp.dbType].length;i++){
1055                                 fl= new File(folder + "/" + FILE_NAME[i] + "_" + database + "." + cp.fileExtension);
1056                                 CmnUtils.debugPrint(fl.toString());
1057                                 fl.delete();
1058                         }
1059
1060                         // disconnect database
1061                         dao.disconnect();
1062                         CmnUtils.infoPrint("\83\81\83^\83f\81[\83^\83A\83\93\83\8d\81[\83h\82ð\8fI\97¹\82µ\82Ü\82µ\82½\81B");
1063
1064                 } catch(SQLException se) {
1065                         try{
1066                                 CmnUtils.errorPrint(se.toString());
1067                                 se.printStackTrace();
1068                                 se = se.getNextException();
1069                                 if(se != null) {
1070                                         System.out.println(se.getMessage());
1071                                 }
1072                                 dao.rollback();
1073                         } catch (Exception see) {}
1074                 } catch (Exception e) {                 
1075                         try{
1076                                 CmnUtils.errorPrint(e.toString());
1077                                 e.printStackTrace();
1078                                 dao.rollback();
1079                         } catch (Exception ee) {}
1080                 } finally{
1081                         try{
1082                                 for(int i=0;i<6;i++){
1083                                         if(pw[i]!=null){
1084                                                 pw[i].close();
1085                                                 pw[i]=null;
1086                                         }
1087                                 }
1088                                 for(int i=0;i<4;i++){
1089                                         if(br[i]!=null){
1090                                                 br[i].close();
1091                                                 br[i]=null;
1092                                         }
1093                                 }
1094                         } catch (Exception e) {}
1095                 }
1096         }
1097         
1098
1099 }
1100