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

JDOQLQuery should throw exception if datastore does not support query canceling #490

Closed
mboapache opened this issue Jun 9, 2024 · 0 comments
Milestone

Comments

@mboapache
Copy link

The JDO query implementation class JDOQLQuery in package org.datanucleus.store.rdbms.query calls method cancelTaskObject, that delegates to the JDBC PreparedStatement.cancel method. The code catches a SQLException thrown by the datastore method and logs a warning message:

    protected boolean cancelTaskObject(Object obj)
    {
        Statement ps = (Statement)obj;
        try
        {
            ps.cancel();
            return true;
        }
        catch (  sqle)
        {
            NucleusLogger.DATASTORE_RETRIEVE.warn("Error cancelling query", sqle);
            return false;
        }
    }

I propose to change method cancelTaskObject to rethrow the datastore exception wrapped into an JDOUnsupportedOptionException in case of a SQLFeatureNotSupportedException and NucleusDataStoreException otherwise:

    protected boolean cancelTaskObject(Object obj)
    {
        Statement ps = (Statement) obj;
        try
	{
            ps.cancel();
            return true;
        }
	catch (SQLFeatureNotSupportedException sqlfnse)
	{
            NucleusLogger.DATASTORE_RETRIEVE.warn("Feature not supported", sqlfnse);
            throw new JDOUnsupportedOptionException("Feature not supported", sqlfnse);
        }
	catch (SQLException sqle)
	{
            NucleusLogger.DATASTORE_RETRIEVE.warn("Error cancelling query", sqle);
            throw new NucleusDataStoreException("Error cancelling query", sqle);
        }
    }

You might consider removing the boolean return of method cancelTaskObject since the caller just uses the return value for a debug log message.

To reproduce the issue please go to the Apache JDO TCK github project https://github.com/apache/db-jdo and use branch JDO-836. Run the following command that executes the TCK test class QueryCancel:
mvn -Djdo.tck.cfglist=cancel.conf clean install

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants