use of org.hibernate.query.spi.QueryImplementor 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.query.spi.QueryImplementor in project hibernate-orm by hibernate.
the class AbstractManipulationCriteriaQuery method interpret.
@Override
public CriteriaInterpretation interpret(RenderingContext renderingContext) {
final String jpaqlString = renderQuery(renderingContext);
return new CriteriaInterpretation() {
@Override
@SuppressWarnings("unchecked")
public QueryImplementor buildCompiledQuery(SessionImplementor entityManager, final InterpretedParameterMetadata interpretedParameterMetadata) {
final Map<String, Class> implicitParameterTypes = extractTypeMap(interpretedParameterMetadata.implicitParameterBindings());
QueryImplementor query = entityManager.createQuery(jpaqlString, null, null, new HibernateEntityManagerImplementor.QueryOptions() {
@Override
public List<ValueHandlerFactory.ValueHandler> getValueHandlers() {
return null;
}
@Override
public Map<String, Class> getNamedParameterExplicitTypes() {
return implicitParameterTypes;
}
@Override
public ResultMetadataValidator getResultMetadataValidator() {
return null;
}
});
for (ImplicitParameterBinding implicitParameterBinding : interpretedParameterMetadata.implicitParameterBindings()) {
implicitParameterBinding.bind(query);
}
return query;
}
private Map<String, Class> extractTypeMap(List<ImplicitParameterBinding> implicitParameterBindings) {
final HashMap<String, Class> map = new HashMap<>();
for (ImplicitParameterBinding implicitParameter : implicitParameterBindings) {
map.put(implicitParameter.getParameterName(), implicitParameter.getJavaType());
}
return map;
}
};
}
use of org.hibernate.query.spi.QueryImplementor in project hibernate-orm by hibernate.
the class SessionImpl method createQuery.
@Override
@SuppressWarnings("unchecked")
public <T> QueryImplementor<T> createQuery(String jpaqlString, Class<T> resultClass, Selection selection, QueryOptions queryOptions) {
try {
final QueryImplementor query = createQuery(jpaqlString);
if (queryOptions.getValueHandlers() == null) {
if (queryOptions.getResultMetadataValidator() != null) {
queryOptions.getResultMetadataValidator().validate(query.getReturnTypes());
}
}
// determine if we need a result transformer
List tupleElements = Tuple.class.equals(resultClass) ? ((CompoundSelectionImpl<Tuple>) selection).getCompoundSelectionItems() : null;
if (queryOptions.getValueHandlers() != null || tupleElements != null) {
query.setResultTransformer(new CriteriaQueryTupleTransformer(queryOptions.getValueHandlers(), tupleElements));
}
return query;
} catch (RuntimeException e) {
throw exceptionConverter.convert(e);
}
}
Aggregations