use of net.heartsome.cat.database.DBOperator in project translationstudio8 by heartsome.
the class TbDbOperatorManager method loadTmDbConn.
/**
* 加载连接 ;
*/
private void loadTmDbConn() {
// 加载连接前先释放已经存在连接
releaseTmDbConn();
if (projConfiger != null) {
List<DatabaseModelBean> tmDbConfigList = projConfiger.getTermBaseDbs(false);
for (int i = 0; i < tmDbConfigList.size(); i++) {
DatabaseModelBean dmb = tmDbConfigList.get(i);
DBOperator db = DatabaseService.getDBOperator(dmb.toDbMetaData());
if (null == db) {
continue;
}
try {
db.start();
} catch (Exception e) {
logger.error(MessageFormat.format(Messages.getString("tb.TbDbOperatorManager.logger1"), dmb.getDbType(), dmb.getDbName()), e);
continue;
}
this.dbOpList.add(db);
}
}
}
use of net.heartsome.cat.database.DBOperator in project translationstudio8 by heartsome.
the class TmDbOperatorManager method releaseTmDbConn.
/**
* 释放连接 ;
*/
private void releaseTmDbConn() {
for (DBOperator dbop : dbOpList) {
try {
if (dbop != null) {
dbop.end();
}
} catch (SQLException e) {
logger.error(Messages.getString("tm.TmDbOperatorManager.logger2") + dbop.getMetaData().getDatabaseName(), e);
// 继续释放其他数据库资源
continue;
}
}
dbOpList.clear();
defaultDbInfo = null;
}
use of net.heartsome.cat.database.DBOperator in project translationstudio8 by heartsome.
the class TmMatcher method deleteFuzzyResult.
public void deleteFuzzyResult(FuzzySearchResult fr) throws Exception {
Object obj = fr.getDbOp();
if (obj == null) {
throw new Exception(Messages.getString("match.TmMatcher.deleteFuzzyResult.msg1"));
}
DBOperator dbOp = (DBOperator) obj;
boolean needEnd = false;
Statement stmt = null;
ResultSet rs = null;
try {
if (dbOp.isClosed()) {
needEnd = true;
dbOp.start();
}
int tuDbPk = fr.getTu().getTmId();
int srcDbPk = fr.getTu().getSource().getDbPk();
int tgtDbPk = fr.getTu().getTarget().getDbPk();
String sql = "SELECT COUNT(*) FROM TEXTDATA WHERE GROUPID = " + tuDbPk + " AND TYPE = 'M'";
Connection conn = dbOp.getConnection();
if (conn == null || conn.isClosed()) {
throw new Exception(Messages.getString("match.TmMatcher.deleteFuzzyResult.msg2"));
}
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
int count = 0;
if (rs.next()) {
count = rs.getInt(1);
}
rs.close();
stmt.close();
if (count == 0) {
throw new Exception(Messages.getString("match.TmMatcher.deleteFuzzyResult.msg3"));
} else if (count > 2) {
// 删除对应的语言
dbOp.beginTransaction();
dbOp.deleteAllTuvRelations(Arrays.asList(tgtDbPk), fr.getTu().getTarget().getLangCode());
sql = "UPDATE MTU SET CHANGEID = '" + fr.getTu().getChangeUser() + "', CHANGEDATE = '" + DateUtils.getTimestampFromUTC(fr.getTu().getChangeDate()) + "' WHERE MTUPKID = " + tuDbPk;
stmt = conn.createStatement();
stmt.executeUpdate(sql);
dbOp.commit();
} else {
// 删除整个 TU
dbOp.beginTransaction();
stmt = conn.createStatement();
sql = "DELETE FROM MTU WHERE MTUPKID = " + tuDbPk;
stmt.addBatch(sql);
sql = "DELETE FROM MPROP WHERE PARENTNAME = 'TU' AND PARENTID = " + tuDbPk;
stmt.addBatch(sql);
sql = "DELETE FROM MNOTE WHERE PARENTNAME = 'TU' AND PARENTID = " + tuDbPk;
stmt.addBatch(sql);
sql = "DELETE FROM MEXTRA WHERE PARENTNAME = 'TU' AND PARENTID = " + +tuDbPk;
stmt.executeBatch();
dbOp.deleteAllTuvRelations(Arrays.asList(srcDbPk), fr.getTu().getSource().getLangCode());
dbOp.deleteAllTuvRelations(Arrays.asList(tgtDbPk), fr.getTu().getTarget().getLangCode());
dbOp.commit();
}
} catch (Exception e) {
logger.error("delete TM in db error", e);
try {
dbOp.rollBack();
} catch (SQLException e1) {
logger.error("delete tm DB rollback error", e);
}
throw e;
} finally {
if (stmt != null) {
try {
stmt.close();
} catch (SQLException e) {
logger.error("delete TM stmt close error", e);
}
}
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
logger.error("delete TM ResultSet close error", e);
}
}
if (needEnd) {
try {
dbOp.end();
} catch (SQLException e) {
logger.error("delete TM DB close conneciton error", e);
}
}
if (needEnd) {
try {
if (dbOp != null) {
dbOp.end();
}
} catch (SQLException e) {
logger.error("delete TM DB close conneciton error", e);
}
}
}
}
use of net.heartsome.cat.database.DBOperator in project translationstudio8 by heartsome.
the class TmMatcher method updateFuzzyResult.
public void updateFuzzyResult(FuzzySearchResult fr) throws Exception {
Object obj = fr.getDbOp();
if (obj == null) {
throw new Exception(Messages.getString("match.TmMatcher.updateFuzzyResult.msg1"));
}
DBOperator dbOp = (DBOperator) obj;
boolean needEnd = false;
PreparedStatement stmt = null;
try {
if (dbOp.isClosed()) {
needEnd = true;
dbOp.start();
}
int tuDbPk = fr.getTu().getTmId();
int srcDbPk = fr.getTu().getSource().getDbPk();
int tgtDbPk = fr.getTu().getTarget().getDbPk();
Connection conn = dbOp.getConnection();
if (conn == null || conn.isClosed()) {
throw new Exception(Messages.getString("match.TmMatcher.updateFuzzyResult.msg2"));
}
dbOp.beginTransaction();
dbOp.deleteAllTuvRelations(Arrays.asList(srcDbPk), fr.getTu().getSource().getLangCode());
dbOp.deleteAllTuvRelations(Arrays.asList(tgtDbPk), fr.getTu().getTarget().getLangCode());
TmxContexts contexts = fr.getTu().getContexts();
saveTuv(dbOp, tuDbPk, fr.getTu().getSource(), contexts == null ? null : contexts.getPreContext(), contexts == null ? null : contexts.getNextContext());
saveTuv(dbOp, tuDbPk, fr.getTu().getTarget(), null, null);
String sql = "UPDATE MTU SET CHANGEID = ?, CHANGEDATE = ? WHERE MTUPKID = ? ";
stmt = conn.prepareStatement(sql);
int i = 1;
stmt.setString(i++, fr.getTu().getChangeUser());
stmt.setTimestamp(i++, DateUtils.getTimestampFromUTC(fr.getTu().getChangeDate()));
stmt.setInt(i++, tuDbPk);
stmt.executeUpdate();
dbOp.commit();
} catch (Exception e) {
logger.error("delete TM in db error", e);
try {
dbOp.rollBack();
} catch (SQLException e1) {
logger.error("delete tm DB rollback error", e);
}
throw e;
} finally {
if (stmt != null) {
try {
stmt.close();
} catch (SQLException e) {
logger.error("delete TM stmt close error", e);
}
}
if (needEnd) {
try {
if (dbOp != null) {
dbOp.end();
}
} catch (SQLException e) {
logger.error("delete TB DB close conneciton error", e);
}
}
}
}
use of net.heartsome.cat.database.DBOperator in project translationstudio8 by heartsome.
the class TmMatcher method fuzzySearch.
public List<FuzzySearchResult> fuzzySearch() {
int maxMatchSize = transParameters.getMaxMatchSize();
int contextSize = transParameters.getContextSize();
int minSimilarity = transParameters.getMinSimilarity();
int tagPelanty = transParameters.getTagPenalty();
boolean isCaseSensitive = transParameters.isCaseSensitive();
boolean isIgnoreTag = transParameters.isIgnoreTag();
FuzzySearchResults results = new FuzzySearchResults(tmDbOperatorManager.getDefaultDbName(), transParameters.getMatchSortStrategry(), maxMatchSize);
List<DBOperator> dbList = tmDbOperatorManager.getDbOperatorList();
if (dbList.size() == 0) {
return results.getSearchResult();
}
String pureText = tuInfoBean.getSrcPureText();
String fullText = tuInfoBean.getSrcFullText();
String srcLang = Utils.convertLangCode(tuInfoBean.getSrcLanguage());
String tgtLang = Utils.convertLangCode(tuInfoBean.getTgtLangugage());
String preContext = tuInfoBean.getPreContext();
String nextContext = tuInfoBean.getNextContext();
if (pureText == null || pureText.equals("") || srcLang == null || srcLang.equals("") || tgtLang == null || tgtLang.equals("")) {
return results.getSearchResult();
}
for (int i = 0; i < dbList.size(); i++) {
try {
dbList.get(i).fuzzySearch(pureText, fullText, srcLang, tgtLang, minSimilarity, isCaseSensitive, maxMatchSize, contextSize, preContext, nextContext, isIgnoreTag, results, tagPelanty);
results.sort();
results.clearResults();
} catch (SQLException e) {
logger.error(Messages.getString("match.TmMatcher.logger1"), e);
continue;
}
}
results.sort();
results.clearResults();
return results.getSearchResult();
}
Aggregations