use of net.heartsome.cat.common.bean.MetaData in project translationstudio8 by heartsome.
the class TermBaseSearchDialog method sortMap.
/**
* 对搜索结果按相似度进行排序
* @param mapItem
* @return ;
*/
private LinkedHashMap<String, Object[]> sortMap(LinkedHashMap<MetaData, HashMap<String, IdentityHashMap<String, String>>> mapItem) {
Iterator<Entry<MetaData, HashMap<String, IdentityHashMap<String, String>>>> it = mapItem.entrySet().iterator();
LinkedHashMap<String, Object[]> mapData = new LinkedHashMap<String, Object[]>();
while (it.hasNext()) {
Entry<MetaData, HashMap<String, IdentityHashMap<String, String>>> entry = it.next();
MetaData metaData = entry.getKey();
HashMap<String, IdentityHashMap<String, String>> mapTerm = entry.getValue();
Iterator<Entry<String, IdentityHashMap<String, String>>> iterator = mapTerm.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<String, IdentityHashMap<String, String>> e = (Map.Entry<String, IdentityHashMap<String, String>>) iterator.next();
String strGroupIdString = e.getKey();
IdentityHashMap<String, String> map = e.getValue();
String key = metaData.getDatabaseName() + "_" + metaData.getServerName() + "_" + strGroupIdString;
Object[] arrObj = new Object[] { metaData, map };
mapData.put(key, arrObj);
}
}
ArrayList<Entry<String, Object[]>> entryList = new ArrayList<Entry<String, Object[]>>(mapData.entrySet());
Collections.sort(entryList, new Comparator<Map.Entry<String, Object[]>>() {
@SuppressWarnings("unchecked")
public int compare(Map.Entry<String, Object[]> arg0, Map.Entry<String, Object[]> arg1) {
IdentityHashMap<String, String> map0 = (IdentityHashMap<String, String>) arg0.getValue()[1];
IdentityHashMap<String, String> map1 = (IdentityHashMap<String, String>) arg1.getValue()[1];
String strSimilarity0 = map0.get("similarity");
String strSimilarity1 = map1.get("similarity");
if (strSimilarity0 == null || strSimilarity1 == null) {
if (strSimilarity0 != null) {
return -1;
} else if (strSimilarity1 != null) {
return 1;
} else {
return 0;
}
} else {
int intData0 = Integer.parseInt(strSimilarity0);
int intData1 = Integer.parseInt(strSimilarity1);
if (intData0 > intData1) {
return -1;
} else if (intData0 < intData1) {
return 1;
} else {
return 0;
}
}
}
});
mapData.clear();
for (Entry<String, Object[]> entry : entryList) {
String key = entry.getKey();
Object[] obj = entry.getValue();
mapData.put(key, obj);
}
return mapData;
}
use of net.heartsome.cat.common.bean.MetaData in project translationstudio8 by heartsome.
the class TermDbManagerDialog method initUI.
/**
* 根据当前操作不同的数据库类型,初始化界面 ;
*/
private void initUI(boolean isAdd) {
MetaData curDbMetaData = dbMetaDataMap.get(getCurrDbType());
if (!isAdd) {
Control[] childrens = locationText.getParent().getChildren();
for (Control c : childrens) {
if (!(c instanceof Composite)) {
if (c instanceof Text || c instanceof Button) {
c.setEnabled(false);
}
} else {
Composite com = (Composite) c;
Control[] ch = com.getChildren();
for (Control chl : ch) {
if (c instanceof Text || c instanceof Button) {
chl.setEnabled(false);
}
}
}
}
} else {
if (curDbMetaData.dataPathSupported()) {
locationText.setEnabled(true);
borwserBtn.setEnabled(true);
} else {
locationText.setEnabled(false);
borwserBtn.setEnabled(false);
}
if (curDbMetaData.serverNameSupported()) {
hostText.setEnabled(true);
} else {
hostText.setEnabled(false);
}
if (curDbMetaData.instanceSupported()) {
instanceText.setEnabled(true);
} else {
instanceText.setEnabled(false);
}
if (curDbMetaData.portSupported()) {
portText.setEnabled(true);
} else {
portText.setEnabled(false);
}
if (curDbMetaData.userNameSupported()) {
usernameText.setEnabled(true);
} else {
usernameText.setEnabled(false);
}
if (curDbMetaData.passwordSupported()) {
passwordText.setEnabled(true);
} else {
passwordText.setEnabled(false);
}
}
}
use of net.heartsome.cat.common.bean.MetaData in project translationstudio8 by heartsome.
the class TermDbManagerDialog method validator.
/**
* 输入验证器 ;
*/
private IStatus validator() {
String instance = currServer.getInstance();
String host = currServer.getHost();
String port = currServer.getPort();
String location = currServer.getItlDBLocation();
String username = currServer.getUserName();
MetaData dbMetaData = dbMetaDataMap.get(currServer.getDbType());
if (dbMetaData.dataPathSupported()) {
File f = new File(location);
if (location == null || location.trim().length() == 0) {
if (dbMetaData.getDbType().equals(Constants.DBTYPE_INTERNALDB)) {
return ValidationStatus.error(Messages.getString("dialog.TermDbManagerDialog.msg5"));
} else if (dbMetaData.getDbType().equals(Constants.DBTYPE_SQLITE)) {
return ValidationStatus.error(Messages.getString("dialog.TermDbManagerDialog.msg11"));
}
} else if (!f.exists()) {
return ValidationStatus.error(Messages.getString("dialog.TermDbManagerDialog.msg12"));
}
}
if (dbMetaData.serverNameSupported()) {
if (host == null || host.trim().length() == 0) {
return ValidationStatus.error(Messages.getString("dialog.TermDbManagerDialog.msg6"));
}
}
if (dbMetaData.portSupported()) {
if (port == null || port.trim().length() == 0) {
return ValidationStatus.error(Messages.getString("dialog.TermDbManagerDialog.msg7"));
}
}
if (dbMetaData.userNameSupported()) {
if (username == null || username.trim().length() == 0) {
return ValidationStatus.error(Messages.getString("dialog.TermDbManagerDialog.msg8"));
}
}
if (dbMetaData.instanceSupported()) {
if (instance == null || instance.trim().length() == 0) {
return ValidationStatus.error(Messages.getString("dialog.TermDbManagerDialog.msg9"));
}
}
return ValidationStatus.ok();
}
use of net.heartsome.cat.common.bean.MetaData in project translationstudio8 by heartsome.
the class NewTermDbBaseInfoPage method saveToServerConfigFile.
private void saveToServerConfigFile(SystemDBOperator dbOp) {
DatabaseConfiger cf = new DatabaseConfiger();
DatabaseModelBean bean = new DatabaseModelBean();
MetaData md = dbOp.getMetaData();
bean.metaDatatToBean(md);
// 判断当前服务器是否已经存在
String serverId = cf.isServerExist(bean, md);
if (serverId == null || serverId.equals("")) {
// 不存在
cf.addServerConfig(bean);
} else {
bean.setId(serverId);
cf.updateServerConfigById(serverId, bean);
}
}
use of net.heartsome.cat.common.bean.MetaData in project translationstudio8 by heartsome.
the class OperateSystemDBImpl 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);
url = url.replace("__FILE_SEPARATOR__", File.separator);
Properties prop = Utils.replaceParams(dbConfig.getConfigProperty(), data);
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;
}
Aggregations