Search in sources :

Example 1 with ResultSetMappingResolutionContext

use of org.hibernate.query.internal.ResultSetMappingResolutionContext in project hibernate-orm by hibernate.

the class NamedProcedureCallDefinitionImpl method resolve.

@Override
public NamedCallableQueryMemento resolve(SessionFactoryImplementor sessionFactory) {
    final Set<String> collectedQuerySpaces = new HashSet<>();
    final boolean specifiesResultClasses = resultClasses != null && resultClasses.length > 0;
    final boolean specifiesResultSetMappings = resultSetMappings != null && resultSetMappings.length > 0;
    ResultSetMappingImpl resultSetMapping = new ResultSetMappingImpl(registeredName);
    if (specifiesResultClasses) {
        Util.resolveResultSetMappingClasses(resultClasses, resultSetMapping, collectedQuerySpaces::add, new ResultSetMappingResolutionContext() {

            @Override
            public SessionFactoryImplementor getSessionFactory() {
                return sessionFactory;
            }
        });
    } else if (specifiesResultSetMappings) {
        Util.resolveResultSetMappingNames(resultSetMappings, resultSetMapping, collectedQuerySpaces::add, new ResultSetMappingResolutionContext() {

            @Override
            public SessionFactoryImplementor getSessionFactory() {
                return sessionFactory;
            }
        });
    }
    return new NamedCallableQueryMementoImpl(getRegistrationName(), procedureName, parameterDefinitions.getParameterStrategy(), parameterDefinitions.toMementos(sessionFactory), resultSetMappings, resultClasses, collectedQuerySpaces, false, null, CacheMode.IGNORE, FlushMode.AUTO, false, null, null, null, hints);
}
Also used : ResultSetMappingImpl(org.hibernate.query.results.ResultSetMappingImpl) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) ResultSetMappingResolutionContext(org.hibernate.query.internal.ResultSetMappingResolutionContext) NamedCallableQueryMementoImpl(org.hibernate.procedure.internal.NamedCallableQueryMementoImpl) HashSet(java.util.HashSet)

Example 2 with ResultSetMappingResolutionContext

use of org.hibernate.query.internal.ResultSetMappingResolutionContext in project hibernate-orm by hibernate.

the class NamedRepoTests method testMappingResolution.

@Test
public void testMappingResolution(SessionFactoryScope sessionFactoryScope) {
    final QueryEngine queryEngine = sessionFactoryScope.getSessionFactory().getQueryEngine();
    final NamedObjectRepository namedObjectRepository = queryEngine.getNamedObjectRepository();
    final NamedResultSetMappingMemento mappingMemento = namedObjectRepository.getResultSetMappingMemento("name");
    final ResultSetMapping mapping = new ResultSetMappingImpl("test");
    final ResultSetMappingResolutionContext resolutionContext = new ResultSetMappingResolutionContext() {

        @Override
        public SessionFactoryImplementor getSessionFactory() {
            return sessionFactoryScope.getSessionFactory();
        }
    };
    mappingMemento.resolve(mapping, querySpace -> {
    }, resolutionContext);
    assertThat(mapping.getNumberOfResultBuilders(), is(1));
    mapping.visitResultBuilders((position, builder) -> {
        assertThat(position, is(0));
        assertThat(builder, instanceOf(ResultBuilderBasicValued.class));
    });
}
Also used : ResultBuilderBasicValued(org.hibernate.query.results.ResultBuilderBasicValued) NamedObjectRepository(org.hibernate.query.named.NamedObjectRepository) ResultSetMapping(org.hibernate.query.results.ResultSetMapping) ResultSetMappingImpl(org.hibernate.query.results.ResultSetMappingImpl) NamedResultSetMappingMemento(org.hibernate.query.named.NamedResultSetMappingMemento) ResultSetMappingResolutionContext(org.hibernate.query.internal.ResultSetMappingResolutionContext) QueryEngine(org.hibernate.query.spi.QueryEngine) Test(org.junit.jupiter.api.Test)

Example 3 with ResultSetMappingResolutionContext

use of org.hibernate.query.internal.ResultSetMappingResolutionContext in project hibernate-orm by hibernate.

the class QueryReturnTest method testQueryReturn.

@Test
public void testQueryReturn() {
    Configuration cfg = new Configuration();
    cfg.setProperty("hibernate.dialect", "org.hibernate.dialect.HSQLDialect");
    cfg.setProperty("hibernate.temp.use_jdbc_metadata_defaults", "false");
    cfg.addInputStream(new ReaderInputStream(new StringReader(QUERY_RETURN_HBM_XML)));
    SessionFactoryImplementor sessionFactory = (SessionFactoryImplementor) cfg.buildSessionFactory();
    try {
        NamedResultSetMappingMemento mappingMemento = sessionFactory.getQueryEngine().getNamedObjectRepository().getResultSetMappingMemento("myQuery");
        Assert.assertNotNull(mappingMemento);
        // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        // NYI
        final ResultSetMapping mapping = new ResultSetMappingImpl("myQuery");
        final ResultSetMappingResolutionContext resolutionContext = new ResultSetMappingResolutionContext() {

            @Override
            public SessionFactoryImplementor getSessionFactory() {
                return sessionFactory;
            }
        };
        mappingMemento.resolve(mapping, querySpace -> {
        }, resolutionContext);
        Assert.assertEquals(1, mapping.getNumberOfResultBuilders());
        mapping.visitResultBuilders((i, resultBuilder) -> {
            Assert.assertTrue(resultBuilder instanceof CompleteResultBuilderEntityValued);
            CompleteResultBuilderEntityValued myQueryRootReturn = (CompleteResultBuilderEntityValued) resultBuilder;
            // Assert.assertEquals( "e", myQueryRootReturn.getTableAlias() );
            Assert.assertEquals("org.hibernate.orm.test.hbm.query.QueryReturnTest$Bar", myQueryRootReturn.getReferencedPart().getEntityName());
        });
    } finally {
        sessionFactory.close();
    }
}
Also used : CompleteResultBuilderEntityValued(org.hibernate.query.results.complete.CompleteResultBuilderEntityValued) ReaderInputStream(org.hibernate.engine.jdbc.ReaderInputStream) Configuration(org.hibernate.cfg.Configuration) ResultSetMapping(org.hibernate.query.results.ResultSetMapping) ResultSetMappingImpl(org.hibernate.query.results.ResultSetMappingImpl) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) StringReader(java.io.StringReader) NamedResultSetMappingMemento(org.hibernate.query.named.NamedResultSetMappingMemento) ResultSetMappingResolutionContext(org.hibernate.query.internal.ResultSetMappingResolutionContext) Test(org.junit.Test)

Aggregations

ResultSetMappingResolutionContext (org.hibernate.query.internal.ResultSetMappingResolutionContext)3 ResultSetMappingImpl (org.hibernate.query.results.ResultSetMappingImpl)3 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)2 NamedResultSetMappingMemento (org.hibernate.query.named.NamedResultSetMappingMemento)2 ResultSetMapping (org.hibernate.query.results.ResultSetMapping)2 StringReader (java.io.StringReader)1 HashSet (java.util.HashSet)1 Configuration (org.hibernate.cfg.Configuration)1 ReaderInputStream (org.hibernate.engine.jdbc.ReaderInputStream)1 NamedCallableQueryMementoImpl (org.hibernate.procedure.internal.NamedCallableQueryMementoImpl)1 NamedObjectRepository (org.hibernate.query.named.NamedObjectRepository)1 ResultBuilderBasicValued (org.hibernate.query.results.ResultBuilderBasicValued)1 CompleteResultBuilderEntityValued (org.hibernate.query.results.complete.CompleteResultBuilderEntityValued)1 QueryEngine (org.hibernate.query.spi.QueryEngine)1 Test (org.junit.Test)1 Test (org.junit.jupiter.api.Test)1