/** * Registers the given parameter. */ void registerParameter(ParameterExpressionImpl<?> p) { if (_params == null) _params = new OrderedMap/*<ParameterExpression<?>, Class<?>*/(); if (!_params.containsKey(p)) { p.setIndex(_params.size()); _params.put(p, p.getJavaType()); } }
/** * Trace log that the query is executing. */ private void logExecution(int op, OrderedMap<Object, Class<?>> types, Object[] params) { OrderedMap<Object, Object> pmap = new OrderedMap<Object, Object>(); if (params.length > 0) { if (types != null && types.size() == params.length) { int i = 0; for (Iterator<Object> itr = types.keySet().iterator(); itr.hasNext();) pmap.put(itr.next(), params[i++]); } else { for (int i = 0; i < params.length; i++) pmap.put(String.valueOf(i), params[i]); } } logExecution(op, pmap); }
public void invalidateCompilation() { if (_params != null) _params.clear(); }
boolean isCollectionValued) { if (parameterTypes == null) parameterTypes = new OrderedMap<Object, Class<?>>(); Object paramKey = positional ? Integer.parseInt(id) : id; if (!parameterTypes.containsKey(paramKey)) parameterTypes.put(paramKey, TYPE_OBJECT); new Object[]{ id }, null); } else { index = parameterTypes.indexOf(id);
/** * Checks that the passed parameters match the declarations. */ protected void assertParameters(StoreQuery q, StoreQuery.Executor ex, Object[] params) { if (!q.requiresParameterDeclarations() || !isParsedQuery()) return; OrderedMap<Object,Class<?>> paramTypes = ex.getOrderedParameterTypes(q); int typeCount = paramTypes.size(); if (typeCount > params.length) throw new UserException(_loc.get("unbound-params", paramTypes.keySet())); Iterator<Map.Entry<Object,Class<?>>> itr = paramTypes.entrySet().iterator(); Map.Entry<Object,Class<?>> entry; for (int i = 0; itr.hasNext(); i++) { entry = itr.next(); if (entry.getValue().isPrimitive() && params[i] == null) throw new UserException(_loc.get("null-primitive-param", entry.getKey())); } }
protected void assertParameters(StoreQuery q, StoreQuery.Executor ex, Map params) { if (!q.requiresParameterDeclarations()) return; OrderedMap<Object,Class<?>> paramTypes = ex.getOrderedParameterTypes(q); for (Object actual : params.keySet()) { if (!paramTypes.containsKey(actual)) throw new UserException(_loc.get("unbound-params", actual, paramTypes.keySet())); } for (Object expected : paramTypes.keySet()) { if (!params.containsKey(expected)) throw new UserException(_loc.get("unbound-params", expected, paramTypes.keySet())); } for (Entry<Object, Class<?>> entry : paramTypes.entrySet()) { if (entry.getValue().isPrimitive() && params.get(entry.getKey()) == null) throw new UserException(_loc.get("null-primitive-param", entry.getKey())); } }
/** * Parse the parameter declarations. */ private OrderedMap<Object, Class<?>> bindParameterTypes() { ctx.lock(); try { if (_params != null) return _params; String params = ctx.getParameterDeclaration(); if (params == null) return EMPTY_ORDERED_PARAMS; List decs = Filters.parseDeclaration(params, ',', "parameters"); if (_params == null) _params = new OrderedMap<Object, Class<?>>(); String name; Class cls; for (int i = 0; i < decs.size(); i += 2) { name = (String) decs.get(i); cls = ctx.classForName(name, null); if (cls == null) throw new UserException(_loc.get("bad-param-type", name)); _params.put(decs.get(i + 1), cls); } return _params; } finally { ctx.unlock(); } }
public static void setImplicitTypes(Value val1, Value val2, Class<?> expected, Resolver resolver, OrderedMap<Object,Class<?>> parameterTypes, String currentQuery) { AbstractExpressionBuilder.setImplicitTypes(val1, val2, expected, resolver); // as well as setting the types for conversions, we also need to // ensure that any parameters are declared with the correct type, // since the JPA spec expects that these will be validated Parameter param = val1 instanceof Parameter ? (Parameter) val1 : val2 instanceof Parameter ? (Parameter) val2 : null; Path path = val1 instanceof Path ? (Path) val1 : val2 instanceof Path ? (Path) val2 : null; // we only check for parameter-to-path comparisons if (param == null || path == null || parameterTypes == null) return; FieldMetaData fmd = path.last(); if (fmd == null) return; if (expected == null) checkEmbeddable(path, currentQuery); Class<?> type = path.getType(); if (type == null) return; Object paramKey = param.getParameterKey(); if (paramKey == null) return; // make sure we have already declared the parameter if (parameterTypes.containsKey(paramKey)) parameterTypes.put(paramKey, type); }
public Object[] toParameterArray(StoreQuery q, Map userParams) { if (userParams == null || userParams.isEmpty()) return StoreQuery.EMPTY_OBJECTS; OrderedMap<Object, Class<?>> paramTypes = getOrderedParameterTypes(q); Object[] arr = new Object[userParams.size()]; int base = positionalParameterBase(userParams.keySet()); for (Object key : paramTypes.keySet()) { int idx = (key instanceof Integer) ? ((Integer)key).intValue() - base : paramTypes.indexOf(key); if (idx >= arr.length || idx < 0) throw new UserException(_loc.get("gap-query-param", new Object[]{q.getContext().getQueryString(), key, userParams.size(), userParams})); arr[idx] = userParams.get(key); } return arr; }
/** * Creates a Object[] from the values of the given user parameters. */ public Object[] toParameterArray(StoreQuery q, Map<?,?> userParams) { if (userParams == null || userParams.isEmpty()) return StoreQuery.EMPTY_OBJECTS; OrderedMap<?,Class<?>> paramTypes = getOrderedParameterTypes(q); Object[] arr = new Object[userParams.size()]; int base = positionalParameterBase(userParams.keySet()); for(Entry<?, Class<?>> entry : paramTypes.entrySet()){ Object key = entry.getKey(); int idx = (key instanceof Integer) ? ((Integer)key).intValue() - base : paramTypes.indexOf(key); if (idx >= arr.length || idx < 0) throw new UserException(_loc.get("gap-query-param", new Object[]{q.getContext().getQueryString(), key, userParams.size(), userParams})); Object value = userParams.get(key); validateParameterValue(key, value, (Class)entry.getValue()); arr[idx] = value; } return arr; }
private void validateParameters() { if (parameterTypes == null || parameterTypes.isEmpty()) { return; boolean namedParms = false; for (Object key : parameterTypes.keySet()) { .getQueryString(), parameterTypes.keySet().toString())); if (numericParms) { throw new UserException(_loc.get("mixed-parameter-types", resolver.getQueryContext() .getQueryString(), parameterTypes.keySet().toString())); if (!parameterTypes.keySet().contains(1)) { throw new UserException(_loc.get("missing-positional-parameter", resolver.getQueryContext() .getQueryString(), parameterTypes.keySet().toString()));
public Set<ParameterExpression<?>> getParameters() { collectParameters(new CriteriaExpressionVisitor.ParameterVisitor(this)); return _params == null ? Collections.EMPTY_SET : (Set) _params.keySet(); }
for (Entry<Object, Class<?>> entry : paramTypes.entrySet()) { Object key = entry.getKey(); Class<?> expectedValueType = entry.getValue();
boolean isCollectionValued) { if (parameterTypes == null) parameterTypes = new OrderedMap<Object, Class<?>>(); Object paramKey = positional ? Integer.parseInt(id) : id; if (!parameterTypes.containsKey(paramKey)) parameterTypes.put(paramKey, TYPE_OBJECT); new Object[]{ id }, null); } else { index = parameterTypes.indexOf(id);
/** * Checks that the passed parameters match the declarations. */ protected void assertParameters(StoreQuery q, StoreQuery.Executor ex, Object[] params) { if (!q.requiresParameterDeclarations() || !isParsedQuery()) return; OrderedMap<Object,Class<?>> paramTypes = ex.getOrderedParameterTypes(q); int typeCount = paramTypes.size(); if (typeCount > params.length) throw new UserException(_loc.get("unbound-params", paramTypes.keySet())); Iterator<Map.Entry<Object,Class<?>>> itr = paramTypes.entrySet().iterator(); Map.Entry<Object,Class<?>> entry; for (int i = 0; itr.hasNext(); i++) { entry = itr.next(); if (entry.getValue().isPrimitive() && params[i] == null) throw new UserException(_loc.get("null-primitive-param", entry.getKey())); } }
protected void assertParameters(StoreQuery q, StoreQuery.Executor ex, Map params) { if (!q.requiresParameterDeclarations()) return; OrderedMap<Object,Class<?>> paramTypes = ex.getOrderedParameterTypes(q); for (Object actual : params.keySet()) { if (!paramTypes.containsKey(actual)) throw new UserException(_loc.get("unbound-params", actual, paramTypes.keySet())); } for (Object expected : paramTypes.keySet()) { if (!params.containsKey(expected)) throw new UserException(_loc.get("unbound-params", expected, paramTypes.keySet())); } for (Entry<Object, Class<?>> entry : paramTypes.entrySet()) { if (entry.getValue().isPrimitive() && params.get(entry.getKey()) == null) throw new UserException(_loc.get("null-primitive-param", entry.getKey())); } }
/** * Parse the parameter declarations. */ private OrderedMap<Object, Class<?>> bindParameterTypes() { ctx.lock(); try { if (_params != null) return _params; String params = ctx.getParameterDeclaration(); if (params == null) return EMPTY_ORDERED_PARAMS; List decs = Filters.parseDeclaration(params, ',', "parameters"); if (_params == null) _params = new OrderedMap<Object, Class<?>>(); String name; Class cls; for (int i = 0; i < decs.size(); i += 2) { name = (String) decs.get(i); cls = ctx.classForName(name, null); if (cls == null) throw new UserException(_loc.get("bad-param-type", name)); _params.put(decs.get(i + 1), cls); } return _params; } finally { ctx.unlock(); } }
public static void setImplicitTypes(Value val1, Value val2, Class<?> expected, Resolver resolver, OrderedMap<Object,Class<?>> parameterTypes, String currentQuery) { AbstractExpressionBuilder.setImplicitTypes(val1, val2, expected, resolver); // as well as setting the types for conversions, we also need to // ensure that any parameters are declared with the correct type, // since the JPA spec expects that these will be validated Parameter param = val1 instanceof Parameter ? (Parameter) val1 : val2 instanceof Parameter ? (Parameter) val2 : null; Path path = val1 instanceof Path ? (Path) val1 : val2 instanceof Path ? (Path) val2 : null; // we only check for parameter-to-path comparisons if (param == null || path == null || parameterTypes == null) return; FieldMetaData fmd = path.last(); if (fmd == null) return; if (expected == null) checkEmbeddable(path, currentQuery); Class<?> type = path.getType(); if (type == null) return; Object paramKey = param.getParameterKey(); if (paramKey == null) return; // make sure we have already declared the parameter if (parameterTypes.containsKey(paramKey)) parameterTypes.put(paramKey, type); }
public Object[] toParameterArray(StoreQuery q, Map userParams) { if (userParams == null || userParams.isEmpty()) return StoreQuery.EMPTY_OBJECTS; OrderedMap<Object, Class<?>> paramTypes = getOrderedParameterTypes(q); Object[] arr = new Object[userParams.size()]; int base = positionalParameterBase(userParams.keySet()); for (Object key : paramTypes.keySet()) { int idx = (key instanceof Integer) ? ((Integer)key).intValue() - base : paramTypes.indexOf(key); if (idx >= arr.length || idx < 0) throw new UserException(_loc.get("gap-query-param", new Object[]{q.getContext().getQueryString(), key, userParams.size(), userParams})); arr[idx] = userParams.get(key); } return arr; }