Skip to content

Commit

Permalink
JDBC ParameterMetaData - Feature not supported handling
Browse files Browse the repository at this point in the history
In some situations, like an "complex" query cannot be parsed by the Oracle JDBC driver, the call of org.eclipse.birt.report.data.oda.jdbc.ParameterMetaData.getParameterType(...) throws an JDBCException.

SQL Example:

SELECT 1 FROM DUAL WHERE 1 < ? AND SYSDATE > TO_DATE('20200101','YYYYMMDD')

The currently implemented MySQL handling (SQLExceptions with state "S1C00") has extened to fit also for Oracle feature not supported exceptions (SQLExceptions with code "17023") and SQLFeatureNotSupportedExceptions.
  • Loading branch information
tkrautinger committed Apr 21, 2020
1 parent 095bf06 commit f51c61f
Showing 1 changed file with 30 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
package org.eclipse.birt.report.data.oda.jdbc;

import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.sql.Types;
import java.util.logging.Logger;

import org.eclipse.datatools.connectivity.oda.IParameterMetaData;
Expand All @@ -30,7 +32,11 @@ public class ParameterMetaData implements IParameterMetaData
/** JDBC ParameterMetaData instance */
private java.sql.ParameterMetaData paraMetadata;

private static Logger logger = Logger.getLogger( ParameterMetaData.class.getName( ) );
private static Logger logger = Logger.getLogger( ParameterMetaData.class.getName( ) );

private static String MYSQL_NOT_SUPPORTED_SQL_STATE = "S1C00";

private static int ORA_NOT_SUPPORTED_ERROR_CODE = 17023;

/**
* assertNotNull(Object o)
Expand Down Expand Up @@ -104,9 +110,9 @@ public int getParameterMode( int param ) throws OdaException
"getParameterMode",
"ParameterMetaData.getParameterMode( )" );
assertNotNull( paraMetadata );
int result = IParameterMetaData.parameterModeUnknown;
try
{
int result = IParameterMetaData.parameterModeUnknown;
if ( paraMetadata.getParameterMode( param ) == java.sql.ParameterMetaData.parameterModeIn )
result = IParameterMetaData.parameterModeIn;
else if ( paraMetadata.getParameterMode( param ) == java.sql.ParameterMetaData.parameterModeOut )
Expand All @@ -117,6 +123,8 @@ else if ( paraMetadata.getParameterMode( param ) == java.sql.ParameterMetaData.p
}
catch ( SQLException e )
{
if ( isFeatureNotSupported( e ) )
return result;
throw new JDBCException( ResourceConstants.PARAMETER_MODE_CANNOT_GET,
e );
}
Expand All @@ -134,7 +142,6 @@ else if ( paraMetadata.getParameterMode( param ) == java.sql.ParameterMetaData.p
*/
public String getParameterName( int param ) throws OdaException
{
// TODO Auto-generated method stub
return null;
}

Expand All @@ -156,8 +163,8 @@ public int getParameterType( int param ) throws OdaException
}
catch ( SQLException e )
{
if ( "S1C00".equals( e.getSQLState( ) ) )
return -1;
if ( isFeatureNotSupported( e ) )
return Types.NULL;
throw new JDBCException( ResourceConstants.PARAMETER_TYPE_CANNOT_GET,
e );
}
Expand Down Expand Up @@ -190,8 +197,8 @@ public String getParameterTypeName( int param ) throws OdaException
}
catch ( SQLException e )
{
if ( "S1C00".equals( e.getSQLState( ) ) )
return "VARCHAR";
if ( isFeatureNotSupported( e ) )
return "";
throw new JDBCException( ResourceConstants.PARAMETER_TYPE_NAME_CANNOT_GET,
e );
}
Expand Down Expand Up @@ -222,7 +229,7 @@ public int getPrecision( int param ) throws OdaException
}
catch ( SQLException e )
{
if ( "S1C00".equals( e.getSQLState( ) ) )
if ( isFeatureNotSupported( e ) )
return 0;
throw new JDBCException( ResourceConstants.PARAMETER_PRECISION_CANNOT_GET,
e );
Expand Down Expand Up @@ -254,7 +261,7 @@ public int getScale( int param ) throws OdaException
}
catch ( SQLException e )
{
if ( "S1C00".equals( e.getSQLState( ) ) )
if ( isFeatureNotSupported( e ) )
return 0;
throw new JDBCException( ResourceConstants.PARAMETER_SCALE_CANNOT_GET,
e );
Expand Down Expand Up @@ -290,7 +297,7 @@ else if ( paraMetadata.isNullable( param ) == java.sql.ParameterMetaData.paramet
}
catch ( SQLException e )
{
if ( "S1C00".equals( e.getSQLState( ) ) )
if ( isFeatureNotSupported( e ) )
return result;
throw new JDBCException( ResourceConstants.PARAMETER_NULLABILITY_CANNOT_DETERMINE,
e );
Expand All @@ -303,4 +310,17 @@ else if ( paraMetadata.isNullable( param ) == java.sql.ParameterMetaData.paramet
}

}

/**
* Returns whether it is an feature not supported exception.
*
* @param exception
* @return
*/
private boolean isFeatureNotSupported( SQLException exception )
{
return exception instanceof SQLFeatureNotSupportedException
|| MYSQL_NOT_SUPPORTED_SQL_STATE.equals( exception.getSQLState( ) )
|| ORA_NOT_SUPPORTED_ERROR_CODE == exception.getErrorCode( );
}
}

0 comments on commit f51c61f

Please sign in to comment.