Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Apply float/double type related changes to properly preserve precisio…
…n according to @gavinking
- Loading branch information
Showing
3 changed files
with
109 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
...e-core/src/main/java/org/hibernate/type/descriptor/jdbc/DoubleSqlFloatTypeDescriptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
* Hibernate, Relational Persistence for Idiomatic Java | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. | ||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
package org.hibernate.type.descriptor.jdbc; | ||
|
||
import java.sql.CallableStatement; | ||
import java.sql.PreparedStatement; | ||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
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.BasicJavaDescriptor; | ||
import org.hibernate.type.descriptor.java.JavaTypeDescriptor; | ||
import org.hibernate.type.descriptor.jdbc.internal.JdbcLiteralFormatterNumericData; | ||
import org.hibernate.type.spi.TypeConfiguration; | ||
|
||
/** | ||
* Descriptor for {@link Types#DOUBLE DOUBLE} handling. | ||
* | ||
* @author Steve Ebersole | ||
*/ | ||
public class DoubleSqlFloatTypeDescriptor implements JdbcTypeDescriptor { | ||
public static final DoubleSqlFloatTypeDescriptor INSTANCE = new DoubleSqlFloatTypeDescriptor(); | ||
|
||
public DoubleSqlFloatTypeDescriptor() { | ||
} | ||
|
||
@Override | ||
public int getJdbcType() { | ||
return Types.FLOAT; | ||
} | ||
|
||
@Override | ||
public String getFriendlyName() { | ||
return "DOUBLE"; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "SqlTypeDescriptor(" + getFriendlyName() + ")"; | ||
} | ||
|
||
@Override | ||
public boolean canBeRemapped() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public <T> BasicJavaDescriptor<T> getJdbcRecommendedJavaTypeMapping(TypeConfiguration typeConfiguration) { | ||
return (BasicJavaDescriptor<T>) typeConfiguration.getJavaTypeDescriptorRegistry().getDescriptor( Double.class ); | ||
} | ||
|
||
@Override | ||
public <T> JdbcLiteralFormatter<T> getJdbcLiteralFormatter(JavaTypeDescriptor<T> javaTypeDescriptor) { | ||
//noinspection unchecked | ||
return new JdbcLiteralFormatterNumericData( javaTypeDescriptor, Double.class ); | ||
} | ||
|
||
@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 | ||
protected void doBind(CallableStatement st, X value, String name, WrapperOptions options) | ||
throws SQLException { | ||
st.setDouble( name, javaTypeDescriptor.unwrap( value, Double.class, options ) ); | ||
} | ||
}; | ||
} | ||
|
||
@Override | ||
public <X> ValueExtractor<X> getExtractor(final JavaTypeDescriptor<X> javaTypeDescriptor) { | ||
return new BasicExtractor<X>( javaTypeDescriptor, this ) { | ||
@Override | ||
protected X doExtract(ResultSet rs, int paramIndex, WrapperOptions options) throws SQLException { | ||
return javaTypeDescriptor.wrap( rs.getDouble( paramIndex ), options ); | ||
} | ||
|
||
@Override | ||
protected X doExtract(CallableStatement statement, int index, WrapperOptions options) throws SQLException { | ||
return javaTypeDescriptor.wrap( statement.getDouble( index ), options ); | ||
} | ||
|
||
@Override | ||
protected X doExtract(CallableStatement statement, String name, WrapperOptions options) throws SQLException { | ||
return javaTypeDescriptor.wrap( statement.getDouble( name ), options ); | ||
} | ||
}; | ||
} | ||
} |
5a33db1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@beikov I don't understand how these changes related to the fix I already included in #4105.
5a33db1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was just about to ask you to review this or tell me how far your PR for this is :)
I can drop this commit after rebasing on top of your merged PR