JdbcStatement( JdbcConnection conn, int id, int resultSetType, int resultSetConcurrency, boolean closeWithResultSet) { this.conn = conn; this.session = conn.getSession(); setTrace(session.getTrace(), TraceObject.STATEMENT, id); this.resultSetType = resultSetType; this.resultSetConcurrency = resultSetConcurrency; this.closedByResultSet = closeWithResultSet; }
/** * INTERNAL. Check if the statement is closed. * * @param write if the next operation is possibly writing * @return true if a reconnect was required * @throws SQLException if it is closed */ protected boolean checkClosed(boolean write) throws SQLException { if (conn == null) { throw Message.getSQLException(ErrorCode.OBJECT_CLOSED); } conn.checkClosed(write); SessionInterface s = conn.getSession(); if (s != session) { session = s; setTrace(session.getTrace()); return true; } return false; }
/** * @param conn Connection. * @param qry Query. * @param explain Explain. * @return Table. * @throws IgniteCheckedException */ private GridMergeTable createMergeTable( JdbcConnection conn, GridCacheSqlQuery qry, boolean explain) throws IgniteCheckedException { try { Session ses = (Session) conn.getSession(); CreateTableData data = new CreateTableData(); data.tableName = "T___"; data.schema = ses.getDatabase().getSchema(ses.getCurrentSchemaName()); data.create = true; if (!explain) { LinkedHashMap<String, ?> colsMap = qry.columns(); assert colsMap != null; ArrayList<Column> cols = new ArrayList<>(colsMap.size()); for (Map.Entry<String, ?> e : colsMap.entrySet()) { String alias = e.getKey(); GridSqlType t = (GridSqlType) e.getValue(); assert !F.isEmpty(alias); Column c = new Column(alias, t.type(), t.precision(), t.scale(), t.displaySize()); cols.add(c); } data.columns = cols; } else data.columns = planColumns(); return new GridMergeTable(data, ctx); } catch (Exception e) { U.closeQuiet(conn); throw new IgniteCheckedException(e); } }
/** * Do the search. * * @param conn the database connection * @param text the query * @param limit the limit * @param offset the offset * @param data whether the raw data should be returned * @return the result set */ protected static ResultSet search( Connection conn, String text, int limit, int offset, boolean data) throws SQLException { SimpleResultSet result = createResultSet(data); if (conn.getMetaData().getURL().startsWith("jdbc:columnlist:")) { // this is just to query the result set columns return result; } if (text == null || text.trim().length() == 0) { return result; } try { IndexAccess access = getIndexAccess(conn); /*## LUCENE2 ## access.modifier.flush(); String path = getIndexPath(conn); IndexReader reader = IndexReader.open(path); Analyzer analyzer = new StandardAnalyzer(); Searcher searcher = new IndexSearcher(reader); QueryParser parser = new QueryParser(LUCENE_FIELD_DATA, analyzer); Query query = parser.parse(text); Hits hits = searcher.search(query); int max = hits.length(); if (limit == 0) { limit = max; } for (int i = 0; i < limit && i + offset < max; i++) { Document doc = hits.doc(i + offset); float score = hits.score(i + offset); //*/ // ## LUCENE3 ## // take a reference as the searcher may change Searcher searcher = access.searcher; // reuse the same analyzer; it's thread-safe; // also allows subclasses to control the analyzer used. Analyzer analyzer = access.writer.getAnalyzer(); QueryParser parser = new QueryParser(Version.LUCENE_30, LUCENE_FIELD_DATA, analyzer); Query query = parser.parse(text); // Lucene 3 insists on a hard limit and will not provide // a total hits value. Take at least 100 which is // an optimal limit for Lucene as any more // will trigger writing results to disk. int maxResults = (limit == 0 ? 100 : limit) + offset; TopDocs docs = searcher.search(query, maxResults); if (limit == 0) { limit = docs.totalHits; } for (int i = 0, len = docs.scoreDocs.length; i < limit && i + offset < docs.totalHits && i + offset < len; i++) { ScoreDoc sd = docs.scoreDocs[i + offset]; Document doc = searcher.doc(sd.doc); float score = sd.score; // */ String q = doc.get(LUCENE_FIELD_QUERY); if (data) { int idx = q.indexOf(" WHERE "); JdbcConnection c = (JdbcConnection) conn; Session session = (Session) c.getSession(); Parser p = new Parser(session); String tab = q.substring(0, idx); ExpressionColumn expr = (ExpressionColumn) p.parseExpression(tab); String schemaName = expr.getOriginalTableAliasName(); String tableName = expr.getColumnName(); q = q.substring(idx + " WHERE ".length()); Object[][] columnData = parseKey(conn, q); result.addRow(schemaName, tableName, columnData[0], columnData[1], score); } else { result.addRow(q, score); } } /*## LUCENE2 ## // TODO keep it open if possible reader.close(); //*/ } catch (Exception e) { throw convertException(e); } return result; }
/** INTERNAL */ public JdbcClob(JdbcConnection conn, Value value, int id) { setTrace(conn.getSession().getTrace(), TraceObject.CLOB, id); this.conn = conn; this.value = value; }