Search in sources :

Example 1 with ExportFilterComponentBean

use of net.heartsome.cat.database.bean.ExportFilterComponentBean in project translationstudio8 by heartsome.

the class TMDatabaseImpl method generationExportTMXFilter.

@Override
public String generationExportTMXFilter(String tableName, ExportFilterBean filterBean) {
    String connector = filterBean.getFilterConnector();
    List<ExportFilterComponentBean> filterOption = filterBean.getFilterOption();
    Map<String, Character> tuMatch = Utils.getFilterMatchMTU("MTU");
    Map<String, Character> mNoteDateMatch = Utils.getFilterMatchMTU("MNOTE");
    Map<String, Character> textDateMatch = Utils.getFilterMatchMTU("TEXTDATA");
    StringBuffer bf = new StringBuffer();
    for (int i = 0; i < filterOption.size(); i++) {
        ExportFilterComponentBean bean = filterOption.get(i);
        Character fieldType = null;
        String field = bean.getMatchDbField();
        String op = bean.getExpressionMatchDb();
        String value = bean.getFilterVlaue();
        if ("MTU".equals(tableName)) {
            // 添加 "A.","B.","C."请参考查询SQL
            fieldType = tuMatch.get(field);
            field = "A." + field;
        } else if ("MNOTE".equals(tableName)) {
            fieldType = mNoteDateMatch.get(field);
            field = "B." + field;
        } else if ("TEXTDATA".equals(tableName)) {
            fieldType = textDateMatch.get(field);
            field = "C." + field;
        }
        if (fieldType == null) {
            continue;
        }
        bf.append(field);
        bf.append(" " + op + " ");
        switch(fieldType) {
            case // 文本内容,包含/不包含内容
            '1':
                if (op.equals("like") || op.equals("not like")) {
                    bf.append(" '%" + value + "%' ");
                } else {
                    bf.append("' " + value + "' ");
                }
                bf.append(connector + " ");
                break;
            case // 日期类型
            '2':
                bf.append(" to_date('" + value + "','yyyy-mm-dd hh24:mi:ss') ");
                bf.append(connector + " ");
                break;
            default:
                return "";
        }
    }
    String result = bf.toString();
    if (result.equals("")) {
        return result;
    }
    return result.substring(0, result.lastIndexOf(connector));
}
Also used : ExportFilterComponentBean(net.heartsome.cat.database.bean.ExportFilterComponentBean)

Example 2 with ExportFilterComponentBean

use of net.heartsome.cat.database.bean.ExportFilterComponentBean 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)

Example 3 with ExportFilterComponentBean

use of net.heartsome.cat.database.bean.ExportFilterComponentBean in project translationstudio8 by heartsome.

the class ExportFilterSettingDialog method initData.

private void initData() {
    if (this.currentFilter != null) {
        Control[] c = dynaComposite.getChildren();
        for (int i = 0; i < c.length; i++) {
            c[i].dispose();
        }
        filterNameText.setText(currentFilter.getFilterName());
        String filterConnector = currentFilter.getFilterConnector();
        if (filterConnector.equals("AND")) {
            isAllCbtn.setSelection(true);
            isAnyCbtn.setSelection(false);
        } else {
            isAllCbtn.setSelection(false);
            isAnyCbtn.setSelection(true);
        }
        List<ExportFilterComponentBean> optionList = currentFilter.getFilterOption();
        if (optionList.size() > 0) {
            ExportFilterComponentBean bean = optionList.get(0);
            ExportFilterComposite exportFilterComponent = new ExportFilterComposite(dynaComposite, SWT.None, ruleType, bean);
            exportFilterComponent.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
            exportFilterComponent.setDeleteButtonEnabled(false);
            dynaComposite.setData("currentNumber", 1);
            for (int i = 1; i < optionList.size(); i++) {
                bean = optionList.get(i);
                exportFilterComponent.addComponent(dynaComposite, bean);
            }
        }
    }
}
Also used : ExportFilterComponentBean(net.heartsome.cat.database.bean.ExportFilterComponentBean) Control(org.eclipse.swt.widgets.Control) GridData(org.eclipse.swt.layout.GridData) Point(org.eclipse.swt.graphics.Point)

Example 4 with ExportFilterComponentBean

use of net.heartsome.cat.database.bean.ExportFilterComponentBean in project translationstudio8 by heartsome.

the class DBOperator method generationExportTMXFilter.

/**
	 * 根据设置的过滤条件生成相应的SQL语句
	 * @param tableName
	 *            过滤条件的表名
	 * @param filterBean
	 *            设置过滤条件
	 * @return 生成SQL条件部分,即where后面的过滤条件,没有过滤条件则返回一个空串;
	 */
public String generationExportTMXFilter(String tableName, ExportFilterBean filterBean) {
    String connector = filterBean.getFilterConnector();
    List<ExportFilterComponentBean> filterOption = filterBean.getFilterOption();
    Map<String, Character> tuMatch = Utils.getFilterMatchMTU("MTU");
    Map<String, Character> mNoteDateMatch = Utils.getFilterMatchMTU("MNOTE");
    Map<String, Character> textDateMatch = Utils.getFilterMatchMTU("TEXTDATA");
    StringBuffer bf = new StringBuffer();
    for (int i = 0; i < filterOption.size(); i++) {
        ExportFilterComponentBean bean = filterOption.get(i);
        Character fieldType = null;
        String field = bean.getMatchDbField();
        String op = bean.getExpressionMatchDb();
        String value = bean.getFilterVlaue();
        if ("MTU".equals(tableName)) {
            // 添加 "A.","B.","C."请参考查询SQL
            fieldType = tuMatch.get(field);
            field = "A." + field;
        } else if ("MNOTE".equals(tableName)) {
            fieldType = mNoteDateMatch.get(field);
            field = "B." + field;
        } else if ("TEXTDATA".equals(tableName)) {
            fieldType = textDateMatch.get(field);
            field = "C." + field;
        }
        if (fieldType == null) {
            continue;
        }
        bf.append(field);
        bf.append(" " + op + " ");
        switch(fieldType) {
            case // 文本内容,包含/不包含内容
            '1':
                if (op.equals("like") || op.equals("not like")) {
                    bf.append(" '%" + value + "%' ");
                } else {
                    bf.append(" '" + value + "' ");
                }
                bf.append(connector + " ");
                break;
            case // 日期类型 目前统一采用where dataField > 'yyyy-MM-dd hh:mm:ss' 此方式不适用于Oracle,参见Oracle实现
            '2':
                bf.append(" '" + value + "' ");
                bf.append(connector + " ");
                break;
            default:
                return "";
        }
    }
    String result = bf.toString();
    if (result.equals("")) {
        return result;
    }
    return result.substring(0, result.lastIndexOf(connector));
}
Also used : ExportFilterComponentBean(net.heartsome.cat.database.bean.ExportFilterComponentBean)

Example 5 with ExportFilterComponentBean

use of net.heartsome.cat.database.bean.ExportFilterComponentBean in project translationstudio8 by heartsome.

the class ExportFilterStoreConfiger method generateContent.

private String generateContent(ExportFilterBean filter) {
    StringBuffer bf = new StringBuffer();
    bf.append("<content name=\"" + filter.getFilterName() + "\" type=\"" + filter.getFilterConnector() + "\">");
    List<ExportFilterComponentBean> options = filter.getFilterOption();
    for (Iterator<ExportFilterComponentBean> iterator = options.iterator(); iterator.hasNext(); ) {
        ExportFilterComponentBean bean = iterator.next();
        bf.append("<option name=\"" + bean.getOptionName() + "\" operator=\"" + bean.getCurrentExpression() + "\" value=\"" + bean.getFilterVlaue() + "\"/>");
    }
    bf.append("</content>");
    return bf.toString();
}
Also used : ExportFilterComponentBean(net.heartsome.cat.database.bean.ExportFilterComponentBean)

Aggregations

ExportFilterComponentBean (net.heartsome.cat.database.bean.ExportFilterComponentBean)8 Control (org.eclipse.swt.widgets.Control)3 ArrayList (java.util.ArrayList)2 ExportFilterBean (net.heartsome.cat.database.bean.ExportFilterBean)2 Point (org.eclipse.swt.graphics.Point)2 AutoPilot (com.ximpleware.AutoPilot)1 NavException (com.ximpleware.NavException)1 XPathEvalException (com.ximpleware.XPathEvalException)1 XPathParseException (com.ximpleware.XPathParseException)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1 DBOperator (net.heartsome.cat.database.DBOperator)1 ExportDatabaseBean (net.heartsome.cat.database.bean.ExportDatabaseBean)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)1 ScrolledComposite (org.eclipse.swt.custom.ScrolledComposite)1 GridData (org.eclipse.swt.layout.GridData)1 Composite (org.eclipse.swt.widgets.Composite)1