use of org.hibernate.query.spi.QueryParameterBinding in project hibernate-orm by hibernate.
the class QueryParameterBindingsImpl method collectPositionalBindTypes.
/**
* @deprecated (since 5.2) expect a different approach to org.hibernate.engine.spi.QueryParameters in 6.0
*/
@Deprecated
public Type[] collectPositionalBindTypes() {
Type[] types = new Type[positionalParameterBindings.size()];
for (Map.Entry<Integer, QueryParameterBinding> entry : positionalParameterBindings.entrySet()) {
final int position = entry.getKey();
Type type = entry.getValue().getBindType();
if (type == null) {
log.debugf("Binding for positional-parameter [%s] did not define type, using SerializableType", position);
type = SerializableType.INSTANCE;
}
types[position] = type;
}
return types;
}
use of org.hibernate.query.spi.QueryParameterBinding in project hibernate-orm by hibernate.
the class QueryParameterBindingsImpl method getBinding.
public QueryParameterBinding getBinding(int position) {
int positionAdjustment = 0;
if (!parameterMetadata.isOrdinalParametersZeroBased()) {
positionAdjustment = -1;
}
QueryParameterBinding binding = null;
if (parameterMetadata != null) {
if (!parameterMetadata.hasPositionalParameters()) {
// no positional parameters, assume jpa named.
binding = locateBinding(Integer.toString(position));
} else {
try {
binding = positionalParameterBindings.get(position + positionAdjustment);
if (binding == null) {
binding = makeBinding(parameterMetadata.getQueryParameter(position));
positionalParameterBindings.put(position + positionAdjustment, binding);
}
} catch (QueryParameterException e) {
// treat this as null binding
}
}
}
if (binding == null) {
throw new IllegalArgumentException("Unknown parameter position: " + position);
}
return binding;
}
use of org.hibernate.query.spi.QueryParameterBinding in project hibernate-orm by hibernate.
the class QueryParameterBindingsImpl method verifyParametersBound.
public void verifyParametersBound(boolean reserveFirstParameter) {
// verify named parameters bound
for (Map.Entry<QueryParameter, QueryParameterBinding> bindEntry : parameterBindingMap.entrySet()) {
if (!bindEntry.getValue().isBound()) {
if (bindEntry.getKey().getName() != null) {
throw new QueryException("Named parameter [" + bindEntry.getKey().getName() + "] not set");
} else {
throw new QueryException("Parameter memento [" + bindEntry.getKey() + "] not set");
}
}
}
// verify position parameters bound
int startIndex = 0;
if (!parameterMetadata.isOrdinalParametersZeroBased()) {
startIndex = 1;
}
for (int i = startIndex; i < positionalParameterBindings.size(); i++) {
QueryParameterBinding binding = null;
if (parameterMetadata.isOrdinalParametersZeroBased()) {
binding = positionalParameterBindings.get(i);
} else {
binding = positionalParameterBindings.get(i - 1);
}
if (binding == null || !binding.isBound()) {
throw new QueryException("Positional parameter [" + i + "] not set");
}
}
// verify position parameter count is correct
final int positionalValueSpan = calculatePositionalValueSpan(reserveFirstParameter);
final int positionCounts = parameterMetadata.getPositionalParameterCount();
if (positionCounts != positionalValueSpan) {
if (reserveFirstParameter && positionCounts - 1 != positionalValueSpan) {
throw new QueryException("Expected positional parameter count: " + (positionCounts - 1) + ", actually detected " + positionalValueSpan);
} else if (!reserveFirstParameter) {
throw new QueryException("Expected positional parameter count: " + (positionCounts) + ", actually detected " + positionalValueSpan);
}
}
}
use of org.hibernate.query.spi.QueryParameterBinding in project hibernate-orm by hibernate.
the class QueryParameterBindingsImpl method calculatePositionalValueSpan.
private int calculatePositionalValueSpan(boolean reserveFirstParameter) {
int positionalValueSpan = 0;
for (QueryParameterBinding binding : positionalParameterBindings.values()) {
if (binding.isBound()) {
Type bindType = binding.getBindType();
if (bindType == null) {
bindType = SerializableType.INSTANCE;
}
positionalValueSpan += bindType.getColumnSpan(sessionFactory);
}
}
return positionalValueSpan;
}
use of org.hibernate.query.spi.QueryParameterBinding in project hibernate-orm by hibernate.
the class QueryParameterBindingsImpl method makeBinding.
@SuppressWarnings("WeakerAccess")
protected QueryParameterBinding makeBinding(QueryParameter queryParameter) {
assert !parameterBindingMap.containsKey(queryParameter);
if (!parameterMetadata.containsReference(queryParameter)) {
throw new IllegalArgumentException("Cannot create binding for parameter reference [" + queryParameter + "] - reference is not a parameter of this query");
}
final QueryParameterBinding binding = makeBinding(queryParameter.getType());
parameterBindingMap.put(queryParameter, binding);
return binding;
}
Aggregations