/* * public void addPatterns(String id, Map<Integer, Set<Integer>> p, PreparedStatement pstmt) throws IOException, SQLException { * for (Map.Entry<Integer, Set<Integer>> en2 : p.entrySet()) { * addPattern(id, en2.getKey(), en2.getValue(), pstmt); * if(useDBForTokenPatterns) * pstmt.addBatch(); * } * } */ /* * public void addPatterns(String sentId, int tokenId, Set<Integer> patterns) throws SQLException, IOException{ * PreparedStatement pstmt = null; * Connection conn= null; * if(useDBForTokenPatterns) { * conn = SQLConnection.getConnection(); * pstmt = getPreparedStmt(conn); * } * * addPattern(sentId, tokenId, patterns, pstmt); * * if(useDBForTokenPatterns){ * pstmt.execute(); * conn.commit(); * pstmt.close(); * conn.close(); * } * } */ /* * private void addPattern(String sentId, int tokenId, Set<Integer> patterns, PreparedStatement pstmt) throws SQLException, IOException { * * if(pstmt != null){ * // ByteArrayOutputStream baos = new ByteArrayOutputStream(); * // ObjectOutputStream oos = new ObjectOutputStream(baos); * // oos.writeObject(patterns); * // byte[] patsAsBytes = baos.toByteArray(); * // ByteArrayInputStream bais = new ByteArrayInputStream(patsAsBytes); * // pstmt.setBinaryStream(1, bais, patsAsBytes.length); * // pstmt.setObject(2, sentId); * // pstmt.setInt(3, tokenId); * // pstmt.setString(4,sentId); * // pstmt.setInt(5, tokenId); * // ByteArrayOutputStream baos2 = new ByteArrayOutputStream(); * // ObjectOutputStream oos2 = new ObjectOutputStream(baos2); * // oos2.writeObject(patterns); * // byte[] patsAsBytes2 = baos2.toByteArray(); * // ByteArrayInputStream bais2 = new ByteArrayInputStream(patsAsBytes2); * // pstmt.setBinaryStream(6, bais2, patsAsBytes2.length); * // pstmt.setString(7,sentId); * // pstmt.setInt(8, tokenId); * * ByteArrayOutputStream baos = new ByteArrayOutputStream(); * ObjectOutputStream oos = new ObjectOutputStream(baos); * oos.writeObject(patterns); * byte[] patsAsBytes = baos.toByteArray(); * ByteArrayInputStream bais = new ByteArrayInputStream(patsAsBytes); * pstmt.setBinaryStream(3, bais, patsAsBytes.length); * pstmt.setObject(1, sentId); * pstmt.setInt(2, tokenId); * * * } else{ * if(!patternsForEachToken.containsKey(sentId)) * patternsForEachToken.put(sentId, new ConcurrentHashMap<Integer, Set<Integer>>()); * patternsForEachToken.get(sentId).put(tokenId, patterns); * } * }*/ /// <exception cref="Java.Sql.SQLException"/> /// <exception cref="System.IO.IOException"/> private void AddPattern(string sentId, IDictionary <int, ICollection <E> > patterns, IPreparedStatement pstmt) { if (pstmt != null) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.WriteObject(patterns); byte[] patsAsBytes = baos.ToByteArray(); ByteArrayInputStream bais = new ByteArrayInputStream(patsAsBytes); pstmt.SetBinaryStream(2, bais, patsAsBytes.Length); pstmt.SetObject(1, sentId); } }