Search in sources :

Example 1 with ParameterMetadataImpl

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);
}
Also used : ParamLocationRecognizer(org.hibernate.engine.query.spi.ParamLocationRecognizer) HashMap(java.util.HashMap) OrdinalParameterDescriptor(org.hibernate.engine.query.spi.OrdinalParameterDescriptor) NamedParameterDescriptor(org.hibernate.engine.query.spi.NamedParameterDescriptor) ParameterMetadataImpl(org.hibernate.query.internal.ParameterMetadataImpl)

Example 2 with ParameterMetadataImpl

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;
}
Also used : ParameterMetadataImpl(org.hibernate.query.internal.ParameterMetadataImpl)

Aggregations

ParameterMetadataImpl (org.hibernate.query.internal.ParameterMetadataImpl)2 HashMap (java.util.HashMap)1 NamedParameterDescriptor (org.hibernate.engine.query.spi.NamedParameterDescriptor)1 OrdinalParameterDescriptor (org.hibernate.engine.query.spi.OrdinalParameterDescriptor)1 ParamLocationRecognizer (org.hibernate.engine.query.spi.ParamLocationRecognizer)1