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

JDBC ParameterMetaData - Feature not supported handling #579

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -29,7 +31,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 @@ -83,39 +89,46 @@ public int getParameterCount() throws OdaException {
* @see
* org.eclipse.datatools.connectivity.IParameterMetaData#getParameterMode(int)
*/
public int getParameterMode(int param) throws OdaException {
logger.logp(java.util.logging.Level.FINEST, ParameterMetaData.class.getName(), "getParameterMode",
"ParameterMetaData.getParameterMode( )");
assertNotNull(paraMetadata);
try {
int result = IParameterMetaData.parameterModeUnknown;
if (paraMetadata.getParameterMode(param) == java.sql.ParameterMetaData.parameterModeIn)
public int getParameterMode( int param ) throws OdaException
{
logger.logp( java.util.logging.Level.FINEST,
ParameterMetaData.class.getName( ),
"getParameterMode",
"ParameterMetaData.getParameterMode( )" );
assertNotNull( paraMetadata );
int result = IParameterMetaData.parameterModeUnknown;
try
{
if ( paraMetadata.getParameterMode( param ) == java.sql.ParameterMetaData.parameterModeIn )
result = IParameterMetaData.parameterModeIn;
else if (paraMetadata.getParameterMode(param) == java.sql.ParameterMetaData.parameterModeOut)
result = IParameterMetaData.parameterModeOut;
else if (paraMetadata.getParameterMode(param) == java.sql.ParameterMetaData.parameterModeInOut)
result = IParameterMetaData.parameterModeInOut;
return result;
} catch (SQLException e) {
throw new JDBCException(ResourceConstants.PARAMETER_MODE_CANNOT_GET, e);
} catch (Exception e) {
}
catch ( SQLException e )
{
if ( isFeatureNotSupported( e ) )
return result;
throw new JDBCException( ResourceConstants.PARAMETER_MODE_CANNOT_GET,
e );
}
catch ( Exception e )
{
// exception thrown by driver when fetch the parameter's mode
throw new JDBCException(ResourceConstants.PARAMETER_MODE_CANNOT_GET, new SQLException(e.getMessage()));
}

}

/*
* (non-Javadoc)
*
* @see
* org.eclipse.datatools.connectivity.oda.IParameterMetaData#getParameterName(
* int)
*/
public String getParameterName(int param) throws OdaException {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc)
* @see org.eclipse.datatools.connectivity.oda.IParameterMetaData#getParameterName(int)
*/
public String getParameterName( int param ) throws OdaException
{
return null;
}

/*
*
Expand All @@ -128,12 +141,17 @@ public int getParameterType(int param) throws OdaException {
assertNotNull(paraMetadata);
try {
/* redirect the call to JDBC ParameterMetaData.getParameterType(int) */
return paraMetadata.getParameterType(param);
} catch (SQLException e) {
if ("S1C00".equals(e.getSQLState()))
return -1;
throw new JDBCException(ResourceConstants.PARAMETER_TYPE_CANNOT_GET, e);
} catch (Exception e) {
return paraMetadata.getParameterType( param );
}
catch ( SQLException e )
{
if ( isFeatureNotSupported( e ) )
return Types.NULL;
throw new JDBCException( ResourceConstants.PARAMETER_TYPE_CANNOT_GET,
e );
}
catch ( Exception e )
{
// exception thrown by driver when fetch the parameter's type
throw new JDBCException(ResourceConstants.PARAMETER_TYPE_CANNOT_GET, new SQLException(e.getMessage()));
}
Expand All @@ -153,12 +171,17 @@ public String getParameterTypeName(int param) throws OdaException {
/*
* redirect the call to JDBC ParameterMetaData.getParameterTypeName(int)
*/
return paraMetadata.getParameterTypeName(param);
} catch (SQLException e) {
if ("S1C00".equals(e.getSQLState()))
return "VARCHAR";
throw new JDBCException(ResourceConstants.PARAMETER_TYPE_NAME_CANNOT_GET, e);
} catch (Exception e) {
return paraMetadata.getParameterTypeName( param );
}
catch ( SQLException e )
{
if ( isFeatureNotSupported( e ) )
return "";
throw new JDBCException( ResourceConstants.PARAMETER_TYPE_NAME_CANNOT_GET,
e );
}
catch ( Exception e )
{
// exception thrown by driver when fetch the parameter's type name
throw new JDBCException(ResourceConstants.PARAMETER_TYPE_NAME_CANNOT_GET, new SQLException(e.getMessage()));
}
Expand All @@ -175,9 +198,11 @@ public int getPrecision(int param) throws OdaException {
assertNotNull(paraMetadata);
try {
/* redirect the call to JDBC ParameterMetaData.getPrecision(int) */
return paraMetadata.getPrecision(param);
} catch (SQLException e) {
if ("S1C00".equals(e.getSQLState()))
return paraMetadata.getPrecision( param );
}
catch ( SQLException e )
{
if ( isFeatureNotSupported( e ) )
return 0;
throw new JDBCException(ResourceConstants.PARAMETER_PRECISION_CANNOT_GET, e);
} catch (Exception e) {
Expand All @@ -197,9 +222,11 @@ public int getScale(int param) throws OdaException {
assertNotNull(paraMetadata);
try {
/* redirect the call to JDBC ParameterMetaData.getScale(int) */
return paraMetadata.getScale(param);
} catch (SQLException e) {
if ("S1C00".equals(e.getSQLState()))
return paraMetadata.getScale( param );
}
catch ( SQLException e )
{
if ( isFeatureNotSupported( e ) )
return 0;
throw new JDBCException(ResourceConstants.PARAMETER_SCALE_CANNOT_GET, e);
} catch (Exception e) {
Expand All @@ -224,8 +251,10 @@ public int isNullable(int param) throws OdaException {
else if (paraMetadata.isNullable(param) == java.sql.ParameterMetaData.parameterNoNulls)
result = IParameterMetaData.parameterNoNulls;
return result;
} catch (SQLException e) {
if ("S1C00".equals(e.getSQLState()))
}
catch ( SQLException e )
{
if ( isFeatureNotSupported( e ) )
return result;
throw new JDBCException(ResourceConstants.PARAMETER_NULLABILITY_CANNOT_DETERMINE, e);
} catch (Exception e) {
Expand All @@ -235,4 +264,17 @@ else if (paraMetadata.isNullable(param) == java.sql.ParameterMetaData.parameterN
}

}

/**
* 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( );
}
}