more extreme solution
This commit is contained in:
parent
a1b0fac8f1
commit
9a0948a32c
|
@ -16,7 +16,6 @@ import java.util.List;
|
||||||
|
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
import org.hibernate.Internal;
|
import org.hibernate.Internal;
|
||||||
import org.hibernate.engine.spi.LazySessionWrapperOptions;
|
|
||||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||||
import org.hibernate.internal.util.CharSequenceHelper;
|
import org.hibernate.internal.util.CharSequenceHelper;
|
||||||
import org.hibernate.metamodel.mapping.EmbeddableMappingType;
|
import org.hibernate.metamodel.mapping.EmbeddableMappingType;
|
||||||
|
@ -1125,14 +1124,9 @@ public class XmlHelper {
|
||||||
//noinspection unchecked
|
//noinspection unchecked
|
||||||
final JavaType<Object> javaType = (JavaType<Object>) pluralJavaType;
|
final JavaType<Object> javaType = (JavaType<Object>) pluralJavaType;
|
||||||
// Produce the XML string for a collection with a null element to find out the root and element tag names
|
// Produce the XML string for a collection with a null element to find out the root and element tag names
|
||||||
final String nullElementXml;
|
final String nullElementXml =
|
||||||
try ( final LazySessionWrapperOptions lazySessionWrapperOptions = new LazySessionWrapperOptions( sessionFactory ) ) {
|
sessionFactory.getSessionFactoryOptions().getXmlFormatMapper()
|
||||||
nullElementXml = sessionFactory.getSessionFactoryOptions().getXmlFormatMapper().toString(
|
.toString( javaType.fromString( "{null}" ), javaType, sessionFactory.getWrapperOptions() );
|
||||||
javaType.fromString( "{null}" ),
|
|
||||||
javaType,
|
|
||||||
lazySessionWrapperOptions
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// There must be an end tag for the root, so find that first
|
// There must be an end tag for the root, so find that first
|
||||||
final int rootCloseTagPosition = nullElementXml.lastIndexOf( '<' );
|
final int rootCloseTagPosition = nullElementXml.lastIndexOf( '<' );
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
package org.hibernate.dialect.function;
|
package org.hibernate.dialect.function;
|
||||||
|
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
import org.hibernate.engine.spi.LazySessionWrapperOptions;
|
|
||||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||||
import org.hibernate.internal.util.NullnessHelper;
|
import org.hibernate.internal.util.NullnessHelper;
|
||||||
import org.hibernate.metamodel.mapping.BasicValuedMapping;
|
import org.hibernate.metamodel.mapping.BasicValuedMapping;
|
||||||
|
@ -485,14 +484,10 @@ public abstract class NumberSeriesGenerateSeriesFunction extends GenerateSeriesF
|
||||||
private String getExpression(Expression expression, String tableIdentifierVariable, String syntheticColumnName, SqmToSqlAstConverter walker) {
|
private String getExpression(Expression expression, String tableIdentifierVariable, String syntheticColumnName, SqmToSqlAstConverter walker) {
|
||||||
if ( expression instanceof Literal literal ) {
|
if ( expression instanceof Literal literal ) {
|
||||||
final SessionFactoryImplementor sessionFactory = walker.getCreationContext().getSessionFactory();
|
final SessionFactoryImplementor sessionFactory = walker.getCreationContext().getSessionFactory();
|
||||||
try ( final LazySessionWrapperOptions wrapperOptions = new LazySessionWrapperOptions( sessionFactory ) ) {
|
|
||||||
//noinspection unchecked
|
//noinspection unchecked
|
||||||
return literal.getJdbcMapping().getJdbcLiteralFormatter().toJdbcLiteral(
|
return literal.getJdbcMapping().getJdbcLiteralFormatter()
|
||||||
literal.getLiteralValue(),
|
.toJdbcLiteral( literal.getLiteralValue(), sessionFactory.getJdbcServices().getDialect(),
|
||||||
sessionFactory.getJdbcServices().getDialect(),
|
sessionFactory.getWrapperOptions() );
|
||||||
wrapperOptions
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if ( expression instanceof ColumnReference columnReference ) {
|
else if ( expression instanceof ColumnReference columnReference ) {
|
||||||
return columnReference.getExpressionText();
|
return columnReference.getExpressionText();
|
||||||
|
|
|
@ -1,90 +0,0 @@
|
||||||
/*
|
|
||||||
* SPDX-License-Identifier: LGPL-2.1-or-later
|
|
||||||
* Copyright Red Hat Inc. and Hibernate Authors
|
|
||||||
*/
|
|
||||||
package org.hibernate.engine.spi;
|
|
||||||
|
|
||||||
import java.util.TimeZone;
|
|
||||||
|
|
||||||
import org.hibernate.Internal;
|
|
||||||
import org.hibernate.dialect.Dialect;
|
|
||||||
import org.hibernate.engine.jdbc.LobCreator;
|
|
||||||
import org.hibernate.internal.FastSessionServices;
|
|
||||||
import org.hibernate.type.descriptor.WrapperOptions;
|
|
||||||
|
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An implementation of {@link WrapperOptions} used for rendering SQL literals,
|
|
||||||
* which is backed by the {@link SessionFactoryImplementor}, and which
|
|
||||||
* {@linkplain SessionFactoryImplementor#openTemporarySession lazily creates a
|
|
||||||
* temporary session if needed.} The temporary session will only be created when
|
|
||||||
* dealing with LOBs.
|
|
||||||
* <p>
|
|
||||||
* This object is {@link AutoCloseable}, and <em>must</em> be explicitly cleaned
|
|
||||||
* up by its creator.
|
|
||||||
*
|
|
||||||
* @apiNote This thing is nasty, and we should find a better way to solve the problem.
|
|
||||||
* Whenever possible, just use {@link SessionFactoryImplementor#getWrapperOptions()}
|
|
||||||
* instead.
|
|
||||||
*/
|
|
||||||
@Internal
|
|
||||||
public class LazySessionWrapperOptions implements WrapperOptions, AutoCloseable {
|
|
||||||
|
|
||||||
private final SessionFactoryImplementor sessionFactory;
|
|
||||||
private final FastSessionServices fastSessionServices;
|
|
||||||
private @Nullable SessionImplementor session;
|
|
||||||
|
|
||||||
public LazySessionWrapperOptions(SessionFactoryImplementor sessionFactory) {
|
|
||||||
this.sessionFactory = sessionFactory;
|
|
||||||
fastSessionServices = sessionFactory.getFastSessionServices();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void cleanup() {
|
|
||||||
if ( session != null ) {
|
|
||||||
session.close();
|
|
||||||
session = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void close() {
|
|
||||||
cleanup();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SharedSessionContractImplementor getSession() {
|
|
||||||
session = sessionFactory.openTemporarySession();
|
|
||||||
return session;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SessionFactoryImplementor getSessionFactory() {
|
|
||||||
return sessionFactory;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean useStreamForLobBinding() {
|
|
||||||
return fastSessionServices.useStreamForLobBinding;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getPreferredSqlTypeCodeForBoolean() {
|
|
||||||
return fastSessionServices.preferredSqlTypeCodeForBoolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TimeZone getJdbcTimeZone() {
|
|
||||||
return fastSessionServices.jdbcTimeZone;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Dialect getDialect() {
|
|
||||||
return fastSessionServices.dialect;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public LobCreator getLobCreator() {
|
|
||||||
return fastSessionServices.jdbcServices.getLobCreator( getSession() );
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -32,7 +32,6 @@ import org.hibernate.dialect.RowLockStrategy;
|
||||||
import org.hibernate.dialect.SelectItemReferenceStrategy;
|
import org.hibernate.dialect.SelectItemReferenceStrategy;
|
||||||
import org.hibernate.engine.jdbc.Size;
|
import org.hibernate.engine.jdbc.Size;
|
||||||
import org.hibernate.engine.jdbc.spi.JdbcServices;
|
import org.hibernate.engine.jdbc.spi.JdbcServices;
|
||||||
import org.hibernate.engine.spi.LazySessionWrapperOptions;
|
|
||||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||||
import org.hibernate.internal.FilterJdbcParameter;
|
import org.hibernate.internal.FilterJdbcParameter;
|
||||||
import org.hibernate.internal.util.MathHelper;
|
import org.hibernate.internal.util.MathHelper;
|
||||||
|
@ -330,7 +329,6 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
|
||||||
// See #visitCteContainer for details about the usage.
|
// See #visitCteContainer for details about the usage.
|
||||||
private int withClauseRecursiveIndex = -1;
|
private int withClauseRecursiveIndex = -1;
|
||||||
private transient FunctionRenderer castFunction;
|
private transient FunctionRenderer castFunction;
|
||||||
private transient LazySessionWrapperOptions lazySessionWrapperOptions;
|
|
||||||
private transient BasicType<Integer> integerType;
|
private transient BasicType<Integer> integerType;
|
||||||
private transient BasicType<String> stringType;
|
private transient BasicType<String> stringType;
|
||||||
private transient BasicType<Boolean> booleanType;
|
private transient BasicType<Boolean> booleanType;
|
||||||
|
@ -373,10 +371,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
|
||||||
}
|
}
|
||||||
|
|
||||||
protected WrapperOptions getWrapperOptions() {
|
protected WrapperOptions getWrapperOptions() {
|
||||||
if ( lazySessionWrapperOptions == null ) {
|
return sessionFactory.getWrapperOptions();
|
||||||
lazySessionWrapperOptions = new LazySessionWrapperOptions( sessionFactory );
|
|
||||||
}
|
|
||||||
return lazySessionWrapperOptions;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public BasicType<Integer> getIntegerType() {
|
public BasicType<Integer> getIntegerType() {
|
||||||
|
@ -419,10 +414,6 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void cleanup() {
|
protected void cleanup() {
|
||||||
if ( lazySessionWrapperOptions != null ) {
|
|
||||||
lazySessionWrapperOptions.cleanup();
|
|
||||||
lazySessionWrapperOptions = null;
|
|
||||||
}
|
|
||||||
this.jdbcParameterBindings = null;
|
this.jdbcParameterBindings = null;
|
||||||
this.lockOptions = null;
|
this.lockOptions = null;
|
||||||
this.limit = null;
|
this.limit = null;
|
||||||
|
|
|
@ -19,24 +19,27 @@ public abstract class BasicJdbcLiteralFormatter<T> extends AbstractJdbcLiteralFo
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
protected <X> X unwrap(Object value, Class<X> unwrapType, WrapperOptions wrapperOptions) {
|
protected <X> X unwrap(Object value, Class<X> unwrapType, WrapperOptions options) {
|
||||||
assert value != null;
|
assert value != null;
|
||||||
|
|
||||||
// for performance reasons, avoid conversions if we can
|
// for performance reasons, avoid conversions if we can
|
||||||
if ( unwrapType.isInstance( value ) ) {
|
if ( unwrapType.isInstance( value ) ) {
|
||||||
return (X) value;
|
return (X) value;
|
||||||
}
|
}
|
||||||
else if ( !getJavaType().isInstance( value ) ) {
|
else {
|
||||||
final T coerce = getJavaType().coerce( value, wrapperOptions.getSession() );
|
final JavaType<T> javaType = getJavaType();
|
||||||
if ( unwrapType.isInstance( coerce ) ) {
|
if ( !javaType.isInstance( value ) ) {
|
||||||
return (X) coerce;
|
final T coerced = javaType.coerce( value, () -> options.getSessionFactory().getTypeConfiguration() );
|
||||||
|
if ( unwrapType.isInstance( coerced ) ) {
|
||||||
|
return (X) coerced;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return getJavaType().unwrap( coerce, unwrapType, wrapperOptions );
|
return javaType.unwrap( coerced, unwrapType, options );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return getJavaType().unwrap( (T) value, unwrapType, wrapperOptions );
|
return javaType.unwrap( (T) value, unwrapType, options );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue