/**
*
Title:
数据库集成服务类,支持对yndc等数据库进行集成
* @version 1.0
*/
public class DBEAIService {
/**
*
数据文件存放目录
*/
private String DEST_DIR = Globals.ManagerHome + "/output";
/**
*
日志记录器
*/
private static Logger log = Logger.getLogger(DBEAIService.class);
public DBEAIService() {
}
/**
*
创建导出脚本
* @param conn
* @param creator
表创建者
* @param filePath
*/
private void createExportFile(Connection conn, String creator,
String filePath) throws Exception {
DBBase dbBase = new DBBase(conn);
String selectTableSql =
"select name from sysibm.systables where creator = '"
+ creator + "' and type='T' order by name";
try {
dbBase.executeQuery(selectTableSql);
} catch (Exception ex) {
throw ex;
} finally {
dbBase.close();
}
DBResult result = dbBase.getSelectDBResult();
List list = new ArrayList();
while (result.next()) {
String table = result.getString(1);
list.add(table);
}
StringBuffer sb = new StringBuffer();
String enterFlag = "\r\n";
for (int i = 0; i < list.size(); i++) {
String tableName = (String) list.get(i);
sb.append("db2 \"export to aa" + String.valueOf(i + 1)
+ ".ixf of ixf select * from " + tableName + "\"");
sb.append(enterFlag);
}
String str = sb.toString();
FileUtility.saveStringToFile(filePath, str, false);
}
/**
*
创建装载脚本
* @param conn
* @param creator
表创建者
* @param filePath
*/
private void createLoadFile(Connection conn, String creator,
String filePath) throws
Exception {
DBBase dbBase = new DBBase(conn);
String selectTableSql =
"select name from sysibm.systables where creator = '"
+ creator + "' and type='T' order by name";
try {
dbBase.executeQuery(selectTableSql);
} catch (Exception ex) {
throw ex;
} finally {
dbBase.close();
}
DBResult result = dbBase.getSelectDBResult();
List list = new ArrayList();
while (result.next()) {
String table = result.getString(1);
list.add(table);
}
StringBuffer sb = new StringBuffer();
String enterFlag = "\r\n";
for (int i = 0; i < list.size(); i++) {
String tableName = (String) list.get(i);
sb.append("db2 \"load from aa" + String.valueOf(i + 1)
+ ".ixf of ixf into " + tableName
+ "COPY NOwithout prompting \"");
sb.append(enterFlag);
}
String str = sb.toString();
FileUtility.saveStringToFile(filePath, str, false);
}
/**
*
获取某个数据库表明的列表
* @param conn
* @param creator
表创建者
* @return
* @throws Exception
*/
private List getTableList(Connection conn, String creator) throws Exception {
DBBase dbBase = new DBBase(conn);
String selectTableSql =
"select name from sysibm.systables where creator = '"
+ creator + "' and type='T' order by name";
try {
dbBase.executeQuery(selectTableSql);
} catch (Exception ex) {
throw ex;
} finally {
dbBase.close();
}
DBResult result = dbBase.getSelectDBResult();
List list = new ArrayList();
while (result.next()) {
String table = result.getString(1);
list.add(table);
}
return list;
}
/**
*
将列表写入到文本文件中
* @param list
* @param filePath
*/
public void saveListToFile(List list, String filePath) throws Exception {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < list.size(); i++) {
String value = (String) list.get(i);
sb.append(value);
sb.append("\r\n");
}
String str = sb.toString();
FileUtility.saveStringToFile(filePath, str, false);
}