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;
}
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);
}
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);
}
Aggregations