Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -475,13 +475,11 @@
return getEntityPersister().getImportedName();
}

default RootGraphImplementor createRootGraph(SharedSessionContractImplementor session) {
if ( getRepresentationStrategy() instanceof EntityRepresentationStrategyMap mapRep ) {
return session.getSessionFactory().createGraphForDynamicEntity( getEntityName() );
}
else {
return session.getSessionFactory().createEntityGraph( getMappedJavaType().getJavaTypeClass() );
}
default RootGraphImplementor<?> createRootGraph(SharedSessionContractImplementor session) {
final var factory = session.getSessionFactory();
return getRepresentationStrategy() instanceof EntityRepresentationStrategyMap strategyMap

Check notice

Code scanning / CodeQL

Unread local variable Note

Variable 'EntityRepresentationStrategyMap strategyMap' is never read.
? factory.createGraphForDynamicEntity( getEntityName() )
: factory.createEntityGraph( getMappedJavaType().getJavaTypeClass() );
}

interface ConstraintOrderedTableConsumer {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@

import org.jboss.logging.BasicLogger;
import org.jboss.logging.Logger;
import org.jboss.logging.annotations.LogMessage;
import org.jboss.logging.annotations.Message;
import org.jboss.logging.annotations.MessageLogger;
import org.jboss.logging.annotations.ValidIdRange;

import java.lang.invoke.MethodHandles;
import java.util.Set;

import static org.jboss.logging.Logger.Level.DEBUG;
import static org.jboss.logging.Logger.Level.TRACE;

/**
* @author Steve Ebersole
Expand All @@ -28,4 +34,45 @@ public interface SqlExecLogger extends BasicLogger {
String LOGGER_NAME = SubSystemLogging.BASE + ".sql.exec";

SqlExecLogger SQL_EXEC_LOGGER = Logger.getMessageLogger( MethodHandles.lookup(), SqlExecLogger.class, LOGGER_NAME );

@LogMessage(level = DEBUG)
@Message(id = 90004001, value = "Collection locking for collection table '%s' - %s")
void collectionLockingForCollectionTable(String keyTableName, String rootPathName);

@LogMessage(level = DEBUG)
@Message(id = 90004002, value = "Follow-on locking for collection table '%s' - %s")
void followOnLockingForCollectionTable(String keyTableName, String rootPathName);

@LogMessage(level = DEBUG)
@Message(id = 90004003, value = "Follow-on locking collected loaded values:\n%s")
void followOnLockingCollectedLoadedValues(String summary);

@LogMessage(level = DEBUG)
@Message(id = 90004010, value = "Starting include-collections locking process - %s")
void startingIncludeCollectionsLockingProcess(String entityName);

@LogMessage(level = DEBUG)
@Message(id = 90004011, value = "Starting follow-on locking process - %s")
void startingFollowOnLockingProcess(String entityName);

@LogMessage(level = DEBUG)
@Message(id = 90004012, value = "Adding table '%s' for follow-on locking - %s")
void addingTableForFollowOnLocking(String tableName, String entityName);

// Trace messages (typesafe)
@LogMessage(level = TRACE)
@Message(id = 90004013, value = "Reading query result cache data [%s]")
void readingQueryResultCacheData(String cacheModeName);

@LogMessage(level = TRACE)
@Message(id = 90004014, value = "Affected query spaces unexpectedly empty")
void affectedQuerySpacesUnexpectedlyEmpty();

@LogMessage(level = TRACE)
@Message(id = 90004015, value = "Affected query spaces %s")
void affectedQuerySpaces(Set<String> querySpaces);

@LogMessage(level = TRACE)
@Message(id = 90004016, value = "Skipping reading query result cache data (query cache %s, cache mode %s)")
void skippingReadingQueryResultCacheData(String queryCacheStatus, String cacheModeName);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.hibernate.metamodel.mapping.MappingModelExpressible;
import org.hibernate.metamodel.mapping.MappingType;
import org.hibernate.metamodel.mapping.SqlExpressible;
import org.hibernate.type.BindableType;
import org.hibernate.sql.ast.SqlAstWalker;
import org.hibernate.sql.ast.tree.expression.JdbcParameter;
import org.hibernate.sql.exec.ExecutionException;
Expand All @@ -27,8 +26,6 @@
import org.hibernate.sql.exec.spi.JdbcParameterBindings;
import org.hibernate.type.BasicType;
import org.hibernate.type.descriptor.java.EnumJavaType;
import org.hibernate.type.descriptor.jdbc.JdbcType;
import org.hibernate.type.descriptor.jdbc.JdbcTypeIndicators;

/**
* @author Steve Ebersole
Expand Down Expand Up @@ -85,12 +82,12 @@ public void bindParameterValue(
int startPosition,
JdbcParameterBindings jdbcParamBindings,
ExecutionContext executionContext) throws SQLException {
final JdbcParameterBinding binding = jdbcParamBindings.getBinding( AbstractJdbcParameter.this );
final var binding = jdbcParamBindings.getBinding( AbstractJdbcParameter.this );
if ( binding == null ) {
throw new ExecutionException( "JDBC parameter value not bound - " + this );
}

final JdbcMapping jdbcMapping = jdbcMapping( executionContext, binding );
final var jdbcMapping = jdbcMapping( executionContext, binding );
bindParameterValue( jdbcMapping, statement, binding.getBindValue(), startPosition, executionContext );
}

Expand Down Expand Up @@ -118,47 +115,41 @@ protected void bindParameterValue(
PreparedStatement statement,
Object bindValue,
int startPosition,
ExecutionContext executionContext) throws SQLException {
ExecutionContext executionContext)
throws SQLException {
//noinspection unchecked
jdbcMapping.getJdbcValueBinder().bind(
statement,
bindValue,
startPosition,
executionContext.getSession()
);
jdbcMapping.getJdbcValueBinder()
.bind( statement, bindValue, startPosition, executionContext.getSession() );
}

private JdbcMapping guessBindType(ExecutionContext executionContext, Object bindValue, JdbcMapping jdbcMapping) {
if ( bindValue == null && jdbcMapping != null ) {
return jdbcMapping;
}
else {
final BindableType<?> parameterType =
final var parameterType =
executionContext.getSession().getFactory().getMappingMetamodel()
.resolveParameterBindType( bindValue );
if ( parameterType == null && bindValue instanceof Enum ) {
return createEnumType( executionContext, (Class) bindValue.getClass() );
}
else {
return parameterType instanceof JdbcMapping ? (JdbcMapping) parameterType : null;
}
return parameterType == null && bindValue instanceof Enum<?> enumValue
? createEnumType( executionContext, enumValue.getClass() )
: parameterType instanceof JdbcMapping ? (JdbcMapping) parameterType : null;
}
}

private static <E extends Enum<E>> BasicType<E> createEnumType(ExecutionContext executionContext, Class<E> enumClass) {
final EnumJavaType<E> enumJavaType = new EnumJavaType<>( enumClass );
final JdbcTypeIndicators indicators =
executionContext.getSession().getTypeConfiguration().getCurrentBaseSqlTypeIndicators();
final JdbcType jdbcType =
final var enumJavaType = new EnumJavaType<>( enumClass );
final var typeConfiguration = executionContext.getSession().getTypeConfiguration();
final var indicators = typeConfiguration.getCurrentBaseSqlTypeIndicators();
final var jdbcType =
// we don't know whether to map the enum as ORDINAL or STRING,
// so just accept the default from the TypeConfiguration, which
// is usually ORDINAL (the default according to JPA)
enumJavaType.getRecommendedJdbcType(indicators);
return indicators.getTypeConfiguration().getBasicTypeRegistry().resolve( enumJavaType, jdbcType );
enumJavaType.getRecommendedJdbcType( indicators );
return typeConfiguration.getBasicTypeRegistry().resolve( enumJavaType, jdbcType );
}

@Override
public MappingModelExpressible getExpressionType() {
public MappingModelExpressible<?> getExpressionType() {
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class JdbcCallImpl implements JdbcOperationQueryCall {
private final JdbcCallFunctionReturn functionReturn;
private final List<JdbcCallParameterRegistration> parameterRegistrations;
private final List<JdbcParameterBinder> parameterBinders;
private final List<JdbcCallParameterExtractor> parameterExtractors;
private final List<JdbcCallParameterExtractor<?>> parameterExtractors;
private final List<JdbcCallRefCursorExtractor> refCursorExtractors;

public JdbcCallImpl(Builder builder) {
Expand All @@ -64,7 +64,7 @@ protected JdbcCallImpl(
JdbcCallFunctionReturn functionReturn,
List<JdbcCallParameterRegistration> parameterRegistrations,
List<JdbcParameterBinder> parameterBinders,
List<JdbcCallParameterExtractor> parameterExtractors,
List<JdbcCallParameterExtractor<?>> parameterExtractors,
List<JdbcCallRefCursorExtractor> refCursorExtractors) {
this.callableName = callableName;
this.functionReturn = functionReturn;
Expand All @@ -74,22 +74,6 @@ protected JdbcCallImpl(
this.refCursorExtractors = refCursorExtractors;
}

protected JdbcCallImpl(
String callableName,
JdbcCallFunctionReturn functionReturn,
List<JdbcCallParameterRegistration> parameterRegistrations,
List<JdbcParameterBinder> parameterBinders,
List<JdbcCallParameterExtractor> parameterExtractors) {
this(
callableName,
functionReturn,
parameterRegistrations,
parameterBinders,
parameterExtractors,
null
);
}

@Override
public String getSqlString() {
return callableName;
Expand Down Expand Up @@ -132,7 +116,7 @@ public boolean isCompatibleWith(
}

@Override
public List<JdbcCallParameterExtractor> getParameterExtractors() {
public List<JdbcCallParameterExtractor<?>> getParameterExtractors() {
return parameterExtractors == null ? emptyList() : parameterExtractors;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.hibernate.sql.exec.spi.JdbcCallParameterExtractor;
import org.hibernate.sql.exec.spi.JdbcCallParameterRegistration;
import org.hibernate.sql.exec.spi.JdbcParameterBinder;
import org.hibernate.type.descriptor.jdbc.JdbcType;

import jakarta.persistence.ParameterMode;

Expand Down Expand Up @@ -108,7 +107,7 @@ private void registerRefCursorParameter(
private void registerOutputParameter(
CallableStatement callableStatement,
SharedSessionContractImplementor session) {
final JdbcType sqlTypeDescriptor = ormType.getJdbcType();
final var sqlTypeDescriptor = ormType.getJdbcType();
try {
sqlTypeDescriptor.registerOutParameter( callableStatement, jdbcParameterPositionStart );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ public ResultSet extractResultSet(
// .getJdbcEnvironment()
// .getExtractedDatabaseMetaData()
// .supportsNamedParameters();
return session.getFactory()
.getServiceRegistry()
return session.getFactory().getServiceRegistry()
.requireService( RefCursorSupport.class )
.getResultSet( callableStatement, jdbcParameterPosition );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package org.hibernate.sql.exec.internal;

import org.checkerframework.checker.nullness.qual.Nullable;
import org.hibernate.query.spi.Limit;
import org.hibernate.query.spi.QueryOptions;
import org.hibernate.sql.ast.tree.expression.JdbcParameter;
import org.hibernate.sql.exec.spi.ExecutionContext;
Expand Down Expand Up @@ -127,26 +126,27 @@

@Override
public boolean isCompatibleWith(JdbcParameterBindings jdbcParameterBindings, QueryOptions queryOptions) {
final var limit = queryOptions.getLimit();
if ( !appliedParameters.isEmpty() ) {
if ( jdbcParameterBindings == null ) {
return false;
}
for ( var entry : appliedParameters.entrySet() ) {
final JdbcParameter parameter = entry.getKey();
final JdbcParameterBinding appliedBinding = entry.getValue();
final var parameter = entry.getKey();
final var appliedBinding = entry.getValue();
// This is a special case where the rendered SQL depends on the presence of the parameter,
// but not specifically on the value. In this case we have to re-generate the SQL if we can't find a binding
// The need for this can be tested with the OracleFollowOnLockingTest#testPessimisticLockWithMaxResultsThenNoFollowOnLocking
// Since the Limit is not part of the query plan cache key, but this has an effect on follow on locking,
// we must treat the absence of Limit parameters, when they were considered for locking, as incompatible
if ( appliedBinding == null ) {
if ( parameter == offsetParameter ) {
if ( queryOptions.getLimit() == null || queryOptions.getLimit().getFirstRowJpa() == 0 ) {
if ( limit == null || limit.getFirstRowJpa() == 0 ) {
return false;
}
}
else if ( parameter == limitParameter ) {
if ( queryOptions.getLimit() == null || queryOptions.getLimit().getMaxRowsJpa() == Integer.MAX_VALUE ) {
if ( limit == null || limit.getMaxRowsJpa() == Integer.MAX_VALUE ) {
return false;
}
}
Expand All @@ -156,16 +156,15 @@
}
// We handle limit and offset parameters below
if ( parameter != offsetParameter && parameter != limitParameter ) {
final JdbcParameterBinding binding = jdbcParameterBindings.getBinding( parameter );
final var binding = jdbcParameterBindings.getBinding( parameter );
// TODO: appliedBinding can be null here, resulting in NPE
if ( binding == null
|| !equal( appliedBinding, binding, appliedBinding.getBindType().getJavaTypeDescriptor() ) ) {

Check warning

Code scanning / CodeQL

Dereferenced variable may be null Warning

Variable
appliedBinding
may be null at this access as suggested by
this
null guard.
return false;
}
}
}
}
final Limit limit = queryOptions.getLimit();
return ( offsetParameter != null || limitParameter != null || limit == null || limit.isEmpty() )
&& isCompatible( offsetParameter, limit == null ? null : limit.getFirstRow(), 0 )
&& isCompatible( limitParameter, limit == null ? null : limit.getMaxRows(), Integer.MAX_VALUE );
Expand All @@ -176,7 +175,7 @@
return requestedValue == null;
}
else {
final JdbcParameterBinding jdbcParameterBinding = appliedParameters.get( parameter );
final var jdbcParameterBinding = appliedParameters.get( parameter );
if ( jdbcParameterBinding == null ) {
// If this query includes the parameter this is only compatible when a requested value is given through the query options
// If not, this query string contains limit/offset but the query options don't request that
Expand Down
Loading