@Test public void testGetNullableBindingValue() throws Exception { DefaultInvocationContext ctx = DefaultInvocationContext.create(); UserBag userBag = new UserBag(); userBag.setName("ash"); User user = new User(); user.setUserBag(userBag); user.setId(100); ctx.addParameter("userId", 9527); ctx.addParameter("user", user); BindingParameterInvoker userIdInvoker = FunctionalBindingParameterInvoker.create(User.class, BindingParameter.create("userId", "", null)); assertThat(ctx.getNullableBindingValue(userIdInvoker), equalTo((Object) 9527)); assertThat(ctx.getNullableBindingValue(userIdInvoker), equalTo((Object) 9527)); BindingParameterInvoker userDotIdInvoker = FunctionalBindingParameterInvoker.create(User.class, BindingParameter.create("user", "id", null)); assertThat(ctx.getNullableBindingValue(userDotIdInvoker), equalTo((Object) 100)); assertThat(ctx.getNullableBindingValue(userDotIdInvoker), equalTo((Object) 100)); BindingParameterInvoker userDotObjIdInvoker = FunctionalBindingParameterInvoker.create(User.class, BindingParameter.create("user", "objId", null)); assertThat(ctx.getNullableBindingValue(userDotObjIdInvoker), nullValue()); assertThat(ctx.getNullableBindingValue(userDotObjIdInvoker), nullValue()); BindingParameterInvoker userDotUserBagDotNameInvoker = FunctionalBindingParameterInvoker.create(User.class, BindingParameter.create("user", "userBag.name", null)); assertThat(ctx.getNullableBindingValue(userDotUserBagDotNameInvoker), equalTo((Object) "ash")); assertThat(ctx.getNullableBindingValue(userDotUserBagDotNameInvoker), equalTo((Object) "ash")); }
@Override @Nullable public Object getNullableBindingValue(BindingParameterInvoker invoker) { String key = getCacheKey(invoker); if (cache.containsKey(key)) { return cache.get(key); } String parameterName = invoker.getBindingParameter().getParameterName(); if (!parameterNameToValueMap.containsKey(parameterName)) { throw new BindingException("Parameter '" + BindingParameter.create(parameterName, "", null) + "' not found, " + "available root parameters are " + transToBindingParameters(parameterNameToValueMap.keySet())); } Object obj = parameterNameToValueMap.get(parameterName); Object value = invoker.invoke(obj); cache.put(key, value); return value; }
DefaultInvocationContext implements InvocationContext { @Override @Nullable public Object getNullableBindingValue(BindingParameterInvoker invoker) { String key = getCacheKey(invoker); if (cache.containsKey(key)) { return cache.get(key); } String parameterName = invoker.getBindingParameter().getParameterName(); if (!parameterNameToValueMap.containsKey(parameterName)) { throw new BindingException("Parameter '" + BindingParameter.create(parameterName, "", null) + "' not found, " + "available root parameters are " + transToBindingParameters(parameterNameToValueMap.keySet())); } Object obj = parameterNameToValueMap.get(parameterName); Object value = invoker.invoke(obj); cache.put(key, value); return value; } }
DefaultInvocationContext implements InvocationContext { @Override @Nullable public Object getNullableBindingValue(BindingParameterInvoker invoker) { String key = getCacheKey(invoker); if (cache.containsKey(key)) { return cache.get(key); } String parameterName = invoker.getBindingParameter().getParameterName(); if (!parameterNameToValueMap.containsKey(parameterName)) { throw new BindingException("Parameter '" + BindingParameter.create(parameterName, "", null) + "' not found, " + "available root parameters are " + transToBindingParameters(parameterNameToValueMap.keySet())); } Object obj = parameterNameToValueMap.get(parameterName); Object value = invoker.invoke(obj); cache.put(key, value); return value; } private  DefaultInvocationContext(); }
DefaultInvocationContext implements InvocationContext { @Override @Nullable public Object getNullableBindingValue(BindingParameterInvoker invoker) { String key = getCacheKey(invoker); if (cache.containsKey(key)) { return cache.get(key); } String parameterName = invoker.getBindingParameter().getParameterName(); if (!parameterNameToValueMap.containsKey(parameterName)) { throw new BindingException("Parameter '" + BindingParameter.create(parameterName, "", null) + "' not found, " + "available root parameters are " + transToBindingParameters(parameterNameToValueMap.keySet())); } Object obj = parameterNameToValueMap.get(parameterName); Object value = invoker.invoke(obj); cache.put(key, value); return value; } private  DefaultInvocationContext(); static DefaultInvocationContext create(); @Override void addParameter(String parameterName, Object parameterValue); @Override Object getBindingValue(BindingParameterInvoker invoker); @Override @Nullable Object getNullableBindingValue(BindingParameterInvoker invoker); @Override void setBindingValue(BindingParameterInvoker invoker, Object value); @Override @Nullable String getGlobalTable(); @Override void setGlobalTable(String globalTable); @Override void writeToSqlBuffer(String str); @Override void appendToArgs(Object obj, TypeHandler<?> typeHandler); @Override BoundSql getBoundSql(); @Override List<Object> getParameterValues(); }
DefaultInvocationContext implements InvocationContext { @Override @Nullable public Object getNullableBindingValue(BindingParameterInvoker invoker) { String key = getCacheKey(invoker); if (cache.containsKey(key)) { return cache.get(key); } String parameterName = invoker.getBindingParameter().getParameterName(); if (!parameterNameToValueMap.containsKey(parameterName)) { throw new BindingException("Parameter '" + BindingParameter.create(parameterName, "", null) + "' not found, " + "available root parameters are " + transToBindingParameters(parameterNameToValueMap.keySet())); } Object obj = parameterNameToValueMap.get(parameterName); Object value = invoker.invoke(obj); cache.put(key, value); return value; } private  DefaultInvocationContext(); static DefaultInvocationContext create(); @Override void addParameter(String parameterName, Object parameterValue); @Override Object getBindingValue(BindingParameterInvoker invoker); @Override @Nullable Object getNullableBindingValue(BindingParameterInvoker invoker); @Override void setBindingValue(BindingParameterInvoker invoker, Object value); @Override @Nullable String getGlobalTable(); @Override void setGlobalTable(String globalTable); @Override void writeToSqlBuffer(String str); @Override void appendToArgs(Object obj, TypeHandler<?> typeHandler); @Override BoundSql getBoundSql(); @Override List<Object> getParameterValues();  }