use of org.hibernate.query.internal.ParameterMetadataImpl in project hibernate-orm by hibernate.
the class NativeQueryInterpreterStandardImpl method getParameterMetadata.
@Override
public ParameterMetadataImpl getParameterMetadata(String nativeQuery) {
final ParamLocationRecognizer recognizer = ParamLocationRecognizer.parseLocations(nativeQuery);
final int size = recognizer.getOrdinalParameterLocationList().size();
final OrdinalParameterDescriptor[] ordinalDescriptors = new OrdinalParameterDescriptor[size];
for (int i = 0; i < size; i++) {
final Integer position = recognizer.getOrdinalParameterLocationList().get(i);
ordinalDescriptors[i] = new OrdinalParameterDescriptor(i, null, position);
}
final Map<String, NamedParameterDescriptor> namedParamDescriptorMap = new HashMap<String, NamedParameterDescriptor>();
final Map<String, ParamLocationRecognizer.NamedParameterDescription> map = recognizer.getNamedParameterDescriptionMap();
for (final String name : map.keySet()) {
final ParamLocationRecognizer.NamedParameterDescription description = map.get(name);
namedParamDescriptorMap.put(name, new NamedParameterDescriptor(name, null, description.buildPositionsArray(), description.isJpaStyle()));
}
return new ParameterMetadataImpl(ordinalDescriptors, namedParamDescriptorMap);
}
use of org.hibernate.query.internal.ParameterMetadataImpl in project hibernate-orm by hibernate.
the class QueryPlanCache method getSQLParameterMetadata.
/**
* Obtain the parameter metadata for given native-sql query.
* <p/>
* for native-sql queries, the param metadata is determined outside any relation to a query plan, because
* query plan creation and/or retrieval for a native-sql query depends on all of the return types having been
* set, which might not be the case up-front when param metadata would be most useful
*
* @param query The query
* @return The parameter metadata
*/
public ParameterMetadata getSQLParameterMetadata(final String query, boolean isOrdinalParameterZeroBased) {
final ParameterMetadataKey key = new ParameterMetadataKey(query, isOrdinalParameterZeroBased);
ParameterMetadataImpl value = parameterMetadataCache.get(key);
if (value == null) {
value = nativeQueryInterpreter.getParameterMetadata(query);
parameterMetadataCache.putIfAbsent(key, value);
}
return value;
}
Aggregations