Search in sources :

Example 6 with NativeSQLQueryReturn

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();
}
Also used : NativeSQLQueryNonScalarReturn(org.hibernate.engine.query.spi.sql.NativeSQLQueryNonScalarReturn) NativeSQLQueryReturn(org.hibernate.engine.query.spi.sql.NativeSQLQueryReturn) NativeSQLQueryJoinReturn(org.hibernate.engine.query.spi.sql.NativeSQLQueryJoinReturn)

Example 7 with NativeSQLQueryReturn

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;
}
Also used : NativeSQLQueryReturn(org.hibernate.engine.query.spi.sql.NativeSQLQueryReturn) ResultSetMappingDefinition(org.hibernate.engine.ResultSetMappingDefinition) MappingException(org.hibernate.MappingException)

Example 8 with NativeSQLQueryReturn

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());
    }
}
Also used : NamedSQLQueryDefinition(org.hibernate.engine.spi.NamedSQLQueryDefinition) HashMap(java.util.HashMap) NativeSQLQueryReturn(org.hibernate.engine.query.spi.sql.NativeSQLQueryReturn) AnnotationException(org.hibernate.AnnotationException) NativeSQLQueryRootReturn(org.hibernate.engine.query.spi.sql.NativeSQLQueryRootReturn) NamedSQLQueryDefinitionBuilder(org.hibernate.engine.spi.NamedSQLQueryDefinitionBuilder)

Aggregations

NativeSQLQueryReturn (org.hibernate.engine.query.spi.sql.NativeSQLQueryReturn)8 NativeSQLQueryRootReturn (org.hibernate.engine.query.spi.sql.NativeSQLQueryRootReturn)4 NativeSQLQueryConstructorReturn (org.hibernate.engine.query.spi.sql.NativeSQLQueryConstructorReturn)3 HashMap (java.util.HashMap)2 ResultSetMappingDefinition (org.hibernate.engine.ResultSetMappingDefinition)2 NativeSQLQueryJoinReturn (org.hibernate.engine.query.spi.sql.NativeSQLQueryJoinReturn)2 NativeSQLQueryNonScalarReturn (org.hibernate.engine.query.spi.sql.NativeSQLQueryNonScalarReturn)2 NativeSQLQueryScalarReturn (org.hibernate.engine.query.spi.sql.NativeSQLQueryScalarReturn)2 NamedSQLQueryDefinition (org.hibernate.engine.spi.NamedSQLQueryDefinition)2 StringReader (java.io.StringReader)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 AnnotationException (org.hibernate.AnnotationException)1 AssertionFailure (org.hibernate.AssertionFailure)1 MappingException (org.hibernate.MappingException)1 Metadata (org.hibernate.boot.Metadata)1 MetadataSources (org.hibernate.boot.MetadataSources)1 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)1 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)1 ClassLoadingException (org.hibernate.boot.registry.classloading.spi.ClassLoadingException)1