Search in sources :

Example 1 with DBOperator

use of net.heartsome.cat.database.DBOperator in project translationstudio8 by heartsome.

the class NewProjectTbPage method checkDbHashMatch.

/**
	 * 需要调用Database模块 检查当前项目在库中是否有语言对的匹配
	 * @param dbModel
	 *            数据库信息;
	 */
private void checkDbHashMatch(DatabaseModelBean dbModel, String type) {
    DBOperator dbOp = DatabaseService.getDBOperator(dbModel.toDbMetaData());
    try {
        dbOp.start();
        dbModel.setHasMatch(dbOp.checkHasMatchs(super.projSourceLang.getCode(), type));
    } catch (Exception e) {
        LOGGER.error("", e);
        e.printStackTrace();
        dbModel.setHasMatch(false);
    } finally {
        try {
            if (dbOp != null) {
                dbOp.end();
            }
        } catch (SQLException e) {
            LOGGER.error("", e);
        }
    }
}
Also used : SQLException(java.sql.SQLException) DBOperator(net.heartsome.cat.database.DBOperator) SQLException(java.sql.SQLException)

Example 2 with DBOperator

use of net.heartsome.cat.database.DBOperator in project translationstudio8 by heartsome.

the class ProjectSettingTBPage method checkDbHashMatch.

/**
	 * 需要调用Database模块 检查当前项目在库中是否有语言对的匹配
	 * @param dbModel
	 *            数据库信息;
	 */
public void checkDbHashMatch(DatabaseModelBean dbModel) {
    Language srcLang = super.projectInfoBean.getSourceLang();
    DBOperator dbOp = DatabaseService.getDBOperator(dbModel.toDbMetaData());
    try {
        if (dbOp != null) {
            dbOp.start();
            dbModel.setHasMatch(dbOp.checkHasMatchs(srcLang.getCode(), "B"));
        }
    } catch (Exception e) {
        LOGGER.error("", e);
        e.printStackTrace();
        dbModel.setHasMatch(false);
    } finally {
        if (dbOp != null) {
            try {
                if (dbOp != null) {
                    dbOp.end();
                }
            } catch (SQLException e) {
                LOGGER.error("", e);
            }
        }
    }
}
Also used : Language(net.heartsome.cat.common.locale.Language) SQLException(java.sql.SQLException) DBOperator(net.heartsome.cat.database.DBOperator) SQLException(java.sql.SQLException)

Example 3 with DBOperator

use of net.heartsome.cat.database.DBOperator in project translationstudio8 by heartsome.

the class TmDbOperatorManager method loadTmDbConn.

/**
	 * 加载连接 ;
	 */
private void loadTmDbConn() {
    // 加载连接前先释放已经存在连接
    releaseTmDbConn();
    if (projConfiger != null) {
        List<DatabaseModelBean> tmDbConfigList = projConfiger.getAllTmDbs();
        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();
                if (dmb.isDefault()) {
                    defaultDbInfo = dmb.getDbName();
                    this.dbOpList.add(0, db);
                } else {
                    this.dbOpList.add(db);
                }
            } catch (Exception e) {
                logger.error(MessageFormat.format(Messages.getString("tm.TmDbOperatorManager.logger1"), dmb.getDbType(), dmb.getDbName()), e);
            }
        }
    }
}
Also used : DatabaseModelBean(net.heartsome.cat.common.bean.DatabaseModelBean) DBOperator(net.heartsome.cat.database.DBOperator) SQLException(java.sql.SQLException)

Example 4 with DBOperator

use of net.heartsome.cat.database.DBOperator in project translationstudio8 by heartsome.

the class TmMatcher method translationUnitAnalysis.

public List<TranslationUnitAnalysisResult> translationUnitAnalysis() {
    int maxMatchSize = transParameters.getMaxMatchSize();
    int contextSize = transParameters.getContextSize();
    int minSimilarity = transParameters.getMinSimilarity();
    int tagPelanty = transParameters.getTagPenalty();
    boolean isCaseSensitive = transParameters.isCaseSensitive();
    boolean isIgnoreTag = transParameters.isIgnoreTag();
    TranslationUnitAnalysisResults results = new TranslationUnitAnalysisResults(tmDbOperatorManager.getDefaultDbName(), transParameters.getMatchSortStrategry(), maxMatchSize);
    List<DBOperator> dbList = tmDbOperatorManager.getDbOperatorList();
    if (dbList.size() == 0) {
        return results.getAnaylysisResults();
    }
    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.getAnaylysisResults();
    }
    for (int i = 0; i < dbList.size(); i++) {
        try {
            dbList.get(i).translationUnitAnalysis(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.getAnaylysisResults();
}
Also used : SQLException(java.sql.SQLException) DBOperator(net.heartsome.cat.database.DBOperator) TranslationUnitAnalysisResults(net.heartsome.cat.database.bean.TranslationUnitAnalysisResults)

Example 5 with DBOperator

use of net.heartsome.cat.database.DBOperator in project translationstudio8 by heartsome.

the class ExportTbxImpl method executeExport.

/**
	 * (non-Javadoc)
	 * @see net.heartsome.cat.document.ExportAbstract#executeExport(org.eclipse.core.runtime.IProgressMonitor)
	 */
@Override
public String executeExport(IProgressMonitor monitor) {
    if (monitor == null) {
        monitor = new NullProgressMonitor();
    }
    String whereResult = "";
    if (this.filterBean != null) {
        StringBuffer whereBf = new StringBuffer();
        String connector = this.filterBean.getFilterConnector();
        List<ExportFilterComponentBean> filterOptions = this.filterBean.getFilterOption();
        whereBf.append(" AND ");
        for (Iterator<ExportFilterComponentBean> iterator = filterOptions.iterator(); iterator.hasNext(); ) {
            ExportFilterComponentBean filterBean = iterator.next();
            whereBf.append("PURE ");
            whereBf.append("LIKE ");
            whereBf.append("'%" + filterBean.getFilterVlaue() + "%' ");
            whereBf.append(connector + " ");
        }
        whereResult = whereBf.toString();
        whereResult = whereResult.substring(0, whereResult.lastIndexOf(connector));
    }
    monitor.beginTask("", dbList.size());
    for (Iterator<ExportDatabaseBean> iterator = dbList.iterator(); iterator.hasNext(); ) {
        ExportDatabaseBean db = iterator.next();
        String srcLang = db.getSrcLang();
        List<String> needLang = db.getHasSelectedLangs();
        DBOperator dbOp = DatabaseService.getDBOperator(db.getDbBean());
        try {
            dbOp.start();
            output = new FileOutputStream(db.getExportFilePath());
            writeHeader(srcLang);
            writeString("<text>\n<body>\n");
            List<Integer> tPkId = dbOp.getAfterFilterTermEntryPK(whereResult, needLang);
            // Fix Bug #2361 TBX文件导出问题--语言不能正确过滤导出 by Jason
            tPkId = dbOp.validateTermEntryPk(tPkId, needLang, srcLang);
            IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 1);
            subMonitor.beginTask(Messages.getString("document.ExportTbxImpl.task1") + db.getDbBean().getDatabaseName(), tPkId.size());
            subMonitor.setTaskName(Messages.getString("document.ExportTbxImpl.task1") + db.getDbBean().getDatabaseName());
            for (int i = 0; i < tPkId.size(); i++) {
                // long l = System.currentTimeMillis();
                if (monitor.isCanceled()) {
                    clearResource();
                    return USER_CANCEL;
                }
                int termEntryPK = tPkId.get(i);
                String termEntry = dbOp.retrieveTermEntry(termEntryPK);
                if (termEntry != null && !termEntry.equals("")) {
                    writeString(termEntry);
                }
                subMonitor.worked(1);
            }
            writeString("</body>\n</text>\n</martif>\n");
        } catch (SQLException e) {
            logger.error(DBOP_ERROR, e);
            e.printStackTrace();
            clearResource();
            return DBOP_ERROR + db.getDbBean().getDbType() + " " + db.getDbBean().getDatabaseName();
        } catch (ClassNotFoundException e) {
            logger.error(JDBC_ERROR, e);
            e.printStackTrace();
            clearResource();
            return JDBC_ERROR + db.getDbBean().getDbType();
        } catch (IOException e) {
            logger.error(FILE_ERROR, e);
            e.printStackTrace();
            clearResource();
            return FILE_ERROR + db.getDbBean().getDbType() + " " + db.getDbBean().getDatabaseName();
        } finally {
            try {
                output.close();
                if (dbOp != null) {
                    dbOp.end();
                }
            } catch (SQLException e) {
                logger.error(RELEASE_DB_ERROR, e);
            } catch (IOException e) {
                logger.error(RELEASE_FILE_ERROR, e);
            }
        }
        filterLangSet(db.getExportFilePath(), srcLang, needLang);
    }
    monitor.done();
    return SUCCESS;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) SQLException(java.sql.SQLException) DBOperator(net.heartsome.cat.database.DBOperator) IOException(java.io.IOException) ExportDatabaseBean(net.heartsome.cat.database.bean.ExportDatabaseBean) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) ExportFilterComponentBean(net.heartsome.cat.database.bean.ExportFilterComponentBean) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) FileOutputStream(java.io.FileOutputStream)

Aggregations

DBOperator (net.heartsome.cat.database.DBOperator)29 SQLException (java.sql.SQLException)28 ArrayList (java.util.ArrayList)9 DatabaseModelBean (net.heartsome.cat.common.bean.DatabaseModelBean)8 MetaData (net.heartsome.cat.common.bean.MetaData)8 SystemDBOperator (net.heartsome.cat.database.SystemDBOperator)6 HashMap (java.util.HashMap)5 MenuItem (org.eclipse.swt.widgets.MenuItem)5 Point (org.eclipse.swt.graphics.Point)4 ResultSet (java.sql.ResultSet)3 Statement (java.sql.Statement)3 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)3 GridItem (org.eclipse.nebula.widgets.grid.GridItem)3 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 IOException (java.io.IOException)2 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 HashSet (java.util.HashSet)2 LinkedHashMap (java.util.LinkedHashMap)2