Search in sources :

Example 1 with SingleIdEntityLoaderStandardImpl

use of org.hibernate.loader.ast.internal.SingleIdEntityLoaderStandardImpl in project hibernate-orm by hibernate.

the class LoadPlanBuilderTest method testCascadeBasedBuild.

@Test
public void testCascadeBasedBuild(SessionFactoryScope scope) {
    final SessionFactoryImplementor sessionFactory = scope.getSessionFactory();
    final EntityPersister entityDescriptor = (EntityPersister) sessionFactory.getRuntimeMetamodels().getEntityMappingType(Message.class);
    final SingleIdEntityLoaderStandardImpl<?> loader = new SingleIdEntityLoaderStandardImpl<>(entityDescriptor, sessionFactory);
    final LoadQueryInfluencers influencers = new LoadQueryInfluencers() {

        @Override
        public CascadingFetchProfile getEnabledCascadingFetchProfile() {
            return CascadingFetchProfile.MERGE;
        }
    };
    final SingleIdLoadPlan<?> loadPlan = loader.resolveLoadPlan(LockOptions.READ, influencers, sessionFactory);
    final List<DomainResult<?>> domainResults = loadPlan.getJdbcSelect().getJdbcValuesMappingProducer().resolve(null, sessionFactory).getDomainResults();
    assertThat(domainResults).hasSize(1);
    final DomainResult<?> domainResult = domainResults.get(0);
    assertThat(domainResult).isInstanceOf(EntityResult.class);
    final EntityResult entityResult = (EntityResult) domainResult;
    assertThat(entityResult.getFetches()).hasSize(2);
    final Fetch txtFetch = entityResult.getFetches().get(0);
    assertThat(txtFetch).isNotNull();
    assertThat(txtFetch.getFetchedMapping().getFetchableName()).isEqualTo("msgTxt");
    assertThat(txtFetch.getTiming()).isEqualTo(FetchTiming.IMMEDIATE);
    final Fetch posterFetch = entityResult.getFetches().get(1);
    assertThat(posterFetch).isNotNull();
    assertThat(posterFetch.getFetchedMapping().getFetchableName()).isEqualTo("poster");
    assertThat(posterFetch.getTiming()).isEqualTo(FetchTiming.IMMEDIATE);
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) LoadQueryInfluencers(org.hibernate.engine.spi.LoadQueryInfluencers) Fetch(org.hibernate.sql.results.graph.Fetch) SingleIdEntityLoaderStandardImpl(org.hibernate.loader.ast.internal.SingleIdEntityLoaderStandardImpl) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) CollectionDomainResult(org.hibernate.sql.results.graph.collection.internal.CollectionDomainResult) DomainResult(org.hibernate.sql.results.graph.DomainResult) EntityResult(org.hibernate.sql.results.graph.entity.EntityResult) Test(org.junit.jupiter.api.Test)

Example 2 with SingleIdEntityLoaderStandardImpl

use of org.hibernate.loader.ast.internal.SingleIdEntityLoaderStandardImpl in project hibernate-orm by hibernate.

the class LoadingSmokeTests method testBasicGet.

@Test
public void testBasicGet(SessionFactoryScope scope) {
    scope.inTransaction(session -> {
        final BasicEntity gotten = session.byId(BasicEntity.class).load(1);
        assertThat(gotten, notNullValue());
        assertThat(Hibernate.isInitialized(gotten), is(true));
        assertThat(gotten.getId(), is(1));
        assertThat(gotten.getData(), is("first"));
        final AbstractEntityPersister entityDescriptor = (AbstractEntityPersister) session.getSessionFactory().getRuntimeMetamodels().getMappingMetamodel().getEntityDescriptor(BasicEntity.class);
        final SingleIdEntityLoader singleIdEntityLoader = entityDescriptor.getSingleIdEntityLoader();
        assertThat(singleIdEntityLoader, instanceOf(SingleIdEntityLoaderStandardImpl.class));
        assertThat(((SingleIdEntityLoaderStandardImpl) singleIdEntityLoader).getNonReusablePlansGenerated().get(), is(0));
    });
}
Also used : SingleIdEntityLoader(org.hibernate.loader.ast.spi.SingleIdEntityLoader) SingleIdEntityLoaderStandardImpl(org.hibernate.loader.ast.internal.SingleIdEntityLoaderStandardImpl) AbstractEntityPersister(org.hibernate.persister.entity.AbstractEntityPersister) BasicEntity(org.hibernate.testing.orm.domain.gambit.BasicEntity) Test(org.junit.jupiter.api.Test)

Example 3 with SingleIdEntityLoaderStandardImpl

use of org.hibernate.loader.ast.internal.SingleIdEntityLoaderStandardImpl in project hibernate-orm by hibernate.

the class LoadPlanBuilderTest method testSimpleBuild.

@Test
public void testSimpleBuild(SessionFactoryScope scope) {
    final SessionFactoryImplementor sessionFactory = scope.getSessionFactory();
    final EntityPersister entityDescriptor = sessionFactory.getRuntimeMetamodels().getMappingMetamodel().getEntityDescriptor(Message.class);
    final SingleIdEntityLoaderStandardImpl<?> loader = new SingleIdEntityLoaderStandardImpl<>(entityDescriptor, sessionFactory);
    final SingleIdLoadPlan<?> loadPlan = loader.resolveLoadPlan(LockOptions.READ, LoadQueryInfluencers.NONE, sessionFactory);
    final List<DomainResult<?>> domainResults = loadPlan.getJdbcSelect().getJdbcValuesMappingProducer().resolve(null, sessionFactory).getDomainResults();
    assertThat(domainResults).hasSize(1);
    final DomainResult<?> domainResult = domainResults.get(0);
    assertThat(domainResult).isInstanceOf(EntityResult.class);
    final EntityResult entityResult = (EntityResult) domainResult;
    assertThat(entityResult.getFetches()).hasSize(2);
    final Fetch txtFetch = entityResult.getFetches().get(0);
    assertThat(txtFetch).isNotNull();
    assertThat(txtFetch.getFetchedMapping().getFetchableName()).isEqualTo("msgTxt");
    assertThat(txtFetch.getTiming()).isEqualTo(FetchTiming.IMMEDIATE);
    final Fetch posterFetch = entityResult.getFetches().get(1);
    assertThat(posterFetch).isNotNull();
    assertThat(posterFetch.getFetchedMapping().getFetchableName()).isEqualTo("poster");
    assertThat(posterFetch.getTiming()).isEqualTo(FetchTiming.DELAYED);
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) Fetch(org.hibernate.sql.results.graph.Fetch) SingleIdEntityLoaderStandardImpl(org.hibernate.loader.ast.internal.SingleIdEntityLoaderStandardImpl) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) CollectionDomainResult(org.hibernate.sql.results.graph.collection.internal.CollectionDomainResult) DomainResult(org.hibernate.sql.results.graph.DomainResult) EntityResult(org.hibernate.sql.results.graph.entity.EntityResult) Test(org.junit.jupiter.api.Test)

Aggregations

SingleIdEntityLoaderStandardImpl (org.hibernate.loader.ast.internal.SingleIdEntityLoaderStandardImpl)3 Test (org.junit.jupiter.api.Test)3 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)2 EntityPersister (org.hibernate.persister.entity.EntityPersister)2 DomainResult (org.hibernate.sql.results.graph.DomainResult)2 Fetch (org.hibernate.sql.results.graph.Fetch)2 CollectionDomainResult (org.hibernate.sql.results.graph.collection.internal.CollectionDomainResult)2 EntityResult (org.hibernate.sql.results.graph.entity.EntityResult)2 LoadQueryInfluencers (org.hibernate.engine.spi.LoadQueryInfluencers)1 SingleIdEntityLoader (org.hibernate.loader.ast.spi.SingleIdEntityLoader)1 AbstractEntityPersister (org.hibernate.persister.entity.AbstractEntityPersister)1 BasicEntity (org.hibernate.testing.orm.domain.gambit.BasicEntity)1