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);
}
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));
});
}
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();
}
}
Aggregations