Search in sources :

Example 91 with PreparedStatement

use of java.sql.PreparedStatement in project translationstudio8 by heartsome.

the class DBOperator method insertHeaderNode.

/**
	 * 将数据插入HEADERNODE表
	 * @param params
	 *            ;
	 * @throws SQLException
	 */
public void insertHeaderNode(Hashtable<String, String> params) throws SQLException {
    PreparedStatement stmt = null;
    try {
        String sql = dbConfig.getOperateDbSQL("insert-mheadernode");
        stmt = conn.prepareStatement(sql);
        int i = 1;
        stmt.setInt(i++, Integer.parseInt(params.get("HEADERID")));
        stmt.setString(i++, params.get("NODENAME"));
        stmt.setString(i++, params.get("NODETYPE"));
        stmt.setString(i++, params.get("CONTENT"));
        stmt.executeUpdate();
    } finally {
        if (stmt != null) {
            stmt.close();
        }
    }
}
Also used : PreparedStatement(java.sql.PreparedStatement)

Example 92 with PreparedStatement

use of java.sql.PreparedStatement in project translationstudio8 by heartsome.

the class DBOperator method addOrRemoveFlag.

/**
	 * 添加/删除&lt;prop type='x-flag'&gt;HS-Flag&lt;/prop&gt;标记
	 * @param blnAddOrRemove
	 *            true 表示添加标记,false 表示删除
	 * @param strTuId
	 *            MTU 表的 ID 值
	 */
public void addOrRemoveFlag(boolean blnAddOrRemove, String strTuId) {
    PreparedStatement stmt = null;
    String sql;
    if (blnAddOrRemove) {
        sql = dbConfig.getOperateDbSQL("insert-tmxprops");
    } else {
        sql = dbConfig.getOperateDbSQL("deleteProp-with-HS-Flag");
    }
    try {
        stmt = conn.prepareStatement(sql);
        if (blnAddOrRemove) {
            int i = 1;
            stmt.setString(i++, "TU");
            stmt.setString(i++, strTuId);
            stmt.setString(i++, Constants.X_FLAG);
            stmt.setString(i++, null);
            stmt.setString(i++, null);
            stmt.setString(i++, Constants.HS_FLAG);
            stmt.executeUpdate();
        } else {
            stmt.setString(1, strTuId);
            stmt.setString(2, Constants.X_FLAG);
            stmt.setString(3, Constants.HS_FLAG);
            stmt.executeUpdate();
        }
    } catch (SQLException e) {
        LOGGER.error("", e);
    } finally {
        if (stmt != null) {
            try {
                stmt.close();
            } catch (SQLException e) {
                LOGGER.error("", e);
            }
        }
    }
}
Also used : SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement)

Example 93 with PreparedStatement

use of java.sql.PreparedStatement in project translationstudio8 by heartsome.

the class DBOperator method findMatch_1.

public Vector<Hashtable<String, String>> findMatch_1(String text, String fullText, String srcLang, String tgtLang, int minSimilarity, boolean caseSensitive, int matchUpperLimit, int contextSize, String preHash, String nextHash, boolean isIngoreTarget) throws SQLException {
    Vector<Hashtable<String, String>> result = new Vector<Hashtable<String, String>>();
    this.commit();
    int[] ngrams = generateNgrams(srcLang, text);
    int size = ngrams.length;
    if (size == 0) {
        return result;
    }
    // long l1 = System.currentTimeMillis();
    int min = size * minSimilarity / 100;
    int max = size * 100 / minSimilarity;
    Map<String, Integer> tpkids = getCandidatesTextDataPks(srcLang, min, max, ngrams);
    // System.out.println("查MATEX_LANG表:"+(System.currentTimeMillis() - l1));
    // 构建SQL
    Iterator<Entry<String, Integer>> it = tpkids.entrySet().iterator();
    StringBuffer bf = new StringBuffer();
    // long l = System.currentTimeMillis();
    while (it.hasNext()) {
        Entry<String, Integer> entry = it.next();
        String tpkid = entry.getKey();
        float c = entry.getValue();
        if (c >= min && c <= max) {
            bf.append(",");
            bf.append(tpkid);
        }
    }
    if (bf.toString().equals("")) {
        return result;
    }
    String textDataSql = dbConfig.getOperateDbSQL("getTMMatch1");
    textDataSql = textDataSql.replace("__SET__", bf.toString().substring(1));
    PreparedStatement stmt = conn.prepareStatement(textDataSql);
    stmt.setString(1, srcLang);
    stmt.setString(2, tgtLang);
    // System.out.println(stmt);
    ResultSet rs = stmt.executeQuery();
    Map<Integer, Map<String, String>> tuSrc = new HashMap<Integer, Map<String, String>>();
    Map<Integer, Map<String, String>> tuTgt = new HashMap<Integer, Map<String, String>>();
    while (rs.next()) {
        Integer groupId = rs.getInt("GROUPID");
        String lang = rs.getString("LANG");
        String pureText = rs.getString("PURE");
        String content = rs.getString("CONTENT");
        String creationId = rs.getString("CREATIONID");
        creationId = creationId == null ? "" : creationId;
        String creationDate = "";
        Timestamp tempCdate = rs.getTimestamp("CREATIONDATE");
        if (tempCdate != null) {
            creationDate = DateUtils.formatToUTC(tempCdate.getTime());
        }
        String changeDate = "";
        Timestamp tempChangeDate = rs.getTimestamp("CHANGEDATE");
        if (tempChangeDate != null) {
            changeDate = DateUtils.formatToUTC(tempChangeDate.getTime());
        }
        String changeid = rs.getString("CHANGEID");
        changeid = changeid == null ? "" : changeid;
        String projectRef = rs.getString("PROJECTREF");
        projectRef = projectRef == null ? "" : projectRef;
        String jobRef = rs.getString("JOBREF");
        jobRef = jobRef == null ? "" : jobRef;
        String client = rs.getString("CLIENT");
        client = client == null ? "" : client;
        if (lang.equalsIgnoreCase(srcLang)) {
            int distance;
            if (caseSensitive) {
                if (isIngoreTarget) {
                    distance = similarity(text, pureText);
                } else {
                    distance = similarity(fullText, content);
                }
            } else {
                if (isIngoreTarget) {
                    distance = similarity(text.toLowerCase(), pureText.toLowerCase());
                } else {
                    distance = similarity(fullText.toLowerCase(), content.toLowerCase());
                }
            }
            if (distance == 100 && CommonFunction.checkEdition("U")) {
                String preContext = rs.getString("PRECONTEXT");
                String nextContext = rs.getString("NEXTCONTEXT");
                if (preContext != null && nextContext != null) {
                    String[] preContexts = preContext.split(",");
                    String[] nextContexts = nextContext.split(",");
                    if (preContexts.length > contextSize) {
                        //$NON-NLS-1$
                        preContext = "";
                        for (int i = 0; i < contextSize; i++) {
                            //$NON-NLS-1$
                            preContext += "," + preContexts[i];
                        }
                        if (!"".equals(preContext)) {
                            //$NON-NLS-1$
                            preContext = preContext.substring(1);
                        }
                    }
                    if (nextContexts.length > contextSize) {
                        //$NON-NLS-1$
                        nextContext = "";
                        for (int i = 0; i < contextSize; i++) {
                            //$NON-NLS-1$
                            nextContext += "," + nextContexts[i];
                        }
                        if (!"".equals(nextContext)) {
                            //$NON-NLS-1$
                            nextContext = nextContext.substring(1);
                        }
                    }
                    if (preHash.equals(preContext) && nextHash.equals(nextContext)) {
                        distance = 101;
                    }
                }
            }
            if (distance >= minSimilarity) {
                Map<String, String> srcMap = new HashMap<String, String>();
                srcMap.put("srcLang", srcLang);
                srcMap.put("srcText", pureText);
                srcMap.put("srcContent", content);
                srcMap.put("srcCreationId", creationId);
                srcMap.put("srcCreationDate", creationDate);
                srcMap.put("srcChangeId", changeid);
                srcMap.put("srcChangeDate", changeDate);
                srcMap.put("srcProjectRef", projectRef);
                srcMap.put("srcJobRef", jobRef);
                srcMap.put("srcClient", client);
                srcMap.put("similarity", distance + "");
                tuSrc.put(groupId, srcMap);
            }
        }
        if (lang.equalsIgnoreCase(tgtLang)) {
            Map<String, String> tgtMap = new HashMap<String, String>();
            tgtMap.put("tgtLang", tgtLang);
            tgtMap.put("tgtText", pureText);
            tgtMap.put("tgtContent", content);
            tgtMap.put("tgtCreationId", creationId);
            tgtMap.put("tgtCreationDate", creationDate);
            tgtMap.put("tgtChangeId", changeid);
            tgtMap.put("tgtChangeDate", changeDate);
            tgtMap.put("tgtProjectRef", projectRef);
            tgtMap.put("tgtJobRef", jobRef);
            tgtMap.put("tgtClient", client);
            tuTgt.put(groupId, tgtMap);
        }
    }
    if (stmt != null) {
        stmt.close();
    }
    if (rs != null) {
        rs.close();
    }
    String dbName = getMetaData().getDatabaseName();
    if (tuSrc.size() > 0) {
        Iterator<Entry<Integer, Map<String, String>>> itr = tuSrc.entrySet().iterator();
        while (itr.hasNext()) {
            Entry<Integer, Map<String, String>> entry = itr.next();
            Integer key = entry.getKey();
            Map<String, String> srcMap = entry.getValue();
            Map<String, String> tgtMap = tuTgt.get(key);
            if (tgtMap == null) {
                continue;
            }
            Hashtable<String, String> tu = new Hashtable<String, String>();
            tu.putAll(srcMap);
            tu.putAll(tgtMap);
            if (!isDuplicated(result, tu)) {
                tu.put("tupkid", key + "");
                // 应用于origin属性
                tu.put("dbName", dbName);
                result.add(tu);
            }
        }
    }
    int resultSize = result.size();
    if (resultSize > 1) {
        Collections.sort(result, new FindMatchComparator());
    }
    while (resultSize > matchUpperLimit) {
        resultSize--;
        result.remove(resultSize);
    }
    // System.out.println(bf.toString());
    return result;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) IdentityHashMap(java.util.IdentityHashMap) Timestamp(java.sql.Timestamp) Entry(java.util.Map.Entry) ResultSet(java.sql.ResultSet) Vector(java.util.Vector) Hashtable(java.util.Hashtable) PreparedStatement(java.sql.PreparedStatement) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) IdentityHashMap(java.util.IdentityHashMap)

Example 94 with PreparedStatement

use of java.sql.PreparedStatement in project translationstudio8 by heartsome.

the class DBOperator method updateTermEntry.

/**
	 * 更新Term Entry表中的记录
	 * @param content
	 *            更新的内容
	 * @param pk
	 *            主键
	 * @throws SQLException
	 *             ;
	 */
public void updateTermEntry(String content, String pk) throws SQLException {
    PreparedStatement pstmt = null;
    try {
        String sql = dbConfig.getOperateDbSQL("upateTermEntry-bypk");
        pstmt = conn.prepareStatement(sql);
        pstmt.setString(1, content);
        pstmt.setInt(2, Integer.parseInt(pk));
        pstmt.executeUpdate();
    } finally {
        if (pstmt != null) {
            pstmt.close();
        }
    }
}
Also used : PreparedStatement(java.sql.PreparedStatement)

Example 95 with PreparedStatement

use of java.sql.PreparedStatement in project translationstudio8 by heartsome.

the class DBOperator method getTuMNote.

public List<TmxNote> getTuMNote(int parentId, String parentName) throws SQLException {
    List<TmxNote> result = new ArrayList<TmxNote>();
    // SELECT CONTENT FROM MNOTE WHERE PARENTID=? AND PARENTNAME=?
    String sql = dbConfig.getOperateDbSQL("get-mnote-byparentid");
    PreparedStatement psmt = null;
    ResultSet rs = null;
    try {
        psmt = conn.prepareStatement(sql);
        psmt.setInt(1, parentId);
        psmt.setString(2, parentName);
        rs = psmt.executeQuery();
        while (rs.next()) {
            TmxNote note = new TmxNote();
            note.setContent(rs.getString(1));
            result.add(note);
        }
    } finally {
        if (rs != null) {
            rs.close();
        }
        if (psmt != null) {
            psmt.close();
        }
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) TmxNote(net.heartsome.cat.common.bean.TmxNote) PreparedStatement(java.sql.PreparedStatement)

Aggregations

PreparedStatement (java.sql.PreparedStatement)6623 ResultSet (java.sql.ResultSet)4065 SQLException (java.sql.SQLException)3538 Connection (java.sql.Connection)2806 Test (org.junit.Test)1103 ArrayList (java.util.ArrayList)963 Properties (java.util.Properties)743 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)345 Statement (java.sql.Statement)273 Timestamp (java.sql.Timestamp)260 DatabaseException (net.jforum.exceptions.DatabaseException)254 PhoenixConnection (org.apache.phoenix.jdbc.PhoenixConnection)251 HashMap (java.util.HashMap)209 BigDecimal (java.math.BigDecimal)207 TransactionLegacy (com.cloud.utils.db.TransactionLegacy)174 DbConnection (com.zimbra.cs.db.DbPool.DbConnection)165 List (java.util.List)150 IOException (java.io.IOException)145 Date (java.util.Date)133 Date (java.sql.Date)126