Java Code Examples for javax.sql.rowset.CachedRowSet#populate()

The following examples show how to use javax.sql.rowset.CachedRowSet#populate() . 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: StatementSelect.java    From cactoos-jdbc with MIT License 5 votes vote down vote up
@Override
public ResultSet result() throws Exception {
    // @checkstyle NestedTryDepthCheck (10 lines)
    try (Connection conn = this.session.connection()) {
        try (PreparedStatement stmt = this.query.prepared(conn)) {
            try (ResultSet rset = stmt.executeQuery()) {
                final RowSetFactory rsf = RowSetProvider.newFactory();
                final CachedRowSet crs = rsf.createCachedRowSet();
                crs.populate(rset);
                return crs;
            }
        }
    }
}
 
Example 2
Source File: TestFBResultSetMetaData.java    From jaybird with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Tests if the columnLabelForName strategy allows com.sun.rowset.CachedRowSetImpl to
 * access rows by their columnLabel.
 */
@Test
public void cachedRowSetImpl_columnLabelForName() throws Exception {
    Properties props = getDefaultPropertiesForConnection();
    props.put("columnLabelForName", "true");

    try (Connection con = DriverManager.getConnection(getUrl(), props)) {
        Statement stmt = con.createStatement();
        ResultSet rs = stmt.executeQuery(
                "SELECT id, simple_field AS column2, int_field AS column3, 2 - 1 AS column4 FROM test_rs_metadata");

        RowSetFactory aFactory = RowSetProvider.newFactory();
        CachedRowSet rowSet = aFactory.createCachedRowSet();
        rowSet.populate(rs);

        assertEquals(1, rowSet.findColumn("id"));
        assertEquals(2, rowSet.findColumn("column2"));
        assertEquals(3, rowSet.findColumn("column3"));
        assertEquals(4, rowSet.findColumn("column4"));

        try {
            rowSet.findColumn("simple_field");
            fail("Looking up column with original column name should fail with columnLabelForName strategy");
        } catch (SQLException ex) {
            // expected
        }
        rowSet.close();
        stmt.close();
    }
}
 
Example 3
Source File: Query.java    From mat-calcite-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public IResult execute(IProgressListener listener) throws Exception {
	Connection con = null;
	Statement st = null;
	ResultSet rs = null;

	try {
		con = CalciteDataSource.getConnection(snapshot);

		st = con.createStatement();
		rs = st.executeQuery(sql);

		RowSetFactory rowSetFactory = RowSetProvider.newFactory();
		CachedRowSet rowSet = rowSetFactory.createCachedRowSet();
		rowSet.populate(rs);

		ResultSetMetaData md = rowSet.getMetaData();
		if (md.getColumnCount() == 1 && "PLAN".equals(md.getColumnName(1))
				&& rowSet.size() == 1
				&& EXPLAIN_PLAN.matcher(sql).find()) {
			rowSet.absolute(1);
			String plan = rowSet.getString(1);
			System.out.println("plan = " + plan);
			{
				Matcher ind = RENAME_INDEX.matcher(plan);
				StringBuffer sb = new StringBuffer();
				while (ind.find()) {
					String className = ind.group(1).replace(", ", ".") + ind.group(2);
					ind.appendReplacement(sb, "GetObjectIdsByClass (class=" + className + ")");
				}
				ind.appendTail(sb);
				plan = sb.toString();
			}
			plan = RENAME_JOIN.matcher(plan).replaceAll("HashJoin ");
			plan = RENAME_CALC.matcher(plan).replaceAll("View ");
			plan = TRIM_ENUMERABLE.matcher(plan).replaceAll("$1 ");
			return new TextResult(plan, false);
		}

		return new RowSetTable(rowSet);
	} finally {
		CalciteDataSource.close(rs, st, con);
	}
}
 
Example 4
Source File: SqlRowSetResultSetExtractor.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * Create a {@link SqlRowSet} that wraps the given {@link ResultSet},
 * representing its data in a disconnected fashion.
 * <p>This implementation creates a Spring {@link ResultSetWrappingSqlRowSet}
 * instance that wraps a standard JDBC {@link CachedRowSet} instance.
 * Can be overridden to use a different implementation.
 * @param rs the original ResultSet (connected)
 * @return the disconnected SqlRowSet
 * @throws SQLException if thrown by JDBC methods
 * @see #newCachedRowSet()
 * @see org.springframework.jdbc.support.rowset.ResultSetWrappingSqlRowSet
 */
protected SqlRowSet createSqlRowSet(ResultSet rs) throws SQLException {
	CachedRowSet rowSet = newCachedRowSet();
	rowSet.populate(rs);
	return new ResultSetWrappingSqlRowSet(rowSet);
}
 
Example 5
Source File: AbstractJdbcAdaptor.java    From kylin-on-parquet-v2 with Apache License 2.0 2 votes vote down vote up
/**
 * Convert a <C>ResultSet</C> to <C>CachedRowSet</C>, because <C>ResultSet</C> relies on the connection kept Open, but <C>CachedRowSet</C> not.
 * @param resultSet
 * @return
 * @throws SQLException
 */
protected CachedRowSet cacheResultSet(ResultSet resultSet) throws SQLException {
    CachedRowSet crs = new FixedCachedRowSetImpl();
    crs.populate(resultSet);
    return crs;
}
 
Example 6
Source File: SqlRowSetResultSetExtractor.java    From java-technology-stack with MIT License 2 votes vote down vote up
/**
 * Create a {@link SqlRowSet} that wraps the given {@link ResultSet},
 * representing its data in a disconnected fashion.
 * <p>This implementation creates a Spring {@link ResultSetWrappingSqlRowSet}
 * instance that wraps a standard JDBC {@link CachedRowSet} instance.
 * Can be overridden to use a different implementation.
 * @param rs the original ResultSet (connected)
 * @return the disconnected SqlRowSet
 * @throws SQLException if thrown by JDBC methods
 * @see #newCachedRowSet()
 * @see org.springframework.jdbc.support.rowset.ResultSetWrappingSqlRowSet
 */
protected SqlRowSet createSqlRowSet(ResultSet rs) throws SQLException {
	CachedRowSet rowSet = newCachedRowSet();
	rowSet.populate(rs);
	return new ResultSetWrappingSqlRowSet(rowSet);
}
 
Example 7
Source File: SqlRowSetResultSetExtractor.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Create a SqlRowSet that wraps the given ResultSet,
 * representing its data in a disconnected fashion.
 * <p>This implementation creates a Spring ResultSetWrappingSqlRowSet
 * instance that wraps a standard JDBC CachedRowSet instance.
 * Can be overridden to use a different implementation.
 * @param rs the original ResultSet (connected)
 * @return the disconnected SqlRowSet
 * @throws SQLException if thrown by JDBC methods
 * @see #newCachedRowSet
 * @see org.springframework.jdbc.support.rowset.ResultSetWrappingSqlRowSet
 */
protected SqlRowSet createSqlRowSet(ResultSet rs) throws SQLException {
	CachedRowSet rowSet = newCachedRowSet();
	rowSet.populate(rs);
	return new ResultSetWrappingSqlRowSet(rowSet);
}
 
Example 8
Source File: SqlRowSetResultSetExtractor.java    From spring4-understanding with Apache License 2.0 2 votes vote down vote up
/**
 * Create a SqlRowSet that wraps the given ResultSet,
 * representing its data in a disconnected fashion.
 * <p>This implementation creates a Spring ResultSetWrappingSqlRowSet
 * instance that wraps a standard JDBC CachedRowSet instance.
 * Can be overridden to use a different implementation.
 * @param rs the original ResultSet (connected)
 * @return the disconnected SqlRowSet
 * @throws SQLException if thrown by JDBC methods
 * @see #newCachedRowSet
 * @see org.springframework.jdbc.support.rowset.ResultSetWrappingSqlRowSet
 */
protected SqlRowSet createSqlRowSet(ResultSet rs) throws SQLException {
	CachedRowSet rowSet = newCachedRowSet();
	rowSet.populate(rs);
	return new ResultSetWrappingSqlRowSet(rowSet);
}
 
Example 9
Source File: AbstractJdbcAdaptor.java    From kylin with Apache License 2.0 2 votes vote down vote up
/**
 * Convert a <C>ResultSet</C> to <C>CachedRowSet</C>, because <C>ResultSet</C> relies on the connection kept Open, but <C>CachedRowSet</C> not.
 * @param resultSet
 * @return
 * @throws SQLException
 */
protected CachedRowSet cacheResultSet(ResultSet resultSet) throws SQLException {
    CachedRowSet crs = new FixedCachedRowSetImpl();
    crs.populate(resultSet);
    return crs;
}
 
Example 10
Source File: SqlRowSetResultSetExtractor.java    From effectivejava with Apache License 2.0 2 votes vote down vote up
/**
 * Create a SqlRowSet that wraps the given ResultSet,
 * representing its data in a disconnected fashion.
 * <p>This implementation creates a Spring ResultSetWrappingSqlRowSet
 * instance that wraps a standard JDBC CachedRowSet instance.
 * Can be overridden to use a different implementation.
 * @param rs the original ResultSet (connected)
 * @return the disconnected SqlRowSet
 * @throws SQLException if thrown by JDBC methods
 * @see #newCachedRowSet
 * @see org.springframework.jdbc.support.rowset.ResultSetWrappingSqlRowSet
 */
protected SqlRowSet createSqlRowSet(ResultSet rs) throws SQLException {
	CachedRowSet rowSet = newCachedRowSet();
	rowSet.populate(rs);
	return new ResultSetWrappingSqlRowSet(rowSet);
}