Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -50,11 +50,11 @@ public InformixSqmToSqlAstConverter(

@Override
public QuerySpec visitQuerySpec(SqmQuerySpec<?> sqmQuerySpec) {
final boolean needsDummy = this.needsDummyTableGroup;
this.needsDummyTableGroup = false;
final boolean needsDummy = needsDummyTableGroup;
needsDummyTableGroup = false;
try {
final QuerySpec querySpec = super.visitQuerySpec( sqmQuerySpec );
if ( this.needsDummyTableGroup ) {
if ( needsDummyTableGroup ) {
querySpec.getFromClause().addRoot(
new StandardTableGroup(
true,
Expand All @@ -70,7 +70,7 @@ public QuerySpec visitQuerySpec(SqmQuerySpec<?> sqmQuerySpec) {
return querySpec;
}
finally {
this.needsDummyTableGroup = needsDummy;
needsDummyTableGroup = needsDummy;
}
}

Expand Down
25 changes: 23 additions & 2 deletions hibernate-core/src/main/java/org/hibernate/SessionFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,9 @@ public interface SessionFactory extends EntityManagerFactory, Referenceable, Ser
String getJndiName();

/**
* Obtain a {@linkplain SessionBuilder session builder} for creating
* new {@link Session}s with certain customized options.
* Obtain a {@linkplain org.hibernate.SessionBuilder session builder}
* for creating new instances of {@link org.hibernate.Session} with
* certain customized options.
*
* @return The session builder
*/
Expand Down Expand Up @@ -456,6 +457,26 @@ default boolean containsFetchProfileDefinition(String name) {
return getDefinedFilterNames().contains( name );
}

/**
* The name assigned to this {@code SessionFactory}, if any.
* <ul>
* <li>When bootstrapping via JPA, this is the persistence unit name.
* <li>Otherwise, the name may be specified by the configuration property
* {@value org.hibernate.cfg.PersistenceSettings#SESSION_FACTORY_NAME}.
* </ul>
* <p>
* If {@value org.hibernate.cfg.PersistenceSettings#SESSION_FACTORY_NAME_IS_JNDI}
* is enabled, then this name is used to bind this object to JNDI, unless
* {@value org.hibernate.cfg.PersistenceSettings#SESSION_FACTORY_JNDI_NAME}
* is also specified.
*
* @see org.hibernate.cfg.PersistenceSettings#SESSION_FACTORY_NAME
* @see org.hibernate.cfg.PersistenceSettings#SESSION_FACTORY_NAME_IS_JNDI
* @see jakarta.persistence.spi.PersistenceUnitInfo#getPersistenceUnitName
*/
@Override
String getName();

/**
* Get the {@linkplain SessionFactoryOptions options} used to build this factory.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,6 @@
*/
package org.hibernate.boot.query;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.function.Supplier;

import org.hibernate.LockMode;
import org.hibernate.MappingException;
import org.hibernate.boot.BootLogging;
Expand Down Expand Up @@ -43,10 +32,9 @@
import org.hibernate.metamodel.mapping.EntityMappingType;
import org.hibernate.metamodel.mapping.PluralAttributeMapping;
import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.query.internal.FetchMementoBasicStandard;
import org.hibernate.query.internal.FetchMementoEmbeddableStandard;
import org.hibernate.query.internal.FetchMementoEntityStandard;
import org.hibernate.spi.NavigablePath;
import org.hibernate.query.internal.FetchMementoBasicStandard;
import org.hibernate.query.internal.FetchMementoHbmStandard;
import org.hibernate.query.internal.FetchMementoHbmStandard.FetchParentMemento;
import org.hibernate.query.internal.NamedResultSetMappingMementoImpl;
Expand All @@ -58,11 +46,23 @@
import org.hibernate.query.named.FetchMementoBasic;
import org.hibernate.query.named.NamedResultSetMappingMemento;
import org.hibernate.query.named.ResultMemento;
import org.hibernate.spi.NavigablePath;
import org.hibernate.sql.results.graph.Fetchable;
import org.hibernate.sql.results.graph.FetchableContainer;
import org.hibernate.sql.results.graph.entity.EntityValuedFetchable;
import org.hibernate.type.BasicType;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.function.Supplier;

/**
* Boot-time descriptor of a result set mapping as defined in an {@code hbm.xml} file
* either implicitly or explicitly
Expand Down Expand Up @@ -372,10 +372,8 @@ public ResultMemento resolve(ResultSetMappingResolutionContext resolutionContext
registrationName
);

final EntityMappingType entityDescriptor = resolutionContext
.getSessionFactory()
.getRuntimeMetamodels()
.getEntityMappingType( entityName );
final EntityMappingType entityDescriptor =
resolutionContext.getMappingMetamodel().getEntityDescriptor( entityName );
applyFetchJoins( joinDescriptorsAccess, tableAlias, propertyFetchDescriptors );

final NavigablePath entityPath = new NavigablePath( entityName );
Expand Down Expand Up @@ -421,10 +419,8 @@ public ResultMemento resolve(ResultSetMappingResolutionContext resolutionContext
@Override
public FetchParentMemento resolveParentMemento(ResultSetMappingResolutionContext resolutionContext) {
if ( thisAsParentMemento == null ) {
final EntityMappingType entityDescriptor = resolutionContext
.getSessionFactory()
.getRuntimeMetamodels()
.getEntityMappingType( entityName );
final EntityMappingType entityDescriptor =
resolutionContext.getMappingMetamodel().getEntityDescriptor( entityName );
thisAsParentMemento = new HbmFetchParentMemento(
new NavigablePath( entityDescriptor.getEntityName() ),
entityDescriptor
Expand Down Expand Up @@ -916,10 +912,9 @@ public ResultMemento resolve(ResultSetMappingResolutionContext resolutionContext
@Override
public FetchParentMemento resolveParentMemento(ResultSetMappingResolutionContext resolutionContext) {
if ( thisAsParentMemento == null ) {
final CollectionPersister collectionDescriptor = resolutionContext.getSessionFactory()
.getRuntimeMetamodels()
.getMappingMetamodel()
.getCollectionDescriptor( collectionPath.getFullPath() );
final CollectionPersister collectionDescriptor =
resolutionContext.getMappingMetamodel()
.getCollectionDescriptor( collectionPath.getFullPath() );

thisAsParentMemento = new HbmFetchParentMemento( collectionPath, collectionDescriptor.getAttributeMapping() );
}
Expand Down Expand Up @@ -957,10 +952,9 @@ public ResultMementoBasicStandard resolve(ResultSetMappingResolutionContext reso
);

if ( hibernateTypeName != null ) {
final BasicType<?> namedType = resolutionContext.getSessionFactory()
.getTypeConfiguration()
.getBasicTypeRegistry()
.getRegisteredType( hibernateTypeName );
final BasicType<?> namedType =
resolutionContext.getTypeConfiguration().getBasicTypeRegistry()
.getRegisteredType( hibernateTypeName );

if ( namedType == null ) {
throw new IllegalArgumentException( "Could not resolve named type : " + hibernateTypeName );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@

import org.hibernate.LockMode;
import org.hibernate.MappingException;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.internal.util.collections.ArrayHelper;
import org.hibernate.metamodel.RuntimeMetamodels;
import org.hibernate.metamodel.mapping.BasicValuedModelPart;
import org.hibernate.metamodel.mapping.EntityDiscriminatorMapping;
import org.hibernate.metamodel.mapping.EntityMappingType;
Expand Down Expand Up @@ -214,10 +212,9 @@ public ResultMemento resolve(ResultSetMappingResolutionContext resolutionContext
(mapping) -> argumentResultMementos.add( mapping.resolve( resolutionContext ) )
);

final SessionFactoryImplementor sessionFactory = resolutionContext.getSessionFactory();
final JavaType<?> targetJtd = sessionFactory.getTypeConfiguration()
.getJavaTypeRegistry()
.getDescriptor( targetJavaType );
final JavaType<?> targetJtd =
resolutionContext.getTypeConfiguration().getJavaTypeRegistry()
.getDescriptor( targetJavaType );

return new ResultMementoInstantiationStandard( targetJtd, argumentResultMementos );
}
Expand Down Expand Up @@ -270,8 +267,8 @@ private static Map<String, AttributeFetchDescriptor> extractFetchMappings(

@Override
public ResultMemento resolve(ResultSetMappingResolutionContext resolutionContext) {
final RuntimeMetamodels runtimeMetamodels = resolutionContext.getSessionFactory().getRuntimeMetamodels();
final EntityMappingType entityDescriptor = runtimeMetamodels.getEntityMappingType( entityName );
final EntityMappingType entityDescriptor =
resolutionContext.getMappingMetamodel().getEntityDescriptor( entityName );

final FetchMementoBasic discriminatorMemento = resolveDiscriminatorMemento(
entityDescriptor,
Expand Down Expand Up @@ -366,8 +363,8 @@ private void addColumn(FieldResult fieldResult) {

@Override
public ResultMemento asResultMemento(NavigablePath path, ResultSetMappingResolutionContext resolutionContext) {
final RuntimeMetamodels runtimeMetamodels = resolutionContext.getSessionFactory().getRuntimeMetamodels();
final EntityMappingType entityMapping = runtimeMetamodels.getEntityMappingType( entityName );
final EntityMappingType entityMapping =
resolutionContext.getMappingMetamodel().getEntityDescriptor( entityName );

final ModelPart subPart = entityMapping.findSubPart( propertyPath, null );

Expand All @@ -386,8 +383,8 @@ public ResultMemento asResultMemento(NavigablePath path, ResultSetMappingResolut

@Override
public FetchMemento resolve(ResultSetMappingResolutionContext resolutionContext) {
final RuntimeMetamodels runtimeMetamodels = resolutionContext.getSessionFactory().getRuntimeMetamodels();
final EntityMappingType entityMapping = runtimeMetamodels.getEntityMappingType( entityName );
final EntityMappingType entityMapping =
resolutionContext.getMappingMetamodel().getEntityDescriptor( entityName );

ModelPart subPart = entityMapping.findSubPart(
propertyPathParts[0],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import java.util.List;
import java.util.Map;

import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.metamodel.mapping.BasicValuedMapping;
import org.hibernate.metamodel.mapping.JdbcMapping;
import org.hibernate.metamodel.model.domain.ReturnableType;
Expand Down Expand Up @@ -92,8 +91,6 @@
CteContainer cteContainer,
QuerySpec querySpec,
SqmToSqlAstConverter converter) {
final SessionFactoryImplementor factory = converter.getCreationContext()
.getSessionFactory();
final QuerySpec outerQuerySpec = new QuerySpec( querySpec.isRoot() );
final String identifierVariable = "hhh_";
final NavigablePath navigablePath = new NavigablePath(
Expand Down Expand Up @@ -400,7 +397,7 @@
columnNames,
false,
true,
factory
converter.getCreationContext().getSessionFactory()

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation Note

Invoking
SqlAstCreationContext.getSessionFactory
should be avoided because it has been deprecated.
);
outerQuerySpec.getFromClause().addRoot( queryPartTableGroup );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.hibernate.metamodel.mapping.JdbcMapping;
import org.hibernate.metamodel.model.domain.DomainType;
import org.hibernate.metamodel.model.domain.ReturnableType;
import org.hibernate.query.BindingContext;
import org.hibernate.query.sqm.SqmExpressible;
import org.hibernate.query.sqm.function.AbstractSqmSelfRenderingFunctionDescriptor;
import org.hibernate.query.sqm.function.FunctionKind;
Expand Down Expand Up @@ -150,7 +151,7 @@ public static class Validator implements ArgumentsValidator {
public void validate(
List<? extends SqmTypedNode<?>> arguments,
String functionName,
TypeConfiguration typeConfiguration) {
BindingContext bindingContext) {
if ( arguments.size() != 1 ) {
throw new FunctionArgumentException(
String.format(
Expand All @@ -166,7 +167,7 @@ public void validate(
final SqmExpressible<?> expressible = argument.getExpressible();
final DomainType<?> domainType;
if ( expressible != null && ( domainType = expressible.getSqmType() ) != null ) {
final JdbcType jdbcType = getJdbcType( domainType, typeConfiguration );
final JdbcType jdbcType = getJdbcType( domainType, bindingContext.getTypeConfiguration() );
if ( !isNumeric( jdbcType ) ) {
throw new FunctionArgumentException(
String.format(
Expand Down Expand Up @@ -230,7 +231,8 @@ public BasicValuedMapping resolveFunctionReturnType(
if ( impliedType != null ) {
return impliedType;
}
final JdbcMapping jdbcMapping = ( (Expression) arguments.get( 0 ) ).getExpressionType().getSingleJdbcMapping();
Expression expression = (Expression) arguments.get( 0 );
final JdbcMapping jdbcMapping = expression.getExpressionType().getSingleJdbcMapping();
if ( jdbcMapping instanceof BasicPluralType<?, ?> ) {
return (BasicValuedMapping) jdbcMapping;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import org.hibernate.QueryException;
import org.hibernate.metamodel.model.domain.ReturnableType;
import org.hibernate.query.BindingContext;
import org.hibernate.query.sqm.function.AbstractSqmSelfRenderingFunctionDescriptor;
import org.hibernate.query.sqm.produce.function.ArgumentTypesValidator;
import org.hibernate.query.sqm.produce.function.ArgumentsValidator;
Expand Down Expand Up @@ -41,7 +42,7 @@ public ChrLiteralEmulation(TypeConfiguration typeConfiguration) {
StandardArgumentsValidators.exactly(1),
new ArgumentsValidator() {
@Override
public void validate(List<? extends SqmTypedNode<?>> arguments, String functionName, TypeConfiguration typeConfiguration) {
public void validate(List<? extends SqmTypedNode<?>> arguments, String functionName, BindingContext bindingContext) {
if ( !( arguments.get( 0 ) instanceof SqmLiteral<?> ) ) {
throw new QueryException(
String.format(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,9 @@ protected CteStatement createSeriesCte(SqmToSqlAstConverter converter) {
}

public static CteStatement createSeriesCte(int maxSeriesSize, SqmToSqlAstConverter converter) {
final BasicType<Long> longType = converter.getCreationContext().getTypeConfiguration()
.getBasicTypeForJavaType( Long.class );
final BasicType<Long> longType =
converter.getCreationContext().getTypeConfiguration()
.getBasicTypeForJavaType( Long.class );
final Expression one = new UnparsedNumericLiteral<>( "1", NumericTypeCategory.LONG, longType );
final List<CteColumn> cteColumns = List.of( new CteColumn( "i", longType ) );

Expand Down
Loading
Loading