Simplify type resolving and ignore a test for Oracle
This commit is contained in:
parent
d4ffbea54f
commit
682cbc7d87
|
@ -6,11 +6,9 @@
|
|||
*/
|
||||
package org.hibernate.query.results;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
@ -22,7 +20,6 @@ import org.hibernate.Internal;
|
|||
import org.hibernate.NotYetImplementedFor6Exception;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
import org.hibernate.internal.util.collections.CollectionHelper;
|
||||
import org.hibernate.metamodel.mapping.BasicValuedMapping;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.query.named.NamedResultSetMappingMemento;
|
||||
|
@ -33,9 +30,6 @@ import org.hibernate.sql.results.graph.basic.BasicResult;
|
|||
import org.hibernate.sql.results.jdbc.spi.JdbcValuesMapping;
|
||||
import org.hibernate.sql.results.jdbc.spi.JdbcValuesMetadata;
|
||||
import org.hibernate.type.BasicType;
|
||||
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.sql.SqlTypeDescriptor;
|
||||
import org.hibernate.type.spi.TypeConfiguration;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
|
@ -184,16 +178,7 @@ public class ResultSetMappingImpl implements ResultSetMapping {
|
|||
JdbcValuesMetadata jdbcResultsMetadata,
|
||||
SessionFactoryImplementor sessionFactory) {
|
||||
final int jdbcPosition = valuesArrayPosition + 1;
|
||||
final SqlTypeDescriptor sqlTypeDescriptor = jdbcResultsMetadata.resolveSqlTypeDescriptor( jdbcPosition );
|
||||
|
||||
final TypeConfiguration typeConfiguration = sessionFactory.getTypeConfiguration();
|
||||
|
||||
final JavaTypeDescriptor<?> javaTypeDescriptor = sqlTypeDescriptor.getJdbcRecommendedJavaTypeMapping( typeConfiguration );
|
||||
|
||||
final BasicType<?> jdbcMapping = typeConfiguration.getBasicTypeRegistry().resolve(
|
||||
javaTypeDescriptor,
|
||||
sqlTypeDescriptor
|
||||
);
|
||||
final BasicType<?> jdbcMapping = jdbcResultsMetadata.resolveType( jdbcPosition, null );
|
||||
|
||||
final String name = jdbcResultsMetadata.resolveColumnName( jdbcPosition );
|
||||
|
||||
|
|
|
@ -18,8 +18,6 @@ import org.hibernate.sql.results.graph.DomainResultCreationState;
|
|||
import org.hibernate.sql.results.graph.basic.BasicResult;
|
||||
import org.hibernate.sql.results.jdbc.spi.JdbcValuesMetadata;
|
||||
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.sql.SqlTypeDescriptor;
|
||||
import org.hibernate.type.spi.TypeConfiguration;
|
||||
|
||||
import static org.hibernate.query.results.ResultsHelper.impl;
|
||||
|
||||
|
@ -75,20 +73,8 @@ public class CompleteResultBuilderBasicValuedStandard implements CompleteResultB
|
|||
if ( explicitType != null ) {
|
||||
basicType = explicitType;
|
||||
}
|
||||
else if ( explicitJavaTypeDescriptor != null ) {
|
||||
final TypeConfiguration typeConfiguration = sessionFactory.getTypeConfiguration();
|
||||
|
||||
final SqlTypeDescriptor sqlTypeDescriptor = jdbcResultsMetadata.resolveSqlTypeDescriptor( jdbcPosition );
|
||||
|
||||
basicType = typeConfiguration.getBasicTypeRegistry().resolve( explicitJavaTypeDescriptor, sqlTypeDescriptor );
|
||||
}
|
||||
else {
|
||||
final TypeConfiguration typeConfiguration = sessionFactory.getTypeConfiguration();
|
||||
|
||||
final SqlTypeDescriptor sqlTypeDescriptor = jdbcResultsMetadata.resolveSqlTypeDescriptor( jdbcPosition );
|
||||
final JavaTypeDescriptor<?> javaTypeDescriptor = sqlTypeDescriptor.getJdbcRecommendedJavaTypeMapping( typeConfiguration );
|
||||
|
||||
basicType = typeConfiguration.getBasicTypeRegistry().resolve( javaTypeDescriptor, sqlTypeDescriptor );
|
||||
basicType = jdbcResultsMetadata.resolveType( jdbcPosition, explicitJavaTypeDescriptor );
|
||||
}
|
||||
|
||||
creationStateImpl.resolveSqlSelection(
|
||||
|
|
|
@ -112,10 +112,7 @@ public class DynamicResultBuilderBasicConverted<O,R> implements DynamicResultBui
|
|||
.getSessionFactory()
|
||||
.getTypeConfiguration();
|
||||
|
||||
final BasicType<?> basicType = typeConfiguration.getBasicTypeRegistry().resolve(
|
||||
basicValueConverter.getRelationalJavaDescriptor(),
|
||||
jdbcResultsMetadata.resolveSqlTypeDescriptor( jdbcPosition )
|
||||
);
|
||||
final BasicType<?> basicType = jdbcResultsMetadata.resolveType( jdbcPosition, basicValueConverter.getRelationalJavaDescriptor() );
|
||||
|
||||
final int valuesArrayPosition = ResultsHelper.jdbcPositionToValuesArrayPosition( jdbcPosition );
|
||||
|
||||
|
|
|
@ -18,8 +18,6 @@ import org.hibernate.sql.results.graph.basic.BasicResult;
|
|||
import org.hibernate.sql.results.jdbc.spi.JdbcValuesMetadata;
|
||||
import org.hibernate.type.BasicType;
|
||||
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.sql.SqlTypeDescriptor;
|
||||
import org.hibernate.type.spi.TypeConfiguration;
|
||||
|
||||
/**
|
||||
* Standard DynamicResultBuilder for basic values.
|
||||
|
@ -88,20 +86,8 @@ public class DynamicResultBuilderBasicStandard implements DynamicResultBuilderBa
|
|||
if ( explicitType != null ) {
|
||||
basicType = explicitType;
|
||||
}
|
||||
else if ( explicitJavaTypeDescriptor != null ) {
|
||||
final TypeConfiguration typeConfiguration = sessionFactory.getTypeConfiguration();
|
||||
|
||||
final SqlTypeDescriptor sqlTypeDescriptor = jdbcResultsMetadata.resolveSqlTypeDescriptor( jdbcPosition );
|
||||
|
||||
basicType = typeConfiguration.getBasicTypeRegistry().resolve( explicitJavaTypeDescriptor, sqlTypeDescriptor );
|
||||
}
|
||||
else {
|
||||
final TypeConfiguration typeConfiguration = sessionFactory.getTypeConfiguration();
|
||||
|
||||
final SqlTypeDescriptor sqlTypeDescriptor = jdbcResultsMetadata.resolveSqlTypeDescriptor( jdbcPosition );
|
||||
final JavaTypeDescriptor<?> javaTypeDescriptor = sqlTypeDescriptor.getJdbcRecommendedJavaTypeMapping( typeConfiguration );
|
||||
|
||||
basicType = typeConfiguration.getBasicTypeRegistry().resolve( javaTypeDescriptor, sqlTypeDescriptor );
|
||||
basicType = jdbcResultsMetadata.resolveType( jdbcPosition, explicitJavaTypeDescriptor );
|
||||
}
|
||||
|
||||
final SqlExpressionResolver sqlExpressionResolver = domainResultCreationState.getSqlAstCreationState().getSqlExpressionResolver();
|
||||
|
|
|
@ -10,9 +10,13 @@ import java.sql.ResultSet;
|
|||
import java.sql.ResultSetMetaData;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.hibernate.engine.jdbc.spi.JdbcServices;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.sql.results.jdbc.spi.JdbcValuesMetadata;
|
||||
import org.hibernate.type.BasicType;
|
||||
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.sql.SqlTypeDescriptor;
|
||||
import org.hibernate.type.spi.TypeConfiguration;
|
||||
|
||||
/**
|
||||
* Access to a JDBC ResultSet and information about it.
|
||||
|
@ -63,20 +67,33 @@ public interface ResultSetAccess extends JdbcValuesMetadata {
|
|||
}
|
||||
}
|
||||
|
||||
default SqlTypeDescriptor resolveSqlTypeDescriptor(int position) {
|
||||
@Override
|
||||
default <J> BasicType<J> resolveType(int position, JavaTypeDescriptor<J> explicitJavaTypeDescriptor) {
|
||||
final JdbcServices jdbcServices = getFactory().getJdbcServices();
|
||||
try {
|
||||
final TypeConfiguration typeConfiguration = getFactory().getTypeConfiguration();
|
||||
final ResultSetMetaData metaData = getResultSet().getMetaData();
|
||||
return getFactory().getJdbcServices()
|
||||
.getDialect()
|
||||
final SqlTypeDescriptor sqlTypeDescriptor = jdbcServices.getDialect()
|
||||
.resolveSqlTypeDescriptor(
|
||||
metaData.getColumnType( position ),
|
||||
metaData.getPrecision( position ),
|
||||
metaData.getScale( position ),
|
||||
getFactory().getTypeConfiguration().getSqlTypeDescriptorRegistry()
|
||||
typeConfiguration.getSqlTypeDescriptorRegistry()
|
||||
);
|
||||
final JavaTypeDescriptor<J> javaTypeDescriptor;
|
||||
if ( explicitJavaTypeDescriptor == null ) {
|
||||
javaTypeDescriptor = sqlTypeDescriptor.getJdbcRecommendedJavaTypeMapping( typeConfiguration );
|
||||
}
|
||||
else {
|
||||
javaTypeDescriptor = explicitJavaTypeDescriptor;
|
||||
}
|
||||
return typeConfiguration.getBasicTypeRegistry().resolve(
|
||||
javaTypeDescriptor,
|
||||
sqlTypeDescriptor
|
||||
);
|
||||
}
|
||||
catch (SQLException e) {
|
||||
throw getFactory().getJdbcServices().getSqlExceptionHelper().convert(
|
||||
throw jdbcServices.getSqlExceptionHelper().convert(
|
||||
e,
|
||||
"Unable to determine JDBC type code for ResultSet position " + position
|
||||
);
|
||||
|
|
|
@ -6,7 +6,10 @@
|
|||
*/
|
||||
package org.hibernate.sql.results.jdbc.spi;
|
||||
|
||||
import org.hibernate.type.BasicType;
|
||||
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.sql.SqlTypeDescriptor;
|
||||
import org.hibernate.type.spi.TypeConfiguration;
|
||||
|
||||
/**
|
||||
* Access to information about the underlying JDBC values
|
||||
|
@ -29,9 +32,8 @@ public interface JdbcValuesMetadata {
|
|||
String resolveColumnName(int position);
|
||||
|
||||
/**
|
||||
* Descriptor of the JDBC/SQL type of a particular result value by
|
||||
* position
|
||||
* The basic type of a particular result value by position
|
||||
*/
|
||||
SqlTypeDescriptor resolveSqlTypeDescriptor(int position);
|
||||
<J> BasicType<J> resolveType(int position, JavaTypeDescriptor<J> explicitJavaTypeDescriptor);
|
||||
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ import java.util.List;
|
|||
|
||||
import org.hibernate.dialect.DB2Dialect;
|
||||
import org.hibernate.dialect.DerbyDialect;
|
||||
import org.hibernate.dialect.OracleDialect;
|
||||
import org.hibernate.dialect.SQLServerDialect;
|
||||
import org.hibernate.metamodel.mapping.EntityMappingType;
|
||||
import org.hibernate.metamodel.mapping.ModelPart;
|
||||
|
@ -82,10 +83,12 @@ public class NativeQueryResultBuilderTests {
|
|||
scope.inTransaction(
|
||||
session -> {
|
||||
// DB2, Derby and SQL Server return an Integer for count by default
|
||||
// Oracle returns a NUMERIC(39,0) i.e. a BigDecimal for count by default
|
||||
Assumptions.assumeThat( session.getJdbcServices().getDialect() )
|
||||
.isNotInstanceOf( DB2Dialect.class )
|
||||
.isNotInstanceOf( DerbyDialect.class )
|
||||
.isNotInstanceOf( SQLServerDialect.class );
|
||||
.isNotInstanceOf( SQLServerDialect.class )
|
||||
.isNotInstanceOf( OracleDialect.class );
|
||||
final String sql = "select count(theString) from EntityOfBasics";
|
||||
final NativeQueryImplementor<?> query = session.createNativeQuery( sql );
|
||||
|
||||
|
|
Loading…
Reference in New Issue