use of org.hibernate.engine.query.spi.sql.NativeSQLQueryReturn in project hibernate-orm by hibernate.
the class SQLQueryReturnProcessor method process.
public ResultAliasContext process() {
// so that role returns can be more easily resolved to their owners
for (NativeSQLQueryReturn queryReturn : queryReturns) {
if (queryReturn instanceof NativeSQLQueryNonScalarReturn) {
NativeSQLQueryNonScalarReturn rtn = (NativeSQLQueryNonScalarReturn) queryReturn;
alias2Return.put(rtn.getAlias(), rtn);
if (rtn instanceof NativeSQLQueryJoinReturn) {
NativeSQLQueryJoinReturn fetchReturn = (NativeSQLQueryJoinReturn) rtn;
alias2OwnerAlias.put(fetchReturn.getAlias(), fetchReturn.getOwnerAlias());
}
}
}
// Now, process the returns
for (NativeSQLQueryReturn queryReturn : queryReturns) {
processReturn(queryReturn);
}
return new ResultAliasContext();
}
use of org.hibernate.engine.query.spi.sql.NativeSQLQueryReturn in project hibernate-orm by hibernate.
the class NativeQueryImpl method setResultSetMapping.
@Override
public NativeQuery setResultSetMapping(String name) {
ResultSetMappingDefinition mapping = getProducer().getFactory().getNamedQueryRepository().getResultSetMappingDefinition(name);
if (mapping == null) {
throw new MappingException("Unknown SqlResultSetMapping [" + name + "]");
}
NativeSQLQueryReturn[] returns = mapping.getQueryReturns();
queryReturns.addAll(Arrays.asList(returns));
return this;
}
use of org.hibernate.engine.query.spi.sql.NativeSQLQueryReturn in project hibernate-orm by hibernate.
the class QueryBinder method bindNativeQuery.
public static void bindNativeQuery(NamedNativeQuery queryAnn, MetadataBuildingContext context, boolean isDefault) {
if (queryAnn == null)
return;
// ResultSetMappingDefinition mappingDefinition = mappings.getResultSetMapping( queryAnn.resultSetMapping() );
if (BinderHelper.isEmptyAnnotationValue(queryAnn.name())) {
throw new AnnotationException("A named query must have a name when used in class or package level");
}
String resultSetMapping = queryAnn.resultSetMapping();
QueryHintDefinition hints = new QueryHintDefinition(queryAnn.hints());
String queryName = queryAnn.query();
NamedSQLQueryDefinitionBuilder builder = new NamedSQLQueryDefinitionBuilder(queryAnn.name()).setQuery(queryName).setQuerySpaces(null).setCacheable(hints.getBoolean(queryName, QueryHints.CACHEABLE)).setCacheRegion(hints.getString(queryName, QueryHints.CACHE_REGION)).setTimeout(hints.getTimeout(queryName)).setFetchSize(hints.getInteger(queryName, QueryHints.FETCH_SIZE)).setFlushMode(hints.getFlushMode(queryName)).setCacheMode(hints.getCacheMode(queryName)).setReadOnly(hints.getBoolean(queryName, QueryHints.READ_ONLY)).setComment(hints.getString(queryName, QueryHints.COMMENT)).setParameterTypes(null).setCallable(hints.getBoolean(queryName, QueryHints.CALLABLE));
if (!BinderHelper.isEmptyAnnotationValue(resultSetMapping)) {
// sql result set usage
builder.setResultSetRef(resultSetMapping).createNamedQueryDefinition();
} else if (!void.class.equals(queryAnn.resultClass())) {
// class mapping usage
// FIXME should be done in a second pass due to entity name?
final NativeSQLQueryRootReturn entityQueryReturn = new NativeSQLQueryRootReturn("alias1", queryAnn.resultClass().getName(), new HashMap(), LockMode.READ);
builder.setQueryReturns(new NativeSQLQueryReturn[] { entityQueryReturn });
} else {
builder.setQueryReturns(new NativeSQLQueryReturn[0]);
}
NamedSQLQueryDefinition query = builder.createNamedQueryDefinition();
if (isDefault) {
context.getMetadataCollector().addDefaultNamedNativeQuery(query);
} else {
context.getMetadataCollector().addNamedNativeQuery(query);
}
if (LOG.isDebugEnabled()) {
LOG.debugf("Binding named native query: %s => %s", queryAnn.name(), queryAnn.query());
}
}
Aggregations