@Test public void databaseWithLogicalTypes() throws Exception { List<Row> expected = new ArrayList<>(); Row row = new Row(); row.add("ID", 1); row.add("NAME", "alice"); row.add("DATE_COL", new Date(CURRENT_TS).toLocalDate()); row.add("TIME_COL", new Time(CURRENT_TS).toLocalTime()); row.add("TIMESTAMP_COL", new Timestamp(CURRENT_TS).toInstant().atZone(ZoneId.of("UTC"))); expected.add(row); row = new Row(); row.add("ID", 2); row.add("NAME", "bob"); row.add("DATE_COL", new Date(CURRENT_TS).toLocalDate()); row.add("TIME_COL", null); row.add("TIMESTAMP_COL", null); expected.add(row); try (Connection conn = getConnection(); Statement stmt = conn.createStatement()) { stmt.execute("SELECT * FROM \"my_table\""); try (ResultSet resultSet = stmt.getResultSet()) { List<Row> actual = DatabaseHandler.getRows(2, resultSet); Assert.assertEquals(expected.get(0).getValue(0), actual.get(0).getValue(0)); Assert.assertEquals(expected.get(0).getValue(1), actual.get(0).getValue(1)); Assert.assertEquals(expected.get(0).getValue(2), actual.get(0).getValue(2)); Assert.assertEquals(expected.get(0).getValue(3), actual.get(0).getValue(3)); Assert.assertEquals(expected.get(0).getValue(4), actual.get(0).getValue(4)); Assert.assertEquals(expected.get(1).getValue(0), actual.get(1).getValue(0)); Assert.assertEquals(expected.get(1).getValue(1), actual.get(1).getValue(1)); Assert.assertEquals(expected.get(1).getValue(2), actual.get(1).getValue(2)); Assert.assertEquals(expected.get(1).getValue(3), actual.get(1).getValue(3)); Assert.assertEquals(expected.get(1).getValue(4), actual.get(1).getValue(4)); } } }
@VisibleForTesting static List<Row> getRows(int lines, ResultSet result) throws SQLException { List<Row> rows = new ArrayList<>(); ResultSetMetaData meta = result.getMetaData(); int count = lines; while (result.next() && count > 0) { Row row = new Row(); for (int i = 1; i < meta.getColumnCount() + 1; ++i) { Object object = result.getObject(i); if (object != null) { if (object instanceof Date) { object = ((Date) object).toLocalDate(); } else if (object instanceof Time) { object = ((Time) object).toLocalTime(); } else if (object instanceof Timestamp) { object = ((Timestamp) object).toInstant().atZone(ZoneId.ofOffset("UTC", ZoneOffset.UTC)); } else if (object.getClass().getName().equals("oracle.sql.ROWID")) { object = object.toString(); } } row.add(meta.getColumnName(i), object); } rows.add(row); count--; } return rows; }
DatabaseHandler extends AbstractWranglerHandler { @VisibleForTesting static List<Row> getRows(int lines, ResultSet result) throws SQLException { List<Row> rows = new ArrayList<>(); ResultSetMetaData meta = result.getMetaData(); int count = lines; while (result.next() && count > 0) { Row row = new Row(); for (int i = 1; i < meta.getColumnCount() + 1; ++i) { Object object = result.getObject(i); if (object != null) { if (object instanceof Date) { object = ((Date) object).toLocalDate(); } else if (object instanceof Time) { object = ((Time) object).toLocalTime(); } else if (object instanceof Timestamp) { object = ((Timestamp) object).toInstant().atZone(ZoneId.ofOffset("UTC", ZoneOffset.UTC)); } else if (object.getClass().getName().equals("oracle.sql.ROWID")) { object = object.toString(); } } row.add(meta.getColumnName(i), object); } rows.add(row); count--; } return rows; } }
DatabaseHandler extends AbstractWranglerHandler { @VisibleForTesting static List<Row> getRows(int lines, ResultSet result) throws SQLException { List<Row> rows = new ArrayList<>(); ResultSetMetaData meta = result.getMetaData(); int count = lines; while (result.next() && count > 0) { Row row = new Row(); for (int i = 1; i < meta.getColumnCount() + 1; ++i) { Object object = result.getObject(i); if (object != null) { if (object instanceof Date) { object = ((Date) object).toLocalDate(); } else if (object instanceof Time) { object = ((Time) object).toLocalTime(); } else if (object instanceof Timestamp) { object = ((Timestamp) object).toInstant().atZone(ZoneId.ofOffset("UTC", ZoneOffset.UTC)); } else if (object.getClass().getName().equals("oracle.sql.ROWID")) { object = object.toString(); } } row.add(meta.getColumnName(i), object); } rows.add(row); count--; } return rows; }  }
DatabaseHandler extends AbstractWranglerHandler { @VisibleForTesting static List<Row> getRows(int lines, ResultSet result) throws SQLException { List<Row> rows = new ArrayList<>(); ResultSetMetaData meta = result.getMetaData(); int count = lines; while (result.next() && count > 0) { Row row = new Row(); for (int i = 1; i < meta.getColumnCount() + 1; ++i) { Object object = result.getObject(i); if (object != null) { if (object instanceof Date) { object = ((Date) object).toLocalDate(); } else if (object instanceof Time) { object = ((Time) object).toLocalTime(); } else if (object instanceof Timestamp) { object = ((Timestamp) object).toInstant().atZone(ZoneId.ofOffset("UTC", ZoneOffset.UTC)); } else if (object.getClass().getName().equals("oracle.sql.ROWID")) { object = object.toString(); } } row.add(meta.getColumnName(i), object); } rows.add(row); count--; } return rows; }  @Override void initialize(SystemHttpServiceContext context); @GET @Path("contexts/{context}/jdbc/drivers") @TransactionPolicy(value = TransactionControl.EXPLICIT) void listDrivers(HttpServiceRequest request, HttpServiceResponder responder,
                          @PathParam("context") String namespace); @GET @Path("contexts/{context}/jdbc/allowed") @TransactionPolicy(value = TransactionControl.EXPLICIT) void listAvailableDrivers(HttpServiceRequest request, HttpServiceResponder responder,
                                   @PathParam("context") String namespace); @POST @Path("contexts/{context}/connections/jdbc/test") @TransactionPolicy(value = TransactionControl.EXPLICIT) void testConnection(HttpServiceRequest request, HttpServiceResponder responder,
                             @PathParam("context") String namespace); @POST @Path("contexts/{context}/connections/databases") @TransactionPolicy(value = TransactionControl.EXPLICIT) void listDatabases(HttpServiceRequest request, HttpServiceResponder responder,
                            @PathParam("context") String namespace); @GET @Path("contexts/{context}/connections/{id}/tables") @TransactionPolicy(value = TransactionControl.EXPLICIT) void listTables(HttpServiceRequest request, HttpServiceResponder responder,
                         @PathParam("context") String namespace, @PathParam("id") String id); @GET @Path("contexts/{context}/connections/{id}/tables/{table}/read") @TransactionPolicy(value = TransactionControl.EXPLICIT) void read(HttpServiceRequest request, HttpServiceResponder responder,
                   @PathParam("context") String namespace, @PathParam("id") String id, @PathParam("table") String table,
                   @QueryParam("lines") int lines,
                   @QueryParam("scope") @DefaultValue(WorkspaceDataset.DEFAULT_SCOPE) String scope); @GET @Path("contexts/{context}/connections/{id}/tables/{table}/specification") @TransactionPolicy(value = TransactionControl.EXPLICIT) void specification(HttpServiceRequest request, HttpServiceResponder responder,
                            @PathParam("context") String namespace, @PathParam("id") String id,
                            @PathParam("table") String table); }
DatabaseHandler extends AbstractWranglerHandler { @VisibleForTesting static List<Row> getRows(int lines, ResultSet result) throws SQLException { List<Row> rows = new ArrayList<>(); ResultSetMetaData meta = result.getMetaData(); int count = lines; while (result.next() && count > 0) { Row row = new Row(); for (int i = 1; i < meta.getColumnCount() + 1; ++i) { Object object = result.getObject(i); if (object != null) { if (object instanceof Date) { object = ((Date) object).toLocalDate(); } else if (object instanceof Time) { object = ((Time) object).toLocalTime(); } else if (object instanceof Timestamp) { object = ((Timestamp) object).toInstant().atZone(ZoneId.ofOffset("UTC", ZoneOffset.UTC)); } else if (object.getClass().getName().equals("oracle.sql.ROWID")) { object = object.toString(); } } row.add(meta.getColumnName(i), object); } rows.add(row); count--; } return rows; }  @Override void initialize(SystemHttpServiceContext context); @GET @Path("contexts/{context}/jdbc/drivers") @TransactionPolicy(value = TransactionControl.EXPLICIT) void listDrivers(HttpServiceRequest request, HttpServiceResponder responder,
                          @PathParam("context") String namespace); @GET @Path("contexts/{context}/jdbc/allowed") @TransactionPolicy(value = TransactionControl.EXPLICIT) void listAvailableDrivers(HttpServiceRequest request, HttpServiceResponder responder,
                                   @PathParam("context") String namespace); @POST @Path("contexts/{context}/connections/jdbc/test") @TransactionPolicy(value = TransactionControl.EXPLICIT) void testConnection(HttpServiceRequest request, HttpServiceResponder responder,
                             @PathParam("context") String namespace); @POST @Path("contexts/{context}/connections/databases") @TransactionPolicy(value = TransactionControl.EXPLICIT) void listDatabases(HttpServiceRequest request, HttpServiceResponder responder,
                            @PathParam("context") String namespace); @GET @Path("contexts/{context}/connections/{id}/tables") @TransactionPolicy(value = TransactionControl.EXPLICIT) void listTables(HttpServiceRequest request, HttpServiceResponder responder,
                         @PathParam("context") String namespace, @PathParam("id") String id); @GET @Path("contexts/{context}/connections/{id}/tables/{table}/read") @TransactionPolicy(value = TransactionControl.EXPLICIT) void read(HttpServiceRequest request, HttpServiceResponder responder,
                   @PathParam("context") String namespace, @PathParam("id") String id, @PathParam("table") String table,
                   @QueryParam("lines") int lines,
                   @QueryParam("scope") @DefaultValue(WorkspaceDataset.DEFAULT_SCOPE) String scope); @GET @Path("contexts/{context}/connections/{id}/tables/{table}/specification") @TransactionPolicy(value = TransactionControl.EXPLICIT) void specification(HttpServiceRequest request, HttpServiceResponder responder,
                            @PathParam("context") String namespace, @PathParam("id") String id,
                            @PathParam("table") String table);  }