use of org.hibernate.engine.spi.NamedSQLQueryDefinition in project hibernate-orm by hibernate.
the class Configuration method reset.
protected void reset() {
implicitNamingStrategy = ImplicitNamingStrategyJpaCompliantImpl.INSTANCE;
physicalNamingStrategy = PhysicalNamingStrategyStandardImpl.INSTANCE;
namedQueries = new HashMap<String, NamedQueryDefinition>();
namedSqlQueries = new HashMap<String, NamedSQLQueryDefinition>();
sqlResultSetMappings = new HashMap<String, ResultSetMappingDefinition>();
namedEntityGraphMap = new HashMap<String, NamedEntityGraphDefinition>();
namedProcedureCallMap = new HashMap<String, NamedProcedureCallDefinition>();
standardServiceRegistryBuilder = new StandardServiceRegistryBuilder(bootstrapServiceRegistry);
entityTuplizerFactory = new EntityTuplizerFactory();
interceptor = EmptyInterceptor.INSTANCE;
properties = new Properties();
properties.putAll(standardServiceRegistryBuilder.getSettings());
}
use of org.hibernate.engine.spi.NamedSQLQueryDefinition in project hibernate-orm by hibernate.
the class AbstractSharedSessionContract method buildQueryFromName.
protected <T> QueryImplementor<T> buildQueryFromName(String name, Class<T> resultType) {
checkOpen();
checkTransactionSynchStatus();
delayedAfterCompletion();
// todo : apply stored setting at the JPA Query level too
final NamedQueryDefinition namedQueryDefinition = getFactory().getNamedQueryRepository().getNamedQueryDefinition(name);
if (namedQueryDefinition != null) {
return createQuery(namedQueryDefinition, resultType);
}
final NamedSQLQueryDefinition nativeQueryDefinition = getFactory().getNamedQueryRepository().getNamedSQLQueryDefinition(name);
if (nativeQueryDefinition != null) {
return (QueryImplementor<T>) createNativeQuery(nativeQueryDefinition, resultType);
}
throw exceptionConverter.convert(new IllegalArgumentException("No query defined for that name [" + name + "]"));
}
use of org.hibernate.engine.spi.NamedSQLQueryDefinition in project hibernate-orm by hibernate.
the class AbstractSharedSessionContract method getNamedQuery.
@Override
public QueryImplementor getNamedQuery(String name) {
checkOpen();
checkTransactionSynchStatus();
delayedAfterCompletion();
// look as HQL/JPQL first
final NamedQueryDefinition queryDefinition = factory.getNamedQueryRepository().getNamedQueryDefinition(name);
if (queryDefinition != null) {
return createQuery(queryDefinition);
}
// then as a native query
final NamedSQLQueryDefinition nativeQueryDefinition = factory.getNamedQueryRepository().getNamedSQLQueryDefinition(name);
if (nativeQueryDefinition != null) {
return createNativeQuery(nativeQueryDefinition, true);
}
throw exceptionConverter.convert(new IllegalArgumentException("No query defined for that name [" + name + "]"));
}
use of org.hibernate.engine.spi.NamedSQLQueryDefinition 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.spi.NamedSQLQueryDefinition in project hibernate-orm by hibernate.
the class QueryReturnTest method testQueryReturn.
@Test
public void testQueryReturn() {
StandardServiceRegistryBuilder serviceRegistryBuilder = new StandardServiceRegistryBuilder().applySetting("hibernate.dialect", "org.hibernate.dialect.HSQLDialect");
StandardServiceRegistry standardServiceRegistry = serviceRegistryBuilder.build();
MetadataSources metadataSources = new MetadataSources(standardServiceRegistry);
try {
metadataSources.addInputStream(new ReaderInputStream(new StringReader(QUERY_RETURN_HBM_XML)));
Metadata metadata = metadataSources.buildMetadata();
NamedSQLQueryDefinition myQuery = metadata.getNamedNativeQueryDefinition("myQuery");
Assert.assertNotNull(myQuery);
NativeSQLQueryReturn[] myQueryReturns = myQuery.getQueryReturns();
Assert.assertNotNull(myQueryReturns);
Assert.assertEquals(1, myQueryReturns.length);
Assert.assertTrue(NativeSQLQueryRootReturn.class.isInstance(myQueryReturns[0]));
NativeSQLQueryRootReturn myQueryRootReturn = (NativeSQLQueryRootReturn) myQueryReturns[0];
Assert.assertEquals("e", myQueryRootReturn.getAlias());
Assert.assertEquals("org.hibernate.test.hbm.query.QueryReturnTest$Bar", myQueryRootReturn.getReturnEntityName());
} finally {
if (standardServiceRegistry instanceof StandardServiceRegistryImpl) {
((StandardServiceRegistryImpl) standardServiceRegistry).destroy();
}
}
}
Aggregations