public Y getNullSafeValue() { return expression.getNullSafeValue(source); }
public final Y getNullSafeValue(X target) { return getValue(target, true); }
@Override public void setValue(Y value) { expression.setValue(source, value); } }
public final void setValue(X target, Y value) { initialize(); try { Object leafObj = getLeafObject(target, false); final Method setter = leafSetter == null && leafObj != null ? ReflectionUtils .getSetter( leafObj.getClass(), explodedPropertyPath[explodedPropertyPath.length - 1]) : leafSetter; setter.invoke(leafObj, value); } catch (RuntimeException ex) { throw ex; } catch (Exception ex) { throw new RuntimeException(ex); } }
@SuppressWarnings("unchecked") public static <X, Y> PropertyPathExpression<X, Y> getExpression( Class<X> source, String propertyPath, Class<Y> valueClass) { final PropertyPathExpressionKey key = new PropertyPathExpressionKey( source, propertyPath); PropertyPathExpression<Object, Object> expression = cache.get(key); if (expression == null) { expression = new PropertyPathExpression<Object, Object>( (Class<Object>) source, propertyPath); final PropertyPathExpression<Object, Object> oldExpression = cache .putIfAbsent(key, expression); if (oldExpression != null) { expression = oldExpression; } } return (PropertyPathExpression<X, Y>) expression; }
@SuppressWarnings("unchecked") private Y getValue(X target, boolean nullSafe) { initialize(); try { Object leafObj = getLeafObject(target, nullSafe); final Method getter = leafGetter == null && leafObj != null ? ReflectionUtils .getGetter( leafObj.getClass(), explodedPropertyPath[explodedPropertyPath.length - 1]) : leafGetter; return nullSafe && leafObj == null ? null : (Y) getter .invoke(leafObj); } catch (RuntimeException ex) { throw ex; } catch (Exception ex) { throw new RuntimeException(ex); } }
public static <X, Y> Y getNullSafeValue(Class<X> source, X target, String propertyPath, Class<Y> valueClass) { return getExpression(source, propertyPath, valueClass) .getNullSafeValue(target); }
@Override public Y getValue() { return expression.getValue(source); }
public static <X, Y> void setValue(Class<X> source, X target, String propertyPath, Y value) { getExpression(source, propertyPath).setValue(target, value); }
@SuppressWarnings("unchecked") public static <X, Y> Y getNullSafeValue(X target, String propertyPath, Class<Y> valueClass) { return target == null ? null : getExpression( (Class<X>) target.getClass(), propertyPath, valueClass) .getNullSafeValue(target); }
/** * Invokes the getter chain based on the source object. First the source * object is used as invocation target for the first getter then the results * of the previous operations will be used for the invocation. * <p> * Example of how the chaining works: * <p> * class A{ B getB(){ // return b element } } * <p> * class B{ String getA(){ // return a element } } * <p> * new LazyGetterMethod(new A(), "a.b").invoke() * <p> * is equal to * <p> * new A().getB().getA() * * @return The result of the last getter in the chain * @throws InvocationTargetException {@link Method#invoke(java.lang.Object, java.lang.Object[]) } * @throws IllegalAccessException {@link Method#invoke(java.lang.Object, java.lang.Object[]) } */ public final Y getValue(X target) { return getValue(target, false); }
@SuppressWarnings("unchecked") public static <X, Y> void setValue(X target, String propertyPath, Y value) { getExpression((Class<X>) target.getClass(), propertyPath).setValue( target, value); }
public void bind(Query query, Collection<Object> value) { Iterator<Object> iterator = value.iterator(); for (int i = 0; i < parameterNames.length; i++) { Object element; if (iterator.hasNext() && (element = iterator.next()) != null) { for (int j = 0; j < parameterNames[i].length; j++) { if (pathExpressions[j] == null) { query.setParameter(parameterNames[i][j], element); } else { query.setParameter(parameterNames[i][j], pathExpressions[j].getNullSafeValue(element)); } } } else { for (int j = 0; j < parameterNames[i].length; j++) { query.setParameter(parameterNames[i][j], null); } } } }
/** * Invokes the getter chain based on the source object. First the source * object is used as invocation target for the first getter then the results * of the previous operations will be used for the invocation. * <p> * Example of how the chaining works: * <p> * class A{ B getB(){ // return b element } } * <p> * class B{ String getA(){ // return a element } } * <p> * new LazyGetterMethod(new A(), "a.b").invoke() * <p> * is equal to * <p> * new A().getB().getA() * * @return The result of the last getter in the chain * @throws InvocationTargetException {@link Method#invoke(java.lang.Object, java.lang.Object[]) } * @throws IllegalAccessException {@link Method#invoke(java.lang.Object, java.lang.Object[]) } */ public Object invoke() throws InvocationTargetException, IllegalAccessException { return expression.getValue(source); } }
expression.setValue(target, valueToPass);
@SuppressWarnings("unchecked") public static <X, Y> Y getValue(X target, String propertyPath, Class<Y> valueClass) { return getExpression((Class<X>) target.getClass(), propertyPath, valueClass).getValue(target); }
public static <X, Y> Y getValue(Class<X> source, X target, String propertyPath, Class<Y> valueClass) { return getExpression(source, propertyPath, valueClass).getValue(target); }