-
Notifications
You must be signed in to change notification settings - Fork 227
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
Conversation
There was a problem hiding this 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<>(); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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!
9e92484
to
ada6c42
Compare
@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? |
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. |
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! |
@laurentgo - Any plans to add a test or few for this? |
yes, still my plan, just need to find some time to wrap it up. |
f191edd
to
7a92285
Compare
@risdenk @joshelser any comment regarding the unit tests? |
Whoops definitely missed there was a commit added to this. Not sure it sends an email :( I can take a look. |
There was a problem hiding this 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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sp nit: overridden
If I merge the checkstyle patch first, I might be able to revert to my lambda implementation :) |
c0ec5f6
to
47bac3d
Compare
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.
47bac3d
to
20707cc
Compare
Friendly ping @laurentgo |
According to JDBC spec, most methods from Connection, Statement,
PreparedStatement and ResultSet should throw an exception if the
resource is closed.