renamed `NamedQueryRepository` to ``NamedObjectRepository`

This commit is contained in:
Steve Ebersole 2020-11-04 14:37:34 -06:00
parent b0b478c274
commit 4f4b42c5df
25 changed files with 94 additions and 87 deletions

View File

@ -86,8 +86,6 @@ import org.hibernate.id.factory.IdentifierGeneratorFactory;
import org.hibernate.id.factory.spi.MutableIdentifierGeneratorFactory;
import org.hibernate.internal.CoreLogging;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.SessionFactoryImpl;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.internal.util.collections.CollectionHelper;
import org.hibernate.mapping.Collection;
import org.hibernate.mapping.Column;
@ -105,7 +103,7 @@ import org.hibernate.mapping.RootClass;
import org.hibernate.mapping.SimpleValue;
import org.hibernate.mapping.Table;
import org.hibernate.mapping.UniqueKey;
import org.hibernate.query.named.NamedQueryRepository;
import org.hibernate.query.named.NamedObjectRepository;
import org.hibernate.query.sqm.function.SqmFunctionDescriptor;
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
import org.hibernate.type.descriptor.sql.SqlTypeDescriptor;
@ -222,7 +220,7 @@ public class InFlightMetadataCollectorImpl implements InFlightMetadataCollector
}
@Override
public NamedQueryRepository buildNamedQueryRepository(SessionFactoryImplementor sessionFactory) {
public NamedObjectRepository buildNamedQueryRepository(SessionFactoryImplementor sessionFactory) {
throw new UnsupportedOperationException( "#buildNamedQueryRepository should not be called on InFlightMetadataCollector" );
}

View File

@ -54,9 +54,8 @@ import org.hibernate.mapping.Property;
import org.hibernate.mapping.Table;
import org.hibernate.procedure.spi.NamedCallableQueryMemento;
import org.hibernate.query.hql.spi.NamedHqlQueryMemento;
import org.hibernate.query.internal.NamedQueryRepositoryImpl;
import org.hibernate.query.named.NamedQueryRepository;
import org.hibernate.query.named.NamedResultSetMappingMemento;
import org.hibernate.query.internal.NamedObjectRepositoryImpl;
import org.hibernate.query.named.NamedObjectRepository;
import org.hibernate.query.sql.spi.NamedNativeQueryMemento;
import org.hibernate.query.sqm.function.SqmFunctionDescriptor;
import org.hibernate.service.spi.ServiceRegistryImplementor;
@ -317,8 +316,8 @@ public class MetadataImpl implements MetadataImplementor, Serializable {
}
@Override
public NamedQueryRepository buildNamedQueryRepository(SessionFactoryImplementor sessionFactory) {
return new NamedQueryRepositoryImpl(
public NamedObjectRepository buildNamedQueryRepository(SessionFactoryImplementor sessionFactory) {
return new NamedObjectRepositoryImpl(
CollectionHelper.mapOfSize( namedQueryMap.size() ),
CollectionHelper.mapOfSize( namedNativeQueryMap.size() ),
CollectionHelper.mapOfSize( namedProcedureCallMap.size() ),

View File

@ -6,10 +6,10 @@
*/
package org.hibernate.boot.query;
import org.hibernate.query.EntityIdentifierNavigablePath;
import org.hibernate.query.NavigablePath;
import org.hibernate.query.named.FetchMemento;
import org.hibernate.query.internal.ResultSetMappingResolutionContext;
import org.hibernate.query.named.NamedObjectRepository;
import org.hibernate.query.named.ResultMemento;
/**
@ -18,7 +18,7 @@ import org.hibernate.query.named.ResultMemento;
public interface FetchDescriptor {
/**
* Resolve the descriptor into a memento capable of being stored in the
* {@link org.hibernate.query.named.NamedQueryRepository}
* {@link NamedObjectRepository}
*/
FetchMemento resolve(ResultSetMappingResolutionContext resolutionContext);

View File

@ -7,6 +7,7 @@
package org.hibernate.boot.query;
import org.hibernate.query.internal.ResultSetMappingResolutionContext;
import org.hibernate.query.named.NamedObjectRepository;
import org.hibernate.query.named.NamedResultSetMappingMemento;
import org.hibernate.query.spi.QueryEngine;
@ -15,7 +16,7 @@ import org.hibernate.query.spi.QueryEngine;
* of native and procedure queries.
*
* Ultimately used to generate a NamedResultSetMappingMemento that is
* stored in the {@link org.hibernate.query.named.NamedQueryRepository}
* stored in the {@link NamedObjectRepository}
* for availability at runtime
*
* @author Steve Ebersole
@ -28,9 +29,9 @@ public interface NamedResultSetMappingDescriptor {
/**
* Create a representation of the described ResultSet mapping for the purpose of
* being stored in Hibernate's {@link org.hibernate.query.named.NamedQueryRepository}
* being stored in Hibernate's {@link NamedObjectRepository}
*
* @see QueryEngine#getNamedQueryRepository()
* @see QueryEngine#getNamedObjectRepository()
*/
NamedResultSetMappingMemento resolve(ResultSetMappingResolutionContext resolutionContext);
}

View File

@ -6,6 +6,7 @@
*/
package org.hibernate.boot.query;
import org.hibernate.query.named.NamedObjectRepository;
import org.hibernate.query.named.ResultMemento;
import org.hibernate.query.internal.ResultSetMappingResolutionContext;
@ -17,7 +18,7 @@ import org.hibernate.query.internal.ResultSetMappingResolutionContext;
public interface ResultDescriptor {
/**
* Resolve the descriptor into a memento capable of being stored in the
* {@link org.hibernate.query.named.NamedQueryRepository}
* {@link NamedObjectRepository}
*/
ResultMemento resolve(ResultSetMappingResolutionContext resolutionContext);
}

View File

@ -30,7 +30,7 @@ import org.hibernate.mapping.FetchProfile;
import org.hibernate.mapping.MappedSuperclass;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Table;
import org.hibernate.query.named.NamedQueryRepository;
import org.hibernate.query.named.NamedObjectRepository;
import org.hibernate.query.sqm.function.SqmFunctionDescriptor;
import org.hibernate.type.Type;
import org.hibernate.type.spi.TypeConfiguration;
@ -230,7 +230,7 @@ public abstract class AbstractDelegatingMetadata implements MetadataImplementor
@Override
public NamedQueryRepository buildNamedQueryRepository(SessionFactoryImplementor sessionFactory) {
public NamedObjectRepository buildNamedQueryRepository(SessionFactoryImplementor sessionFactory) {
return delegate.buildNamedQueryRepository( sessionFactory );
}
}

View File

@ -13,7 +13,7 @@ import org.hibernate.boot.Metadata;
import org.hibernate.engine.spi.Mapping;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.mapping.MappedSuperclass;
import org.hibernate.query.named.NamedQueryRepository;
import org.hibernate.query.named.NamedObjectRepository;
import org.hibernate.type.spi.TypeConfiguration;
/**
@ -38,7 +38,7 @@ public interface MetadataImplementor extends Metadata, Mapping {
*/
TypeConfiguration getTypeConfiguration();
NamedQueryRepository buildNamedQueryRepository(SessionFactoryImplementor sessionFactory);
NamedObjectRepository buildNamedQueryRepository(SessionFactoryImplementor sessionFactory);
void validate() throws MappingException;

View File

@ -701,7 +701,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
try {
if ( StringHelper.isNotEmpty( resultSetMappingName ) ) {
final NamedResultSetMappingMemento resultSetMappingMemento = getFactory().getQueryEngine()
.getNamedQueryRepository()
.getNamedObjectRepository()
.getResultSetMappingMemento( resultSetMappingName );
if ( resultSetMappingMemento == null ) {
@ -772,7 +772,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
// first see if it is a named HQL query
final NamedHqlQueryMemento namedHqlDescriptor = getFactory().getQueryEngine()
.getNamedQueryRepository()
.getNamedObjectRepository()
.getHqlQueryMemento( queryName );
if ( namedHqlDescriptor != null ) {
@ -784,7 +784,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
// otherwise, see if it is a named native query
final NamedNativeQueryMemento namedNativeDescriptor = getFactory().getQueryEngine()
.getNamedQueryRepository()
.getNamedObjectRepository()
.getNativeQueryMemento( queryName );
if ( namedNativeDescriptor != null ) {
@ -806,7 +806,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
@Override
public NativeQueryImplementor getNamedNativeQuery(String queryName) {
final NamedNativeQueryMemento namedNativeDescriptor = getFactory().getQueryEngine()
.getNamedQueryRepository()
.getNamedObjectRepository()
.getNativeQueryMemento( queryName );
if ( namedNativeDescriptor != null ) {
@ -819,7 +819,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
@Override
public NativeQueryImplementor getNamedNativeQuery(String queryName, String resultSetMapping) {
final NamedNativeQueryMemento namedNativeDescriptor = getFactory().getQueryEngine()
.getNamedQueryRepository()
.getNamedObjectRepository()
.getNativeQueryMemento( queryName );
if ( namedNativeDescriptor != null ) {
@ -834,7 +834,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
public ProcedureCall getNamedProcedureCall(String name) {
checkOpen();
final NamedCallableQueryMemento memento = factory.getQueryEngine().getNamedQueryRepository().getCallableQueryMemento( name );
final NamedCallableQueryMemento memento = factory.getQueryEngine().getNamedObjectRepository().getCallableQueryMemento( name );
if ( memento == null ) {
throw new IllegalArgumentException(
"Could not find named stored procedure call with that registration name : " + name

View File

@ -310,7 +310,7 @@ public class SessionFactoryImpl implements SessionFactoryImplementor {
this.queryEngine.prepare( this, bootMetamodel, bootstrapContext );
if ( options.isNamedQueryStartupCheckingEnabled() ) {
queryEngine.getNamedQueryRepository().checkNamedQueries( queryEngine );
queryEngine.getNamedObjectRepository().checkNamedQueries( queryEngine );
}
// todo (6.0) : manage old getMultiTableBulkIdStrategy
@ -854,7 +854,7 @@ public class SessionFactoryImpl implements SessionFactoryImplementor {
try {
final ProcedureCallImplementor unwrapped = query.unwrap( ProcedureCallImplementor.class );
if ( unwrapped != null ) {
getQueryEngine().getNamedQueryRepository().registerCallableQueryMemento(
getQueryEngine().getNamedObjectRepository().registerCallableQueryMemento(
name,
unwrapped.toMemento( name )
);
@ -871,13 +871,13 @@ public class SessionFactoryImpl implements SessionFactoryImplementor {
if ( hibernateQuery != null ) {
// create and register the proper NamedQueryDefinition...
if ( hibernateQuery instanceof NativeQueryImplementor ) {
getQueryEngine().getNamedQueryRepository().registerNativeQueryMemento(
getQueryEngine().getNamedObjectRepository().registerNativeQueryMemento(
name,
( (NativeQueryImplementor) hibernateQuery ).toMemento( name )
);
}
else {
getQueryEngine().getNamedQueryRepository().registerHqlQueryMemento(
getQueryEngine().getNamedObjectRepository().registerHqlQueryMemento(
name,
( ( HqlQueryImplementor ) hibernateQuery ).toMemento( name )
);

View File

@ -113,7 +113,6 @@ import org.hibernate.event.spi.SaveOrUpdateEventListener;
import org.hibernate.graph.GraphSemantic;
import org.hibernate.graph.RootGraph;
import org.hibernate.graph.internal.RootGraphImpl;
import org.hibernate.graph.spi.GraphImplementor;
import org.hibernate.graph.spi.RootGraphImplementor;
import org.hibernate.jpa.AvailableSettings;
import org.hibernate.jpa.QueryHints;
@ -3023,7 +3022,7 @@ public class SessionImpl
checkOpen();
try {
final NamedCallableQueryMemento memento = getFactory().getQueryEngine()
.getNamedQueryRepository()
.getNamedObjectRepository()
.getCallableQueryMemento( name );
if ( memento == null ) {
throw new IllegalArgumentException( "No @NamedStoredProcedureQuery was found with that name : " + name );

View File

@ -12,7 +12,7 @@ import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.loader.ast.spi.SingleIdEntityLoader;
import org.hibernate.metamodel.mapping.EntityMappingType;
import org.hibernate.query.named.NamedQueryMemento;
import org.hibernate.query.named.NamedQueryRepository;
import org.hibernate.query.named.NamedObjectRepository;
import org.hibernate.query.spi.QueryImplementor;
import org.hibernate.query.sql.spi.NamedNativeQueryMemento;
@ -41,14 +41,14 @@ public class SingleIdEntityLoaderProvidedQueryImpl<T> implements SingleIdEntityL
private static NamedQueryMemento resolveNamedQuery(
String queryName,
SessionFactoryImplementor sf) {
final NamedQueryRepository namedQueryRepository = sf.getQueryEngine().getNamedQueryRepository();
final NamedObjectRepository namedObjectRepository = sf.getQueryEngine().getNamedObjectRepository();
final NamedNativeQueryMemento nativeQueryMemento = namedQueryRepository.getNativeQueryMemento( queryName );
final NamedNativeQueryMemento nativeQueryMemento = namedObjectRepository.getNativeQueryMemento( queryName );
if ( nativeQueryMemento != null ) {
return nativeQueryMemento;
}
return namedQueryRepository.getHqlQueryMemento( queryName );
return namedObjectRepository.getHqlQueryMemento( queryName );
}
@Override

View File

@ -11,7 +11,7 @@ import java.util.function.Consumer;
import org.hibernate.NotYetImplementedFor6Exception;
import org.hibernate.internal.util.collections.ArrayHelper;
import org.hibernate.query.internal.ResultSetMappingResolutionContext;
import org.hibernate.query.named.NamedQueryRepository;
import org.hibernate.query.named.NamedObjectRepository;
import org.hibernate.query.named.NamedResultSetMappingMemento;
import org.hibernate.query.results.ResultSetMapping;
@ -53,10 +53,10 @@ public class Util {
ResultSetMapping resultSetMapping,
Consumer<String> querySpaceConsumer,
ResultSetMappingResolutionContext context) {
final NamedQueryRepository namedQueryRepository = context.getSessionFactory().getQueryEngine().getNamedQueryRepository();
final NamedObjectRepository namedObjectRepository = context.getSessionFactory().getQueryEngine().getNamedObjectRepository();
for ( String resultSetMappingName : resultSetMappingNames ) {
final NamedResultSetMappingMemento memento = namedQueryRepository.getResultSetMappingMemento( resultSetMappingName );
final NamedResultSetMappingMemento memento = namedObjectRepository.getResultSetMappingMemento( resultSetMappingName );
memento.resolve(
resultSetMapping,
querySpaceConsumer,

View File

@ -17,7 +17,7 @@ import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.procedure.spi.NamedCallableQueryMemento;
import org.hibernate.query.hql.HqlTranslator;
import org.hibernate.query.hql.spi.NamedHqlQueryMemento;
import org.hibernate.query.named.NamedQueryRepository;
import org.hibernate.query.named.NamedObjectRepository;
import org.hibernate.query.named.NamedResultSetMappingMemento;
import org.hibernate.query.spi.QueryEngine;
import org.hibernate.query.spi.QueryInterpretationCache;
@ -28,15 +28,15 @@ import org.jboss.logging.Logger;
/**
* @author Steve Ebersole
*/
public class NamedQueryRepositoryImpl implements NamedQueryRepository {
private static final Logger log = Logger.getLogger( NamedQueryRepository.class );
public class NamedObjectRepositoryImpl implements NamedObjectRepository {
private static final Logger log = Logger.getLogger( NamedObjectRepository.class );
private final Map<String, NamedHqlQueryMemento> hqlMementoMap;
private final Map<String, NamedNativeQueryMemento> sqlMementoMap;
private final Map<String, NamedCallableQueryMemento> callableMementoMap;
private final Map<String, NamedResultSetMappingMemento> resultSetMappingMementoMap;
public NamedQueryRepositoryImpl(
public NamedObjectRepositoryImpl(
Map<String,NamedHqlQueryMemento> hqlMementoMap,
Map<String,NamedNativeQueryMemento> sqlMementoMap,
Map<String,NamedCallableQueryMemento> callableMementoMap,

View File

@ -10,7 +10,7 @@ import org.hibernate.Incubating;
/**
* Contract for Query impls that can be converted to a named query memento to be
* stored in the {@link NamedQueryRepository}
* stored in the {@link NamedObjectRepository}
*
* @author Steve Ebersole
*/

View File

@ -27,7 +27,7 @@ import org.hibernate.query.sql.spi.NamedNativeQueryMemento;
* @author Steve Ebersole
*/
@Incubating
public interface NamedQueryRepository {
public interface NamedObjectRepository {
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Named HQL Memento

View File

@ -17,7 +17,7 @@ import org.hibernate.query.spi.QueryParameterImplementor;
/**
* The runtime representation of named queries. They are stored in and
* available through the QueryEngine's {@link NamedQueryRepository}.
* available through the QueryEngine's {@link NamedObjectRepository}.
*
* This is the base contract for all specific types of named query mementos
*

View File

@ -24,7 +24,7 @@ import org.hibernate.query.hql.internal.StandardHqlTranslator;
import org.hibernate.query.hql.spi.SqmCreationOptions;
import org.hibernate.query.internal.QueryInterpretationCacheDisabledImpl;
import org.hibernate.query.internal.QueryInterpretationCacheStandardImpl;
import org.hibernate.query.named.NamedQueryRepository;
import org.hibernate.query.named.NamedObjectRepository;
import org.hibernate.query.sqm.NodeBuilder;
import org.hibernate.query.sqm.function.SqmFunctionRegistry;
import org.hibernate.query.sqm.internal.SqmCreationOptionsStandard;
@ -79,7 +79,7 @@ public class QueryEngine {
);
}
private final NamedQueryRepository namedQueryRepository;
private final NamedObjectRepository namedObjectRepository;
private final SqmCriteriaNodeBuilder criteriaBuilder;
private final HqlTranslator hqlTranslator;
private final SqmTranslatorFactory sqmTranslatorFactory;
@ -89,7 +89,7 @@ public class QueryEngine {
public QueryEngine(
Supplier<JpaMetamodel> jpaMetamodelAccess,
NamedQueryRepository namedQueryRepository,
NamedObjectRepository namedObjectRepository,
HqlTranslator hqlTranslator,
SqmTranslatorFactory sqmTranslatorFactory,
NativeQueryInterpreter nativeQueryInterpreter,
@ -97,7 +97,7 @@ public class QueryEngine {
Dialect dialect,
SqmFunctionRegistry userDefinedRegistry,
ServiceRegistry serviceRegistry) {
this.namedQueryRepository = namedQueryRepository;
this.namedObjectRepository = namedObjectRepository;
this.sqmTranslatorFactory = sqmTranslatorFactory;
this.nativeQueryInterpreter = nativeQueryInterpreter;
this.interpretationCache = interpretationCache;
@ -133,11 +133,11 @@ public class QueryEngine {
public QueryEngine(
JpaMetamodel jpaMetamodel,
boolean useStrictJpaCompliance,
NamedQueryRepository namedQueryRepository,
NamedObjectRepository namedObjectRepository,
NativeQueryInterpreter nativeQueryInterpreter,
Dialect dialect,
ServiceRegistry serviceRegistry) {
this.namedQueryRepository = namedQueryRepository;
this.namedObjectRepository = namedObjectRepository;
this.sqmTranslatorFactory = null;
this.nativeQueryInterpreter = nativeQueryInterpreter;
@ -293,11 +293,11 @@ public class QueryEngine {
SessionFactoryImplementor sessionFactory,
MetadataImplementor bootMetamodel,
BootstrapContext bootstrapContext) {
namedQueryRepository.prepare( sessionFactory, bootMetamodel, bootstrapContext );
namedObjectRepository.prepare( sessionFactory, bootMetamodel, bootstrapContext );
//checking for named queries
if ( sessionFactory.getSessionFactoryOptions().isNamedQueryStartupCheckingEnabled() ) {
final Map<String, HibernateException> errors = namedQueryRepository.checkNamedQueries( this );
final Map<String, HibernateException> errors = namedObjectRepository.checkNamedQueries( this );
if ( !errors.isEmpty() ) {
StringBuilder failingQueries = new StringBuilder( "Errors in named queries: " );
@ -312,8 +312,8 @@ public class QueryEngine {
}
}
public NamedQueryRepository getNamedQueryRepository() {
return namedQueryRepository;
public NamedObjectRepository getNamedObjectRepository() {
return namedObjectRepository;
}
public SqmCriteriaNodeBuilder getCriteriaBuilder() {
@ -341,8 +341,8 @@ public class QueryEngine {
}
public void close() {
if ( namedQueryRepository != null ) {
namedQueryRepository.close();
if ( namedObjectRepository != null ) {
namedObjectRepository.close();
}
if ( criteriaBuilder != null ) {

View File

@ -139,7 +139,7 @@ public class NativeQueryImpl<R>
if ( memento.getResultMappingName() != null ) {
final NamedResultSetMappingMemento resultSetMappingMemento = session.getFactory()
.getQueryEngine()
.getNamedQueryRepository()
.getNamedObjectRepository()
.getResultSetMappingMemento( memento.getResultMappingName() );
resultSetMappingMemento.resolve( resultSetMapping, querySpaceConsumer, context );
return true;
@ -240,7 +240,7 @@ public class NativeQueryImpl<R>
(resultSetMapping, querySpaceConsumer, context) -> {
final NamedResultSetMappingMemento mappingMemento = session.getFactory()
.getQueryEngine()
.getNamedQueryRepository()
.getNamedObjectRepository()
.getResultSetMappingMemento( resultSetMappingName );
assert mappingMemento != null;
mappingMemento.resolve( resultSetMapping, querySpaceConsumer, context );

View File

@ -22,7 +22,8 @@ import org.hibernate.metamodel.spi.RuntimeModelCreationContext;
import org.hibernate.query.hql.HqlTranslator;
import org.hibernate.query.hql.internal.StandardHqlTranslator;
import org.hibernate.query.hql.spi.SqmCreationOptions;
import org.hibernate.query.internal.NamedQueryRepositoryImpl;
import org.hibernate.query.internal.NamedObjectRepositoryImpl;
import org.hibernate.query.named.NamedObjectRepository;
import org.hibernate.query.spi.QueryEngine;
import org.hibernate.query.sqm.spi.SqmCreationContext;
import org.hibernate.query.sqm.tree.SqmStatement;
@ -39,7 +40,7 @@ import org.junit.jupiter.api.Test;
/**
* Tests making sure that HQL queries can fully be translated without a SessionFactory.
*
* todo (6.0) : have a way to directly load these translations into the {@link org.hibernate.query.named.NamedQueryRepository}
* todo (6.0) : have a way to directly load these translations into the {@link NamedObjectRepository}
* directly. For example Quarkus could store its build-time translations and directly here during boot-strap of the SF
*
* @author Steve Ebersole
@ -116,7 +117,7 @@ public class HqlTranslationNoFactoryTests {
jpaMetamodel,
// we don't want strict JPA query compliance
false,
new NamedQueryRepositoryImpl( Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap() ),
new NamedObjectRepositoryImpl( Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap() ),
// NativeQueryInterpreter
null,
// this is exclusively to build the SqmFunctionRegistry, maybe Quarkus should just build it directly and pass

View File

@ -11,7 +11,7 @@ import javax.persistence.FlushModeType;
import org.hibernate.CacheMode;
import org.hibernate.query.Query;
import org.hibernate.query.hql.spi.NamedHqlQueryMemento;
import org.hibernate.query.named.NamedQueryRepository;
import org.hibernate.query.named.NamedObjectRepository;
import org.hibernate.query.spi.QueryImplementor;
import org.hibernate.testing.orm.junit.DomainModel;
@ -31,14 +31,14 @@ import static org.hamcrest.MatcherAssert.assertThat;
public class SimpleNamedQueryTests {
@Test
public void testBinding(SessionFactoryScope scope) {
final NamedQueryRepository namedQueryRepository = scope.getSessionFactory()
final NamedObjectRepository namedObjectRepository = scope.getSessionFactory()
.getQueryEngine()
.getNamedQueryRepository();
.getNamedObjectRepository();
final NamedHqlQueryMemento simpleMemento = namedQueryRepository.getHqlQueryMemento( "simple" );
final NamedHqlQueryMemento simpleMemento = namedObjectRepository.getHqlQueryMemento( "simple" );
assertThat( simpleMemento, notNullValue() );
final NamedHqlQueryMemento restrictedMemento = namedQueryRepository.getHqlQueryMemento( "restricted" );
final NamedHqlQueryMemento restrictedMemento = namedObjectRepository.getHqlQueryMemento( "restricted" );
assertThat( restrictedMemento, notNullValue() );
}
@ -50,14 +50,14 @@ public class SimpleNamedQueryTests {
session.createNamedQuery( "restricted" ).setParameter( "name", "a name" ).list();
}
);
final NamedQueryRepository namedQueryRepository = scope.getSessionFactory()
final NamedObjectRepository namedObjectRepository = scope.getSessionFactory()
.getQueryEngine()
.getNamedQueryRepository();
.getNamedObjectRepository();
final NamedHqlQueryMemento simpleMemento = namedQueryRepository.getHqlQueryMemento( "simple" );
final NamedHqlQueryMemento simpleMemento = namedObjectRepository.getHqlQueryMemento( "simple" );
assertThat( simpleMemento, notNullValue() );
final NamedHqlQueryMemento restrictedMemento = namedQueryRepository.getHqlQueryMemento( "restricted" );
final NamedHqlQueryMemento restrictedMemento = namedObjectRepository.getHqlQueryMemento( "restricted" );
assertThat( restrictedMemento, notNullValue() );
}

View File

@ -17,7 +17,7 @@ import org.junit.jupiter.api.BeforeEach;
*/
@DomainModel( annotatedClasses = SimpleEntityWithNamedMappings.class )
@SessionFactory
public class BaseUsageTest {
public abstract class AbstractUsageTest {
@BeforeEach
public void prepareData(SessionFactoryScope scope) {
scope.inTransaction(

View File

@ -18,9 +18,9 @@ import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.notNullValue;
/**
* @author Steve Ebersole
* Tests for basic-valued SqlResultSetMapping handling and usage
*/
public class BasicResultTests extends BaseUsageTest {
public class BasicResultTests extends AbstractUsageTest {
@Test
public void testSimpleScalarMapping(SessionFactoryScope scope) {
scope.inTransaction(
@ -28,7 +28,7 @@ public class BasicResultTests extends BaseUsageTest {
// make sure it is in the repository
final NamedResultSetMappingMemento mappingMemento = session.getSessionFactory()
.getQueryEngine()
.getNamedQueryRepository()
.getNamedObjectRepository()
.getResultSetMappingMemento( "name" );
assertThat( mappingMemento, notNullValue() );
@ -52,7 +52,7 @@ public class BasicResultTests extends BaseUsageTest {
// make sure it is in the repository
final NamedResultSetMappingMemento mappingMemento = session.getSessionFactory()
.getQueryEngine()
.getNamedQueryRepository()
.getNamedObjectRepository()
.getResultSetMappingMemento( "id_name" );
assertThat( mappingMemento, notNullValue() );

View File

@ -55,7 +55,7 @@ import static org.hamcrest.Matchers.notNullValue;
)
}
)
public class EntityResultTests extends BaseUsageTest {
public class EntityResultTests extends AbstractUsageTest {
@Test
public void testSimpleEntityResultMapping(SessionFactoryScope scope) {
@ -64,7 +64,7 @@ public class EntityResultTests extends BaseUsageTest {
// make sure it is in the repository
final NamedResultSetMappingMemento mappingMemento = session.getSessionFactory()
.getQueryEngine()
.getNamedQueryRepository()
.getNamedObjectRepository()
.getResultSetMappingMemento( "entity" );
assertThat( mappingMemento, notNullValue() );
@ -92,7 +92,7 @@ public class EntityResultTests extends BaseUsageTest {
// make sure it is in the repository
final NamedResultSetMappingMemento mappingMemento = session.getSessionFactory()
.getQueryEngine()
.getNamedQueryRepository()
.getNamedObjectRepository()
.getResultSetMappingMemento(
"entity-none" );
assertThat( mappingMemento, notNullValue() );
@ -121,7 +121,7 @@ public class EntityResultTests extends BaseUsageTest {
// make sure it is in the repository
final NamedResultSetMappingMemento mappingMemento = session.getSessionFactory()
.getQueryEngine()
.getNamedQueryRepository()
.getNamedObjectRepository()
.getResultSetMappingMemento(
"entity-id-notes" );
assertThat( mappingMemento, notNullValue() );

View File

@ -20,7 +20,7 @@ import static org.hamcrest.Matchers.notNullValue;
/**
* @author Steve Ebersole
*/
public class InstantiationResultTests extends BaseUsageTest {
public class InstantiationResultTests extends AbstractUsageTest {
@Test
public void testSimpleInstantiationOfScalars(SessionFactoryScope scope) {
@ -29,7 +29,7 @@ public class InstantiationResultTests extends BaseUsageTest {
// make sure it is in the repository
final NamedResultSetMappingMemento mappingMemento = session.getSessionFactory()
.getQueryEngine()
.getNamedQueryRepository()
.getNamedObjectRepository()
.getResultSetMappingMemento(
"id_name_dto" );
assertThat( mappingMemento, notNullValue() );

View File

@ -6,35 +6,43 @@
*/
package org.hibernate.orm.test.query.resultmapping;
import java.util.List;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.query.internal.ResultSetMappingResolutionContext;
import org.hibernate.query.named.NamedQueryRepository;
import org.hibernate.query.named.NamedObjectRepository;
import org.hibernate.query.named.NamedResultSetMappingMemento;
import org.hibernate.query.results.ResultBuilderBasicValued;
import org.hibernate.query.results.ResultSetMapping;
import org.hibernate.query.results.ResultSetMappingImpl;
import org.hibernate.query.spi.QueryEngine;
import org.hibernate.query.sql.spi.NativeQueryImplementor;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.hamcrest.Matchers;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
/**
* @author Steve Ebersole
* Simple tests for SqlResultSetMapping handling and usage
*/
@DomainModel( annotatedClasses = SimpleEntityWithNamedMappings.class )
@SessionFactory
public class SimpleNamedMappingTests {
public class NamedRepoTests {
@Test
public void testMappingResolution(SessionFactoryScope sessionFactoryScope) {
final QueryEngine queryEngine = sessionFactoryScope.getSessionFactory().getQueryEngine();
final NamedQueryRepository namedQueryRepository = queryEngine.getNamedQueryRepository();
final NamedResultSetMappingMemento mappingMemento = namedQueryRepository.getResultSetMappingMemento( "name" );
final NamedObjectRepository namedObjectRepository = queryEngine.getNamedObjectRepository();
final NamedResultSetMappingMemento mappingMemento = namedObjectRepository.getResultSetMappingMemento( "name" );
final ResultSetMapping mapping = new ResultSetMappingImpl( "test" );