Search in sources :

Example 1 with SQLQueryReturnProcessor

use of org.hibernate.loader.custom.sql.SQLQueryReturnProcessor in project hibernate-orm by hibernate.

the class Util method resolveResultSetMappings.

/**
 * Resolve the given result set mapping names
 *
 * @param context The context for the resolution.  See {@link ResultSetMappingResolutionContext}
 * @param resultSetMappingNames The names of the result-set-mappings to resolve
 */
public static void resolveResultSetMappings(ResultSetMappingResolutionContext context, String... resultSetMappingNames) {
    for (String resultSetMappingName : resultSetMappingNames) {
        log.tracef("Starting attempt resolve named result-set-mapping : %s", resultSetMappingName);
        final ResultSetMappingDefinition mapping = context.findResultSetMapping(resultSetMappingName);
        if (mapping == null) {
            throw new UnknownSqlResultSetMappingException("Unknown SqlResultSetMapping [" + resultSetMappingName + "]");
        }
        log.tracef("Found result-set-mapping : %s", mapping.traceLoggableFormat());
        context.addQueryReturns(mapping.getQueryReturns());
        final SQLQueryReturnProcessor processor = new SQLQueryReturnProcessor(mapping.getQueryReturns(), context.getSessionFactory());
        final SQLQueryReturnProcessor.ResultAliasContext processResult = processor.process();
        context.addQuerySpaces(processResult.collectQuerySpaces());
    }
}
Also used : UnknownSqlResultSetMappingException(org.hibernate.procedure.UnknownSqlResultSetMappingException) SQLQueryReturnProcessor(org.hibernate.loader.custom.sql.SQLQueryReturnProcessor) ResultSetMappingDefinition(org.hibernate.engine.ResultSetMappingDefinition)

Example 2 with SQLQueryReturnProcessor

use of org.hibernate.loader.custom.sql.SQLQueryReturnProcessor in project hibernate-orm by hibernate.

the class OutputsImpl method buildSpecializedCustomLoader.

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Hooks into Hibernate's Loader hierarchy for ResultSet -> Object mapping
private static CustomLoaderExtension buildSpecializedCustomLoader(final ResultContext context) {
    // might be better to just manually construct the Return(s).. SQLQueryReturnProcessor does a lot of
    // work that is really unnecessary here.
    final SQLQueryReturnProcessor processor = new SQLQueryReturnProcessor(context.getQueryReturns(), context.getSession().getFactory());
    processor.process();
    final List<org.hibernate.loader.custom.Return> customReturns = processor.generateCallableReturns();
    CustomQuery customQuery = new CustomQuery() {

        @Override
        public String getSQL() {
            return context.getSql();
        }

        @Override
        public Set<String> getQuerySpaces() {
            return context.getSynchronizedQuerySpaces();
        }

        @Override
        public List<ParameterBinder> getParameterValueBinders() {
            // no parameters in terms of embedded in the SQL string
            return Collections.emptyList();
        }

        @Override
        public List<org.hibernate.loader.custom.Return> getCustomQueryReturns() {
            return customReturns;
        }
    };
    return new CustomLoaderExtension(customQuery, context.getQueryParameters(), context.getSession());
}
Also used : Return(org.hibernate.loader.custom.Return) RootReturn(org.hibernate.loader.custom.RootReturn) ParameterBinder(org.hibernate.param.ParameterBinder) CustomQuery(org.hibernate.loader.custom.CustomQuery) SQLQueryReturnProcessor(org.hibernate.loader.custom.sql.SQLQueryReturnProcessor)

Aggregations

SQLQueryReturnProcessor (org.hibernate.loader.custom.sql.SQLQueryReturnProcessor)2 ResultSetMappingDefinition (org.hibernate.engine.ResultSetMappingDefinition)1 CustomQuery (org.hibernate.loader.custom.CustomQuery)1 Return (org.hibernate.loader.custom.Return)1 RootReturn (org.hibernate.loader.custom.RootReturn)1 ParameterBinder (org.hibernate.param.ParameterBinder)1 UnknownSqlResultSetMappingException (org.hibernate.procedure.UnknownSqlResultSetMappingException)1