/** * Return the value bound to the parameter. * * @param pos * position of the parameter * @return parameter value * * @throws IllegalStateException * if this parameter has not been bound */ public Object getParameterValue(int pos) { Parameter<?> param = getParameter(pos); assertBound(param); return _boundParams.get(param); }
/** * Binds the given values as positional parameters. The n-th array element value is set to a Parameter with (n+1)-th * positional identifier. */ public OpenJPAQuery<X> setParameters(Object... params) { assertOpen(); _em.assertNotCloseInvoked(); lock(); try { clearBinding(); for (int i = 0; params != null && i < params.length; i++) { setParameter(i + 1, params[i]); } return this; } finally { unlock(); } }
/** * Binds the given value to the given parameter. Validates if the parameter can accept the value by its type. */ void bindValue(Parameter<?> param, Object value) { Object bindVal = assertValueAssignable(param, value); _boundParams.put(param, bindVal); }
/** * Sets the value of the given positional parameter after conversion of the given value to the given Temporal Type. */ public OpenJPAQuery<X> setParameter(int position, Calendar value, TemporalType t) { return setParameter(position, convertTemporalType(value, t)); }
/** * Gets the array of positional parameter values. The n-th array element represents (n+1)-th positional parameter. * If a parameter has been declared but not bound to a value then the value is null and hence is indistinguishable * from the value being actually null. If the parameter indexing is not contiguous then the unspecified parameters * are considered as null. */ public Object[] getPositionalParameters() { lock(); try { Set<Integer> positionalKeys = getDeclaredParameterKeys(Integer.class); Object[] result = new Object[calculateMaxKey(positionalKeys)]; for (Integer pos : positionalKeys) { Parameter<?> param = getParameter(pos); result[pos.intValue() - 1] = isBound(param) ? getParameterValue(pos) : null; } return result; } finally { unlock(); } }
return setParameter("_" + String.valueOf(pos), value); assertOpen(); _em.assertNotCloseInvoked(); lock(); try { if (pos < 1) { if (isNative() || isProcedure()) { param = new ParameterImpl<Object>(pos, Object.class); declareParameter(pos, param); } else { param = getParameter(pos); bindValue(param, value); unlock();
/** * Sets the parameter of the given name to the given value. */ public OpenJPAQuery<X> setParameter(String name, Object value) { assertOpen(); _em.assertNotCloseInvoked(); lock(); try { // native queries can not have named parameters if (isNative()) { throw new IllegalArgumentException(_loc.get("no-named-params", name, getQueryString()).toString()); } else { bindValue(getParameter(name), value); } return this; } finally { unlock(); } }
void assertBound(Parameter<?> param) { if (!isBound(param)) { throw new IllegalStateException(_loc.get("param-not-bound", param, getQueryString(), getBoundParameterKeys()).getMessage()); } }
/** * Get the positional parameter with the given position. The parameter may just have been declared and not bound to * a value. * * @param position * specified in the user query. * @return parameter object * @throws IllegalArgumentException * if the parameter with the given position does not exist */ public Parameter<?> getParameter(int pos) { if (_convertPositionalParams == true) { return getParameter("_" + String.valueOf(pos)); } Parameter<?> param = getDeclaredParameters().get(pos); if (param == null) throw new IllegalArgumentException(_loc.get("param-missing-pos", pos, getQueryString(), getDeclaredParameterKeys()).getMessage()); return param; }
/** * Get the parameter object corresponding to the declared parameter of the given name. This method is not required * to be supported for native queries. * * @throws IllegalArgumentException * if the parameter of the specified name does not exist * @throws IllegalStateException * if invoked on a native query */ public Parameter<?> getParameter(String name) { if (isNative()) { throw new IllegalStateException(_loc.get("param-named-non-native", name).getMessage()); } Parameter<?> param = getDeclaredParameters().get(name); if (param == null) { Set<ParameterExpression> exps = getDeclaredParameterKeys(ParameterExpression.class); for (ParameterExpression<?> e : exps) { if (name.equals(e.getName())) return e; } throw new IllegalArgumentException(_loc.get("param-missing-name", name, getQueryString(), getDeclaredParameterKeys()).getMessage()); } return param; }
paramTypes = getParamTypes(); throw new IllegalArgumentException("parameter identifier " + key + " unrecognized"); declareParameter(key, param);
/** * Affirms if declared parameters use position identifier. */ public boolean hasPositionalParameters() { return !getDeclaredParameterKeys(Integer.class).isEmpty(); }
public <T> OpenJPAQuery<X> setParameter(Parameter<T> p, T arg1) { bindValue(p, arg1); if (BindableParameter.class.isInstance(p)) { BindableParameter.class.cast(p).setValue(arg1); } return this; }
Object convertTemporalType(Calendar value, TemporalType type) { return convertTemporalType(value.getTime(), type); }
/** * Gets the array of positional parameter values. The n-th array element represents (n+1)-th positional parameter. * If a parameter has been declared but not bound to a value then the value is null and hence is indistinguishable * from the value being actually null. If the parameter indexing is not contiguous then the unspecified parameters * are considered as null. */ public Object[] getPositionalParameters() { lock(); try { Set<Integer> positionalKeys = getDeclaredParameterKeys(Integer.class); Object[] result = new Object[calculateMaxKey(positionalKeys)]; for (Integer pos : positionalKeys) { Parameter<?> param = getParameter(pos); result[pos.intValue() - 1] = isBound(param) ? getParameterValue(pos) : null; } return result; } finally { unlock(); } }
return setParameter("_" + String.valueOf(pos), value); assertOpen(); _em.assertNotCloseInvoked(); lock(); try { if (pos < 1) { if (isNative() || isProcedure()) { param = new ParameterImpl<Object>(pos, Object.class); declareParameter(pos, param); } else { param = getParameter(pos); bindValue(param, value); unlock();
/** * Sets the parameter of the given name to the given value. */ public OpenJPAQuery<X> setParameter(String name, Object value) { assertOpen(); _em.assertNotCloseInvoked(); lock(); try { // native queries can not have named parameters if (isNative()) { throw new IllegalArgumentException(_loc.get("no-named-params", name, getQueryString()).toString()); } else { bindValue(getParameter(name), value); } return this; } finally { unlock(); } }
/** * Sets the value of the given named parameter after conversion of the given value to the given Temporal Type. */ public OpenJPAQuery<X> setParameter(int position, Date value, TemporalType type) { return setParameter(position, convertTemporalType(value, type)); }
void assertBound(Parameter<?> param) { if (!isBound(param)) { throw new IllegalStateException(_loc.get("param-not-bound", param, getQueryString(), getBoundParameterKeys()).getMessage()); } }
/** * Get the positional parameter with the given position. The parameter may just have been declared and not bound to * a value. * * @param position * specified in the user query. * @return parameter object * @throws IllegalArgumentException * if the parameter with the given position does not exist */ public Parameter<?> getParameter(int pos) { if (_convertPositionalParams == true) { return getParameter("_" + String.valueOf(pos)); } Parameter<?> param = getDeclaredParameters().get(pos); if (param == null) throw new IllegalArgumentException(_loc.get("param-missing-pos", pos, getQueryString(), getDeclaredParameterKeys()).getMessage()); return param; }