@Override public <X> GridValueExtractor<X> getExtractor(final JavaTypeDescriptor<X> javaTypeDescriptor) { return new GridValueExtractor<X>() { @Override public X extract(Tuple resultset, String name) { final X result = (X) resultset.get( name ); if ( result == null ) { return null; } else { byte[] bytes = Base64ByteArrayTypeDescriptor.INSTANCE.fromString( (String) result ); return javaTypeDescriptor.wrap( bytes, null ); } } }; }
@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() ); } } }; }
@Override @SuppressWarnings("unchecked") public <X> ValueBinder<X> getBinder(JavaTypeDescriptor<X> javaTypeDescriptor) { // Get the binder for the intermediate type representation final ValueBinder realBinder = delegate.getBinder( intermediateJavaTypeDescriptor ); return new BasicBinder<X>( javaTypeDescriptor, this ) { @Override @SuppressWarnings("unchecked") protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException { final Object convertedValue; try { convertedValue = converter.convertToDatabaseColumn( value ); } catch (PersistenceException pe) { throw pe; } catch (RuntimeException re) { throw new PersistenceException( "Error attempting to apply AttributeConverter", re ); } realBinder.bind( st, convertedValue, index, options ); } }; }
@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 { st.setClob( index, javaTypeDescriptor.unwrap( value, Clob.class, options ) ); } }; }
@Override public <X> BasicBinder<X> getBlobBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) { return new BasicBinder<X>( javaTypeDescriptor, this ) { @Override protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException { BlobTypeDescriptor descriptor = BLOB_BINDING; if ( byte[].class.isInstance( value ) ) { // performance shortcut for binding BLOB data in byte[] format descriptor = PRIMITIVE_ARRAY_BINDING; } else if ( options.useStreamForLobBinding() ) { descriptor = STREAM_BINDING; } descriptor.getBlobBinder( javaTypeDescriptor ).doBind( st, value, index, options ); } }; }
@Override public void contribute(TypeContributions typeContributions, ServiceRegistry serviceRegistry) { JsonType jtype; JavaTypeDescriptor jdesc; try { jtype = JsonType.INSTANCE; jdesc = JsonJavaTypeDescriptor.INSTANCE; } catch (Throwable t) { // Avoid logging system for a project so small System.err.println("JSON type contribution failed! Message: " + t.getMessage()); t.printStackTrace(System.err); return; } JavaTypeDescriptorRegistry.INSTANCE.addDescriptor(jdesc); typeContributions.contributeType(jtype); }
public <X> ValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) { return new BasicBinder<X>(javaTypeDescriptor, (SqlTypeDescriptor) this) { @Override protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException { if (cal == null) { st.setDate(index, javaTypeDescriptor.unwrap(value, Date.class, options)); } else { st.setDate(index, javaTypeDescriptor.unwrap(value, Date.class, options), cal); } } }; }
@Override public <X> GridValueExtractor<X> getExtractor(JavaTypeDescriptor<X> javaTypeDescriptor) { return new GridValueExtractor<X>() { @Override public X extract(Tuple resultset, String name) { final String result = (String) resultset.get(name); if (result == null) { log.tracef("found [null] as column [$s]", name); return null; } else { Date date = null; try { date = new SimpleDateFormat("yyyyMMdd").parse(result); } catch (ParseException e) { throw new HibernateException("Unable to read date from datastore " + result, e); } { log.tracef("found [$s] as column [$s]", result, name); } return (X) date; } } }; }
@Override public <X> GridValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) { return new BasicGridBinder<X>( javaTypeDescriptor, this ) { @Override protected void doBind(Tuple resultset, X value, String[] names, WrapperOptions options) { byte[] unwrap = javaTypeDescriptor.unwrap( value, byte[].class, options ); resultset.put( names[0], Base64ByteArrayTypeDescriptor.INSTANCE.toString( unwrap ) ); } }; }
public <X> ValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) { return new BasicBinder<X>( javaTypeDescriptor, this ) { @Override protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException { st.setObject( index, javaTypeDescriptor.unwrap( value, UUID.class, options ), getSqlType() ); } }; }
public AttributeConverterTypeAdapter( String name, AttributeConverter<? extends T,?> attributeConverter, SqlTypeDescriptor sqlTypeDescriptorAdapter, Class modelType, Class jdbcType, JavaTypeDescriptor<T> entityAttributeJavaTypeDescriptor) { super( sqlTypeDescriptorAdapter, entityAttributeJavaTypeDescriptor ); this.name = name; this.modelType = modelType; this.jdbcType = jdbcType; this.attributeConverter = attributeConverter; log.debug( "Created AttributeConverterTypeAdapter -> " + name ); }
public AttributeConverterSqlTypeDescriptorAdapter( AttributeConverter converter, SqlTypeDescriptor delegate, JavaTypeDescriptor intermediateJavaTypeDescriptor) { this.converter = converter; this.delegate = delegate; this.intermediateJavaTypeDescriptor = intermediateJavaTypeDescriptor; }
@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 { if ( options.useStreamForLobBinding() ) { STREAM_BINDING.getClobBinder( javaTypeDescriptor ).doBind( st, value, index, options ); } else { CLOB_BINDING.getClobBinder( javaTypeDescriptor ).doBind( st, value, index, options ); } } }; }
@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() ); } }; }
public <X> ValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) { return new BasicBinder<X>( javaTypeDescriptor, this ) { @Override protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException { st.setBoolean( index, javaTypeDescriptor.unwrap( value, Boolean.class, options ) ); } }; }
@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 { if ( options.useStreamForLobBinding() ) { STREAM_BINDING.getNClobBinder( javaTypeDescriptor ).doBind( st, value, index, options ); } else { NCLOB_BINDING.getNClobBinder( javaTypeDescriptor ).doBind( st, value, index, options ); } } }; }
@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 { st.setNClob( index, javaTypeDescriptor.unwrap( value, NClob.class, options ) ); } }; }
@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() ); } }; }
@Override public <X> ValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) { return new BasicBinder<X>( javaTypeDescriptor, this ) { @Override protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException { st.setTime( index, javaTypeDescriptor.unwrap( value, Time.class, options ) ); } }; }
public <X> ValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) { return new BasicBinder<X>( javaTypeDescriptor, this ) { @Override protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException { st.setBytes( index, javaTypeDescriptor.unwrap( value, byte[].class, options ) ); } }; }
@Override public <X> ValueBinder<X> getBinder(JavaTypeDescriptor<X> javaTypeDescriptor) { if ( Serializable.class.isAssignableFrom( javaTypeDescriptor.getJavaTypeClass() ) ) { return VarbinaryTypeDescriptor.INSTANCE.getBinder( javaTypeDescriptor ); } return new BasicBinder<X>( javaTypeDescriptor, this ) { @Override protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException { st.setObject( index, value, jdbcTypeCode ); } }; }
@Override public <X> ValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) { return new BasicBinder<X>( javaTypeDescriptor, this ) { @Override protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException { st.setLong( index, javaTypeDescriptor.unwrap( value, Long.class, options ) ); } }; }
@Override public <X> ValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) { return new BasicBinder<X>( javaTypeDescriptor, this ) { @Override protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException { st.setTimestamp( index, javaTypeDescriptor.unwrap( value, Timestamp.class, options ) ); } }; }
@Override public <X> ValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) { return new BasicBinder<X>( javaTypeDescriptor, this ) { @Override protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException { st.setDouble( index, javaTypeDescriptor.unwrap( value, Double.class, options ) ); } }; }
@Override public <X> ValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) { return new BasicBinder<X>( javaTypeDescriptor, this ) { @Override protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException { st.setShort( index, javaTypeDescriptor.unwrap( value, Short.class, options ) ); } }; }
@Override public <X> ValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) { return new BasicBinder<X>( javaTypeDescriptor, this ) { @Override protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException { st.setBigDecimal( index, javaTypeDescriptor.unwrap( value, BigDecimal.class, options ) ); } }; }
@Override public <X> BasicBinder<X> getBlobBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) { return new BasicBinder<X>( javaTypeDescriptor, this ) { @Override public void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException { st.setBytes( index, javaTypeDescriptor.unwrap( value, byte[].class, options ) ); } }; }
@Override public <X> BasicBinder<X> getBlobBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) { return new BasicBinder<X>( javaTypeDescriptor, this ) { @Override protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException { st.setBlob( index, javaTypeDescriptor.unwrap( value, Blob.class, options ) ); } }; }
@Override public <X> BasicBinder<X> getBlobBinder(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 BinaryStream binaryStream = javaTypeDescriptor.unwrap( value, BinaryStream.class, options ); st.setBinaryStream( index, binaryStream.getInputStream(), binaryStream.getLength() ); } }; }
@Override public <X> ValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) { return new BasicBinder<X>( javaTypeDescriptor, this ) { @Override protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException { st.setFloat( index, javaTypeDescriptor.unwrap( value, Float.class, options ) ); } }; }
@Override public <X> ValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) { return new BasicBinder<X>( javaTypeDescriptor, this ) { @Override protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException { st.setInt( index, javaTypeDescriptor.unwrap( value, Integer.class, options ) ); } }; }
@Override public <X> ValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) { return new BasicBinder<X>( javaTypeDescriptor, this ) { @Override protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException { st.setString( index, javaTypeDescriptor.unwrap( value, String.class, options ) ); } }; }
@Override public <X> ValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) { return new BasicBinder<X>( javaTypeDescriptor, this ) { @Override protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException { st.setDate( index, javaTypeDescriptor.unwrap( value, Date.class, options ) ); } }; }
@Override public <X> ValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) { return new BasicBinder<X>( javaTypeDescriptor, this ) { @Override protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException { st.setNString( index, javaTypeDescriptor.unwrap( value, String.class, options ) ); } }; }
@Override public <X> ValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) { return new BasicBinder<X>( javaTypeDescriptor, this ) { @Override protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException { st.setBoolean( index, javaTypeDescriptor.unwrap( value, Boolean.class, options ) ); } }; }
@Override public <X> ValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) { return new BasicBinder<X>( javaTypeDescriptor, this ) { @Override protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException { st.setByte( index, javaTypeDescriptor.unwrap( value, Byte.class, options ) ); } }; }
@Override public <X> GridValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) { return new BasicGridBinder<X>( javaTypeDescriptor, this ) { @Override protected void doBind(Tuple resultset, X value, String[] names, WrapperOptions options) { resultset.put( names[0], javaTypeDescriptor.unwrap( value, targetClass, options ) ); } }; }
@Override public <X> ValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) { return new BasicBinder<X>(javaTypeDescriptor, this) { @Override protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException { AbstractArrayTypeDescriptor<Object> abstractArrayTypeDescriptor = (AbstractArrayTypeDescriptor<Object>) javaTypeDescriptor; st.setArray(index, st.getConnection().createArrayOf( abstractArrayTypeDescriptor.getSqlArrayType(), abstractArrayTypeDescriptor.unwrap(value, Object[].class, options) )); } }; }