@DataProvider(name = "RowSetValues") private Object[][] RowSetValues() throws SQLException { RowSetFactory rsf = RowSetProvider.newFactory(); RowSetFactory rsf1 = RowSetProvider.newFactory(STUB_FACTORY_CLASSNAME, null); return new Object[][]{ {rsf, DEFAULT_CACHEDROWSET_CLASSNAME}, {rsf, DEFAULT_FILTEREDROWSET_CLASSNAME}, {rsf, DEFAULT_JDBCROWSET_CLASSNAME}, {rsf, DEFAULT_JOINROWSET_CLASSNAME}, {rsf, DEFAULT_WEBROWSET_CLASSNAME}, {rsf1, STUB_CACHEDROWSET_CLASSNAME}, {rsf1, STUB_FILTEREDROWSET_CLASSNAME}, {rsf1, STUB_JDBCROWSET_CLASSNAME}, {rsf1, STUB_JOINROWSET_CLASSNAME}, {rsf1, STUB_WEBROWSET_CLASSNAME} }; }
@Override public IResult execute(IProgressListener listener) throws Exception { Connection con = null; Statement st = null; ResultSet rs = null; try { con = OptiqDataSource.getConnection(snapshot); st = con.createStatement(); rs = st.executeQuery(sql); RowSetFactory rowSetFactory = RowSetProvider.newFactory(); CachedRowSet rowSet = rowSetFactory.createCachedRowSet(); rowSet.populate(rs); return new RowSetTable(rowSet); } finally { OptiqDataSource.close(rs, st, con); } }
private void fillWithQuery(String query) { try { RowSetFactory rowSetFactory = RowSetProvider.newFactory(); dataModel = rowSetFactory.createJdbcRowSet(); dataModel.setUrl(conn.getMetaData().getURL()); dataModel.setUsername(conn.getMetaData().getUserName()); dataModel.setPassword(""); dataModel.setCommand(query); dataModel.execute(); columnsMetaData = dataModel.getMetaData(); fireTableDataChanged(); } catch (SQLException ex) { ex.printStackTrace(); } }
public static void main(String[] args) throws SQLException { Connection conn = CreateH2Database.createSimpleDatabase("~/test", true, true); RowSetFactory rowSetFactory = RowSetProvider.newFactory(); JdbcRowSet dataModel = rowSetFactory.createJdbcRowSet(); dataModel.setUrl(conn.getMetaData().getURL()); dataModel.setUsername(conn.getMetaData().getUserName()); dataModel.setPassword(""); dataModel.setCommand("select * from test_table"); dataModel.execute(); // now update the database dataModel.absolute(1); dataModel.setString(2, "Hello world 2"); // This throws an exception but according to // http://docs.oracle.com/javase/tutorial/jdbc/basics/jdbcrowset.html#updating-column-value // it shouldn't try { dataModel.updateRow(); } catch (Exception ex) { ex.printStackTrace(); } conn.close(); }
private void validateRowSetImpl(RowSetFactory rsf, String implName) throws SQLException { assertNotNull(rsf, "RowSetFactory should not be null"); switch (implName) { case DEFAULT_CACHEDROWSET_CLASSNAME: assertTrue(rsf.createCachedRowSet() instanceof com.sun.rowset.CachedRowSetImpl); break; case DEFAULT_FILTEREDROWSET_CLASSNAME: assertTrue(rsf.createFilteredRowSet() instanceof com.sun.rowset.FilteredRowSetImpl); break; case DEFAULT_JDBCROWSET_CLASSNAME: assertTrue(rsf.createJdbcRowSet() instanceof com.sun.rowset.JdbcRowSetImpl); break; case DEFAULT_JOINROWSET_CLASSNAME: assertTrue(rsf.createJoinRowSet() instanceof com.sun.rowset.JoinRowSetImpl); break; case DEFAULT_WEBROWSET_CLASSNAME: assertTrue(rsf.createWebRowSet() instanceof com.sun.rowset.WebRowSetImpl); break; case STUB_CACHEDROWSET_CLASSNAME: assertTrue(rsf.createCachedRowSet() instanceof util.StubCachedRowSetImpl); break; case STUB_FILTEREDROWSET_CLASSNAME: assertTrue(rsf.createFilteredRowSet() instanceof util.StubFilteredRowSetImpl); break; case STUB_JDBCROWSET_CLASSNAME: assertTrue(rsf.createJdbcRowSet() instanceof util.StubJdbcRowSetImpl); break; case STUB_WEBROWSET_CLASSNAME: assertTrue(rsf.createWebRowSet() instanceof util.StubWebRowSetImpl); break; } }
private void validateProvider(RowSetFactory rsf, String implName) { assertNotNull(rsf, "RowSetFactory should not be null"); switch (implName) { case DEFFAULT_FACTORY_CLASSNAME: assertTrue(rsf instanceof RowSetFactoryImpl); break; case STUB_FACTORY_CLASSNAME: assertTrue(rsf instanceof StubRowSetFactory); break; default: } }
@DataProvider(name = "RowSetFactoryValues") private Object[][] RowSetFactoryValues() throws SQLException { RowSetFactory rsf = RowSetProvider.newFactory(); RowSetFactory rsf1 = RowSetProvider.newFactory(STUB_FACTORY_CLASSNAME, null); RowSetFactory rsf2 = RowSetProvider.newFactory(DEFFAULT_FACTORY_CLASSNAME, null); return new Object[][]{ {rsf, NO_VALADATE_IMPL}, {rsf, DEFFAULT_FACTORY_CLASSNAME}, {rsf1, STUB_FACTORY_CLASSNAME}, {rsf2, DEFFAULT_FACTORY_CLASSNAME} }; }
public static void main(String[] args) throws Exception { RowSet rs; RowSetFactory rsFactory = RowSetProvider.newFactory(); rs = rsFactory.createCachedRowSet(); rs.setUrl("jdbc:postgresql:tmclub"); rs.setUsername("ian"); rs.setPassword("secret"); rs.setCommand("select * from members where name like ?"); rs.setString(1, "I%"); // This will cause the RowSet to connect, fetch its data, and // disconnect rs.execute(); // Some time later, the client tries to do something. // Suppose we want to update data: while (rs.next()) { if (rs.getInt("id") == 42) { rs.setString(1, "Marvin"); rs.updateRow(); // Normal JDBC // This additional call tells the CachedRowSet to connect // to its database and send the updated data back. rs.updateRow(); } } // If we're all done... rs.close(); }
@Test(dataProvider = "RowSetValues", enabled = true) public void test(RowSetFactory rsf, String impl) throws SQLException { validateRowSetImpl(rsf, impl); }
@Test(dataProvider = "RowSetFactoryValues") public void test(RowSetFactory rsf, String impl) throws SQLException { validateProvider(rsf, impl); }
@Test(expectedExceptions = SQLException.class) public void test03() throws SQLException { System.setProperty("javax.sql.rowset.RowSetFactory", "invalid.RowSetFactoryImpl"); RowSetFactory rsf = RowSetProvider.newFactory(); }
@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); } }