From ffe1c1f05d701dd72d4f69a4ca7cb579923d313d Mon Sep 17 00:00:00 2001 From: ychen Date: Sat, 27 Apr 2013 16:55:25 +0800 Subject: [PATCH] Fixed JBoss + Sybase database issue.[bug375294] --- .../birt/report/data/oda/jdbc/ResultSet.java | 155 ++++++++++++------ 1 file changed, 105 insertions(+), 50 deletions(-) diff --git a/data/org.eclipse.birt.report.data.oda.jdbc/src/org/eclipse/birt/report/data/oda/jdbc/ResultSet.java b/data/org.eclipse.birt.report.data.oda.jdbc/src/org/eclipse/birt/report/data/oda/jdbc/ResultSet.java index 4210c85c063..4a619ddd01d 100644 --- a/data/org.eclipse.birt.report.data.oda.jdbc/src/org/eclipse/birt/report/data/oda/jdbc/ResultSet.java +++ b/data/org.eclipse.birt.report.data.oda.jdbc/src/org/eclipse/birt/report/data/oda/jdbc/ResultSet.java @@ -13,6 +13,7 @@ import java.io.ByteArrayInputStream; import java.io.InputStream; +import java.lang.reflect.Method; import java.math.BigDecimal; import java.sql.Date; import java.sql.SQLException; @@ -550,47 +551,74 @@ public IBlob getBlob( String columnName ) throws OdaException java.sql.Blob blob = rs.getBlob( columnName ); return new Blob( blob ); } - // especially for MS Access, which does not support getBlob method - catch ( UnsupportedOperationException e1 ) + // bugzilla 375294 + catch ( Exception e ) { - try + Exception e1 = null; + + if ( e.getClass( ).getName( ).equals( "org.jboss.util.NestedSQLException" ) ) { - InputStream inputStream = rs.getBinaryStream( columnName ); - return new Blob( SqlBlobUtil.newBlob( inputStream ) ); + Class cls = e.getClass( ); + Method meth = null; + try + { + meth = cls.getMethod( "getNested", null ); + e1 = (Exception) meth.invoke( e, null ); + } + catch ( Exception e2 ) + { + + } + logger.log( Level.WARNING, e.getLocalizedMessage( ) ); + return null; } - catch ( SQLException e2 ) + else { - logger.log( Level.WARNING, e2.getLocalizedMessage( ) ); - return null; + e1 = e; } - } - catch ( SQLException e ) - { - // especially for the PostgreSQL driver, which does blobs via byte - // array - try + // especially for MS Access, which does not support getBlob method + if ( e1 instanceof UnsupportedOperationException ) { - byte[] bytes = rs.getBytes( columnName ); - if( bytes == null ) + try + { + InputStream inputStream = rs.getBinaryStream( columnName ); + return new Blob( SqlBlobUtil.newBlob( inputStream ) ); + } + catch ( SQLException e2 ) + { + logger.log( Level.WARNING, e2.getLocalizedMessage( ) ); return null; - return new Blob( SqlBlobUtil.newBlob( new ByteArrayInputStream( bytes ) ) ); + } } - catch ( SQLException e2 ) + else if ( e1 instanceof SQLException ) { + // especially for the PostgreSQL driver, which does blobs via byte + // array try { - Object value = rs.getObject( columnName ); - if ( value instanceof IBlob ) - return (IBlob) value; + byte[] bytes = rs.getBytes( columnName ); + if ( bytes == null ) + return null; + return new Blob( SqlBlobUtil.newBlob( new ByteArrayInputStream( bytes ) ) ); } - catch ( SQLException ex ) + catch ( SQLException e2 ) { + try + { + Object value = rs.getObject( columnName ); + if ( value instanceof IBlob ) + return (IBlob) value; + } + catch ( SQLException ex ) + { + } + + logger.log( Level.WARNING, e2.getLocalizedMessage( ) ); + return null; } - - logger.log( Level.WARNING, e2.getLocalizedMessage( ) ); - return null; } } + return null; } /* (non-Javadoc) @@ -604,47 +632,74 @@ public IBlob getBlob( int index ) throws OdaException java.sql.Blob blob = rs.getBlob( index ); return new Blob( blob ); } - // especially for MS Access, which does not support getBlob method - catch ( UnsupportedOperationException e1 ) + // bugzilla 375294 + catch ( Exception e ) { - try + Exception e1 = null; + + if ( e.getClass( ).getName( ).equals( "org.jboss.util.NestedSQLException" ) ) { - InputStream inputStream = rs.getBinaryStream( index ); - return new Blob( SqlBlobUtil.newBlob( inputStream ) ); + Class cls = e.getClass( ); + Method meth = null; + try + { + meth = cls.getMethod( "getNested", null ); + e1 = (Exception) meth.invoke( e, null ); + } + catch ( Exception e2 ) + { + + } + logger.log( Level.WARNING, e.getLocalizedMessage( ) ); + return null; } - catch ( SQLException e2 ) + else { - logger.log( Level.WARNING, e2.getLocalizedMessage( ) ); - return null; + e1 = e; } - } - catch ( SQLException e ) - { - // especially for the PostgreSQL driver, which does blobs via byte - // array - try + // especially for MS Access, which does not support getBlob method + if ( e1 instanceof UnsupportedOperationException ) { - byte[] bytes = rs.getBytes( index ); - if ( bytes == null ) + try + { + InputStream inputStream = rs.getBinaryStream( index ); + return new Blob( SqlBlobUtil.newBlob( inputStream ) ); + } + catch ( SQLException e2 ) + { + logger.log( Level.WARNING, e2.getLocalizedMessage( ) ); return null; - return new Blob( SqlBlobUtil.newBlob( new ByteArrayInputStream( bytes ) ) ); + } } - catch ( SQLException e2 ) + else if ( e1 instanceof SQLException ) { + // especially for the PostgreSQL driver, which does blobs via byte + // array try { - Object value = rs.getObject( index ); - if ( value instanceof IBlob ) - return (IBlob) value; + byte[] bytes = rs.getBytes( index ); + if ( bytes == null ) + return null; + return new Blob( SqlBlobUtil.newBlob( new ByteArrayInputStream( bytes ) ) ); } - catch ( SQLException ex ) + catch ( SQLException e2 ) { + try + { + Object value = rs.getObject( index ); + if ( value instanceof IBlob ) + return (IBlob) value; + } + catch ( SQLException ex ) + { + } + + logger.log( Level.WARNING, e.getLocalizedMessage( ) ); + return null; } - - logger.log( Level.WARNING, e.getLocalizedMessage( ) ); - return null; } } + return null; } /* (non-Javadoc)