Java Code Examples for javax.sql.rowset.CachedRowSet#next()
The following examples show how to use
javax.sql.rowset.CachedRowSet#next() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JdbcRowSetLiveTest.java From tutorials with MIT License | 6 votes |
@Test public void createCachedRowSet_DeleteRecord_ThenCorrect() throws Exception { CachedRowSet crs = new CachedRowSetImpl(); crs.setUsername(username); crs.setPassword(password); crs.setUrl(url); crs.setCommand(sql); crs.execute(); crs.addRowSetListener(new ExampleListener()); while (crs.next()) { if (crs.getInt("id") == 1) { System.out.println("CRS found customer1 and will remove the record."); crs.deleteRow(); break; } } }
Example 2
Source File: DefaultAdaptor.java From kylin-on-parquet-v2 with Apache License 2.0 | 5 votes |
@Override public List<String> listColumns(String database, String tableName) throws SQLException { List<String> ret = new ArrayList<>(); CachedRowSet columnsRs = getTableColumns(database, tableName); while (columnsRs.next()) { String name = columnsRs.getString("COLUMN_NAME"); if (StringUtils.isNotBlank(name)) { ret.add(name); } } return ret; }
Example 3
Source File: DefaultAdaptor.java From kylin-on-parquet-v2 with Apache License 2.0 | 5 votes |
/** * Get All columns for sql case sensitive * @return * @throws SQLException */ public List<String> listColumns() throws SQLException { List<String> ret = new ArrayList<>(); if (columnsCache == null || columnsCache.size() == 0) { CachedRowSet columnsRs = null; try (Connection conn = getConnection(); ResultSet rs = conn.getMetaData().getColumns(null, null, null, null)) { columnsRs = cacheResultSet(rs); } while (columnsRs.next()) { String database = columnsRs.getString("TABLE_SCHEM") != null ? columnsRs.getString("TABLE_SCHEM") : columnsRs.getString("TABLE_CAT"); String table = columnsRs.getString("TABLE_NAME"); String column = columnsRs.getString("COLUMN_NAME"); String cacheKey = joiner.join(config.datasourceId, config.url, database, table, "columns"); List<String> cachedColumns = columnsCache.getIfPresent(cacheKey); if (cachedColumns == null) { cachedColumns = new ArrayList<>(); columnsCache.put(cacheKey, cachedColumns); logger.debug("Add column cache for table {}.{}", database, table); } if (!cachedColumns.contains(column)) { cachedColumns.add(column); } ret.add(column); } } else { for (Map.Entry<String, List<String>> entry : columnsCache.asMap().entrySet()) { ret.addAll(entry.getValue()); } } return ret; }
Example 4
Source File: CachedRunningQuery.java From datawave with Apache License 2.0 | 5 votes |
/** * Convert the cached row set into a result list. * * @param cachedRowSet * @param pageByteTrigger * @return */ private ResultsPage convert(CachedRowSet cachedRowSet, long pageByteTrigger) { boolean hitPageByteTrigger = false; List<CacheableQueryRow> cacheableQueryRowList = new ArrayList<>(); try { cachedRowSet.beforeFirst(); long resultBytes = 0; while (cachedRowSet.next() && !hitPageByteTrigger) { CacheableQueryRow row = CacheableQueryRowReader.createRow(cachedRowSet, this.fixedFieldsInEvent); cacheableQueryRowList.add(row); if (pageByteTrigger != 0) { resultBytes += ObjectSizeOf.Sizer.getObjectSize(row); if (resultBytes >= pageByteTrigger) { hitPageByteTrigger = true; } } } } catch (SQLException | RuntimeException e) { log.error(e.getMessage(), e); } if (this.cacheableLogic == null) { return new ResultsPage(); } else { return new ResultsPage(this.cacheableLogic.readFromCache(cacheableQueryRowList), (hitPageByteTrigger ? ResultsPage.Status.PARTIAL : ResultsPage.Status.COMPLETE)); } }
Example 5
Source File: CachedRunningQuery.java From datawave with Apache License 2.0 | 5 votes |
private ResultsPage convert(CachedRowSet cachedRowSet, Integer rowBegin, Integer rowEnd, long pageByteTrigger) { boolean hitPageByteTrigger = false; List<CacheableQueryRow> cacheableQueryRowList = new ArrayList<>(); try { long resultBytes = 0; while (cachedRowSet.next() && cachedRowSet.getRow() <= rowEnd && !hitPageByteTrigger) { if (log.isTraceEnabled()) log.trace("CRS.position: " + cachedRowSet.getRow() + ", size: " + cachedRowSet.size()); CacheableQueryRow row = CacheableQueryRowReader.createRow(cachedRowSet, this.fixedFieldsInEvent); cacheableQueryRowList.add(row); if (pageByteTrigger != 0) { resultBytes += ObjectSizeOf.Sizer.getObjectSize(row); if (resultBytes >= pageByteTrigger) { hitPageByteTrigger = true; } } } } catch (SQLException | RuntimeException e) { log.error(e.getMessage(), e); } if (this.cacheableLogic == null) { return new ResultsPage(); } else { return new ResultsPage(this.cacheableLogic.readFromCache(cacheableQueryRowList), (hitPageByteTrigger ? ResultsPage.Status.PARTIAL : ResultsPage.Status.COMPLETE)); } }
Example 6
Source File: DefaultAdaptor.java From kylin with Apache License 2.0 | 5 votes |
@Override public List<String> listColumns(String database, String tableName) throws SQLException { List<String> ret = new ArrayList<>(); CachedRowSet columnsRs = getTableColumns(database, tableName); while (columnsRs.next()) { String name = columnsRs.getString("COLUMN_NAME"); if (StringUtils.isNotBlank(name)) { ret.add(name); } } return ret; }
Example 7
Source File: DefaultAdaptor.java From kylin with Apache License 2.0 | 5 votes |
/** * Get All columns for sql case sensitive * @return * @throws SQLException */ public List<String> listColumns() throws SQLException { List<String> ret = new ArrayList<>(); if (columnsCache == null || columnsCache.size() == 0) { CachedRowSet columnsRs = null; try (Connection conn = getConnection(); ResultSet rs = conn.getMetaData().getColumns(null, null, null, null)) { columnsRs = cacheResultSet(rs); } while (columnsRs.next()) { String database = columnsRs.getString("TABLE_SCHEM") != null ? columnsRs.getString("TABLE_SCHEM") : columnsRs.getString("TABLE_CAT"); String table = columnsRs.getString("TABLE_NAME"); String column = columnsRs.getString("COLUMN_NAME"); String cacheKey = joiner.join(config.datasourceId, config.url, database, table, "columns"); List<String> cachedColumns = columnsCache.getIfPresent(cacheKey); if (cachedColumns == null) { cachedColumns = new ArrayList<>(); columnsCache.put(cacheKey, cachedColumns); logger.debug("Add column cache for table {}.{}", database, table); } if (!cachedColumns.contains(column)) { cachedColumns.add(column); } ret.add(column); } } else { for (Map.Entry<String, List<String>> entry : columnsCache.asMap().entrySet()) { ret.addAll(entry.getValue()); } } return ret; }