korlov42 commented on code in PR #6507: URL: https://github.com/apache/ignite-3/pull/6507#discussion_r2313009424
########## modules/jdbc/src/main/java/org/apache/ignite/internal/jdbc2/JdbcResultSet.java: ########## @@ -0,0 +1,2162 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.jdbc2; + +import static java.nio.charset.StandardCharsets.UTF_8; + +import java.io.InputStream; +import java.io.Reader; +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.net.MalformedURLException; +import java.net.URL; +import java.nio.ByteBuffer; +import java.sql.Array; +import java.sql.Blob; +import java.sql.Clob; +import java.sql.Date; +import java.sql.NClob; +import java.sql.Ref; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.RowId; +import java.sql.SQLException; +import java.sql.SQLFeatureNotSupportedException; +import java.sql.SQLWarning; +import java.sql.SQLXML; +import java.sql.Statement; +import java.sql.Time; +import java.sql.Timestamp; +import java.text.DecimalFormat; +import java.text.DecimalFormatSymbols; +import java.text.ParseException; +import java.time.Instant; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeFormatterBuilder; +import java.time.temporal.ChronoField; +import java.time.temporal.TemporalAccessor; +import java.util.Calendar; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; +import java.util.UUID; +import java.util.function.Supplier; +import org.apache.ignite.internal.jdbc.proto.SqlStateCode; +import org.apache.ignite.internal.util.StringUtils; +import org.apache.ignite.sql.ResultSetMetadata; +import org.apache.ignite.sql.SqlRow; + +/** + * JDBC ResultSet adapter backed by {@code org.apache.ignite.sql.ResultSet<SqlRow>}. + * + * <p>This is a minimal implementation to provide forward-only, read-only access to rows. + * Many optional JDBC operations are not supported and will throw SQLFeatureNotSupportedException.</p> + */ +public class JdbcResultSet implements ResultSet { + /** Decimal format to convert string to decimal. */ + private static final ThreadLocal<DecimalFormat> decimalFormat = new ThreadLocal<>() { + /** {@inheritDoc} */ + @Override + protected DecimalFormat initialValue() { + DecimalFormatSymbols symbols = new DecimalFormatSymbols(); + + symbols.setGroupingSeparator(','); + symbols.setDecimalSeparator('.'); + + DecimalFormat decimalFormat = new DecimalFormat("", symbols); + + decimalFormat.setParseBigDecimal(true); + + return decimalFormat; + } + }; + + private final org.apache.ignite.sql.ResultSet<SqlRow> rs; + + private final Statement statement; + + private final Supplier<ZoneId> getZoneId; + + private Map<String, Integer> columnOrder; + + private int fetchSize; + + private SqlRow currentRow; Review Comment: let's mark as `@Nullable` ########## modules/jdbc/src/main/java/org/apache/ignite/internal/jdbc2/JdbcResultSet.java: ########## @@ -0,0 +1,2162 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.jdbc2; + +import static java.nio.charset.StandardCharsets.UTF_8; + +import java.io.InputStream; +import java.io.Reader; +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.net.MalformedURLException; +import java.net.URL; +import java.nio.ByteBuffer; +import java.sql.Array; +import java.sql.Blob; +import java.sql.Clob; +import java.sql.Date; +import java.sql.NClob; +import java.sql.Ref; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.RowId; +import java.sql.SQLException; +import java.sql.SQLFeatureNotSupportedException; +import java.sql.SQLWarning; +import java.sql.SQLXML; +import java.sql.Statement; +import java.sql.Time; +import java.sql.Timestamp; +import java.text.DecimalFormat; +import java.text.DecimalFormatSymbols; +import java.text.ParseException; +import java.time.Instant; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeFormatterBuilder; +import java.time.temporal.ChronoField; +import java.time.temporal.TemporalAccessor; +import java.util.Calendar; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; +import java.util.UUID; +import java.util.function.Supplier; +import org.apache.ignite.internal.jdbc.proto.SqlStateCode; +import org.apache.ignite.internal.util.StringUtils; +import org.apache.ignite.sql.ResultSetMetadata; +import org.apache.ignite.sql.SqlRow; + +/** + * JDBC ResultSet adapter backed by {@code org.apache.ignite.sql.ResultSet<SqlRow>}. + * + * <p>This is a minimal implementation to provide forward-only, read-only access to rows. + * Many optional JDBC operations are not supported and will throw SQLFeatureNotSupportedException.</p> + */ +public class JdbcResultSet implements ResultSet { + /** Decimal format to convert string to decimal. */ + private static final ThreadLocal<DecimalFormat> decimalFormat = new ThreadLocal<>() { + /** {@inheritDoc} */ + @Override + protected DecimalFormat initialValue() { + DecimalFormatSymbols symbols = new DecimalFormatSymbols(); + + symbols.setGroupingSeparator(','); + symbols.setDecimalSeparator('.'); + + DecimalFormat decimalFormat = new DecimalFormat("", symbols); + + decimalFormat.setParseBigDecimal(true); + + return decimalFormat; + } + }; + + private final org.apache.ignite.sql.ResultSet<SqlRow> rs; + + private final Statement statement; + + private final Supplier<ZoneId> getZoneId; + + private Map<String, Integer> columnOrder; + + private int fetchSize; + + private SqlRow currentRow; + + private int currentPosition; + + private boolean closed; + + private boolean wasNull; + + private JdbcResultSetMetadata meta; + + /** + * Constructor. + */ + public JdbcResultSet( + org.apache.ignite.sql.ResultSet<SqlRow> rs, + Statement statement, + Supplier<ZoneId> getZoneId, + int fetchSize + ) { + this.rs = rs; + this.statement = statement; + this.getZoneId = getZoneId; + this.fetchSize = fetchSize; + this.currentRow = null; + this.closed = false; + this.wasNull = false; + } + + @Override + public boolean next() throws SQLException { + ensureNotClosed(); + if (!rs.hasNext()) { + currentRow = null; + return false; + } + currentRow = rs.next(); + currentPosition += 1; Review Comment: nitpick: `currentPosition++` seems more natural to me ########## modules/jdbc/src/main/java/org/apache/ignite/internal/jdbc2/JdbcResultSet.java: ########## @@ -0,0 +1,2162 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.jdbc2; + +import static java.nio.charset.StandardCharsets.UTF_8; + +import java.io.InputStream; +import java.io.Reader; +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.net.MalformedURLException; +import java.net.URL; +import java.nio.ByteBuffer; +import java.sql.Array; +import java.sql.Blob; +import java.sql.Clob; +import java.sql.Date; +import java.sql.NClob; +import java.sql.Ref; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.RowId; +import java.sql.SQLException; +import java.sql.SQLFeatureNotSupportedException; +import java.sql.SQLWarning; +import java.sql.SQLXML; +import java.sql.Statement; +import java.sql.Time; +import java.sql.Timestamp; +import java.text.DecimalFormat; +import java.text.DecimalFormatSymbols; +import java.text.ParseException; +import java.time.Instant; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeFormatterBuilder; +import java.time.temporal.ChronoField; +import java.time.temporal.TemporalAccessor; +import java.util.Calendar; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; +import java.util.UUID; +import java.util.function.Supplier; +import org.apache.ignite.internal.jdbc.proto.SqlStateCode; +import org.apache.ignite.internal.util.StringUtils; +import org.apache.ignite.sql.ResultSetMetadata; +import org.apache.ignite.sql.SqlRow; + +/** + * JDBC ResultSet adapter backed by {@code org.apache.ignite.sql.ResultSet<SqlRow>}. + * + * <p>This is a minimal implementation to provide forward-only, read-only access to rows. + * Many optional JDBC operations are not supported and will throw SQLFeatureNotSupportedException.</p> + */ +public class JdbcResultSet implements ResultSet { + /** Decimal format to convert string to decimal. */ + private static final ThreadLocal<DecimalFormat> decimalFormat = new ThreadLocal<>() { Review Comment: why do we need this formatter? AFAIS, conversion from string to BD is as simple as `new BigDecimal(s.trim())` ########## modules/jdbc/src/main/java/org/apache/ignite/internal/jdbc2/JdbcResultSet.java: ########## @@ -0,0 +1,2162 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.jdbc2; + +import static java.nio.charset.StandardCharsets.UTF_8; + +import java.io.InputStream; +import java.io.Reader; +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.net.MalformedURLException; +import java.net.URL; +import java.nio.ByteBuffer; +import java.sql.Array; +import java.sql.Blob; +import java.sql.Clob; +import java.sql.Date; +import java.sql.NClob; +import java.sql.Ref; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.RowId; +import java.sql.SQLException; +import java.sql.SQLFeatureNotSupportedException; +import java.sql.SQLWarning; +import java.sql.SQLXML; +import java.sql.Statement; +import java.sql.Time; +import java.sql.Timestamp; +import java.text.DecimalFormat; +import java.text.DecimalFormatSymbols; +import java.text.ParseException; +import java.time.Instant; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeFormatterBuilder; +import java.time.temporal.ChronoField; +import java.time.temporal.TemporalAccessor; +import java.util.Calendar; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; +import java.util.UUID; +import java.util.function.Supplier; +import org.apache.ignite.internal.jdbc.proto.SqlStateCode; +import org.apache.ignite.internal.util.StringUtils; +import org.apache.ignite.sql.ResultSetMetadata; +import org.apache.ignite.sql.SqlRow; + +/** + * JDBC ResultSet adapter backed by {@code org.apache.ignite.sql.ResultSet<SqlRow>}. + * + * <p>This is a minimal implementation to provide forward-only, read-only access to rows. + * Many optional JDBC operations are not supported and will throw SQLFeatureNotSupportedException.</p> + */ +public class JdbcResultSet implements ResultSet { + /** Decimal format to convert string to decimal. */ + private static final ThreadLocal<DecimalFormat> decimalFormat = new ThreadLocal<>() { + /** {@inheritDoc} */ + @Override + protected DecimalFormat initialValue() { + DecimalFormatSymbols symbols = new DecimalFormatSymbols(); + + symbols.setGroupingSeparator(','); + symbols.setDecimalSeparator('.'); + + DecimalFormat decimalFormat = new DecimalFormat("", symbols); + + decimalFormat.setParseBigDecimal(true); + + return decimalFormat; + } + }; + + private final org.apache.ignite.sql.ResultSet<SqlRow> rs; + + private final Statement statement; + + private final Supplier<ZoneId> getZoneId; + + private Map<String, Integer> columnOrder; + + private int fetchSize; + + private SqlRow currentRow; + + private int currentPosition; + + private boolean closed; + + private boolean wasNull; + + private JdbcResultSetMetadata meta; + + /** + * Constructor. + */ + public JdbcResultSet( + org.apache.ignite.sql.ResultSet<SqlRow> rs, + Statement statement, + Supplier<ZoneId> getZoneId, + int fetchSize + ) { + this.rs = rs; + this.statement = statement; + this.getZoneId = getZoneId; + this.fetchSize = fetchSize; + this.currentRow = null; + this.closed = false; + this.wasNull = false; + } + + @Override + public boolean next() throws SQLException { + ensureNotClosed(); + if (!rs.hasNext()) { + currentRow = null; + return false; + } + currentRow = rs.next(); + currentPosition += 1; + return currentRow != null; + } + + @Override + public void close() throws SQLException { + closed = true; + rs.close(); + } + + /** {@inheritDoc} */ + @Override + public boolean wasNull() throws SQLException { + ensureNotClosed(); + ensureHasCurrentRow(); + + return wasNull; + } + + /** {@inheritDoc} */ + @Override + public String getString(int colIdx) throws SQLException { Review Comment: let's mark return type of all getters as `@Nullable` ########## modules/jdbc/src/main/java/org/apache/ignite/internal/jdbc2/JdbcResultSet.java: ########## @@ -0,0 +1,2162 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.jdbc2; + +import static java.nio.charset.StandardCharsets.UTF_8; + +import java.io.InputStream; +import java.io.Reader; +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.net.MalformedURLException; +import java.net.URL; +import java.nio.ByteBuffer; +import java.sql.Array; +import java.sql.Blob; +import java.sql.Clob; +import java.sql.Date; +import java.sql.NClob; +import java.sql.Ref; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.RowId; +import java.sql.SQLException; +import java.sql.SQLFeatureNotSupportedException; +import java.sql.SQLWarning; +import java.sql.SQLXML; +import java.sql.Statement; +import java.sql.Time; +import java.sql.Timestamp; +import java.text.DecimalFormat; +import java.text.DecimalFormatSymbols; +import java.text.ParseException; +import java.time.Instant; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeFormatterBuilder; +import java.time.temporal.ChronoField; +import java.time.temporal.TemporalAccessor; +import java.util.Calendar; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; +import java.util.UUID; +import java.util.function.Supplier; +import org.apache.ignite.internal.jdbc.proto.SqlStateCode; +import org.apache.ignite.internal.util.StringUtils; +import org.apache.ignite.sql.ResultSetMetadata; +import org.apache.ignite.sql.SqlRow; + +/** + * JDBC ResultSet adapter backed by {@code org.apache.ignite.sql.ResultSet<SqlRow>}. + * + * <p>This is a minimal implementation to provide forward-only, read-only access to rows. + * Many optional JDBC operations are not supported and will throw SQLFeatureNotSupportedException.</p> + */ +public class JdbcResultSet implements ResultSet { + /** Decimal format to convert string to decimal. */ + private static final ThreadLocal<DecimalFormat> decimalFormat = new ThreadLocal<>() { + /** {@inheritDoc} */ + @Override + protected DecimalFormat initialValue() { + DecimalFormatSymbols symbols = new DecimalFormatSymbols(); + + symbols.setGroupingSeparator(','); + symbols.setDecimalSeparator('.'); + + DecimalFormat decimalFormat = new DecimalFormat("", symbols); + + decimalFormat.setParseBigDecimal(true); + + return decimalFormat; + } + }; + + private final org.apache.ignite.sql.ResultSet<SqlRow> rs; + + private final Statement statement; + + private final Supplier<ZoneId> getZoneId; + + private Map<String, Integer> columnOrder; + + private int fetchSize; + + private SqlRow currentRow; + + private int currentPosition; + + private boolean closed; + + private boolean wasNull; + + private JdbcResultSetMetadata meta; + + /** + * Constructor. + */ + public JdbcResultSet( + org.apache.ignite.sql.ResultSet<SqlRow> rs, + Statement statement, + Supplier<ZoneId> getZoneId, + int fetchSize + ) { + this.rs = rs; + this.statement = statement; + this.getZoneId = getZoneId; + this.fetchSize = fetchSize; + this.currentRow = null; + this.closed = false; + this.wasNull = false; + } + + @Override + public boolean next() throws SQLException { + ensureNotClosed(); + if (!rs.hasNext()) { + currentRow = null; + return false; + } + currentRow = rs.next(); + currentPosition += 1; + return currentRow != null; + } + + @Override + public void close() throws SQLException { + closed = true; + rs.close(); Review Comment: it's declared that method `close` throws `java.sql.SQLException`, but method `close` on `org.apache.ignite.sql.ResultSet` may throw any sort of Ignite-specific-and-not-only errors. We need to introduce exception conversion ########## modules/jdbc/src/main/java/org/apache/ignite/internal/jdbc2/JdbcResultSet.java: ########## @@ -0,0 +1,2162 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.jdbc2; + +import static java.nio.charset.StandardCharsets.UTF_8; + +import java.io.InputStream; +import java.io.Reader; +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.net.MalformedURLException; +import java.net.URL; +import java.nio.ByteBuffer; +import java.sql.Array; +import java.sql.Blob; +import java.sql.Clob; +import java.sql.Date; +import java.sql.NClob; +import java.sql.Ref; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.RowId; +import java.sql.SQLException; +import java.sql.SQLFeatureNotSupportedException; +import java.sql.SQLWarning; +import java.sql.SQLXML; +import java.sql.Statement; +import java.sql.Time; +import java.sql.Timestamp; +import java.text.DecimalFormat; +import java.text.DecimalFormatSymbols; +import java.text.ParseException; +import java.time.Instant; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeFormatterBuilder; +import java.time.temporal.ChronoField; +import java.time.temporal.TemporalAccessor; +import java.util.Calendar; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; +import java.util.UUID; +import java.util.function.Supplier; +import org.apache.ignite.internal.jdbc.proto.SqlStateCode; +import org.apache.ignite.internal.util.StringUtils; +import org.apache.ignite.sql.ResultSetMetadata; +import org.apache.ignite.sql.SqlRow; + +/** + * JDBC ResultSet adapter backed by {@code org.apache.ignite.sql.ResultSet<SqlRow>}. + * + * <p>This is a minimal implementation to provide forward-only, read-only access to rows. + * Many optional JDBC operations are not supported and will throw SQLFeatureNotSupportedException.</p> + */ +public class JdbcResultSet implements ResultSet { + /** Decimal format to convert string to decimal. */ + private static final ThreadLocal<DecimalFormat> decimalFormat = new ThreadLocal<>() { + /** {@inheritDoc} */ + @Override + protected DecimalFormat initialValue() { + DecimalFormatSymbols symbols = new DecimalFormatSymbols(); + + symbols.setGroupingSeparator(','); + symbols.setDecimalSeparator('.'); + + DecimalFormat decimalFormat = new DecimalFormat("", symbols); + + decimalFormat.setParseBigDecimal(true); + + return decimalFormat; + } + }; + + private final org.apache.ignite.sql.ResultSet<SqlRow> rs; + + private final Statement statement; + + private final Supplier<ZoneId> getZoneId; + + private Map<String, Integer> columnOrder; + + private int fetchSize; + + private SqlRow currentRow; + + private int currentPosition; + + private boolean closed; + + private boolean wasNull; + + private JdbcResultSetMetadata meta; + + /** + * Constructor. + */ + public JdbcResultSet( + org.apache.ignite.sql.ResultSet<SqlRow> rs, + Statement statement, + Supplier<ZoneId> getZoneId, + int fetchSize + ) { + this.rs = rs; + this.statement = statement; + this.getZoneId = getZoneId; + this.fetchSize = fetchSize; + this.currentRow = null; + this.closed = false; + this.wasNull = false; + } + + @Override + public boolean next() throws SQLException { + ensureNotClosed(); + if (!rs.hasNext()) { + currentRow = null; + return false; + } + currentRow = rs.next(); + currentPosition += 1; + return currentRow != null; + } + + @Override + public void close() throws SQLException { + closed = true; + rs.close(); + } + + /** {@inheritDoc} */ + @Override + public boolean wasNull() throws SQLException { + ensureNotClosed(); + ensureHasCurrentRow(); + + return wasNull; + } + + /** {@inheritDoc} */ + @Override + public String getString(int colIdx) throws SQLException { + Object value = getValue(colIdx); + + if (value == null) { + return null; + } else if (value instanceof Instant) { + LocalDateTime localDateTime = instantWithLocalTimeZone((Instant) value); + + initMetadata(); Review Comment: first, why do we need lazy initialization in case of simple wrappers like `JdbcResultSetMetadata`? second, meta is used all temporal types but initialized only for value of class `Instant`. How is it supposed to work for `LocalTime ` and `LocalDateTime `. We need to improve test coverage ########## modules/jdbc/src/main/java/org/apache/ignite/internal/jdbc2/JdbcResultSet.java: ########## @@ -0,0 +1,2162 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.jdbc2; + +import static java.nio.charset.StandardCharsets.UTF_8; + +import java.io.InputStream; +import java.io.Reader; +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.net.MalformedURLException; +import java.net.URL; +import java.nio.ByteBuffer; +import java.sql.Array; +import java.sql.Blob; +import java.sql.Clob; +import java.sql.Date; +import java.sql.NClob; +import java.sql.Ref; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.RowId; +import java.sql.SQLException; +import java.sql.SQLFeatureNotSupportedException; +import java.sql.SQLWarning; +import java.sql.SQLXML; +import java.sql.Statement; +import java.sql.Time; +import java.sql.Timestamp; +import java.text.DecimalFormat; +import java.text.DecimalFormatSymbols; +import java.text.ParseException; +import java.time.Instant; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeFormatterBuilder; +import java.time.temporal.ChronoField; +import java.time.temporal.TemporalAccessor; +import java.util.Calendar; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; +import java.util.UUID; +import java.util.function.Supplier; +import org.apache.ignite.internal.jdbc.proto.SqlStateCode; +import org.apache.ignite.internal.util.StringUtils; +import org.apache.ignite.sql.ResultSetMetadata; +import org.apache.ignite.sql.SqlRow; + +/** + * JDBC ResultSet adapter backed by {@code org.apache.ignite.sql.ResultSet<SqlRow>}. + * + * <p>This is a minimal implementation to provide forward-only, read-only access to rows. + * Many optional JDBC operations are not supported and will throw SQLFeatureNotSupportedException.</p> + */ +public class JdbcResultSet implements ResultSet { + /** Decimal format to convert string to decimal. */ + private static final ThreadLocal<DecimalFormat> decimalFormat = new ThreadLocal<>() { + /** {@inheritDoc} */ + @Override + protected DecimalFormat initialValue() { + DecimalFormatSymbols symbols = new DecimalFormatSymbols(); + + symbols.setGroupingSeparator(','); + symbols.setDecimalSeparator('.'); + + DecimalFormat decimalFormat = new DecimalFormat("", symbols); + + decimalFormat.setParseBigDecimal(true); + + return decimalFormat; + } + }; + + private final org.apache.ignite.sql.ResultSet<SqlRow> rs; + + private final Statement statement; + + private final Supplier<ZoneId> getZoneId; + + private Map<String, Integer> columnOrder; + + private int fetchSize; + + private SqlRow currentRow; + + private int currentPosition; + + private boolean closed; + + private boolean wasNull; + + private JdbcResultSetMetadata meta; + + /** + * Constructor. + */ + public JdbcResultSet( + org.apache.ignite.sql.ResultSet<SqlRow> rs, + Statement statement, + Supplier<ZoneId> getZoneId, + int fetchSize + ) { + this.rs = rs; + this.statement = statement; + this.getZoneId = getZoneId; + this.fetchSize = fetchSize; + this.currentRow = null; + this.closed = false; + this.wasNull = false; + } + + @Override + public boolean next() throws SQLException { + ensureNotClosed(); + if (!rs.hasNext()) { + currentRow = null; + return false; + } + currentRow = rs.next(); + currentPosition += 1; + return currentRow != null; + } + + @Override + public void close() throws SQLException { + closed = true; + rs.close(); + } + + /** {@inheritDoc} */ + @Override + public boolean wasNull() throws SQLException { + ensureNotClosed(); + ensureHasCurrentRow(); Review Comment: `ensureHasCurrentRow()` doesn't feel correct in this context. Assume I've read the entire dataset, and now I would like to check if the last column of the last row was null. The last column access resulted in NULL (in fact this doesn't matter, let's just stick with particular value for simplicity), but this method will throw an exception. But if I requested the very first row but but didn't access any column, this method returns false. I think, we either need to ensure column access, or just return current value of `wasNull` attribute with value `false` in case there has not been column access yet (personally, I prefer to stick with the latter for simplicity) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
