Skip to content

Commit

Permalink
Fixed JBoss + Sybase database issue.[bug375294]
Browse files Browse the repository at this point in the history
  • Loading branch information
ychen committed Apr 27, 2013
1 parent 5eeefcf commit ffe1c1f
Showing 1 changed file with 105 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit ffe1c1f

Please sign in to comment.