use of net.heartsome.cat.common.bean.MetaData in project translationstudio8 by heartsome.
the class OperateSystemDBImpl method addSysDb.
public void addSysDb(String dbName, String quality, int type) {
MetaData data = null;
try {
data = (MetaData) metaData.clone();
data.setDatabaseName(Constants.HSSYSDB);
} catch (CloneNotSupportedException e) {
LOGGER.warn("", e);
return;
}
String driver = dbConfig.getDriver();
String url = Utils.replaceParams(dbConfig.getDbURL(), data);
url = url.replace("__FILE_SEPARATOR__", File.separator);
Properties prop = Utils.replaceParams(dbConfig.getConfigProperty(), data);
PreparedStatement stmt = null;
try {
conn = getConnection(driver, url, prop);
String insertDb = Utils.replaceParams(dbConfig.getInsertSysDb(), data);
stmt = conn.prepareStatement(insertDb);
stmt.setString(1, dbName);
stmt.setString(2, quality);
stmt.setInt(3, type);
stmt.execute();
} catch (ClassNotFoundException e) {
LOGGER.warn("", e);
} catch (SQLException e) {
LOGGER.warn("", e);
} finally {
freeConnection(stmt, conn);
}
}
use of net.heartsome.cat.common.bean.MetaData in project translationstudio8 by heartsome.
the class TmDbManagerDialog method searchCurrServerDatabase.
private List<DatabaseManagerDbListBean> searchCurrServerDatabase(SystemDBOperator sysDbOp, DatabaseModelBean currServer) {
List<DatabaseManagerDbListBean> temp = new ArrayList<DatabaseManagerDbListBean>();
// 检查是否创建了系统库
if (!sysDbOp.checkSysDb()) {
// MessageDialog.openInformation(getShell(), "提示信息",
// "当前服务器上没有创建任何库");
setLastSelectedServer(null);
return null;
}
// 检查是否创建了库
List<String> dbNames = sysDbOp.getSysDbNames(Constants.DB_TYPE_TM);
if (dbNames.size() == 0) {
// MessageDialog.openInformation(getShell(), "提示信息",
// "当前服务器上没有创建任何库");
setLastSelectedServer(null);
return null;
}
// 获取数据库相关资料,封装了库名称和语言
MetaData metaData = currServer.toDbMetaData();
DBOperator dbop = DatabaseService.getDBOperator(metaData);
for (int i = 0; i < dbNames.size(); i++) {
DatabaseManagerDbListBean bean = new DatabaseManagerDbListBean();
String dbName = dbNames.get(i);
bean.setIndex(i + 1 + "");
bean.setDbName(dbName);
metaData.setDatabaseName(dbName);
dbop.setMetaData(metaData);
String lang = "";
try {
dbop.start();
List<String> langs = dbop.getLanguages();
for (int j = 0; j < langs.size(); j++) {
lang += langs.get(j);
if (j != langs.size() - 1) {
lang += ", ";
}
}
} catch (Exception e1) {
logger.error("", e1);
continue;
} finally {
try {
if (dbop != null) {
dbop.end();
}
} catch (SQLException e) {
logger.error("", e);
}
}
if (lang.equals("")) {
bean.setLangs(Messages.getString("dialog.TmDbManagerDialog.msg10"));
} else {
bean.setLangs(lang);
}
temp.add(bean);
}
return temp;
}
use of net.heartsome.cat.common.bean.MetaData in project translationstudio8 by heartsome.
the class DatabaseService method getSystemSuportDbMetaData.
/**
* 获取系统支持数据库的元数据
* @return ;
*/
public static Map<String, MetaData> getSystemSuportDbMetaData() {
Map<String, MetaData> map = new HashMap<String, MetaData>();
List<SystemDBOperator> sysDbOp = getSystemDbOperaterList();
for (int i = 0; i < sysDbOp.size(); i++) {
SystemDBOperator dbOp = sysDbOp.get(i);
map.put(dbOp.getMetaData().getDbType(), dbOp.getMetaData());
}
return map;
}
use of net.heartsome.cat.common.bean.MetaData in project translationstudio8 by heartsome.
the class SystemDBOperator method getSysDbNames.
/**
* 得到系统库中的存储的数据库名称
* @return
* @throws SQLException
*/
public List<String> getSysDbNames(int type) {
MetaData data = null;
try {
data = (MetaData) metaData.clone();
data.setDatabaseName(Constants.HSSYSDB);
} catch (CloneNotSupportedException e) {
logger.warn("", e);
return null;
}
String driver = dbConfig.getDriver();
String url = Utils.replaceParams(dbConfig.getDbURL(), data);
Properties prop = Utils.replaceParams(dbConfig.getConfigProperty(), data);
Connection conn = null;
PreparedStatement stmt = null;
ResultSet rs = null;
List<String> result = new ArrayList<String>();
try {
conn = getConnection(driver, url, prop);
String sql = dbConfig.getSysDbList();
stmt = conn.prepareStatement(sql);
stmt.setInt(1, type);
rs = stmt.executeQuery();
while (rs.next()) {
result.add(rs.getString("DBNAME"));
}
} catch (ClassNotFoundException e) {
logger.warn("", e);
} catch (SQLException e) {
logger.warn("", e);
} finally {
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
logger.warn("", e);
}
}
freeConnection(stmt, conn);
}
return result;
}
use of net.heartsome.cat.common.bean.MetaData in project translationstudio8 by heartsome.
the class DatabaseService method getSysDbOperateByMetaData.
/**
* 通过数据库元数据库获取数据库连接,主要取数据库类型
* @param metaData
* @return ;
*/
public static SystemDBOperator getSysDbOperateByMetaData(MetaData metaData) {
@SuppressWarnings({ "rawtypes", "unchecked" }) ServiceTracker tracker = new ServiceTracker(Activator.context, DBServiceProvider.class.getName(), null);
tracker.open();
try {
Object[] services = tracker.getServices();
for (Object i : services) {
DBServiceProvider serviceProvider = (DBServiceProvider) i;
SystemDBOperator temp = serviceProvider.getOperateDBInstance();
if (temp == null) {
continue;
}
MetaData tempMetaData = temp.getMetaData();
if (tempMetaData.getDbType().equals(metaData.getDbType())) {
tempMetaData.setDatabaseName(metaData.getDatabaseName());
tempMetaData.setDataPath(metaData.getDataPath());
tempMetaData.setInstance(metaData.getInstance());
tempMetaData.setPassword(metaData.getPassword());
tempMetaData.setPort(metaData.getPort());
tempMetaData.setServerName(metaData.getServerName());
tempMetaData.setTB(metaData.isTB());
tempMetaData.setTM(metaData.isTM());
tempMetaData.setUserName(metaData.getUserName());
return temp;
}
}
} finally {
tracker.close();
}
return null;
}
Aggregations