HHH-5138 - Redesign types + introduce TypeRegistry & TypeResolver

git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@19345 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
Steve Ebersole 2010-05-03 00:04:27 +00:00
parent 8bc9bbf098
commit bdc83cb2e6
57 changed files with 466 additions and 85 deletions

View File

@ -31,8 +31,8 @@ import org.hibernate.HibernateException;
import org.hibernate.engine.SessionImplementor; import org.hibernate.engine.SessionImplementor;
import org.hibernate.engine.jdbc.LobCreator; import org.hibernate.engine.jdbc.LobCreator;
import org.hibernate.engine.jdbc.NonContextualLobCreator; import org.hibernate.engine.jdbc.NonContextualLobCreator;
import org.hibernate.type.descriptor.WrapperOptions;
import org.hibernate.type.descriptor.java.JavaTypeDescriptor; import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
import org.hibernate.type.descriptor.java.WrapperOptions;
import org.hibernate.type.descriptor.sql.SqlTypeDescriptor; import org.hibernate.type.descriptor.sql.SqlTypeDescriptor;
/** /**

View File

@ -40,9 +40,9 @@ import org.hibernate.engine.Mapping;
import org.hibernate.engine.SessionFactoryImplementor; import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.engine.SessionImplementor; import org.hibernate.engine.SessionImplementor;
import org.hibernate.engine.jdbc.LobCreator; import org.hibernate.engine.jdbc.LobCreator;
import org.hibernate.type.descriptor.WrapperOptions;
import org.hibernate.type.descriptor.java.JavaTypeDescriptor; import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
import org.hibernate.type.descriptor.java.MutabilityPlan; import org.hibernate.type.descriptor.java.MutabilityPlan;
import org.hibernate.type.descriptor.java.WrapperOptions;
import org.hibernate.type.descriptor.sql.SqlTypeDescriptor; import org.hibernate.type.descriptor.sql.SqlTypeDescriptor;
import org.hibernate.util.ArrayHelper; import org.hibernate.util.ArrayHelper;

View File

@ -0,0 +1,47 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.type.descriptor;
import java.io.InputStream;
/**
* Wraps a binary stream to also provide the length which is needed when binding.
*
* @author Steve Ebersole
*/
public interface BinaryStream {
/**
* Retrieve the input stream.
*
* @return The input stream
*/
public InputStream getInputStream();
/**
* Retrieve the length of the input stream
*
* @return The input stream length
*/
public int getLength();
}

View File

@ -0,0 +1,49 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.type.descriptor;
import java.io.Reader;
/**
* Wraps a character stream (reader) to also provide the length (number of characters) which is needed
* when binding.
*
* @author Steve Ebersole
*/
public interface CharacterStream {
/**
* Retrieve the reader.
*
* @return The reader.
*/
public Reader getReader();
/**
* Retrieve the number of characters. JDBC 3 and earlier defined the length in terms of int type rather than
* long type :(
*
* @return The number of characters.
*/
public int getLength();
}

View File

@ -0,0 +1,46 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.type.descriptor;
import java.sql.PreparedStatement;
import java.sql.SQLException;
/**
* Contract for binding values to a {@link PreparedStatement}.
*
* @author Steve Ebersole
*/
public interface ValueBinder<X> {
/**
* Bind a value to a prepared statement.
*
* @param st The prepared statement to which to bind the value.
* @param value The value to bind.
* @param index The position at which to bind the value within the prepared statement
* @param options The options.
*
* @throws SQLException Indicates a JDBC error occurred.
*/
public void bind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException;
}

View File

@ -0,0 +1,47 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.type.descriptor;
import java.sql.ResultSet;
import java.sql.SQLException;
/**
* Contract for extracting a value from a {@link ResultSet}.
*
* @author Steve Ebersole
*/
public interface ValueExtractor<X> {
/**
* Extract value from result set
*
* @param rs The result set from which to extract the value
* @param name The name by which to extract the value from the result set
* @param options The options
*
* @return The extracted value
*
* @throws SQLException Indicates a JDBC error occurred.
*/
public X extract(ResultSet rs, String name, WrapperOptions options) throws SQLException;
}

View File

@ -21,7 +21,7 @@
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*/ */
package org.hibernate.type.descriptor.java; package org.hibernate.type.descriptor;
import org.hibernate.engine.jdbc.LobCreator; import org.hibernate.engine.jdbc.LobCreator;

View File

@ -26,6 +26,8 @@ package org.hibernate.type.descriptor.java;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.BigInteger; import java.math.BigInteger;
import org.hibernate.type.descriptor.WrapperOptions;
/** /**
* Descriptor for {@link BigDecimal} handling. * Descriptor for {@link BigDecimal} handling.
* *

View File

@ -26,6 +26,8 @@ package org.hibernate.type.descriptor.java;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.BigInteger; import java.math.BigInteger;
import org.hibernate.type.descriptor.WrapperOptions;
/** /**
* Descriptor for {@link BigInteger} handling. * Descriptor for {@link BigInteger} handling.
* *

View File

@ -0,0 +1,52 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.type.descriptor.java;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import org.hibernate.type.descriptor.BinaryStream;
/**
* Implementation of {@link BinaryStream}
*
* @author Steve Ebersole
*/
public class BinaryStreamImpl implements BinaryStream {
private final ByteArrayInputStream stream;
private final int length;
public BinaryStreamImpl(byte[] bytes) {
this.stream = new ByteArrayInputStream( bytes );
this.length = bytes.length;
}
public InputStream getInputStream() {
return stream;
}
public int getLength() {
return length;
}
}

View File

@ -31,6 +31,7 @@ import java.util.Comparator;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.engine.jdbc.BlobProxy; import org.hibernate.engine.jdbc.BlobProxy;
import org.hibernate.engine.jdbc.WrappedBlob; import org.hibernate.engine.jdbc.WrappedBlob;
import org.hibernate.type.descriptor.WrapperOptions;
/** /**
* Descriptor for {@link Blob} handling. * Descriptor for {@link Blob} handling.

View File

@ -23,6 +23,8 @@
*/ */
package org.hibernate.type.descriptor.java; package org.hibernate.type.descriptor.java;
import org.hibernate.type.descriptor.WrapperOptions;
import static java.lang.Boolean.TRUE; import static java.lang.Boolean.TRUE;
import static java.lang.Boolean.FALSE; import static java.lang.Boolean.FALSE;

View File

@ -29,6 +29,8 @@ import java.sql.Blob;
import java.sql.SQLException; import java.sql.SQLException;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.type.descriptor.BinaryStream;
import org.hibernate.type.descriptor.WrapperOptions;
/** /**
* TODO : javadoc * TODO : javadoc
@ -86,6 +88,9 @@ public class ByteArrayTypeDescriptor extends AbstractTypeDescriptor<Byte[]> {
if ( InputStream.class.isAssignableFrom( type ) ) { if ( InputStream.class.isAssignableFrom( type ) ) {
return (X) new ByteArrayInputStream( unwrapBytes( value ) ); return (X) new ByteArrayInputStream( unwrapBytes( value ) );
} }
if ( BinaryStream.class.isAssignableFrom( type ) ) {
return (X) new BinaryStreamImpl( unwrapBytes( value ) );
}
if ( Blob.class.isAssignableFrom( type ) ) { if ( Blob.class.isAssignableFrom( type ) ) {
return (X) options.getLobCreator().createBlob( unwrapBytes( value ) ); return (X) options.getLobCreator().createBlob( unwrapBytes( value ) );
} }

View File

@ -23,6 +23,8 @@
*/ */
package org.hibernate.type.descriptor.java; package org.hibernate.type.descriptor.java;
import org.hibernate.type.descriptor.WrapperOptions;
/** /**
* Descriptor for {@link Byte} handling. * Descriptor for {@link Byte} handling.
* *

View File

@ -29,6 +29,7 @@ import java.util.Date;
import java.util.GregorianCalendar; import java.util.GregorianCalendar;
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;
import org.hibernate.type.descriptor.WrapperOptions;
import org.hibernate.util.CalendarComparator; import org.hibernate.util.CalendarComparator;
/** /**

View File

@ -29,6 +29,7 @@ import java.util.Date;
import java.util.GregorianCalendar; import java.util.GregorianCalendar;
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;
import org.hibernate.type.descriptor.WrapperOptions;
import org.hibernate.util.CalendarComparator; import org.hibernate.util.CalendarComparator;
/** /**

View File

@ -30,6 +30,8 @@ import java.sql.SQLException;
import java.util.Arrays; import java.util.Arrays;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.type.descriptor.CharacterStream;
import org.hibernate.type.descriptor.WrapperOptions;
/** /**
* TODO : javadoc * TODO : javadoc
@ -84,6 +86,9 @@ public class CharacterArrayTypeDescriptor extends AbstractTypeDescriptor<Charact
if ( Reader.class.isAssignableFrom( type ) ) { if ( Reader.class.isAssignableFrom( type ) ) {
return (X) new StringReader( new String( unwrapChars( value ) ) ); return (X) new StringReader( new String( unwrapChars( value ) ) );
} }
if ( CharacterStream.class.isAssignableFrom( type ) ) {
return (X) new CharacterStreamImpl( new String( unwrapChars( value ) ) );
}
throw unknownUnwrap( type ); throw unknownUnwrap( type );
} }

View File

@ -0,0 +1,52 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.type.descriptor.java;
import java.io.Reader;
import java.io.StringReader;
import org.hibernate.type.descriptor.CharacterStream;
/**
* Implementation of {@link CharacterStream}
*
* @author Steve Ebersole
*/
public class CharacterStreamImpl implements CharacterStream {
private final StringReader reader;
private final int length;
public CharacterStreamImpl(String chars) {
reader = new StringReader( chars );
length = chars.length();
}
public Reader getReader() {
return reader;
}
public int getLength() {
return length;
}
}

View File

@ -24,7 +24,7 @@
package org.hibernate.type.descriptor.java; package org.hibernate.type.descriptor.java;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.MappingException; import org.hibernate.type.descriptor.WrapperOptions;
/** /**
* Descriptor for {@link Character} handling. * Descriptor for {@link Character} handling.

View File

@ -24,6 +24,7 @@
package org.hibernate.type.descriptor.java; package org.hibernate.type.descriptor.java;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.type.descriptor.WrapperOptions;
import org.hibernate.util.ReflectHelper; import org.hibernate.util.ReflectHelper;
/** /**

View File

@ -31,6 +31,7 @@ import java.util.Comparator;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.engine.jdbc.ClobProxy; import org.hibernate.engine.jdbc.ClobProxy;
import org.hibernate.engine.jdbc.WrappedClob; import org.hibernate.engine.jdbc.WrappedClob;
import org.hibernate.type.descriptor.WrapperOptions;
/** /**
* Descriptor for {@link Clob} handling. * Descriptor for {@link Clob} handling.

View File

@ -25,6 +25,8 @@ package org.hibernate.type.descriptor.java;
import java.util.Currency; import java.util.Currency;
import org.hibernate.type.descriptor.WrapperOptions;
/** /**
* TODO : javadoc * TODO : javadoc
* *

View File

@ -30,6 +30,7 @@ import java.util.Date;
import java.util.GregorianCalendar; import java.util.GregorianCalendar;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.type.descriptor.WrapperOptions;
/** /**
* TODO : javadoc * TODO : javadoc

View File

@ -26,6 +26,8 @@ package org.hibernate.type.descriptor.java;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.BigInteger; import java.math.BigInteger;
import org.hibernate.type.descriptor.WrapperOptions;
/** /**
* Descriptor for {@link Double} handling. * Descriptor for {@link Double} handling.
* *

View File

@ -26,6 +26,8 @@ package org.hibernate.type.descriptor.java;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.BigInteger; import java.math.BigInteger;
import org.hibernate.type.descriptor.WrapperOptions;
/** /**
* Descriptor for {@link Float} handling. * Descriptor for {@link Float} handling.
* *

View File

@ -26,6 +26,8 @@ package org.hibernate.type.descriptor.java;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.BigInteger; import java.math.BigInteger;
import org.hibernate.type.descriptor.WrapperOptions;
/** /**
* Descriptor for {@link Integer} handling. * Descriptor for {@link Integer} handling.
* *

View File

@ -26,6 +26,8 @@ package org.hibernate.type.descriptor.java;
import java.io.Serializable; import java.io.Serializable;
import java.util.Comparator; import java.util.Comparator;
import org.hibernate.type.descriptor.WrapperOptions;
/** /**
* Descriptor for the Java side of a value mapping. * Descriptor for the Java side of a value mapping.
* *

View File

@ -30,6 +30,7 @@ import java.util.Date;
import java.util.GregorianCalendar; import java.util.GregorianCalendar;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.type.descriptor.WrapperOptions;
/** /**
* TODO : javadoc * TODO : javadoc

View File

@ -31,6 +31,7 @@ import java.util.Date;
import java.util.GregorianCalendar; import java.util.GregorianCalendar;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.type.descriptor.WrapperOptions;
/** /**
* TODO : javadoc * TODO : javadoc

View File

@ -32,6 +32,7 @@ import java.util.GregorianCalendar;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;
import org.hibernate.type.descriptor.WrapperOptions;
/** /**
* TODO : javadoc * TODO : javadoc

View File

@ -27,6 +27,8 @@ import java.util.Comparator;
import java.util.Locale; import java.util.Locale;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import org.hibernate.type.descriptor.WrapperOptions;
/** /**
* TODO : javadoc * TODO : javadoc
* *

View File

@ -26,6 +26,8 @@ package org.hibernate.type.descriptor.java;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.BigInteger; import java.math.BigInteger;
import org.hibernate.type.descriptor.WrapperOptions;
/** /**
* Descriptor for {@link Long} handling. * Descriptor for {@link Long} handling.
* *

View File

@ -30,6 +30,8 @@ import java.sql.SQLException;
import java.util.Arrays; import java.util.Arrays;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.type.descriptor.BinaryStream;
import org.hibernate.type.descriptor.WrapperOptions;
/** /**
* Descriptor for {@code byte[]} handling. * Descriptor for {@code byte[]} handling.
@ -97,6 +99,9 @@ public class PrimitiveByteArrayTypeDescriptor extends AbstractTypeDescriptor<byt
if ( InputStream.class.isAssignableFrom( type ) ) { if ( InputStream.class.isAssignableFrom( type ) ) {
return (X) new ByteArrayInputStream( value ); return (X) new ByteArrayInputStream( value );
} }
if ( BinaryStream.class.isAssignableFrom( type ) ) {
return (X) new BinaryStreamImpl( value );
}
if ( Blob.class.isAssignableFrom( type ) ) { if ( Blob.class.isAssignableFrom( type ) ) {
return (X) options.getLobCreator().createBlob( value ); return (X) options.getLobCreator().createBlob( value );
} }

View File

@ -30,6 +30,8 @@ import java.sql.SQLException;
import java.util.Arrays; import java.util.Arrays;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.type.descriptor.CharacterStream;
import org.hibernate.type.descriptor.WrapperOptions;
/** /**
* TODO : javadoc * TODO : javadoc
@ -84,6 +86,9 @@ public class PrimitiveCharacterArrayTypeDescriptor extends AbstractTypeDescripto
if ( Reader.class.isAssignableFrom( type ) ) { if ( Reader.class.isAssignableFrom( type ) ) {
return (X) new StringReader( new String( value ) ); return (X) new StringReader( new String( value ) );
} }
if ( CharacterStream.class.isAssignableFrom( type ) ) {
return (X) new CharacterStreamImpl( new String( value ) );
}
throw unknownUnwrap( type ); throw unknownUnwrap( type );
} }

View File

@ -27,6 +27,8 @@ import java.io.ByteArrayInputStream;
import java.io.InputStream; import java.io.InputStream;
import java.io.Serializable; import java.io.Serializable;
import org.hibernate.type.descriptor.BinaryStream;
import org.hibernate.type.descriptor.WrapperOptions;
import org.hibernate.util.SerializationHelper; import org.hibernate.util.SerializationHelper;
/** /**
@ -85,6 +87,9 @@ public class SerializableTypeDescriptor<T extends Serializable> extends Abstract
if ( InputStream.class.isAssignableFrom( type ) ) { if ( InputStream.class.isAssignableFrom( type ) ) {
return (X) new ByteArrayInputStream( toBytes( value ) ); return (X) new ByteArrayInputStream( toBytes( value ) );
} }
if ( BinaryStream.class.isAssignableFrom( type ) ) {
return (X) new BinaryStreamImpl( toBytes( value ) );
}
throw unknownUnwrap( type ); throw unknownUnwrap( type );
} }

View File

@ -23,6 +23,8 @@
*/ */
package org.hibernate.type.descriptor.java; package org.hibernate.type.descriptor.java;
import org.hibernate.type.descriptor.WrapperOptions;
/** /**
* Descriptor for {@link Short} handling. * Descriptor for {@link Short} handling.
* *

View File

@ -29,6 +29,8 @@ import java.sql.Clob;
import java.sql.SQLException; import java.sql.SQLException;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.type.descriptor.CharacterStream;
import org.hibernate.type.descriptor.WrapperOptions;
/** /**
* Descriptor for {@link String} handling. * Descriptor for {@link String} handling.
@ -61,6 +63,9 @@ public class StringTypeDescriptor extends AbstractTypeDescriptor<String> {
if ( Reader.class.isAssignableFrom( type ) ) { if ( Reader.class.isAssignableFrom( type ) ) {
return (X) new StringReader( (String) value ); return (X) new StringReader( (String) value );
} }
if ( CharacterStream.class.isAssignableFrom( type ) ) {
return (X) new CharacterStreamImpl( (String) value );
}
if ( Clob.class.isAssignableFrom( type ) ) { if ( Clob.class.isAssignableFrom( type ) ) {
return (X) options.getLobCreator().createClob( value ); return (X) options.getLobCreator().createClob( value );
} }

View File

@ -26,6 +26,8 @@ package org.hibernate.type.descriptor.java;
import java.util.Comparator; import java.util.Comparator;
import java.util.TimeZone; import java.util.TimeZone;
import org.hibernate.type.descriptor.WrapperOptions;
/** /**
* TODO : javadoc * TODO : javadoc
* *

View File

@ -29,17 +29,16 @@ import java.sql.SQLException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.hibernate.type.descriptor.ValueBinder;
import org.hibernate.type.descriptor.WrapperOptions;
import org.hibernate.type.descriptor.java.JavaTypeDescriptor; import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
import org.hibernate.type.descriptor.java.WrapperOptions;
import static org.hibernate.type.descriptor.sql.SqlTypeDescriptor.Binder;
/** /**
* Convenience base implementation of {@link Binder} * Convenience base implementation of {@link ValueBinder}
* *
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public abstract class BasicBinder<J> implements Binder<J> { public abstract class BasicBinder<J> implements ValueBinder<J> {
private static final Logger log = LoggerFactory.getLogger( BasicBinder.class ); private static final Logger log = LoggerFactory.getLogger( BasicBinder.class );
private final JavaTypeDescriptor<J> javaDescriptor; private final JavaTypeDescriptor<J> javaDescriptor;

View File

@ -29,17 +29,16 @@ import java.sql.SQLException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.hibernate.type.descriptor.ValueExtractor;
import org.hibernate.type.descriptor.WrapperOptions;
import org.hibernate.type.descriptor.java.JavaTypeDescriptor; import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
import org.hibernate.type.descriptor.java.WrapperOptions;
import static org.hibernate.type.descriptor.sql.SqlTypeDescriptor.Extractor;
/** /**
* Convenience base implementation of {@link Extractor} * Convenience base implementation of {@link org.hibernate.type.descriptor.ValueExtractor}
* *
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public abstract class BasicExtractor<J> implements Extractor<J> { public abstract class BasicExtractor<J> implements ValueExtractor<J> {
private static final Logger log = LoggerFactory.getLogger( BasicExtractor.class ); private static final Logger log = LoggerFactory.getLogger( BasicExtractor.class );
private final JavaTypeDescriptor<J> javaDescriptor; private final JavaTypeDescriptor<J> javaDescriptor;

View File

@ -28,8 +28,10 @@ import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Types; import java.sql.Types;
import org.hibernate.type.descriptor.ValueBinder;
import org.hibernate.type.descriptor.ValueExtractor;
import org.hibernate.type.descriptor.WrapperOptions;
import org.hibernate.type.descriptor.java.JavaTypeDescriptor; import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
import org.hibernate.type.descriptor.java.WrapperOptions;
/** /**
* Descriptor for {@link Types#BIGINT BIGINT} handling. * Descriptor for {@link Types#BIGINT BIGINT} handling.
@ -43,7 +45,7 @@ public class BigIntTypeDescriptor implements SqlTypeDescriptor {
return Types.BIGINT; return Types.BIGINT;
} }
public <X> Binder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) { public <X> ValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicBinder<X>( javaTypeDescriptor, this ) { return new BasicBinder<X>( javaTypeDescriptor, this ) {
@Override @Override
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException { protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException {
@ -52,7 +54,7 @@ public class BigIntTypeDescriptor implements SqlTypeDescriptor {
}; };
} }
public <X> Extractor<X> getExtractor(final JavaTypeDescriptor<X> javaTypeDescriptor) { public <X> ValueExtractor<X> getExtractor(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicExtractor<X>( javaTypeDescriptor, this ) { return new BasicExtractor<X>( javaTypeDescriptor, this ) {
@Override @Override
protected X doExtract(ResultSet rs, String name, WrapperOptions options) throws SQLException { protected X doExtract(ResultSet rs, String name, WrapperOptions options) throws SQLException {

View File

@ -28,8 +28,10 @@ import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Types; import java.sql.Types;
import org.hibernate.type.descriptor.ValueBinder;
import org.hibernate.type.descriptor.ValueExtractor;
import org.hibernate.type.descriptor.WrapperOptions;
import org.hibernate.type.descriptor.java.JavaTypeDescriptor; import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
import org.hibernate.type.descriptor.java.WrapperOptions;
/** /**
* Descriptor for {@link Types#BIT BIT} handling. * Descriptor for {@link Types#BIT BIT} handling.
@ -46,7 +48,7 @@ public class BitTypeDescriptor implements SqlTypeDescriptor {
return Types.BIT; return Types.BIT;
} }
public <X> Binder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) { public <X> ValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicBinder<X>( javaTypeDescriptor, this ) { return new BasicBinder<X>( javaTypeDescriptor, this ) {
@Override @Override
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException { protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException {
@ -55,7 +57,7 @@ public class BitTypeDescriptor implements SqlTypeDescriptor {
}; };
} }
public <X> Extractor<X> getExtractor(final JavaTypeDescriptor<X> javaTypeDescriptor) { public <X> ValueExtractor<X> getExtractor(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicExtractor<X>( javaTypeDescriptor, this ) { return new BasicExtractor<X>( javaTypeDescriptor, this ) {
@Override @Override
protected X doExtract(ResultSet rs, String name, WrapperOptions options) throws SQLException { protected X doExtract(ResultSet rs, String name, WrapperOptions options) throws SQLException {

View File

@ -30,8 +30,11 @@ import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Types; import java.sql.Types;
import org.hibernate.type.descriptor.BinaryStream;
import org.hibernate.type.descriptor.ValueBinder;
import org.hibernate.type.descriptor.ValueExtractor;
import org.hibernate.type.descriptor.java.JavaTypeDescriptor; import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
import org.hibernate.type.descriptor.java.WrapperOptions; import org.hibernate.type.descriptor.WrapperOptions;
/** /**
* Descriptor for {@link Types#BLOB BLOB} handling. * Descriptor for {@link Types#BLOB BLOB} handling.
@ -45,12 +48,13 @@ public class BlobTypeDescriptor implements SqlTypeDescriptor {
return Types.BLOB; return Types.BLOB;
} }
public <X> Binder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) { public <X> ValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicBinder<X>( javaTypeDescriptor, this ) { return new BasicBinder<X>( javaTypeDescriptor, this ) {
@Override @Override
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException { protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException {
if ( options.useStreamForLobBinding() ) { if ( options.useStreamForLobBinding() ) {
st.setBinaryStream( index, getJavaDescriptor().unwrap( value, InputStream.class, options ) ); final BinaryStream binaryStream = javaTypeDescriptor.unwrap( value, BinaryStream.class, options );
st.setBinaryStream( index, binaryStream.getInputStream(), binaryStream.getLength() );
} }
else { else {
st.setBlob( index, javaTypeDescriptor.unwrap( value, Blob.class, options ) ); st.setBlob( index, javaTypeDescriptor.unwrap( value, Blob.class, options ) );
@ -59,7 +63,7 @@ public class BlobTypeDescriptor implements SqlTypeDescriptor {
}; };
} }
public <X> Extractor<X> getExtractor(final JavaTypeDescriptor<X> javaTypeDescriptor) { public <X> ValueExtractor<X> getExtractor(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicExtractor<X>( javaTypeDescriptor, this ) { return new BasicExtractor<X>( javaTypeDescriptor, this ) {
@Override @Override
protected X doExtract(ResultSet rs, String name, WrapperOptions options) throws SQLException { protected X doExtract(ResultSet rs, String name, WrapperOptions options) throws SQLException {

View File

@ -30,8 +30,11 @@ import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Types; import java.sql.Types;
import org.hibernate.type.descriptor.CharacterStream;
import org.hibernate.type.descriptor.ValueBinder;
import org.hibernate.type.descriptor.ValueExtractor;
import org.hibernate.type.descriptor.WrapperOptions;
import org.hibernate.type.descriptor.java.JavaTypeDescriptor; import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
import org.hibernate.type.descriptor.java.WrapperOptions;
/** /**
* Descriptor for {@link Types#CLOB CLOB} handling. * Descriptor for {@link Types#CLOB CLOB} handling.
@ -45,12 +48,13 @@ public class ClobTypeDescriptor implements SqlTypeDescriptor {
return Types.CLOB; return Types.CLOB;
} }
public <X> Binder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) { public <X> ValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicBinder<X>( javaTypeDescriptor, this ) { return new BasicBinder<X>( javaTypeDescriptor, this ) {
@Override @Override
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException { protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException {
if ( options.useStreamForLobBinding() ) { if ( options.useStreamForLobBinding() ) {
st.setCharacterStream( index, getJavaDescriptor().unwrap( value, Reader.class, options ) ); final CharacterStream characterStream = javaTypeDescriptor.unwrap( value, CharacterStream.class, options );
st.setCharacterStream( index, characterStream.getReader(), characterStream.getLength() );
} }
else { else {
st.setClob( index, javaTypeDescriptor.unwrap( value, Clob.class, options ) ); st.setClob( index, javaTypeDescriptor.unwrap( value, Clob.class, options ) );
@ -59,7 +63,7 @@ public class ClobTypeDescriptor implements SqlTypeDescriptor {
}; };
} }
public <X> Extractor<X> getExtractor(final JavaTypeDescriptor<X> javaTypeDescriptor) { public <X> ValueExtractor<X> getExtractor(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicExtractor<X>( javaTypeDescriptor, this ) { return new BasicExtractor<X>( javaTypeDescriptor, this ) {
@Override @Override
protected X doExtract(ResultSet rs, String name, WrapperOptions options) throws SQLException { protected X doExtract(ResultSet rs, String name, WrapperOptions options) throws SQLException {

View File

@ -29,8 +29,10 @@ import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Types; import java.sql.Types;
import org.hibernate.type.descriptor.ValueBinder;
import org.hibernate.type.descriptor.ValueExtractor;
import org.hibernate.type.descriptor.WrapperOptions;
import org.hibernate.type.descriptor.java.JavaTypeDescriptor; import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
import org.hibernate.type.descriptor.java.WrapperOptions;
/** /**
* Descriptor for {@link Types#DATE DATE} handling. * Descriptor for {@link Types#DATE DATE} handling.
@ -44,7 +46,7 @@ public class DateTypeDescriptor implements SqlTypeDescriptor {
return Types.DATE; return Types.DATE;
} }
public <X> Binder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) { public <X> ValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicBinder<X>( javaTypeDescriptor, this ) { return new BasicBinder<X>( javaTypeDescriptor, this ) {
@Override @Override
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException { protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException {
@ -53,7 +55,7 @@ public class DateTypeDescriptor implements SqlTypeDescriptor {
}; };
} }
public <X> Extractor<X> getExtractor(final JavaTypeDescriptor<X> javaTypeDescriptor) { public <X> ValueExtractor<X> getExtractor(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicExtractor<X>( javaTypeDescriptor, this ) { return new BasicExtractor<X>( javaTypeDescriptor, this ) {
@Override @Override
protected X doExtract(ResultSet rs, String name, WrapperOptions options) throws SQLException { protected X doExtract(ResultSet rs, String name, WrapperOptions options) throws SQLException {

View File

@ -29,8 +29,10 @@ import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Types; import java.sql.Types;
import org.hibernate.type.descriptor.ValueBinder;
import org.hibernate.type.descriptor.ValueExtractor;
import org.hibernate.type.descriptor.java.JavaTypeDescriptor; import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
import org.hibernate.type.descriptor.java.WrapperOptions; import org.hibernate.type.descriptor.WrapperOptions;
/** /**
* Descriptor for {@link Types#DECIMAL DECIMAL} handling. * Descriptor for {@link Types#DECIMAL DECIMAL} handling.
@ -44,7 +46,7 @@ public class DecimalTypeDescriptor implements SqlTypeDescriptor {
return Types.DECIMAL; return Types.DECIMAL;
} }
public <X> Binder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) { public <X> ValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicBinder<X>( javaTypeDescriptor, this ) { return new BasicBinder<X>( javaTypeDescriptor, this ) {
@Override @Override
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException { protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException {
@ -53,7 +55,7 @@ public class DecimalTypeDescriptor implements SqlTypeDescriptor {
}; };
} }
public <X> Extractor<X> getExtractor(final JavaTypeDescriptor<X> javaTypeDescriptor) { public <X> ValueExtractor<X> getExtractor(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicExtractor<X>( javaTypeDescriptor, this ) { return new BasicExtractor<X>( javaTypeDescriptor, this ) {
@Override @Override
protected X doExtract(ResultSet rs, String name, WrapperOptions options) throws SQLException { protected X doExtract(ResultSet rs, String name, WrapperOptions options) throws SQLException {

View File

@ -28,8 +28,10 @@ import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Types; import java.sql.Types;
import org.hibernate.type.descriptor.ValueBinder;
import org.hibernate.type.descriptor.ValueExtractor;
import org.hibernate.type.descriptor.WrapperOptions;
import org.hibernate.type.descriptor.java.JavaTypeDescriptor; import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
import org.hibernate.type.descriptor.java.WrapperOptions;
/** /**
* Descriptor for {@link Types#DOUBLE DOUBLE} handling. * Descriptor for {@link Types#DOUBLE DOUBLE} handling.
@ -43,7 +45,7 @@ public class DoubleTypeDescriptor implements SqlTypeDescriptor {
return Types.DOUBLE; return Types.DOUBLE;
} }
public <X> Binder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) { public <X> ValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicBinder<X>( javaTypeDescriptor, this ) { return new BasicBinder<X>( javaTypeDescriptor, this ) {
@Override @Override
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException { protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException {
@ -52,7 +54,7 @@ public class DoubleTypeDescriptor implements SqlTypeDescriptor {
}; };
} }
public <X> Extractor<X> getExtractor(final JavaTypeDescriptor<X> javaTypeDescriptor) { public <X> ValueExtractor<X> getExtractor(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicExtractor<X>( javaTypeDescriptor, this ) { return new BasicExtractor<X>( javaTypeDescriptor, this ) {
@Override @Override
protected X doExtract(ResultSet rs, String name, WrapperOptions options) throws SQLException { protected X doExtract(ResultSet rs, String name, WrapperOptions options) throws SQLException {

View File

@ -28,8 +28,10 @@ import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Types; import java.sql.Types;
import org.hibernate.type.descriptor.ValueBinder;
import org.hibernate.type.descriptor.ValueExtractor;
import org.hibernate.type.descriptor.WrapperOptions;
import org.hibernate.type.descriptor.java.JavaTypeDescriptor; import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
import org.hibernate.type.descriptor.java.WrapperOptions;
/** /**
* Descriptor for {@link Types#INTEGER INTEGER} handling. * Descriptor for {@link Types#INTEGER INTEGER} handling.
@ -43,7 +45,7 @@ public class IntegerTypeDescriptor implements SqlTypeDescriptor {
return Types.INTEGER; return Types.INTEGER;
} }
public <X> Binder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) { public <X> ValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicBinder<X>( javaTypeDescriptor, this ) { return new BasicBinder<X>( javaTypeDescriptor, this ) {
@Override @Override
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException { protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException {
@ -52,7 +54,7 @@ public class IntegerTypeDescriptor implements SqlTypeDescriptor {
}; };
} }
public <X> Extractor<X> getExtractor(final JavaTypeDescriptor<X> javaTypeDescriptor) { public <X> ValueExtractor<X> getExtractor(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicExtractor<X>( javaTypeDescriptor, this ) { return new BasicExtractor<X>( javaTypeDescriptor, this ) {
@Override @Override
protected X doExtract(ResultSet rs, String name, WrapperOptions options) throws SQLException { protected X doExtract(ResultSet rs, String name, WrapperOptions options) throws SQLException {

View File

@ -28,8 +28,10 @@ import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Types; import java.sql.Types;
import org.hibernate.type.descriptor.ValueBinder;
import org.hibernate.type.descriptor.ValueExtractor;
import org.hibernate.type.descriptor.java.JavaTypeDescriptor; import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
import org.hibernate.type.descriptor.java.WrapperOptions; import org.hibernate.type.descriptor.WrapperOptions;
/** /**
* Descriptor for {@link Types#REAL REAL} handling. * Descriptor for {@link Types#REAL REAL} handling.
@ -43,7 +45,7 @@ public class RealTypeDescriptor implements SqlTypeDescriptor {
return Types.REAL; return Types.REAL;
} }
public <X> Binder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) { public <X> ValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicBinder<X>( javaTypeDescriptor, this ) { return new BasicBinder<X>( javaTypeDescriptor, this ) {
@Override @Override
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException { protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException {
@ -52,7 +54,7 @@ public class RealTypeDescriptor implements SqlTypeDescriptor {
}; };
} }
public <X> Extractor<X> getExtractor(final JavaTypeDescriptor<X> javaTypeDescriptor) { public <X> ValueExtractor<X> getExtractor(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicExtractor<X>( javaTypeDescriptor, this ) { return new BasicExtractor<X>( javaTypeDescriptor, this ) {
@Override @Override
protected X doExtract(ResultSet rs, String name, WrapperOptions options) throws SQLException { protected X doExtract(ResultSet rs, String name, WrapperOptions options) throws SQLException {

View File

@ -28,8 +28,10 @@ import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Types; import java.sql.Types;
import org.hibernate.type.descriptor.ValueBinder;
import org.hibernate.type.descriptor.ValueExtractor;
import org.hibernate.type.descriptor.WrapperOptions;
import org.hibernate.type.descriptor.java.JavaTypeDescriptor; import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
import org.hibernate.type.descriptor.java.WrapperOptions;
/** /**
* Descriptor for {@link Types#SMALLINT SMALLINT} handling. * Descriptor for {@link Types#SMALLINT SMALLINT} handling.
@ -43,7 +45,7 @@ public class SmallIntTypeDescriptor implements SqlTypeDescriptor {
return Types.SMALLINT; return Types.SMALLINT;
} }
public <X> Binder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) { public <X> ValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicBinder<X>( javaTypeDescriptor, this ) { return new BasicBinder<X>( javaTypeDescriptor, this ) {
@Override @Override
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException { protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException {
@ -52,7 +54,7 @@ public class SmallIntTypeDescriptor implements SqlTypeDescriptor {
}; };
} }
public <X> Extractor<X> getExtractor(final JavaTypeDescriptor<X> javaTypeDescriptor) { public <X> ValueExtractor<X> getExtractor(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicExtractor<X>( javaTypeDescriptor, this ) { return new BasicExtractor<X>( javaTypeDescriptor, this ) {
@Override @Override
protected X doExtract(ResultSet rs, String name, WrapperOptions options) throws SQLException { protected X doExtract(ResultSet rs, String name, WrapperOptions options) throws SQLException {

View File

@ -24,12 +24,10 @@
package org.hibernate.type.descriptor.sql; package org.hibernate.type.descriptor.sql;
import java.io.Serializable; import java.io.Serializable;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.hibernate.type.descriptor.ValueBinder;
import org.hibernate.type.descriptor.ValueExtractor;
import org.hibernate.type.descriptor.java.JavaTypeDescriptor; import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
import org.hibernate.type.descriptor.java.WrapperOptions;
/** /**
* Descriptor for the <tt>SQL</tt>/<tt>JDBC</tt> side of a value mapping. * Descriptor for the <tt>SQL</tt>/<tt>JDBC</tt> side of a value mapping.
@ -44,15 +42,7 @@ public interface SqlTypeDescriptor extends Serializable {
*/ */
public int getSqlType(); public int getSqlType();
public static interface Binder<X> { public <X> ValueBinder<X> getBinder(JavaTypeDescriptor<X> javaTypeDescriptor);
public void bind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException;
}
public <X> Binder<X> getBinder(JavaTypeDescriptor<X> javaTypeDescriptor); public <X> ValueExtractor<X> getExtractor(JavaTypeDescriptor<X> javaTypeDescriptor);
public static interface Extractor<X> {
public X extract(ResultSet rs, String name, WrapperOptions options) throws SQLException;
}
public <X> Extractor<X> getExtractor(JavaTypeDescriptor<X> javaTypeDescriptor);
} }

View File

@ -29,8 +29,10 @@ import java.sql.SQLException;
import java.sql.Time; import java.sql.Time;
import java.sql.Types; import java.sql.Types;
import org.hibernate.type.descriptor.ValueBinder;
import org.hibernate.type.descriptor.ValueExtractor;
import org.hibernate.type.descriptor.java.JavaTypeDescriptor; import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
import org.hibernate.type.descriptor.java.WrapperOptions; import org.hibernate.type.descriptor.WrapperOptions;
/** /**
* Descriptor for {@link Types#TIME TIME} handling. * Descriptor for {@link Types#TIME TIME} handling.
@ -44,7 +46,7 @@ public class TimeTypeDescriptor implements SqlTypeDescriptor {
return Types.TIME; return Types.TIME;
} }
public <X> Binder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) { public <X> ValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicBinder<X>( javaTypeDescriptor, this ) { return new BasicBinder<X>( javaTypeDescriptor, this ) {
@Override @Override
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException { protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException {
@ -53,7 +55,7 @@ public class TimeTypeDescriptor implements SqlTypeDescriptor {
}; };
} }
public <X> Extractor<X> getExtractor(final JavaTypeDescriptor<X> javaTypeDescriptor) { public <X> ValueExtractor<X> getExtractor(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicExtractor<X>( javaTypeDescriptor, this ) { return new BasicExtractor<X>( javaTypeDescriptor, this ) {
@Override @Override
protected X doExtract(ResultSet rs, String name, WrapperOptions options) throws SQLException { protected X doExtract(ResultSet rs, String name, WrapperOptions options) throws SQLException {

View File

@ -29,8 +29,10 @@ import java.sql.SQLException;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.sql.Types; import java.sql.Types;
import org.hibernate.type.descriptor.ValueBinder;
import org.hibernate.type.descriptor.ValueExtractor;
import org.hibernate.type.descriptor.java.JavaTypeDescriptor; import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
import org.hibernate.type.descriptor.java.WrapperOptions; import org.hibernate.type.descriptor.WrapperOptions;
/** /**
* Descriptor for {@link Types#TIMESTAMP TIMESTAMP} handling. * Descriptor for {@link Types#TIMESTAMP TIMESTAMP} handling.
@ -44,7 +46,7 @@ public class TimestampTypeDescriptor implements SqlTypeDescriptor {
return Types.TIMESTAMP; return Types.TIMESTAMP;
} }
public <X> Binder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) { public <X> ValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicBinder<X>( javaTypeDescriptor, this ) { return new BasicBinder<X>( javaTypeDescriptor, this ) {
@Override @Override
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException { protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException {
@ -53,7 +55,7 @@ public class TimestampTypeDescriptor implements SqlTypeDescriptor {
}; };
} }
public <X> Extractor<X> getExtractor(final JavaTypeDescriptor<X> javaTypeDescriptor) { public <X> ValueExtractor<X> getExtractor(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicExtractor<X>( javaTypeDescriptor, this ) { return new BasicExtractor<X>( javaTypeDescriptor, this ) {
@Override @Override
protected X doExtract(ResultSet rs, String name, WrapperOptions options) throws SQLException { protected X doExtract(ResultSet rs, String name, WrapperOptions options) throws SQLException {

View File

@ -28,8 +28,10 @@ import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Types; import java.sql.Types;
import org.hibernate.type.descriptor.ValueBinder;
import org.hibernate.type.descriptor.ValueExtractor;
import org.hibernate.type.descriptor.WrapperOptions;
import org.hibernate.type.descriptor.java.JavaTypeDescriptor; import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
import org.hibernate.type.descriptor.java.WrapperOptions;
/** /**
* Descriptor for {@link Types#TINYINT TINYINT} handling. * Descriptor for {@link Types#TINYINT TINYINT} handling.
@ -46,7 +48,7 @@ public class TinyIntTypeDescriptor implements SqlTypeDescriptor {
return Types.TINYINT; return Types.TINYINT;
} }
public <X> Binder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) { public <X> ValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicBinder<X>( javaTypeDescriptor, this ) { return new BasicBinder<X>( javaTypeDescriptor, this ) {
@Override @Override
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException { protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException {
@ -55,7 +57,7 @@ public class TinyIntTypeDescriptor implements SqlTypeDescriptor {
}; };
} }
public <X> Extractor<X> getExtractor(final JavaTypeDescriptor<X> javaTypeDescriptor) { public <X> ValueExtractor<X> getExtractor(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicExtractor<X>( javaTypeDescriptor, this ) { return new BasicExtractor<X>( javaTypeDescriptor, this ) {
@Override @Override
protected X doExtract(ResultSet rs, String name, WrapperOptions options) throws SQLException { protected X doExtract(ResultSet rs, String name, WrapperOptions options) throws SQLException {

View File

@ -28,8 +28,10 @@ import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Types; import java.sql.Types;
import org.hibernate.type.descriptor.ValueBinder;
import org.hibernate.type.descriptor.ValueExtractor;
import org.hibernate.type.descriptor.WrapperOptions;
import org.hibernate.type.descriptor.java.JavaTypeDescriptor; import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
import org.hibernate.type.descriptor.java.WrapperOptions;
/** /**
* Descriptor for {@link Types#VARBINARY VARBINARY} handling. * Descriptor for {@link Types#VARBINARY VARBINARY} handling.
@ -43,7 +45,7 @@ public class VarbinaryTypeDescriptor implements SqlTypeDescriptor {
return Types.VARBINARY; return Types.VARBINARY;
} }
public <X> Binder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) { public <X> ValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicBinder<X>( javaTypeDescriptor, this ) { return new BasicBinder<X>( javaTypeDescriptor, this ) {
@Override @Override
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException { protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException {
@ -52,7 +54,7 @@ public class VarbinaryTypeDescriptor implements SqlTypeDescriptor {
}; };
} }
public <X> Extractor<X> getExtractor(final JavaTypeDescriptor<X> javaTypeDescriptor) { public <X> ValueExtractor<X> getExtractor(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicExtractor<X>( javaTypeDescriptor, this ) { return new BasicExtractor<X>( javaTypeDescriptor, this ) {
@Override @Override
protected X doExtract(ResultSet rs, String name, WrapperOptions options) throws SQLException { protected X doExtract(ResultSet rs, String name, WrapperOptions options) throws SQLException {

View File

@ -28,8 +28,10 @@ import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Types; import java.sql.Types;
import org.hibernate.type.descriptor.ValueBinder;
import org.hibernate.type.descriptor.ValueExtractor;
import org.hibernate.type.descriptor.WrapperOptions;
import org.hibernate.type.descriptor.java.JavaTypeDescriptor; import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
import org.hibernate.type.descriptor.java.WrapperOptions;
/** /**
* Descriptor for {@link Types#VARCHAR VARCHAR} handling. * Descriptor for {@link Types#VARCHAR VARCHAR} handling.
@ -43,7 +45,7 @@ public class VarcharTypeDescriptor implements SqlTypeDescriptor {
return Types.VARCHAR; return Types.VARCHAR;
} }
public <X> Binder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) { public <X> ValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicBinder<X>( javaTypeDescriptor, this ) { return new BasicBinder<X>( javaTypeDescriptor, this ) {
@Override @Override
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException { protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException {
@ -52,7 +54,7 @@ public class VarcharTypeDescriptor implements SqlTypeDescriptor {
}; };
} }
public <X> Extractor<X> getExtractor(final JavaTypeDescriptor<X> javaTypeDescriptor) { public <X> ValueExtractor<X> getExtractor(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicExtractor<X>( javaTypeDescriptor, this ) { return new BasicExtractor<X>( javaTypeDescriptor, this ) {
@Override @Override
protected X doExtract(ResultSet rs, String name, WrapperOptions options) throws SQLException { protected X doExtract(ResultSet rs, String name, WrapperOptions options) throws SQLException {

View File

@ -32,10 +32,11 @@ import junit.framework.TestCase;
import org.hibernate.engine.jdbc.LobCreator; import org.hibernate.engine.jdbc.LobCreator;
import org.hibernate.engine.jdbc.NonContextualLobCreator; import org.hibernate.engine.jdbc.NonContextualLobCreator;
import org.hibernate.type.descriptor.ValueBinder;
import org.hibernate.type.descriptor.ValueExtractor;
import org.hibernate.type.descriptor.WrapperOptions;
import org.hibernate.type.descriptor.java.StringTypeDescriptor; import org.hibernate.type.descriptor.java.StringTypeDescriptor;
import org.hibernate.type.descriptor.java.WrapperOptions;
import org.hibernate.type.descriptor.sql.ClobTypeDescriptor; import org.hibernate.type.descriptor.sql.ClobTypeDescriptor;
import org.hibernate.type.descriptor.sql.SqlTypeDescriptor;
import org.hibernate.type.descriptor.sql.VarcharTypeDescriptor; import org.hibernate.type.descriptor.sql.VarcharTypeDescriptor;
/** /**
@ -63,8 +64,8 @@ public class StringValueMappingTest extends TestCase {
public static final int BIND_POSITION = -1; public static final int BIND_POSITION = -1;
public void testNormalVarcharHandling() throws SQLException { public void testNormalVarcharHandling() throws SQLException {
final SqlTypeDescriptor.Extractor<String> extractor = varcharSqlDescriptor.getExtractor( stringJavaDescriptor ); final ValueExtractor<String> extractor = varcharSqlDescriptor.getExtractor( stringJavaDescriptor );
final SqlTypeDescriptor.Binder<String> binder = varcharSqlDescriptor.getBinder( stringJavaDescriptor ); final ValueBinder<String> binder = varcharSqlDescriptor.getBinder( stringJavaDescriptor );
final String fixture = "string value"; final String fixture = "string value";
@ -77,8 +78,8 @@ public class StringValueMappingTest extends TestCase {
} }
public void testNullVarcharHandling() throws SQLException { public void testNullVarcharHandling() throws SQLException {
final SqlTypeDescriptor.Extractor<String> extractor = varcharSqlDescriptor.getExtractor( stringJavaDescriptor ); final ValueExtractor<String> extractor = varcharSqlDescriptor.getExtractor( stringJavaDescriptor );
final SqlTypeDescriptor.Binder<String> binder = varcharSqlDescriptor.getBinder( stringJavaDescriptor ); final ValueBinder<String> binder = varcharSqlDescriptor.getBinder( stringJavaDescriptor );
final String fixture = null; final String fixture = null;
@ -91,8 +92,8 @@ public class StringValueMappingTest extends TestCase {
} }
public void testNormalClobHandling() throws SQLException { public void testNormalClobHandling() throws SQLException {
final SqlTypeDescriptor.Extractor<String> extractor = clobSqlDescriptor.getExtractor( stringJavaDescriptor ); final ValueExtractor<String> extractor = clobSqlDescriptor.getExtractor( stringJavaDescriptor );
final SqlTypeDescriptor.Binder<String> binder = clobSqlDescriptor.getBinder( stringJavaDescriptor ); final ValueBinder<String> binder = clobSqlDescriptor.getBinder( stringJavaDescriptor );
final String fixture = "clob string"; final String fixture = "clob string";
final Clob clob = new StringClobImpl( fixture ); final Clob clob = new StringClobImpl( fixture );
@ -106,8 +107,8 @@ public class StringValueMappingTest extends TestCase {
} }
public void testNullClobHandling() throws SQLException { public void testNullClobHandling() throws SQLException {
final SqlTypeDescriptor.Extractor<String> extractor = clobSqlDescriptor.getExtractor( stringJavaDescriptor ); final ValueExtractor<String> extractor = clobSqlDescriptor.getExtractor( stringJavaDescriptor );
final SqlTypeDescriptor.Binder<String> binder = clobSqlDescriptor.getBinder( stringJavaDescriptor ); final ValueBinder<String> binder = clobSqlDescriptor.getBinder( stringJavaDescriptor );
final String fixture = null; final String fixture = null;
final Clob clob = null; final Clob clob = null;