HHH-9678 - Change built-in SqlTypeDescriptor impls to not auto-register themselves with SqlTypeDescriptorRegistry

(cherry picked from commit f6322b5cdd)

Conflicts:
	working-5.0-migration-guide.md
This commit is contained in:
Steve Ebersole 2015-03-23 11:19:02 -05:00
parent ec849edfad
commit a736487745
27 changed files with 130 additions and 138 deletions

View File

@ -43,7 +43,6 @@ public class BigIntTypeDescriptor implements SqlTypeDescriptor {
public static final BigIntTypeDescriptor INSTANCE = new BigIntTypeDescriptor();
public BigIntTypeDescriptor() {
SqlTypeDescriptorRegistry.INSTANCE.addDescriptor( this );
}
@Override

View File

@ -33,7 +33,6 @@ public class BinaryTypeDescriptor extends VarbinaryTypeDescriptor {
public static final BinaryTypeDescriptor INSTANCE = new BinaryTypeDescriptor();
public BinaryTypeDescriptor() {
SqlTypeDescriptorRegistry.INSTANCE.addDescriptor( this );
}
@Override

View File

@ -46,7 +46,6 @@ public class BitTypeDescriptor implements SqlTypeDescriptor {
public static final BitTypeDescriptor INSTANCE = new BitTypeDescriptor();
public BitTypeDescriptor() {
SqlTypeDescriptorRegistry.INSTANCE.addDescriptor( this );
}
public int getSqlType() {

View File

@ -86,10 +86,6 @@ public abstract class BlobTypeDescriptor implements SqlTypeDescriptor {
}
public static final BlobTypeDescriptor DEFAULT = new BlobTypeDescriptor() {
{
SqlTypeDescriptorRegistry.INSTANCE.addDescriptor( this );
}
@Override
public <X> BasicBinder<X> getBlobBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicBinder<X>( javaTypeDescriptor, this ) {

View File

@ -43,7 +43,6 @@ public class BooleanTypeDescriptor implements SqlTypeDescriptor {
public static final BooleanTypeDescriptor INSTANCE = new BooleanTypeDescriptor();
public BooleanTypeDescriptor() {
SqlTypeDescriptorRegistry.INSTANCE.addDescriptor( this );
}
public int getSqlType() {

View File

@ -33,7 +33,6 @@ public class CharTypeDescriptor extends VarcharTypeDescriptor {
public static final CharTypeDescriptor INSTANCE = new CharTypeDescriptor();
public CharTypeDescriptor() {
SqlTypeDescriptorRegistry.INSTANCE.addDescriptor( this );
}
@Override

View File

@ -83,92 +83,84 @@ public abstract class ClobTypeDescriptor implements SqlTypeDescriptor {
}
public static final ClobTypeDescriptor DEFAULT =
new ClobTypeDescriptor() {
{
SqlTypeDescriptorRegistry.INSTANCE.addDescriptor( this );
}
public static final ClobTypeDescriptor DEFAULT = new ClobTypeDescriptor() {
@Override
public <X> BasicBinder<X> getClobBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicBinder<X>( javaTypeDescriptor, this ) {
@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 );
}
}
};
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 );
}
}
};
}
};
public static final ClobTypeDescriptor CLOB_BINDING =
new ClobTypeDescriptor() {
public static final ClobTypeDescriptor CLOB_BINDING = new ClobTypeDescriptor() {
@Override
public <X> BasicBinder<X> getClobBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicBinder<X>( javaTypeDescriptor, this ) {
@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 ) );
}
};
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options)
throws SQLException {
st.setClob( index, javaTypeDescriptor.unwrap( value, Clob.class, options ) );
}
};
}
};
public static final ClobTypeDescriptor STREAM_BINDING =
new ClobTypeDescriptor() {
public static final ClobTypeDescriptor STREAM_BINDING = new ClobTypeDescriptor() {
@Override
public <X> BasicBinder<X> getClobBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicBinder<X>( javaTypeDescriptor, this ) {
@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() );
}
};
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 static final ClobTypeDescriptor STREAM_BINDING_EXTRACTING =
new ClobTypeDescriptor() {
public static final ClobTypeDescriptor STREAM_BINDING_EXTRACTING = new ClobTypeDescriptor() {
@Override
public <X> BasicBinder<X> getClobBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicBinder<X>( javaTypeDescriptor, this ) {
@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> ValueExtractor<X> getExtractor(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicExtractor<X>( javaTypeDescriptor, this ) {
@Override
protected X doExtract(ResultSet rs, String name, WrapperOptions options) throws SQLException {
return javaTypeDescriptor.wrap( rs.getCharacterStream( name ), options );
}
@Override
protected X doExtract(CallableStatement statement, int index, WrapperOptions options)
throws SQLException {
return javaTypeDescriptor.wrap( statement.getCharacterStream( index ), options );
}
@Override
protected X doExtract(CallableStatement statement, String name, WrapperOptions options)
throws SQLException {
return javaTypeDescriptor.wrap( statement.getCharacterStream( name ), options );
}
};
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> ValueExtractor<X> getExtractor(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicExtractor<X>( javaTypeDescriptor, this ) {
@Override
protected X doExtract(ResultSet rs, String name, WrapperOptions options) throws SQLException {
return javaTypeDescriptor.wrap( rs.getCharacterStream( name ), options );
}
@Override
protected X doExtract(CallableStatement statement, int index, WrapperOptions options)
throws SQLException {
return javaTypeDescriptor.wrap( statement.getCharacterStream( index ), options );
}
@Override
protected X doExtract(CallableStatement statement, String name, WrapperOptions options)
throws SQLException {
return javaTypeDescriptor.wrap( statement.getCharacterStream( name ), options );
}
};
}
};
}

View File

@ -44,7 +44,6 @@ public class DateTypeDescriptor implements SqlTypeDescriptor {
public static final DateTypeDescriptor INSTANCE = new DateTypeDescriptor();
public DateTypeDescriptor() {
SqlTypeDescriptorRegistry.INSTANCE.addDescriptor( this );
}
@Override

View File

@ -44,7 +44,6 @@ public class DecimalTypeDescriptor implements SqlTypeDescriptor {
public static final DecimalTypeDescriptor INSTANCE = new DecimalTypeDescriptor();
public DecimalTypeDescriptor() {
SqlTypeDescriptorRegistry.INSTANCE.addDescriptor( this );
}
@Override

View File

@ -43,7 +43,6 @@ public class DoubleTypeDescriptor implements SqlTypeDescriptor {
public static final DoubleTypeDescriptor INSTANCE = new DoubleTypeDescriptor();
public DoubleTypeDescriptor() {
SqlTypeDescriptorRegistry.INSTANCE.addDescriptor( this );
}
@Override

View File

@ -34,7 +34,6 @@ public class FloatTypeDescriptor extends RealTypeDescriptor {
public static final FloatTypeDescriptor INSTANCE = new FloatTypeDescriptor();
public FloatTypeDescriptor() {
SqlTypeDescriptorRegistry.INSTANCE.addDescriptor( this );
}
@Override

View File

@ -43,7 +43,6 @@ public class IntegerTypeDescriptor implements SqlTypeDescriptor {
public static final IntegerTypeDescriptor INSTANCE = new IntegerTypeDescriptor();
public IntegerTypeDescriptor() {
SqlTypeDescriptorRegistry.INSTANCE.addDescriptor( this );
}
@Override

View File

@ -34,7 +34,6 @@ public class LongNVarcharTypeDescriptor extends NVarcharTypeDescriptor {
public static final LongNVarcharTypeDescriptor INSTANCE = new LongNVarcharTypeDescriptor();
public LongNVarcharTypeDescriptor() {
SqlTypeDescriptorRegistry.INSTANCE.addDescriptor( this );
}
@Override

View File

@ -34,7 +34,6 @@ public class LongVarbinaryTypeDescriptor extends VarbinaryTypeDescriptor {
public static final LongVarbinaryTypeDescriptor INSTANCE = new LongVarbinaryTypeDescriptor();
public LongVarbinaryTypeDescriptor() {
SqlTypeDescriptorRegistry.INSTANCE.addDescriptor( this );
}
@Override

View File

@ -34,7 +34,6 @@ public class LongVarcharTypeDescriptor extends VarcharTypeDescriptor {
public static final LongVarcharTypeDescriptor INSTANCE = new LongVarcharTypeDescriptor();
public LongVarcharTypeDescriptor() {
SqlTypeDescriptorRegistry.INSTANCE.addDescriptor( this );
}
@Override

View File

@ -34,7 +34,6 @@ public class NCharTypeDescriptor extends NVarcharTypeDescriptor {
public static final NCharTypeDescriptor INSTANCE = new NCharTypeDescriptor();
public NCharTypeDescriptor() {
SqlTypeDescriptorRegistry.INSTANCE.addDescriptor( this );
}
@Override

View File

@ -83,54 +83,47 @@ public abstract class NClobTypeDescriptor implements SqlTypeDescriptor {
}
public static final NClobTypeDescriptor DEFAULT =
new NClobTypeDescriptor() {
{
SqlTypeDescriptorRegistry.INSTANCE.addDescriptor( this );
}
public static final NClobTypeDescriptor DEFAULT = new NClobTypeDescriptor() {
@Override
public <X> BasicBinder<X> getNClobBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicBinder<X>( javaTypeDescriptor, this ) {
@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 );
}
}
};
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 );
}
}
};
}
};
public static final NClobTypeDescriptor NCLOB_BINDING =
new NClobTypeDescriptor() {
public static final NClobTypeDescriptor NCLOB_BINDING = new NClobTypeDescriptor() {
@Override
public <X> BasicBinder<X> getNClobBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicBinder<X>( javaTypeDescriptor, this ) {
@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 ) );
}
};
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options)
throws SQLException {
st.setNClob( index, javaTypeDescriptor.unwrap( value, NClob.class, options ) );
}
};
}
};
public static final NClobTypeDescriptor STREAM_BINDING =
new NClobTypeDescriptor() {
public static final NClobTypeDescriptor STREAM_BINDING = new NClobTypeDescriptor() {
@Override
public <X> BasicBinder<X> getNClobBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicBinder<X>( javaTypeDescriptor, this ) {
@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() );
}
};
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() );
}
};
}
};
}

View File

@ -43,7 +43,6 @@ public class NVarcharTypeDescriptor implements SqlTypeDescriptor {
public static final NVarcharTypeDescriptor INSTANCE = new NVarcharTypeDescriptor();
public NVarcharTypeDescriptor() {
SqlTypeDescriptorRegistry.INSTANCE.addDescriptor( this );
}
@Override

View File

@ -34,7 +34,6 @@ public class NumericTypeDescriptor extends DecimalTypeDescriptor {
public static final NumericTypeDescriptor INSTANCE = new NumericTypeDescriptor();
public NumericTypeDescriptor() {
SqlTypeDescriptorRegistry.INSTANCE.addDescriptor( this );
}
@Override

View File

@ -43,7 +43,6 @@ public class RealTypeDescriptor implements SqlTypeDescriptor {
public static final RealTypeDescriptor INSTANCE = new RealTypeDescriptor();
public RealTypeDescriptor() {
SqlTypeDescriptorRegistry.INSTANCE.addDescriptor( this );
}
@Override

View File

@ -43,7 +43,6 @@ public class SmallIntTypeDescriptor implements SqlTypeDescriptor {
public static final SmallIntTypeDescriptor INSTANCE = new SmallIntTypeDescriptor();
public SmallIntTypeDescriptor() {
SqlTypeDescriptorRegistry.INSTANCE.addDescriptor( this );
}
@Override

View File

@ -50,6 +50,40 @@ public class SqlTypeDescriptorRegistry {
private ConcurrentHashMap<Integer,SqlTypeDescriptor> descriptorMap = new ConcurrentHashMap<Integer, SqlTypeDescriptor>();
private SqlTypeDescriptorRegistry() {
addDescriptor( BooleanTypeDescriptor.INSTANCE );
addDescriptor( BitTypeDescriptor.INSTANCE );
addDescriptor( BigIntTypeDescriptor.INSTANCE );
addDescriptor( DecimalTypeDescriptor.INSTANCE );
addDescriptor( DoubleTypeDescriptor.INSTANCE );
addDescriptor( FloatTypeDescriptor.INSTANCE );
addDescriptor( IntegerTypeDescriptor.INSTANCE );
addDescriptor( NumericTypeDescriptor.INSTANCE );
addDescriptor( RealTypeDescriptor.INSTANCE );
addDescriptor( SmallIntTypeDescriptor.INSTANCE );
addDescriptor( TinyIntTypeDescriptor.INSTANCE );
addDescriptor( DateTypeDescriptor.INSTANCE );
addDescriptor( TimestampTypeDescriptor.INSTANCE );
addDescriptor( TimeTypeDescriptor.INSTANCE );
addDescriptor( BinaryTypeDescriptor.INSTANCE );
addDescriptor( VarbinaryTypeDescriptor.INSTANCE );
addDescriptor( LongVarbinaryTypeDescriptor.INSTANCE );
addDescriptor( BlobTypeDescriptor.DEFAULT );
addDescriptor( CharTypeDescriptor.INSTANCE );
addDescriptor( VarcharTypeDescriptor.INSTANCE );
addDescriptor( LongVarcharTypeDescriptor.INSTANCE );
addDescriptor( ClobTypeDescriptor.DEFAULT );
addDescriptor( NCharTypeDescriptor.INSTANCE );
addDescriptor( NVarcharTypeDescriptor.INSTANCE );
addDescriptor( LongNVarcharTypeDescriptor.INSTANCE );
addDescriptor( NClobTypeDescriptor.DEFAULT );
}
public void addDescriptor(SqlTypeDescriptor sqlTypeDescriptor) {
descriptorMap.put( sqlTypeDescriptor.getSqlType(), sqlTypeDescriptor );
}

View File

@ -44,7 +44,6 @@ public class TimeTypeDescriptor implements SqlTypeDescriptor {
public static final TimeTypeDescriptor INSTANCE = new TimeTypeDescriptor();
public TimeTypeDescriptor() {
SqlTypeDescriptorRegistry.INSTANCE.addDescriptor( this );
}
@Override

View File

@ -44,7 +44,6 @@ public class TimestampTypeDescriptor implements SqlTypeDescriptor {
public static final TimestampTypeDescriptor INSTANCE = new TimestampTypeDescriptor();
public TimestampTypeDescriptor() {
SqlTypeDescriptorRegistry.INSTANCE.addDescriptor( this );
}
@Override

View File

@ -46,7 +46,6 @@ public class TinyIntTypeDescriptor implements SqlTypeDescriptor {
public static final TinyIntTypeDescriptor INSTANCE = new TinyIntTypeDescriptor();
public TinyIntTypeDescriptor() {
SqlTypeDescriptorRegistry.INSTANCE.addDescriptor( this );
}
@Override

View File

@ -43,7 +43,6 @@ public class VarbinaryTypeDescriptor implements SqlTypeDescriptor {
public static final VarbinaryTypeDescriptor INSTANCE = new VarbinaryTypeDescriptor();
public VarbinaryTypeDescriptor() {
SqlTypeDescriptorRegistry.INSTANCE.addDescriptor( this );
}
public int getSqlType() {

View File

@ -43,7 +43,6 @@ public class VarcharTypeDescriptor implements SqlTypeDescriptor {
public static final VarcharTypeDescriptor INSTANCE = new VarcharTypeDescriptor();
public VarcharTypeDescriptor() {
SqlTypeDescriptorRegistry.INSTANCE.addDescriptor( this );
}
@Override