OSDN Git Service

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