private void closeStatement() { if (curStatement != null) { for (DBCResultSet resultSet : curResultSets) { resultSet.close(); } curResultSets.clear(); try { curStatement.close(); } catch (Throwable e) { log.error("Error closing statement", e); } curStatement = null; } }
@Override public void fetchStart( DBCSession session, final DBCResultSet resultSet, long offset, long maxRows) throws DBCException { this.rows.clear(); this.offset = offset; this.maxRows = maxRows; if (!nextSegmentRead) { // Get columns metadata DBCResultSetMetaData metaData = resultSet.getMeta(); List<DBCAttributeMetaData> rsAttributes = metaData.getAttributes(); columnsCount = rsAttributes.size(); // Extract column info metaColumns = new DBDAttributeBindingMeta[columnsCount]; for (int i = 0; i < columnsCount; i++) { metaColumns[i] = DBUtils.getAttributeBinding(session, rsAttributes.get(i)); } resultSetViewer.setMetaData(metaColumns); } }
private boolean fetchQueryData( DBCSession session, DBCResultSet resultSet, SQLQueryResult result, DBDDataReceiver dataReceiver, boolean updateStatistics) throws DBCException { if (dataReceiver == null) { // No data pump - skip fetching stage return false; } if (resultSet == null) { return false; } boolean keepCursor = keepStatementOpen(); if (keepCursor) { curResultSets.add(resultSet); } DBRProgressMonitor monitor = session.getProgressMonitor(); monitor.subTask("Fetch result set"); long rowCount = 0; dataReceiver.fetchStart(session, resultSet, rsOffset, rsMaxRows); try { // Retrieve source entity if (result != null) { DBCResultSetMetaData rsMeta = resultSet.getMeta(); String sourceName = null; // resultSet.getResultSetName(); for (DBCAttributeMetaData attr : rsMeta.getAttributes()) { String entityName = attr.getEntityName(); if (!CommonUtils.isEmpty(entityName)) { if (sourceName == null) { sourceName = entityName; } else if (!sourceName.equals(entityName)) { // Multiple source entities sourceName += "(+)"; break; } } } /* if (CommonUtils.isEmpty(sourceName)) { try { sourceName = resultSet.getResultSetName(); } catch (DBCException e) { log.debug(e); } } */ if (CommonUtils.isEmpty(sourceName)) { sourceName = "Result"; } result.setResultSetName(sourceName); } long fetchStartTime = System.currentTimeMillis(); // Fetch all rows while ((!hasLimits() || rowCount < rsMaxRows) && resultSet.nextRow()) { if (monitor.isCanceled()) { break; } rowCount++; if (rowCount > 0 && rowCount % 100 == 0) { monitor.subTask(rowCount + " rows fetched"); monitor.worked(100); } dataReceiver.fetchRow(session, resultSet); } if (updateStatistics) { statistics.addFetchTime(System.currentTimeMillis() - fetchStartTime); } } finally { if (!keepCursor) { try { resultSet.close(); } catch (Throwable e) { log.error("Error while closing resultset", e); } } try { dataReceiver.fetchEnd(session, resultSet); } catch (Throwable e) { log.error("Error while handling end of result set fetch", e); } dataReceiver.close(); } if (result != null) { result.setRowCount(rowCount); } if (updateStatistics) { statistics.setRowsFetched(rowCount); } monitor.subTask(rowCount + " rows fetched"); return true; }