Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CALCITE-2219] Check if resource is closed, and throws #33

Closed
wants to merge 2 commits into from

Conversation

laurentgo
Copy link
Contributor

According to JDBC spec, most methods from Connection, Statement,
PreparedStatement and ResultSet should throw an exception if the
resource is closed.

Copy link
Contributor

@risdenk risdenk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look reasonable to me. Only a few minor comments.

throw HELPER.unsupported();
checkOpen();
// Always return an empty map since custom types is not supported
return new HashMap<>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be more correct to return SQLFeatureNotSupportedException? I don't think it matters either way but below is from the javadoc for Connection.

SQLFeatureNotSupportedException - if the JDBC driver does not support this method

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, probably more correct. I think I got the truncated version of the javadoc on this one. I will revert.

@@ -392,14 +420,17 @@ public void setClientInfo(Properties properties)
}

public String getClientInfo(String name) throws SQLException {
throw HELPER.unsupported();
checkOpen();
return null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be return this.getClientInfo().getProperty(name) now that getClientInfo() returns a Properties object. This would remove the need for the added checkOpen() and explicit return null.

}

public void setMaxFieldSize(int max) throws SQLException {
throw connection.HELPER.unsupported();
throw AvaticaConnection.HELPER.unsupported();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to make this be a noop instead of returning unsupported now that getMaxFieldSize() is set to always return 0.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not if the value is set to something different from 0, if not supported

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok that makes sense. Thanks!

@joshelser
Copy link
Member

@laurentgo any chance I could request that you write a test case for one of this scenarios? Maybe the one in which lead you to find that this bug existed?
Otherwise, looks good to me too.

@laurentgo
Copy link
Contributor Author

Not really triggered by a bug, but more by the extra code in Drill and Dremio JDBC drivers to implements the JDBC spec. Let me see if can reuse the same strategy as the Drill code (helper class to iterate over methods and check that the methods throws the correct exception).

There are also lots of methods where unsupported is thrown instead of a sqlexception for closed. I wonder if the correct thing to do would be to check first for closed, and then throw unsupported, and if it's fine for now.

@joshelser
Copy link
Member

Not really triggered by a bug, but more by the extra code in Drill and Dremio JDBC drivers to implements the JDBC spec. Let me see if can reuse the same strategy as the Drill code (helper class to iterate over methods and check that the methods throws the correct exception).

Ok. I definitely didn't want to suggest that you try to cover every single one of these methods you fixed up :). I like to see at least one test added when we fix straighforward bugs like this, even if it is known that we're only catching one case. Appreciate you looking into it!

@risdenk
Copy link
Contributor

risdenk commented Apr 28, 2018

@laurentgo - Any plans to add a test or few for this?

@laurentgo
Copy link
Contributor Author

yes, still my plan, just need to find some time to wrap it up.

@laurentgo laurentgo force-pushed the laurentgo/CALCITE-2219 branch 3 times, most recently from f191edd to 7a92285 Compare June 5, 2018 14:32
@laurentgo
Copy link
Contributor Author

@risdenk @joshelser any comment regarding the unit tests?

@risdenk
Copy link
Contributor

risdenk commented Jun 7, 2018

Whoops definitely missed there was a commit added to this. Not sure it sends an email :( I can take a look.

Copy link
Contributor

@risdenk risdenk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good. Only a few minor spelling items. Testing framework for closed is cool.

Also checked in combination with PR #56 to make sure there weren't going to be new checkstyle issues.

One thing that could be improved is using Lambdas with JDK 8 instead of full methods. Only found this since IDE suggested it.

import static org.junit.Assert.fail;

/**
* Helper class for tests checkign close behavior
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sp nit: checking


private static final Predicate<? super Method> METHOD_FILTER = new Predicate<Method>() {
public boolean test(Method m) {
// Skip methods not overriden by Avatica
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sp nit: overridden

public class AvaticaClosedPreparedStatementTest {
private static final Predicate<? super Method> METHOD_FILTER = new Predicate<Method>() {
public boolean test(Method m) {
// Skip methods not overriden by Avatica
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sp nit: overridden

public class AvaticaClosedResultSetTest {
private static final Predicate<? super Method> METHOD_FILTER = new Predicate<Method>() {
public boolean test(Method m) {
// Skip methods not overriden by Avatica
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sp nit: overridden

@laurentgo
Copy link
Contributor Author

If I merge the checkstyle patch first, I might be able to revert to my lambda implementation :)

@laurentgo laurentgo force-pushed the laurentgo/CALCITE-2219 branch 2 times, most recently from c0ec5f6 to 47bac3d Compare June 9, 2018 01:01
Fix warnings about accessing AvaticaConnection.HELPER static field by
using a class instance.
According to JDBC spec, most methods from Connection, Statement,
PreparedStatement and ResultSet should throw an exception if the
resource is closed.
@F21
Copy link
Member

F21 commented Jun 13, 2018

Friendly ping @laurentgo

@asfgit asfgit closed this in 2ebfd80 Jun 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants