--- /dev/null
+package com.rapide_act;
+
+import java.io.BufferedInputStream;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.BufferedWriter;
+import java.io.BufferedReader;
+import java.io.PrintWriter;
+import java.io.PrintWriter;
+import java.util.Date;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.Properties;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
+import java.sql.PreparedStatement;
+import java.sql.Timestamp;
+import java.sql.Blob;
+import java.sql.Clob;
+
+public class RapideMetaLoader{
+
+ private String database = null;
+
+ public static void main(String args[]){
+ try {
+ if (args.length > 0){
+ RapideMetaLoader RapideMetaLoader = new RapideMetaLoader(args[0]);
+ RapideMetaLoader.metaLoad();
+ } else {
+ RapideMetaLoader RapideMetaLoader = new RapideMetaLoader(null);
+ RapideMetaLoader.metaLoad();
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ RapideMetaLoader(String _database) {
+ super();
+ database = _database;
+ }
+
+
+ private void metaLoad(){
+ Connection conn = null;
+ PreparedStatement stmt = null;
+ BufferedReader br = null;
+ File folder = null;
+ File subFolder = null;
+ String strLine = null;
+ String strMltLine = null;
+ String tbName = null;
+ String viewName = null;
+ String procName = null;
+ String [] flName = null;
+ File [] inFiles = null;
+ int tb_count = 0;
+ String [] sqlLine = null;
+
+ CmnProperty cp = null;
+ DataAccessObjects dao = null;
+
+ try {
+ cp = new CmnProperty();
+ cp.setProperty(database);
+
+ if (cp.dbType != cp.DB_TYPE_ORACLE){
+ throw new Exception("\83f\81[\83^\83x\81[\83X\82ª\91Î\8fÛ\8aO\82Å\82·\81B[" + cp.DB_TYPE_NAME[cp.dbType] + "]");
+ }
+ if(cp.inFolder != null){
+ folder = new File(cp.inFolder);
+ } else {
+ if (database != null){
+ folder = new File(cp.DEFAULT_IN_FOLDER + "/DDL_" + database.toUpperCase());
+ } else {
+ folder = new File(cp.DEFAULT_IN_FOLDER + "/DDL_" + cp.DB_TYPE_NAME[cp.dbType].toUpperCase());
+ }
+ }
+ CmnUtils.infoPrint("-->\93ü\97Í\8c³\83t\83H\83\8b\83_='" + folder + "'");
+ CmnUtils.infoPrint("\83\81\83^\83f\81[\83^\83\8d\81[\83h\82ð\8aJ\8en\82µ\82Ü\82µ\82½\81B");
+
+ // Connect
+ dao = new DataAccessObjects(cp);
+ conn = dao.connect();
+
+ if(cp.isDrop){
+ executeSqlFile(dao, stmt, folder + "/" + cp.SQL_FILE_NAME[cp.DROP_TABLE], cp, true);
+ executeSqlFile(dao, stmt, folder + "/" + cp.SQL_FILE_NAME[cp.DROP_VIEW], cp, true);
+ executeSqlFile(dao, stmt, folder + "/" + cp.SQL_FILE_NAME[cp.DROP_PROCEDURE], cp, true);
+ executeSqlFile(dao, stmt, folder + "/" + cp.SQL_FILE_NAME[cp.DROP_SYNONYM], cp, true);
+ executeSqlFile(dao, stmt, folder + "/" + cp.SQL_FILE_NAME[cp.DROP_SEQUENCE], cp, true);
+ executeSqlFile(dao, stmt, folder + "/" + cp.SQL_FILE_NAME[cp.DROP_FK], cp, true);
+ }
+ subFolder = new File(folder + "/TABLES");
+ inFiles = subFolder.listFiles();
+ tb_count = 0;
+ if(inFiles != null) {
+ for(int k=0;k<inFiles.length;k++){
+ flName = CmnUtils.splitDot(inFiles[k].getName());
+ tbName = flName[0];
+ executeSqlFile(dao, stmt, subFolder + "/" + inFiles[k].getName(), cp, false);
+ }
+ }
+ executeSqlFile(dao, stmt, folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_PKEY], cp, false);
+ executeSqlFile(dao, stmt, folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_UKEY], cp, false);
+ executeSqlFile(dao, stmt, folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_INDEX], cp, false);
+ subFolder = new File(folder + "/VIEWS");
+ inFiles = subFolder.listFiles();
+ int view_count = 0;
+ if(inFiles != null) {
+ for(int k=0;k<inFiles.length;k++){
+ flName = CmnUtils.splitDot(inFiles[k].getName());
+ viewName = flName[0];
+ executeSqlFile(dao, stmt, subFolder + "/" + inFiles[k].getName(), cp, false);
+ }
+ }
+ subFolder = new File(folder + "/PROCEDURES");
+ inFiles = subFolder.listFiles();
+ int proc_count = 0;
+ if(inFiles != null) {
+ for(int k=0;k<inFiles.length;k++){
+ flName = CmnUtils.splitDot(inFiles[k].getName());
+ procName = flName[0];
+ executeSqlFile(dao, stmt, subFolder + "/" + inFiles[k].getName(), cp, false);
+ }
+ }
+ executeSqlFile(dao, stmt, folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_SEQUENCE], cp, false);
+ executeSqlFile(dao, stmt, folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_FK], cp, false);
+
+ CmnUtils.infoPrint("\83\81\83^\83f\81[\83^\83\8d\81[\83h\82ð\8fI\97¹\82µ\82Ü\82µ\82½\81B");
+
+ } catch(SQLException se) {
+ try{
+ CmnUtils.errorPrint(se.toString());
+ se.printStackTrace();
+ se = se.getNextException();
+ if(se != null) {
+ System.out.println(se.getMessage());
+ }
+ dao.rollback();
+ } catch (Exception see) {}
+ } catch (Exception e) {
+ try{
+ CmnUtils.errorPrint(e.toString());
+ e.printStackTrace();
+ dao.rollback();
+ } catch (Exception ee) {}
+ } finally{
+ try{
+ dao.disconnect();
+ if(stmt != null){
+ stmt.close();
+ stmt=null;
+ }
+ if(br!=null){
+ br.close();
+ br=null;
+ }
+ } catch (Exception e) {}
+ }
+ }
+
+ private void executeSqlFile(DataAccessObjects _dao, PreparedStatement _stmt, String _infile, CmnProperty _cp, boolean _isResume) throws Exception{
+ BufferedReader br = null;
+ String strLine = null;
+ String strMltLine = "";
+ String [] sqlLine = null;
+
+ File infile = new File(_infile);
+ if (infile.exists()){
+ br = new BufferedReader(new InputStreamReader(new FileInputStream(_infile), _cp.fileEncoding));
+ while((strLine=br.readLine()) != null){
+ strMltLine += _cp.inColLineSeparator + strLine;
+ }
+ sqlLine = CmnUtils.split(strMltLine, ";");
+ for(int l = 0;l<sqlLine.length;l++){
+ if(!sqlLine[l].equals("")){
+ try {
+ _stmt = _dao.prepareSql(sqlLine[l]);
+ _stmt.executeUpdate();
+ if(_stmt != null){
+ _stmt.close();
+ _stmt=null;
+ }
+ } catch (Exception e) {
+ if(!_isResume){
+ throw e;
+ }
+ }
+ }
+ }
+ }
+ }
+
+}
+
import java.sql.Clob;
public class RapideMetaUnloader{
- protected static final int FL_TABLE = 0;
- protected static final int FL_INDEX = 1;
- protected static final int FL_VIEW = 2;
- protected static final int FL_PROCEDURE = 3;
- protected static final int FL_SEQ = 4;
- protected static final int FL_SYNONYM = 5;
- protected static final int FL_DBLINK = 6;
- protected static final int FL_OBJPRIVS = 7;
- protected static final int FL_SYSPRIVS = 8;
- protected static final int FL_ROLEPRIVS = 9;
- protected static final int FL_OBJ = 10;
- protected static final int FL_FK = 11;
- protected static final String [] FILE_NAME = {
+
+ private static final int FL_TABLE = 0;
+ private static final int FL_INDEX = 1;
+ private static final int FL_VIEW = 2;
+ private static final int FL_PROCEDURE = 3;
+ private static final int FL_SEQ = 4;
+ private static final int FL_SYNONYM = 5;
+ private static final int FL_OBJ = 6;
+ private static final int FL_FK = 7;
+ private static final String [] FILE_NAME = {
"TABLEDEF",
"INDEXDEF",
"VIEWDEF",
"PROCDEF",
"SEQDEF",
"SYNMDEF",
- "DBLNKDEF",
- "OBJPRVDEF",
- "SYSPRVDEF",
- "ROLPRVDEF",
"OBJDEF",
"FKDEF"
};
+ " from user_sequences "
+ " order by sequence_name",
"select "
- + " owner,"
+ " synonym_name,"
+ " table_owner,"
+ " table_name,"
+ " db_link "
- + "from all_synonyms "
- + "order by owner,synonym_name,table_name",
- "select "
- + " db_link,"
- + " username,"
- + " password,"
- + " host,"
- + " created "
- + "from user_db_links "
- + "order by db_link",
- "select "
- + " grantee,"
- + " owner,"
- + " table_name,"
- + " grantor,"
- + " privilege,"
- + " grantable,"
- + " hierarchy "
- + "from user_tab_privs "
- + "order by grantee,owner,table_name,grantor,privilege",
- "select "
- + " username,"
- + " privilege "
- + "from user_sys_privs "
- + "order by username,privilege",
- "select "
- + " username,"
- + " granted_role "
- + "from user_role_privs "
- + "order by username,granted_role",
+ + "from user_synonyms "
+ + "order by synonym_name,table_owner,table_name",
"select "
+ " a.table_name,"
+ " a.object_name,"
br[0] = new BufferedReader(new FileReader(folder + "/" + FILE_NAME[FL_TABLE] + "_" + database +".csv"));
subFolder = new File(folder + "/TABLES");
subFolder.mkdir();
- pw[1] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + "createTable.sql"))));
- pw[2] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + "dropTable.sql"))));
- pw[3] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + "truncateTable.sql"))));
+ pw[1] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_TABLE]))));
+ pw[2] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + cp.SQL_FILE_NAME[cp.DROP_TABLE]))));
+ pw[3] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + cp.SQL_FILE_NAME[cp.TRUNCATE_TABLE]))));
tableName = "";
tableCmnt = "";
if(!strLine.equals("")){
strSplit = CmnUtils.splitCsv(strLine);
if (!tableName.equals("")){
- sbTbCnts.append(" " + colName);
+ sbTbCnts.append(" " + cp.sqlQuoted + colName + cp.sqlQuoted);
sbTbCnts.append(" " + colType);
- if(!colCmnt.equals(""))sbTbCmnt.append("COMMENT ON COLUMN " + tableName + "." + colName + " IS '" + colCmnt + "';");
+ if(!colCmnt.equals(""))sbTbCmnt.append("COMMENT ON COLUMN " + cp.sqlQuoted + tableName + cp.sqlQuoted + "." + cp.sqlQuoted + colName + cp.sqlQuoted + " IS '" + colCmnt + "';");
if(!colCmnt.equals(""))sbTbCmnt.append(cp.lineSeparator);
if (!colType.equals("BLOB") && !colType.equals("CLOB") && !colType.equals("TIMESTAMP") && !colType.equals("DATE") && !colType.equals("LONG") && !colType.equals("LONG RAW")){
if (!colLen.equals(""))sbTbCnts.append("(" + colLen);
if (colNoN.equals("\81\9b"))sbTbCnts.append(" NOT NULL");
if (!strSplit[0].equals(tableName)){
pw[1].println("@TABLES/" + tableName + ".sql");
- pw[2].println("DROP TABLE " + tableName + " PURGE;");
- pw[3].println("TRUNCATE TABLE " + tableName + ";");
+ pw[2].println("DROP TABLE " + cp.sqlQuoted + tableName + cp.sqlQuoted + " PURGE;");
+ pw[3].println("TRUNCATE TABLE " + cp.sqlQuoted + tableName + cp.sqlQuoted + ";");
sbTbCnts.append(cp.lineSeparator);
sbTbCnts.append(");");
sbTbCnts.append(cp.lineSeparator);
pw[0] = null;
sbTbCnts = new StringBuffer();
sbTbCmnt = new StringBuffer();
- sbTbCnts.append("CREATE TABLE " + strSplit[0]);
+ sbTbCnts.append("CREATE TABLE " + cp.sqlQuoted + strSplit[0] + cp.sqlQuoted);
sbTbCnts.append(cp.lineSeparator);
sbTbCnts.append("(");
sbTbCnts.append(cp.lineSeparator);
- if(!strSplit[1].equals(""))sbTbCmnt.append("COMMENT ON TABLE " + strSplit[0] + " IS '" + strSplit[1] +"';");
+ if(!strSplit[1].equals(""))sbTbCmnt.append("COMMENT ON TABLE " + cp.sqlQuoted + strSplit[0] + cp.sqlQuoted + " IS '" + strSplit[1] +"';");
if(!strSplit[1].equals(""))sbTbCmnt.append(cp.lineSeparator);
} else {
sbTbCnts.append(",");
}
}
else {
- sbTbCnts.append("CREATE TABLE " + strSplit[0]);
+ sbTbCnts.append("CREATE TABLE " + cp.sqlQuoted + strSplit[0] + cp.sqlQuoted);
sbTbCnts.append(cp.lineSeparator);
sbTbCnts.append("(");
sbTbCnts.append(cp.lineSeparator);
- if(!strSplit[1].equals(""))sbTbCmnt.append("COMMENT ON TABLE " + strSplit[0] + " IS '" + strSplit[1] +"';");
+ if(!strSplit[1].equals(""))sbTbCmnt.append("COMMENT ON TABLE " + cp.sqlQuoted + strSplit[0] + cp.sqlQuoted + " IS '" + strSplit[1] +"';");
if(!strSplit[1].equals(""))sbTbCmnt.append(cp.lineSeparator);
}
for(int i=0;i<strSplit.length;i++)CmnUtils.debugPrint("'" + strSplit[i] + "'");
}
if (!tableName.equals("")){
- sbTbCnts.append(" " + colName);
+ sbTbCnts.append(" " + cp.sqlQuoted + colName + cp.sqlQuoted);
sbTbCnts.append(" " + colType);
- if(!colCmnt.equals(""))sbTbCmnt.append("COMMENT ON COLUMN " + tableName + "." + colName + " IS '" + colCmnt + "';");
+ if(!colCmnt.equals(""))sbTbCmnt.append("COMMENT ON COLUMN " + cp.sqlQuoted + tableName + cp.sqlQuoted + "." + cp.sqlQuoted + colName + cp.sqlQuoted + " IS '" + colCmnt + "';");
if(!colCmnt.equals(""))sbTbCmnt.append(cp.lineSeparator);
if (!colType.equals("BLOB") && !colType.equals("TIMESTAMP") && !colType.equals("DATE") && !colType.equals("LONG") && !colType.equals("LONG RAW")){
if (!colLen.equals(""))sbTbCnts.append("(" + colLen);
if (!colDflt.equals(""))sbTbCnts.append(" DEFAULT " + colDflt.trim());
if (colNoN.equals("\81\9b"))sbTbCnts.append(" NOT NULL");
pw[1].println("@TABLES/" + tableName + ".sql");
- pw[2].println("DROP TABLE " + tableName + " PURGE;");
- pw[3].println("TRUNCATE TABLE " + tableName + ";");
+ pw[2].println("DROP TABLE " + cp.sqlQuoted + tableName + cp.sqlQuoted + " PURGE;");
+ pw[3].println("TRUNCATE TABLE " + cp.sqlQuoted + tableName + cp.sqlQuoted + ";");
sbTbCnts.append(cp.lineSeparator);
sbTbCnts.append(");");
sbTbCnts.append(cp.lineSeparator);
// Index Contents start
br[0] = new BufferedReader(new FileReader(folder + "/" + FILE_NAME[FL_INDEX] + "_" + database +".csv"));
- pw[0] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + "createPrimaryKey.sql"))));
- pw[1] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + "createUniqueKey.sql"))));
- pw[2] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + "createIndex.sql"))));
- pw[3] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + "dropPrimaryKey.sql"))));
- pw[4] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + "dropUniqueKey.sql"))));
- pw[5] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + "dropIndex.sql"))));
+ pw[0] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_PKEY]))));
+ pw[1] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_UKEY]))));
+ pw[2] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_INDEX]))));
+ pw[3] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + cp.SQL_FILE_NAME[cp.DROP_PKEY]))));
+ pw[4] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + cp.SQL_FILE_NAME[cp.DROP_UKEY]))));
+ pw[5] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + cp.SQL_FILE_NAME[cp.DROP_INDEX]))));
//Initial Process
tableName = "";
if (!strSplit[1].equals(indexName)){
//Post Process
if (colPos.equals("1")){
- sbIxCnts.append(colName);
- if (constraintType.equals("U"))sbIx2Cnts.append(colName);
+ sbIxCnts.append(cp.sqlQuoted + colName + cp.sqlQuoted);
+ if (constraintType.equals("U"))sbIx2Cnts.append(cp.sqlQuoted + colName + cp.sqlQuoted);
} else {
- sbIxCnts.append(", " + colName);
- if (constraintType.equals("U"))sbIx2Cnts.append(", " + colName);
+ sbIxCnts.append(", " + cp.sqlQuoted + colName + cp.sqlQuoted);
+ if (constraintType.equals("U"))sbIx2Cnts.append(", " + cp.sqlQuoted + colName + cp.sqlQuoted);
}
sbIxCnts.append(");");
sbIxCnts.append(cp.lineSeparator);
//Index Changed Process
if (strSplit[3].equals("P")){
- sbIxCnts.append("ALTER TABLE " + strSplit[0] + " ADD CONSTRAINT " + strSplit[1] + " PRIMARY KEY(");
- sbIx2Cnts.append("ALTER TABLE " + strSplit[0] + " DROP CONSTRAINT " + strSplit[1] + ";");
+ sbIxCnts.append("ALTER TABLE " + cp.sqlQuoted + strSplit[0] + cp.sqlQuoted + " ADD CONSTRAINT " + cp.sqlQuoted + strSplit[1] + cp.sqlQuoted + " PRIMARY KEY(");
+ sbIx2Cnts.append("ALTER TABLE " + cp.sqlQuoted + strSplit[0] + cp.sqlQuoted + " DROP CONSTRAINT " + cp.sqlQuoted + strSplit[1] + cp.sqlQuoted + ";");
} else if (strSplit[3].equals("U")){
- sbIxCnts.append("ALTER TABLE " + strSplit[0] + " ADD CONSTRAINT " + strSplit[1] + " UNIQUE(");
- sbIx2Cnts.append("ALTER TABLE " + strSplit[0] + " DROP UNIQUE(");
+ sbIxCnts.append("ALTER TABLE " + cp.sqlQuoted + strSplit[0] + cp.sqlQuoted + " ADD CONSTRAINT " + cp.sqlQuoted + strSplit[1] + cp.sqlQuoted + " UNIQUE(");
+ sbIx2Cnts.append("ALTER TABLE " + cp.sqlQuoted + strSplit[0] + cp.sqlQuoted + " DROP UNIQUE(");
} else if (strSplit[3].equals("")){
- sbIxCnts.append("CREATE INDEX " + strSplit[1] + " ON " + strSplit[0] + "(");
+ sbIxCnts.append("CREATE INDEX " + cp.sqlQuoted + strSplit[1] + cp.sqlQuoted + " ON " + strSplit[0] + "(");
}
- sbIx3Cnts.append("DROP INDEX " + strSplit[1] + ";");
+ sbIx3Cnts.append("DROP INDEX " + cp.sqlQuoted + strSplit[1] + cp.sqlQuoted + ";");
} else if (strSplit[1].equals(indexName)){
if (colPos.equals("1")){
- sbIxCnts.append(colName);
- if (constraintType.equals("U"))sbIx2Cnts.append(colName);
+ sbIxCnts.append(cp.sqlQuoted + colName + cp.sqlQuoted);
+ if (constraintType.equals("U"))sbIx2Cnts.append(cp.sqlQuoted + colName + cp.sqlQuoted);
} else {
- sbIxCnts.append(", " + colName);
- if (constraintType.equals("U"))sbIx2Cnts.append(", " + colName);
+ sbIxCnts.append(", " + cp.sqlQuoted + colName + cp.sqlQuoted);
+ if (constraintType.equals("U"))sbIx2Cnts.append(", " + cp.sqlQuoted + colName + cp.sqlQuoted);
}
}
}
//1st Line Process
else {
if (strSplit[3].equals("P")){
- sbIxCnts.append("ALTER TABLE " + strSplit[0] + " ADD CONSTRAINT " + strSplit[1] + " PRIMARY KEY(");
- sbIx2Cnts.append("ALTER TABLE " + strSplit[0] + " DROP CONSTRAINT " + strSplit[1] + ";");
+ sbIxCnts.append("ALTER TABLE " + cp.sqlQuoted + strSplit[0] + cp.sqlQuoted + " ADD CONSTRAINT " + cp.sqlQuoted + strSplit[1] + cp.sqlQuoted + " PRIMARY KEY(");
+ sbIx2Cnts.append("ALTER TABLE " + cp.sqlQuoted + strSplit[0] + cp.sqlQuoted + " DROP CONSTRAINT " + cp.sqlQuoted + strSplit[1] + cp.sqlQuoted + ";");
} else if (strSplit[3].equals("U")){
- sbIxCnts.append("ALTER TABLE " + strSplit[0] + " ADD CONSTRAINT " + strSplit[1] + " UNIQUE(");
- sbIx2Cnts.append("ALTER TABLE " + strSplit[0] + " DROP UNIQUE(");
+ sbIxCnts.append("ALTER TABLE " + cp.sqlQuoted + strSplit[0] + cp.sqlQuoted + " ADD CONSTRAINT " + cp.sqlQuoted + strSplit[1] + cp.sqlQuoted + " UNIQUE(");
+ sbIx2Cnts.append("ALTER TABLE " + cp.sqlQuoted + strSplit[0] + cp.sqlQuoted + " DROP UNIQUE(");
} else if (strSplit[3].equals("")){
- sbIxCnts.append("CREATE INDEX " + strSplit[1] + " ON " + strSplit[0] + "(");
+ sbIxCnts.append("CREATE INDEX " + cp.sqlQuoted + strSplit[1] + cp.sqlQuoted + " ON " + cp.sqlQuoted + strSplit[0] + cp.sqlQuoted + "(");
}
- sbIx3Cnts.append("DROP INDEX " + strSplit[1] + ";");
+ sbIx3Cnts.append("DROP INDEX " + cp.sqlQuoted + strSplit[1] + cp.sqlQuoted + ";");
}
for(int i=0;i<strSplit.length;i++)CmnUtils.debugPrint("'" + strSplit[i] + "'");
if (!indexName.equals("")){
//Post Process
if (colPos.equals("1")){
- sbIxCnts.append(colName);
- if (constraintType.equals("U"))sbIx2Cnts.append(colName);
+ sbIxCnts.append(cp.sqlQuoted + colName + cp.sqlQuoted);
+ if (constraintType.equals("U"))sbIx2Cnts.append(cp.sqlQuoted + colName + cp.sqlQuoted);
} else {
- sbIxCnts.append(", " + colName);
- if (constraintType.equals("U"))sbIx2Cnts.append(", " + colName);
+ sbIxCnts.append(", " + cp.sqlQuoted + colName + cp.sqlQuoted);
+ if (constraintType.equals("U"))sbIx2Cnts.append(", " + cp.sqlQuoted + colName + cp.sqlQuoted);
}
sbIxCnts.append(");");
sbIxCnts.append(cp.lineSeparator);
br[0] = new BufferedReader(new FileReader(folder + "/" + FILE_NAME[FL_VIEW] + "_" + database +".csv"));
subFolder = new File(folder + "/VIEWS");
subFolder.mkdir();
- pw[1] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + "createView.sql"))));
- pw[2] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + "dropView.sql"))));
+ pw[1] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_VIEW]))));
+ pw[2] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + cp.SQL_FILE_NAME[cp.DROP_VIEW]))));
while((strLine=br[0].readLine()) != null){
strSplit = CmnUtils.splitCsv(strLine);
CmnUtils.debugPrint("'" + strSplit[0] + "'");
strSplit2 = CmnUtils.splitCrLf(strContents);
for(int i=0;i<strSplit2.length;i++)if(!strSplit2[i].trim().equals(""))pw[0].println(strSplit2[i]);
pw[0].println(";");
- if (!strSplit[1].equals(""))pw[0].println("COMMENT ON TABLE " + strSplit[0] + " IS '" + strSplit[1] + "';");
+ if (!strSplit[1].equals(""))pw[0].println("COMMENT ON TABLE " + cp.sqlQuoted + strSplit[0] + cp.sqlQuoted + " IS '" + strSplit[1] + "';");
for(int i=0;i<alData.size();i++){
if ((i+1) % columnCount == 0){
- if (!alData.get(i).equals(""))pw[0].println("COMMENT ON COLUMN " + strSplit[0] + "." + alData.get(i-1) + " IS '" + alData.get(i) + "';");
+ if (!alData.get(i).equals(""))pw[0].println("COMMENT ON COLUMN " + cp.sqlQuoted + strSplit[0] + cp.sqlQuoted + "." + alData.get(i-1) + " IS '" + alData.get(i) + "';");
}
}
pw[0].close();
br[0] = new BufferedReader(new FileReader(folder + "/" + FILE_NAME[FL_PROCEDURE] + "_" + database +".csv"));
subFolder = new File(folder + "/PROCEDURES");
subFolder.mkdir();
- pw[1] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + "createProcedure.sql"))));
- pw[2] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + "dropProcedure.sql"))));
+ pw[1] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_PROCEDURE]))));
+ pw[2] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + cp.SQL_FILE_NAME[cp.DROP_PROCEDURE]))));
while((strLine=br[0].readLine()) != null){
strSplit = CmnUtils.splitCsv(strLine);
CmnUtils.debugPrint("'" + strSplit[0] + "'");
// Sequence Contents start
br[0] = new BufferedReader(new FileReader(folder + "/" + FILE_NAME[FL_SEQ] + "_" + database +".csv"));
- pw[1] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + "createSequence.sql"))));
- pw[2] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + "dropSequence.sql"))));
+ pw[1] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_SEQUENCE]))));
+ pw[2] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + cp.SQL_FILE_NAME[cp.DROP_SEQUENCE]))));
while((strLine=br[0].readLine()) != null){
strSplit = CmnUtils.splitCsv(strLine);
odFg = strSplit[5];
cacheSz = strSplit[6];
lstNo = strSplit[7];
- pw[1].print("CREATE SEQUENCE \"" + seqName + "\" MINVALUE " + minVal + " MAXVALUE " + maxVal + " INCREMENT BY " + incSz + " START WITH " + lstNo + " CACHE " + cacheSz);
+ pw[1].print("CREATE SEQUENCE \"" + cp.sqlQuoted + seqName + cp.sqlQuoted + "\" MINVALUE " + minVal + " MAXVALUE " + maxVal + " INCREMENT BY " + incSz + " START WITH " + lstNo + " CACHE " + cacheSz);
if (odFg.equals("N")){
pw[1].print(" NOORDER");
} else {
pw[1].print(" CYCLE");
}
pw[1].println(";");
- pw[2].println("DROP SEQUENCE \"" + seqName + "\";");
+ pw[2].println("DROP SEQUENCE \"" + cp.sqlQuoted + seqName + cp.sqlQuoted + "\";");
for(int i=0;i<strSplit.length;i++)CmnUtils.debugPrint("'" + strSplit[i] + "'");
}
for(int i=1;i<3;i++)pw[i].close();
// Synonym Contents start
br[0] = new BufferedReader(new FileReader(folder + "/" + FILE_NAME[FL_SYNONYM] + "_" + database +".csv"));
- pw[1] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + "createSynonym.sql"))));
- pw[2] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + "dropSynonym.sql"))));
+ pw[1] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_SYNONYM]))));
+ pw[2] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + cp.SQL_FILE_NAME[cp.DROP_SYNONYM]))));
while((strLine=br[0].readLine()) != null){
strSplit = CmnUtils.splitCsv(strLine);
- synmOwner = strSplit[0];
- synmName = strSplit[1];
- tbOwner = strSplit[2];
- tbName = strSplit[3];
- dbLnk = strSplit[4];
+ synmName = strSplit[0];
+ tbOwner = strSplit[1];
+ tbName = strSplit[2];
+ dbLnk = strSplit[3];
- pw[1].print("CREATE SYNONYM \"" + synmOwner + "\"." + "\"" + synmName + "\" FOR ");
+ pw[1].print("CREATE SYNONYM " + cp.sqlQuoted + synmName + cp.sqlQuoted + " FOR ");
if(dbLnk.equals("")){
- pw[1].print(tbOwner + "." + tbName);
+ pw[1].print(cp.sqlQuoted + tbOwner + cp.sqlQuoted + "." + cp.sqlQuoted + tbName + cp.sqlQuoted );
} else {
- pw[1].print(tbName + "@" + dbLnk);
+ pw[1].print(cp.sqlQuoted + tbName + cp.sqlQuoted + "@" + cp.sqlQuoted + dbLnk + cp.sqlQuoted );
}
pw[1].println(";");
- pw[2].println("DROP SYNONYM \"" + synmOwner + "\"." + "\"" + synmName + "\";");
+ pw[2].println("DROP SYNONYM " + cp.sqlQuoted + synmName + cp.sqlQuoted + ";");
for(int i=0;i<strSplit.length;i++)CmnUtils.debugPrint("'" + strSplit[i] + "'");
}
for(int i=1;i<3;i++)pw[i].close();
br[0] = null;
// Synonym Contents end
- // DBlink Contents start
- br[0] = new BufferedReader(new FileReader(folder + "/" + FILE_NAME[FL_DBLINK] + "_" + database +".csv"));
- pw[1] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + "createDBLinks.sql"))));
- pw[2] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + "dropDBLinks.sql"))));
-
- while((strLine=br[0].readLine()) != null){
- strSplit = CmnUtils.splitCsv(strLine);
- dbLnk = strSplit[0];
- userName = strSplit[1];
- passWord = strSplit[2];
- host = strSplit[3];
- created = strSplit[4];
- if(passWord.equals(""))passWord = userName;
- pw[1].println("CREATE DATABASE LINK " + dbLnk + " CONNECT TO " + passWord + " IDENTIFIED BY " + userName + " USING '" + host + "';");
- pw[2].println("DROP DATABASE LINK " + dbLnk + ";");
- for(int i=0;i<strSplit.length;i++)CmnUtils.debugPrint("'" + strSplit[i] + "'");
- }
- for(int i=1;i<3;i++)pw[i].close();
- for(int i=1;i<3;i++)pw[i]=null;
- br[0].close();
- br[0] = null;
- // DBlink Contents end
-
- // objPrivs Contents start
- br[0] = new BufferedReader(new FileReader(folder + "/" + FILE_NAME[FL_OBJPRIVS] + "_" + database +".csv"));
- pw[1] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + "grantObjPrivs.sql"))));
- pw[2] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + "revokeObjPrivs.sql"))));
-
- while((strLine=br[0].readLine()) != null){
- strSplit = CmnUtils.splitCsv(strLine);
- grntee = strSplit[0];
- tbOwner = strSplit[1];
- tbName = strSplit[2];
- grntor = strSplit[3];
- prvs = strSplit[4];
- grntabl = strSplit[5];
- hrchy = strSplit[6];
- pw[1].println("GRANT " + prvs + " ON " + tbOwner + "." + tbName + " TO " + grntee + ";");
- pw[2].println("REVOKE " + prvs + " ON " + tbOwner + "." + tbName + " FROM " + grntee + ";");
- for(int i=0;i<strSplit.length;i++)CmnUtils.debugPrint("'" + strSplit[i] + "'");
- }
- for(int i=1;i<3;i++)pw[i].close();
- for(int i=1;i<3;i++)pw[i]=null;
- br[0].close();
- br[0] = null;
- // objPrivs Contents end
-
- // sysPrivs Contents start
- br[0] = new BufferedReader(new FileReader(folder + "/" + FILE_NAME[FL_SYSPRIVS] + "_" + database +".csv"));
- pw[1] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + "grantSysPrivs.sql"))));
- pw[2] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + "revokeSysPrivs.sql"))));
-
- while((strLine=br[0].readLine()) != null){
- strSplit = CmnUtils.splitCsv(strLine);
- grntee = strSplit[0];
- prvs = strSplit[1];
- pw[1].println("GRANT " + prvs + " TO " + grntee + ";");
- pw[2].println("REVOKE " + prvs + " FROM " + grntee + ";");
- for(int i=0;i<strSplit.length;i++)CmnUtils.debugPrint("'" + strSplit[i] + "'");
- }
- pw[1].close();
- pw[1] = null;
- pw[2].close();
- pw[2] = null;
- br[0].close();
- br[0] = null;
- // sysPrivs Contents end
-
- // RolePrivs Contents start
- br[0] = new BufferedReader(new FileReader(folder + "/" + FILE_NAME[FL_ROLEPRIVS] + "_" + database +".csv"));
- pw[1] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + "grantRolePrivs.sql"))));
- pw[2] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + "revokeRolePrivs.sql"))));
-
- while((strLine=br[0].readLine()) != null){
- strSplit = CmnUtils.splitCsv(strLine);
- grntee = strSplit[0];
- grntrl = strSplit[1];
- pw[1].println("GRANT " + grntrl + " TO " + grntee + ";");
- pw[2].println("REVOKE " + grntrl + " FROM " + grntee + ";");
- for(int i=0;i<strSplit.length;i++)CmnUtils.debugPrint("'" + strSplit[i] + "'");
+ // Fk Contents start
+ File csvFile = new File(folder + "/" + FILE_NAME[FL_FK] + "_" + database +".csv");
+ if (csvFile.length() > 0) {
+ br[0] = new BufferedReader(new FileReader(folder + "/" + FILE_NAME[FL_FK] + "_" + database +".csv"));
+ pw[1] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_FK]))));
+ pw[2] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + cp.SQL_FILE_NAME[cp.DROP_FK]))));
+ tbName = "";
+ fkName = "";
+ fkCol = "";
+ fkColPos = "";
+ rtbName = "";
+ rfkName = "";
+ rfkCol = "";
+ rfkColPos = "";
+
+ while((strLine=br[0].readLine()) != null){
+ strSplit = CmnUtils.splitCsv(strLine);
+ if(!fkName.equals(strSplit[1]) && !fkName.equals("")){
+ pw[1].println("ALTER TABLE " + cp.sqlQuoted + tbName + cp.sqlQuoted + " ADD CONSTRAINT " + cp.sqlQuoted + fkName + " FOREIGN KEY (" + cp.sqlQuoted + fkCol + cp.sqlQuoted + ") REFERENCES " + cp.sqlQuoted + rtbName + cp.sqlQuoted + " (" + cp.sqlQuoted + rfkCol + cp.sqlQuoted + ");");
+ pw[2].println("ALTER TABLE " + cp.sqlQuoted + tbName + cp.sqlQuoted + " DROP CONSTRAINT " + cp.sqlQuoted + fkName + ";");
+ for(int i=0;i<strSplit.length;i++)CmnUtils.debugPrint("'" + strSplit[i] + "'");
+ tbName = strSplit[0];
+ fkName = strSplit[1];
+ fkCol = strSplit[2];
+ fkColPos = strSplit[3];
+ rtbName = strSplit[4];
+ rfkName = strSplit[5];
+ rfkCol = strSplit[6];
+ rfkColPos = strSplit[7];
+ } else {
+ if(fkName.equals("")){
+ tbName = strSplit[0];
+ fkName = strSplit[1];
+ fkCol = strSplit[2];
+ fkColPos = strSplit[3];
+ rtbName = strSplit[4];
+ rfkName = strSplit[5];
+ rfkCol = strSplit[6];
+ rfkColPos = strSplit[7];
+ } else {
+ if (strSplit[3].equals(strSplit[7])) {
+ fkCol = fkCol + cp.sqlQuoted + ", " + cp.sqlQuoted + strSplit[2] + cp.sqlQuoted;
+ rfkCol = rfkCol + ", " + cp.sqlQuoted + strSplit[6] + cp.sqlQuoted;
+ }
+ }
+ }
+
+ }
+ pw[1].println("ALTER TABLE " + cp.sqlQuoted + tbName + cp.sqlQuoted + " ADD CONSTRAINT " + cp.sqlQuoted + fkName + cp.sqlQuoted + " FOREIGN KEY (" + cp.sqlQuoted + fkCol + cp.sqlQuoted + ") REFERENCES " + cp.sqlQuoted + rtbName + cp.sqlQuoted + " (" + cp.sqlQuoted + rfkCol + cp.sqlQuoted + ");");
+ pw[2].println("ALTER TABLE " + cp.sqlQuoted + cp.sqlQuoted + tbName + cp.sqlQuoted + " DROP CONSTRAINT " + cp.sqlQuoted + fkName + cp.sqlQuoted + ";");
+ for(int i=1;i<3;i++)pw[i].close();
+ for(int i=1;i<3;i++)pw[i]=null;
+ br[0].close();
+ br[0] = null;
}
- for(int i=1;i<3;i++)pw[i].close();
- for(int i=1;i<3;i++)pw[i]=null;
- br[0].close();
- br[0] = null;
- // RolePrivs Contents end
+ // Fk Contents end
// Rhysical Contents start
if(cp.isPhysical){
// physical index setting
br[0] = new BufferedReader(new FileReader(folder + "/" + FILE_NAME[FL_OBJ] + "_" + database +".csv"));
- br[1] = new BufferedReader(new FileReader(folder + "/" + "createPrimaryKey.sql"));
- br[2] = new BufferedReader(new FileReader(folder + "/" + "createUniqueKey.sql"));
- br[3] = new BufferedReader(new FileReader(folder + "/" + "createIndex.sql"));
- pw[1] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + "createPrimaryKey.sql.phy"))));
- pw[2] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + "createUniqueKey.sql.phy"))));
- pw[3] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + "createIndex.sql.phy"))));
+ br[1] = new BufferedReader(new FileReader(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_PKEY]));
+ br[2] = new BufferedReader(new FileReader(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_UKEY]));
+ br[3] = new BufferedReader(new FileReader(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_INDEX]));
+ pw[1] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_PKEY] + ".phy"))));
+ pw[2] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_UKEY] + ".phy"))));
+ pw[3] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_INDEX] + ".phy"))));
alData = new ArrayList<String>();
int rowNo;
String [] rowData;
}
while((strLine=br[1].readLine()) != null){
strSplit = CmnUtils.splitSpace(strLine);
- rowNo = CmnUtils.getArrayRowNo(alData, 12, 1, strSplit[5]);
+ rowNo = CmnUtils.getArrayRowNo(alData, 12, 1, strSplit[5].replaceAll(cp.sqlQuoted,""));
if (rowNo != -1){
rowData = rowData = CmnUtils.getArrayRowData(alData, 12, rowNo);
CmnUtils.debugPrint(strSplit[5] + ":" + rowNo);
if(!freeLst.equals(""))pw[1].print(" FREELISTS " + freeLst);
if(!flstGrp.equals(""))pw[1].print(" FREELIST GROUPS " + flstGrp);
pw[1].print(" BUFFER_POOL " + bufPool + ")");
- pw[1].print(" TABLESPACE " + "\"" + tblSpace + "\"");
+ pw[1].print(" TABLESPACE " + cp.sqlQuoted + tblSpace + cp.sqlQuoted);
if(logging.equals("NO")){
pw[1].println(" NOLOGGING;");
} else {
}
while((strLine=br[2].readLine()) != null){
strSplit = CmnUtils.splitSpace(strLine);
- rowNo = CmnUtils.getArrayRowNo(alData, 12, 1, strSplit[5]);
+ rowNo = CmnUtils.getArrayRowNo(alData, 12, 1, strSplit[5].replaceAll(cp.sqlQuoted,""));
if (rowNo != -1){
rowData = rowData = CmnUtils.getArrayRowData(alData, 12, rowNo);
CmnUtils.debugPrint(strSplit[5] + ":" + rowNo);
if(!freeLst.equals(""))pw[2].print(" FREELISTS " + freeLst);
if(!flstGrp.equals(""))pw[2].print(" FREELIST GROUPS " + flstGrp);
pw[2].print(" BUFFER_POOL " + bufPool + ")");
- pw[2].print(" TABLESPACE " + "\"" + tblSpace + "\"");
+ pw[2].print(" TABLESPACE " + cp.sqlQuoted + tblSpace + cp.sqlQuoted);
if(logging.equals("NO")){
pw[2].println(" NOLOGGING;");
} else {
}
while((strLine=br[3].readLine()) != null){
strSplit = CmnUtils.splitSpace(strLine);
- rowNo = CmnUtils.getArrayRowNo(alData, 12, 1, strSplit[2]);
+ rowNo = CmnUtils.getArrayRowNo(alData, 12, 1, strSplit[2].replaceAll(cp.sqlQuoted,""));
+ CmnUtils.debugPrint("rowNo=" + rowNo);
if (rowNo != -1){
rowData = CmnUtils.getArrayRowData(alData, 12, rowNo);
- CmnUtils.debugPrint(strSplit[2] + ":" + rowNo);
for(int i=0;i<rowData.length;i++)CmnUtils.debugPrint(rowData[i]);
tbName = rowData[0];
objName = rowData[1];
if(!freeLst.equals(""))pw[3].print(" FREELISTS " + freeLst);
if(!flstGrp.equals(""))pw[3].print(" FREELIST GROUPS " + flstGrp);
pw[3].print(" BUFFER_POOL " + bufPool + ")");
- pw[3].print(" TABLESPACE " + "\"" + tblSpace + "\"");
+ pw[3].print(" TABLESPACE " + cp.sqlQuoted + tblSpace + cp.sqlQuoted);
if(logging.equals("NO")){
pw[3].println(" NOLOGGING;");
} else {
File [] fmFl = new File[6];
File [] toFl = new File[6];
- fmFl[0] = new File(folder + "/" + "createPrimaryKey.sql.phy");
- fmFl[1] = new File(folder + "/" + "createUniqueKey.sql.phy");
- fmFl[2] = new File(folder + "/" + "createIndex.sql.phy");
- toFl[0] = new File(folder + "/" + "createPrimaryKey.sql");
- toFl[1] = new File(folder + "/" + "createUniqueKey.sql");
- toFl[2] = new File(folder + "/" + "createIndex.sql");
+ fmFl[0] = new File(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_PKEY] + ".phy");
+ fmFl[1] = new File(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_UKEY] + ".phy");
+ fmFl[2] = new File(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_INDEX] + ".phy");
+ toFl[0] = new File(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_PKEY]);
+ toFl[1] = new File(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_UKEY]);
+ toFl[2] = new File(folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_INDEX]);
for(int i=0;i<3;i++){
CmnUtils.debugPrint(fmFl[i].toString() + ">" + toFl[i].toString());
toFl[i].delete();
if(!freeLst.equals(""))pw[0].print(" FREELISTS " + freeLst);
if(!flstGrp.equals(""))pw[0].print(" FREELIST GROUPS " + flstGrp);
pw[0].print(" BUFFER_POOL " + bufPool + ")");
- pw[0].print(" TABLESPACE " + "\"" + tblSpace + "\"");
+ pw[0].print(" TABLESPACE " + cp.sqlQuoted + tblSpace + cp.sqlQuoted);
if(logging.equals("NO")){
pw[0].println(" NOLOGGING;");
} else {
}
// Rhysical Contents end
- // Fk Contents start
- File csvFile = new File(folder + "/" + FILE_NAME[FL_FK] + "_" + database +".csv");
- if (csvFile.length() > 0) {
- br[0] = new BufferedReader(new FileReader(folder + "/" + FILE_NAME[FL_FK] + "_" + database +".csv"));
- pw[1] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + "createFk.sql"))));
- pw[2] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + "dropFk.sql"))));
- pw[3] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + "enableFk.sql"))));
- pw[4] = new PrintWriter(new BufferedWriter(new FileWriter(new File(folder + "/" + "disableFk.sql"))));
- tbName = "";
- fkName = "";
- fkCol = "";
- fkColPos = "";
- rtbName = "";
- rfkName = "";
- rfkCol = "";
- rfkColPos = "";
-
- while((strLine=br[0].readLine()) != null){
- strSplit = CmnUtils.splitCsv(strLine);
- if(!fkName.equals(strSplit[1]) && !fkName.equals("")){
- pw[1].println("ALTER TABLE \"" + tbName + "\" ADD CONSTRAINT \"" + fkName + "\" FOREIGN KEY (\"" + fkCol + "\") REFERENCES \"" + rtbName + "\" (\"" + rfkCol + "\");");
- pw[2].println("ALTER TABLE \"" + tbName + "\" DROP CONSTRAINT \"" + fkName + "\";");
- pw[3].println("ALTER TABLE \"" + tbName + "\" ENABLE CONSTRAINT \"" + fkName + "\";");
- pw[4].println("ALTER TABLE \"" + tbName + "\" DISABLE CONSTRAINT \"" + fkName + "\";");
- for(int i=0;i<strSplit.length;i++)CmnUtils.debugPrint("'" + strSplit[i] + "'");
- tbName = strSplit[0];
- fkName = strSplit[1];
- fkCol = strSplit[2];
- fkColPos = strSplit[3];
- rtbName = strSplit[4];
- rfkName = strSplit[5];
- rfkCol = strSplit[6];
- rfkColPos = strSplit[7];
- } else {
- if(fkName.equals("")){
- tbName = strSplit[0];
- fkName = strSplit[1];
- fkCol = strSplit[2];
- fkColPos = strSplit[3];
- rtbName = strSplit[4];
- rfkName = strSplit[5];
- rfkCol = strSplit[6];
- rfkColPos = strSplit[7];
- } else {
- if (strSplit[3].equals(strSplit[7])) {
- fkCol = fkCol + "\", \"" + strSplit[2];
- rfkCol = rfkCol + "\", \"" + strSplit[6];
- }
- }
- }
-
- }
- pw[1].println("ALTER TABLE \"" + tbName + "\" ADD CONSTRAINT \"" + fkName + "\" FOREIGN KEY (\"" + fkCol + "\") REFERENCES \"" + rtbName + "\" (\"" + rfkCol + "\");");
- pw[2].println("ALTER TABLE \"" + tbName + "\" DROP CONSTRAINT \"" + fkName + "\";");
- pw[3].println("ALTER TABLE \"" + tbName + "\" ENABLE CONSTRAINT \"" + fkName + "\";");
- pw[4].println("ALTER TABLE \"" + tbName + "\" DISABLE CONSTRAINT \"" + fkName + "\";");
- for(int i=1;i<5;i++)pw[i].close();
- for(int i=1;i<5;i++)pw[i]=null;
- br[0].close();
- br[0] = null;
- }
- // Fk Contents end
-
// Remove work file
File fl= null;
for(int i=0;i<sql.length;i++){