1 package com.rapide_act;
3 import java.io.BufferedInputStream;
4 import java.io.FileInputStream;
5 import java.io.IOException;
6 import java.io.InputStream;
7 import java.io.InputStreamReader;
9 import java.io.FileReader;
10 import java.io.FileWriter;
11 import java.io.BufferedWriter;
12 import java.io.BufferedReader;
13 import java.io.PrintWriter;
14 import java.io.PrintWriter;
15 import java.util.Date;
16 import java.util.ArrayList;
17 import java.util.Iterator;
18 import java.util.Properties;
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;
29 public class RapideMetaLoader{
31 private String database = null;
33 public static void main(String args[]){
36 RapideMetaLoader RapideMetaLoader = new RapideMetaLoader(args[0]);
37 RapideMetaLoader.metaLoad();
39 RapideMetaLoader RapideMetaLoader = new RapideMetaLoader(null);
40 RapideMetaLoader.metaLoad();
42 } catch (Exception e) {
47 RapideMetaLoader(String _database) {
53 private void metaLoad(){
54 Connection conn = null;
55 PreparedStatement stmt = null;
56 BufferedReader br = null;
58 File subFolder = null;
59 String strLine = null;
60 String strMltLine = null;
62 String viewName = null;
63 String procName = null;
64 String [] flName = null;
65 File [] inFiles = null;
67 String [] sqlLine = null;
69 CmnProperty cp = null;
70 DataAccessObjects dao = null;
73 cp = new CmnProperty();
74 cp.setProperty(database);
76 if (cp.dbType != cp.DB_TYPE_ORACLE){
77 throw new Exception("
\83f
\81[
\83^
\83x
\81[
\83X
\82ª
\91Î
\8fÛ
\8aO
\82Å
\82·
\81B[" + cp.DB_TYPE_NAME[cp.dbType] + "]");
79 if(cp.inFolder != null){
80 folder = new File(cp.inFolder);
82 if (database != null){
83 folder = new File(cp.DEFAULT_IN_FOLDER + "/DDL_" + database.toUpperCase());
85 folder = new File(cp.DEFAULT_IN_FOLDER + "/DDL_" + cp.DB_TYPE_NAME[cp.dbType].toUpperCase());
88 CmnUtils.infoPrint("-->
\93ü
\97Í
\8c³
\83t
\83H
\83\8b\83_='" + folder + "'");
89 CmnUtils.infoPrint("
\83\81\83^
\83f
\81[
\83^
\83\8d\81[
\83h
\82ð
\8aJ
\8en
\82µ
\82Ü
\82µ
\82½
\81B");
92 dao = new DataAccessObjects(cp);
96 executeSqlFile(dao, stmt, folder + "/" + cp.SQL_FILE_NAME[cp.DROP_TABLE], cp, true);
97 executeSqlFile(dao, stmt, folder + "/" + cp.SQL_FILE_NAME[cp.DROP_VIEW], cp, true);
98 executeSqlFile(dao, stmt, folder + "/" + cp.SQL_FILE_NAME[cp.DROP_PROCEDURE], cp, true);
99 executeSqlFile(dao, stmt, folder + "/" + cp.SQL_FILE_NAME[cp.DROP_SYNONYM], cp, true);
100 executeSqlFile(dao, stmt, folder + "/" + cp.SQL_FILE_NAME[cp.DROP_SEQUENCE], cp, true);
101 executeSqlFile(dao, stmt, folder + "/" + cp.SQL_FILE_NAME[cp.DROP_FK], cp, true);
103 subFolder = new File(folder + "/TABLES");
104 inFiles = subFolder.listFiles();
106 if(inFiles != null) {
107 for(int k=0;k<inFiles.length;k++){
108 flName = CmnUtils.splitDot(inFiles[k].getName());
110 executeSqlFile(dao, stmt, subFolder + "/" + inFiles[k].getName(), cp, false);
113 executeSqlFile(dao, stmt, folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_PKEY], cp, false);
114 executeSqlFile(dao, stmt, folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_UKEY], cp, false);
115 executeSqlFile(dao, stmt, folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_INDEX], cp, false);
116 subFolder = new File(folder + "/VIEWS");
117 inFiles = subFolder.listFiles();
119 if(inFiles != null) {
120 for(int k=0;k<inFiles.length;k++){
121 flName = CmnUtils.splitDot(inFiles[k].getName());
122 viewName = flName[0];
123 executeSqlFile(dao, stmt, subFolder + "/" + inFiles[k].getName(), cp, false);
126 subFolder = new File(folder + "/PROCEDURES");
127 inFiles = subFolder.listFiles();
129 if(inFiles != null) {
130 for(int k=0;k<inFiles.length;k++){
131 flName = CmnUtils.splitDot(inFiles[k].getName());
132 procName = flName[0];
133 executeSqlFile(dao, stmt, subFolder + "/" + inFiles[k].getName(), cp, false);
136 executeSqlFile(dao, stmt, folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_SEQUENCE], cp, false);
137 executeSqlFile(dao, stmt, folder + "/" + cp.SQL_FILE_NAME[cp.CREATE_FK], cp, false);
139 CmnUtils.infoPrint("
\83\81\83^
\83f
\81[
\83^
\83\8d\81[
\83h
\82ð
\8fI
\97¹
\82µ
\82Ü
\82µ
\82½
\81B");
141 } catch(SQLException se) {
143 CmnUtils.errorPrint(se.toString());
144 se.printStackTrace();
145 se = se.getNextException();
147 System.out.println(se.getMessage());
150 } catch (Exception see) {}
151 } catch (Exception e) {
153 CmnUtils.errorPrint(e.toString());
156 } catch (Exception ee) {}
168 } catch (Exception e) {}
172 private void executeSqlFile(DataAccessObjects _dao, PreparedStatement _stmt, String _infile, CmnProperty _cp, boolean _isResume) throws Exception{
173 BufferedReader br = null;
174 String strLine = null;
175 String strMltLine = "";
176 String [] sqlLine = null;
178 File infile = new File(_infile);
179 if (infile.exists()){
180 br = new BufferedReader(new InputStreamReader(new FileInputStream(_infile), _cp.fileEncoding));
181 while((strLine=br.readLine()) != null){
182 strMltLine += _cp.inColLineSeparator + strLine;
184 sqlLine = CmnUtils.split(strMltLine, ";");
185 for(int l = 0;l<sqlLine.length;l++){
186 if(!sqlLine[l].equals("")){
188 _stmt = _dao.prepareSql(sqlLine[l]);
189 _stmt.executeUpdate();
194 } catch (Exception e) {