use of org.hibernate.query.named.NamedResultSetMappingMemento in project hibernate-orm by hibernate.
the class NamedObjectRepositoryImpl method prepare.
@Override
public void prepare(SessionFactoryImplementor sessionFactory, MetadataImplementor bootMetamodel, BootstrapContext bootstrapContext) {
bootMetamodel.visitNamedHqlQueryDefinitions(namedHqlQueryDefinition -> {
final NamedSqmQueryMemento resolved = namedHqlQueryDefinition.resolve(sessionFactory);
sqmMementoMap.put(namedHqlQueryDefinition.getRegistrationName(), resolved);
});
bootMetamodel.visitNamedNativeQueryDefinitions(namedNativeQueryDefinition -> {
final NamedNativeQueryMemento resolved = namedNativeQueryDefinition.resolve(sessionFactory);
sqlMementoMap.put(namedNativeQueryDefinition.getRegistrationName(), resolved);
});
bootMetamodel.visitNamedResultSetMappingDefinition(namedResultSetMappingDefinition -> {
final NamedResultSetMappingMemento resolved = namedResultSetMappingDefinition.resolve(() -> sessionFactory);
resultSetMappingMementoMap.put(namedResultSetMappingDefinition.getRegistrationName(), resolved);
});
bootMetamodel.visitNamedProcedureCallDefinition(namedProcedureCallDefinition -> {
final NamedCallableQueryMemento resolved = namedProcedureCallDefinition.resolve(sessionFactory);
callableMementoMap.put(namedProcedureCallDefinition.getRegistrationName(), resolved);
});
}
use of org.hibernate.query.named.NamedResultSetMappingMemento in project hibernate-orm by hibernate.
the class Util method resolveResultSetMappingNames.
public static void resolveResultSetMappingNames(String[] resultSetMappingNames, ResultSetMapping resultSetMapping, Consumer<String> querySpaceConsumer, ResultSetMappingResolutionContext context) {
final NamedObjectRepository namedObjectRepository = context.getSessionFactory().getQueryEngine().getNamedObjectRepository();
for (String resultSetMappingName : resultSetMappingNames) {
final NamedResultSetMappingMemento memento = namedObjectRepository.getResultSetMappingMemento(resultSetMappingName);
if (memento == null) {
throw new UnknownSqlResultSetMappingException("Unknown SqlResultSetMapping [" + resultSetMappingName + "]");
}
memento.resolve(resultSetMapping, querySpaceConsumer, context);
}
}
use of org.hibernate.query.named.NamedResultSetMappingMemento 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.named.NamedResultSetMappingMemento in project hibernate-orm by hibernate.
the class BasicResultTests method testSimpleScalarMapping.
@Test
public void testSimpleScalarMapping(SessionFactoryScope scope) {
scope.inTransaction(session -> {
// make sure it is in the repository
final NamedResultSetMappingMemento mappingMemento = session.getSessionFactory().getQueryEngine().getNamedObjectRepository().getResultSetMappingMemento("name");
assertThat(mappingMemento, notNullValue());
// apply it to a native-query
final String qryString = "select name from SimpleEntityWithNamedMappings";
final List<String> names = session.createNativeQuery(qryString, "name").list();
assertThat(names.size(), is(1));
assertThat(names.get(0), is("test"));
// todo (6.0) : should also try executing the ProcedureCall once that functionality is implemented
session.createStoredProcedureCall("abc", "name");
});
}
use of org.hibernate.query.named.NamedResultSetMappingMemento in project hibernate-orm by hibernate.
the class EntityResultTests method testSimpleEntityResultMapping.
@Test
public void testSimpleEntityResultMapping(SessionFactoryScope scope) {
scope.inTransaction(session -> {
// make sure it is in the repository
final NamedResultSetMappingMemento mappingMemento = session.getSessionFactory().getQueryEngine().getNamedObjectRepository().getResultSetMappingMemento("entity");
assertThat(mappingMemento, notNullValue());
// apply it to a native-query
final String qryString = "select id, name, notes from SimpleEntityWithNamedMappings";
final List<SimpleEntityWithNamedMappings> results = session.createNativeQuery(qryString, "entity").list();
assertThat(results.size(), is(1));
final SimpleEntityWithNamedMappings entity = results.get(0);
assertThat(entity.getId(), is(1));
assertThat(entity.getName(), is("test"));
assertThat(entity.getNotes(), is("notes"));
// todo (6.0) : should also try executing the ProcedureCall once that functionality is implemented
session.createStoredProcedureCall("abc", "entity");
});
}
Aggregations