@Override public <X> BasicBinder<X> getClobBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) { return new BasicBinder<X>( javaTypeDescriptor, this ) { @Override protected void doBind(final PreparedStatement st, final X value, final int index, final WrapperOptions options) throws SQLException { final CharacterStream characterStream = javaTypeDescriptor.unwrap( value, CharacterStream.class, options ); if ( value instanceof ClobImplementer ) { st.setCharacterStream( index, new CloseSuppressingReader( characterStream.asReader() ), characterStream.getLength() ); } else { st.setCharacterStream( index, characterStream.asReader(), characterStream.getLength() ); } } }; }
@Override public <X> BasicBinder<X> getNClobBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) { return new BasicBinder<X>( javaTypeDescriptor, this ) { @Override protected void doBind(final PreparedStatement st, final X value, final int index, final WrapperOptions options) throws SQLException { final CharacterStream characterStream = javaTypeDescriptor.unwrap( value, CharacterStream.class, options ); if ( value instanceof NClobImplementer ) { st.setCharacterStream( index, new CloseSuppressingReader( characterStream.asReader() ), characterStream.getLength() ); } else { st.setCharacterStream( index, characterStream.asReader(), characterStream.getLength() ); } } }; }
@SuppressWarnings({ "unchecked" }) @Override public <X> X unwrap(Character[] value, Class<X> type, WrapperOptions options) { if ( value == null ) { return null; } if ( Character[].class.isAssignableFrom( type ) ) { return (X) value; } if ( String.class.isAssignableFrom( type ) ) { return (X) new String( unwrapChars( value ) ); } if ( Clob.class.isAssignableFrom( type ) ) { return (X) options.getLobCreator().createClob( new String( unwrapChars( value ) ) ); } if ( Reader.class.isAssignableFrom( type ) ) { return (X) new StringReader( new String( unwrapChars( value ) ) ); } if ( CharacterStream.class.isAssignableFrom( type ) ) { return (X) new CharacterStreamImpl( new String( unwrapChars( value ) ) ); } throw unknownUnwrap( type ); }
@SuppressWarnings({ "unchecked" }) public <X> X unwrap(String value, Class<X> type, WrapperOptions options) { if ( value == null ) { return null; } if ( String.class.isAssignableFrom( type ) ) { return (X) value; } if ( Reader.class.isAssignableFrom( type ) ) { return (X) new StringReader( value ); } if ( CharacterStream.class.isAssignableFrom( type ) ) { return (X) new CharacterStreamImpl( value ); } if ( Clob.class.isAssignableFrom( type ) ) { return (X) options.getLobCreator().createClob( value ); } if ( DataHelper.isNClob( type ) ) { return (X) options.getLobCreator().createNClob( value ); } throw unknownUnwrap( type ); }
@SuppressWarnings({ "unchecked" }) public <X> X unwrap(char[] value, Class<X> type, WrapperOptions options) { if ( value == null ) { return null; } if ( char[].class.isAssignableFrom( type ) ) { return (X) value; } if ( String.class.isAssignableFrom( type ) ) { return (X) new String( value ); } if ( Clob.class.isAssignableFrom( type ) ) { return (X) options.getLobCreator().createClob( new String( value ) ); } if ( Reader.class.isAssignableFrom( type ) ) { return (X) new StringReader( new String( value ) ); } if ( CharacterStream.class.isAssignableFrom( type ) ) { return (X) new CharacterStreamImpl( new String( value ) ); } throw unknownUnwrap( type ); }
@SuppressWarnings({ "unchecked" }) public <X> X unwrap(final Clob value, Class<X> type, WrapperOptions options) { if ( value == null ) { return null; } try { if ( CharacterStream.class.isAssignableFrom( type ) ) { if ( ClobImplementer.class.isInstance( value ) ) { // if the incoming Clob is a wrapper, just pass along its CharacterStream return (X) ( (ClobImplementer) value ).getUnderlyingStream(); } else { // otherwise we need to build a CharacterStream... return (X) new CharacterStreamImpl( DataHelper.extractString( value.getCharacterStream() ) ); } } else if (Clob.class.isAssignableFrom( type )) { final Clob clob = WrappedClob.class.isInstance( value ) ? ( (WrappedClob) value ).getWrappedClob() : value; return (X) clob; } } catch ( SQLException e ) { throw new HibernateException( "Unable to access clob stream", e ); } throw unknownUnwrap( type ); }
@SuppressWarnings({ "unchecked" }) public <X> X unwrap(final NClob value, Class<X> type, WrapperOptions options) { if ( value == null ) { return null; } try { if ( CharacterStream.class.isAssignableFrom( type ) ) { if ( NClobImplementer.class.isInstance( value ) ) { // if the incoming NClob is a wrapper, just pass along its BinaryStream return (X) ( (NClobImplementer) value ).getUnderlyingStream(); } else { // otherwise we need to build a BinaryStream... return (X) new CharacterStreamImpl( DataHelper.extractString( value.getCharacterStream() ) ); } } else if (NClob.class.isAssignableFrom( type )) { final NClob nclob = WrappedNClob.class.isInstance( value ) ? ( (WrappedNClob) value ).getWrappedNClob() : value; return (X) nclob; } } catch ( SQLException e ) { throw new HibernateException( "Unable to access nclob stream", e ); } throw unknownUnwrap( type ); }
@Override public <X> BasicBinder<X> getClobBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) { return new BasicBinder<X>( javaTypeDescriptor, this ) { @Override protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException { final CharacterStream characterStream = javaTypeDescriptor.unwrap( value, CharacterStream.class, options ); st.setCharacterStream( index, characterStream.asReader(), characterStream.getLength() ); } }; }
@Override public <X> BasicBinder<X> getNClobBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) { return new BasicBinder<X>( javaTypeDescriptor, this ) { @Override protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException { final CharacterStream characterStream = javaTypeDescriptor.unwrap( value, CharacterStream.class, options ); st.setCharacterStream( index, characterStream.asReader(), characterStream.getLength() ); } }; }
@SuppressWarnings({ "unchecked" }) public <X> X unwrap(final NClob value, Class<X> type, WrapperOptions options) { if ( value == null ) { return null; } try { if ( CharacterStream.class.isAssignableFrom( type ) ) { if ( NClobImplementer.class.isInstance( value ) ) { // if the incoming Clob is a wrapper, just pass along its CharacterStream return (X) ( (NClobImplementer) value ).getUnderlyingStream(); } else { // otherwise we need to build a CharacterStream... return (X) new CharacterStreamImpl( DataHelper.extractString( value.getCharacterStream() ) ); } } else if (Clob.class.isAssignableFrom( type )) { final Clob clob = WrappedClob.class.isInstance( value ) ? ( (WrappedClob) value ).getWrappedClob() : value; return (X) clob; } } catch ( SQLException e ) { throw new HibernateException( "Unable to access clob stream", e ); } throw unknownUnwrap( type ); }
@Override public <X> X unwrap(Calendar value, Class<X> type, WrapperOptions options) { if (value == null) { return null; } if (Calendar.class.isAssignableFrom(type)) { return (X) value; } if (CharacterStream.class.isAssignableFrom(type)) { return (X) new CharacterStreamImpl(value.toString()); } throw unknownUnwrap(type); }