Search in sources :

Example 1 with NativeSQLQuerySpecification

use of org.hibernate.engine.query.spi.sql.NativeSQLQuerySpecification in project hibernate-orm by hibernate.

the class NamedQueryRepository method checkNamedQueries.

public Map<String, HibernateException> checkNamedQueries(QueryPlanCache queryPlanCache) {
    Map<String, HibernateException> errors = new HashMap<String, HibernateException>();
    // Check named HQL queries
    log.debugf("Checking %s named HQL queries", namedQueryDefinitionMap.size());
    for (NamedQueryDefinition namedQueryDefinition : namedQueryDefinitionMap.values()) {
        // this will throw an error if there's something wrong.
        try {
            log.debugf("Checking named query: %s", namedQueryDefinition.getName());
            //TODO: BUG! this currently fails for named queries for non-POJO entities
            queryPlanCache.getHQLQueryPlan(namedQueryDefinition.getQueryString(), false, Collections.EMPTY_MAP);
        } catch (HibernateException e) {
            errors.put(namedQueryDefinition.getName(), e);
        }
    }
    // Check native-sql queries
    log.debugf("Checking %s named SQL queries", namedSqlQueryDefinitionMap.size());
    for (NamedSQLQueryDefinition namedSQLQueryDefinition : namedSqlQueryDefinitionMap.values()) {
        // this will throw an error if there's something wrong.
        try {
            log.debugf("Checking named SQL query: %s", namedSQLQueryDefinition.getName());
            // TODO : would be really nice to cache the spec on the query-def so as to not have to re-calc the hash;
            // currently not doable though because of the resultset-ref stuff...
            NativeSQLQuerySpecification spec;
            if (namedSQLQueryDefinition.getResultSetRef() != null) {
                ResultSetMappingDefinition definition = getResultSetMappingDefinition(namedSQLQueryDefinition.getResultSetRef());
                if (definition == null) {
                    throw new MappingException("Unable to find resultset-ref definition: " + namedSQLQueryDefinition.getResultSetRef());
                }
                spec = new NativeSQLQuerySpecification(namedSQLQueryDefinition.getQueryString(), definition.getQueryReturns(), namedSQLQueryDefinition.getQuerySpaces());
            } else {
                spec = new NativeSQLQuerySpecification(namedSQLQueryDefinition.getQueryString(), namedSQLQueryDefinition.getQueryReturns(), namedSQLQueryDefinition.getQuerySpaces());
            }
            queryPlanCache.getNativeSQLQueryPlan(spec);
        } catch (HibernateException e) {
            errors.put(namedSQLQueryDefinition.getName(), e);
        }
    }
    return errors;
}
Also used : NamedSQLQueryDefinition(org.hibernate.engine.spi.NamedSQLQueryDefinition) HashMap(java.util.HashMap) HibernateException(org.hibernate.HibernateException) NamedQueryDefinition(org.hibernate.engine.spi.NamedQueryDefinition) NativeSQLQuerySpecification(org.hibernate.engine.query.spi.sql.NativeSQLQuerySpecification) ResultSetMappingDefinition(org.hibernate.engine.ResultSetMappingDefinition) MappingException(org.hibernate.MappingException)

Example 2 with NativeSQLQuerySpecification

use of org.hibernate.engine.query.spi.sql.NativeSQLQuerySpecification in project hibernate-orm by hibernate.

the class NativeQueryImpl method doScroll.

@Override
protected ScrollableResultsImplementor doScroll(ScrollMode scrollMode) {
    final NativeSQLQuerySpecification nativeSQLQuerySpecification = generateQuerySpecification();
    final QueryParameters queryParameters = getQueryParameters();
    queryParameters.setScrollMode(scrollMode);
    return getProducer().scroll(nativeSQLQuerySpecification, queryParameters);
}
Also used : QueryParameters(org.hibernate.engine.spi.QueryParameters) NativeSQLQuerySpecification(org.hibernate.engine.query.spi.sql.NativeSQLQuerySpecification)

Example 3 with NativeSQLQuerySpecification

use of org.hibernate.engine.query.spi.sql.NativeSQLQuerySpecification in project hibernate-orm by hibernate.

the class NativeSQLQueryPlanEqualsTest method testNativeSQLQuerySpecEquals.

@Test
public void testNativeSQLQuerySpecEquals() {
    QueryPlanCache cache = new QueryPlanCache(sessionFactory());
    NativeSQLQuerySpecification firstSpec = createSpec();
    NativeSQLQuerySpecification secondSpec = createSpec();
    NativeSQLQueryPlan firstPlan = cache.getNativeSQLQueryPlan(firstSpec);
    NativeSQLQueryPlan secondPlan = cache.getNativeSQLQueryPlan(secondSpec);
    assertEquals(firstPlan, secondPlan);
}
Also used : QueryPlanCache(org.hibernate.engine.query.spi.QueryPlanCache) NativeSQLQueryPlan(org.hibernate.engine.query.spi.NativeSQLQueryPlan) NativeSQLQuerySpecification(org.hibernate.engine.query.spi.sql.NativeSQLQuerySpecification) Test(org.junit.Test)

Aggregations

NativeSQLQuerySpecification (org.hibernate.engine.query.spi.sql.NativeSQLQuerySpecification)3 HashMap (java.util.HashMap)1 HibernateException (org.hibernate.HibernateException)1 MappingException (org.hibernate.MappingException)1 ResultSetMappingDefinition (org.hibernate.engine.ResultSetMappingDefinition)1 NativeSQLQueryPlan (org.hibernate.engine.query.spi.NativeSQLQueryPlan)1 QueryPlanCache (org.hibernate.engine.query.spi.QueryPlanCache)1 NamedQueryDefinition (org.hibernate.engine.spi.NamedQueryDefinition)1 NamedSQLQueryDefinition (org.hibernate.engine.spi.NamedSQLQueryDefinition)1 QueryParameters (org.hibernate.engine.spi.QueryParameters)1 Test (org.junit.Test)1