@Test public void testTryExpandBindingParameter() throws Exception { List<Annotation> empty = Collections.emptyList(); ParameterDescriptor p0 = ParameterDescriptor.create(0, String.class, empty, "1"); ParameterDescriptor p1 = ParameterDescriptor.create(1, User.class, empty, "2"); List<ParameterDescriptor> pds = Arrays.asList(p0, p1); ParameterContext ctx = DefaultParameterContext.create(pds); BindingParameter bp = BindingParameter.create("userBag", "item.itemId", null); BindingParameter nbp = ctx.tryExpandBindingParameter(bp); assertThat(nbp, equalTo(BindingParameter.create("2", "userBag.item.itemId", null))); bp = BindingParameter.create("userId", "", null); nbp = ctx.tryExpandBindingParameter(bp); assertThat(nbp, equalTo(BindingParameter.create("2", "userId", null))); bp = BindingParameter.create("userIds", "", null); nbp = ctx.tryExpandBindingParameter(bp); assertThat(nbp, nullValue()); }
@Override @Nullable public BindingParameter tryExpandBindingParameter(BindingParameter bindingParameter) { if (!nameToTypeMap.containsKey(bindingParameter.getParameterName())) { BindingParameter newBindingParameter = bindingParameter.rightShift(); List<String> parameterNames = new ArrayList<String>(); for (Map.Entry<String, Type> entry : nameToTypeMap.entrySet()) { Type type = entry.getValue(); try { FunctionalBindingParameterInvoker.create(type, newBindingParameter); } catch (BindingException e) { continue; } parameterNames.add(entry.getKey()); } int num = parameterNames.size(); if (num > 0) { if (num != 1) { throw new BindingException("Root parameters " + transToBindingParameters(parameterNames) + " has the same property '" + newBindingParameter.getPropertyPath() + "', so can't auto expand"); } return BindingParameter.create( parameterNames.get(0), newBindingParameter.getPropertyPath(), newBindingParameter.getJdbcType()); } } return null; }
DefaultParameterContext implements ParameterContext { @Override @Nullable public BindingParameter tryExpandBindingParameter(BindingParameter bindingParameter) { if (!nameToTypeMap.containsKey(bindingParameter.getParameterName())) { BindingParameter newBindingParameter = bindingParameter.rightShift(); List<String> parameterNames = new ArrayList<String>(); for (Map.Entry<String, Type> entry : nameToTypeMap.entrySet()) { Type type = entry.getValue(); try { FunctionalBindingParameterInvoker.create(type, newBindingParameter); } catch (BindingException e) { continue; } parameterNames.add(entry.getKey()); } int num = parameterNames.size(); if (num > 0) { if (num != 1) { throw new BindingException("Root parameters " + transToBindingParameters(parameterNames) + " has the same property '" + newBindingParameter.getPropertyPath() + "', so can't auto expand"); } return BindingParameter.create( parameterNames.get(0), newBindingParameter.getPropertyPath(), newBindingParameter.getJdbcType()); } } return null; } }
DefaultParameterContext implements ParameterContext { @Override @Nullable public BindingParameter tryExpandBindingParameter(BindingParameter bindingParameter) { if (!nameToTypeMap.containsKey(bindingParameter.getParameterName())) { BindingParameter newBindingParameter = bindingParameter.rightShift(); List<String> parameterNames = new ArrayList<String>(); for (Map.Entry<String, Type> entry : nameToTypeMap.entrySet()) { Type type = entry.getValue(); try { FunctionalBindingParameterInvoker.create(type, newBindingParameter); } catch (BindingException e) { continue; } parameterNames.add(entry.getKey()); } int num = parameterNames.size(); if (num > 0) { if (num != 1) { throw new BindingException("Root parameters " + transToBindingParameters(parameterNames) + " has the same property '" + newBindingParameter.getPropertyPath() + "', so can't auto expand"); } return BindingParameter.create( parameterNames.get(0), newBindingParameter.getPropertyPath(), newBindingParameter.getJdbcType()); } } return null; } private  DefaultParameterContext(List<ParameterDescriptor> parameterDescriptors); }
DefaultParameterContext implements ParameterContext { @Override @Nullable public BindingParameter tryExpandBindingParameter(BindingParameter bindingParameter) { if (!nameToTypeMap.containsKey(bindingParameter.getParameterName())) { BindingParameter newBindingParameter = bindingParameter.rightShift(); List<String> parameterNames = new ArrayList<String>(); for (Map.Entry<String, Type> entry : nameToTypeMap.entrySet()) { Type type = entry.getValue(); try { FunctionalBindingParameterInvoker.create(type, newBindingParameter); } catch (BindingException e) { continue; } parameterNames.add(entry.getKey()); } int num = parameterNames.size(); if (num > 0) { if (num != 1) { throw new BindingException("Root parameters " + transToBindingParameters(parameterNames) + " has the same property '" + newBindingParameter.getPropertyPath() + "', so can't auto expand"); } return BindingParameter.create( parameterNames.get(0), newBindingParameter.getPropertyPath(), newBindingParameter.getJdbcType()); } } return null; } private  DefaultParameterContext(List<ParameterDescriptor> parameterDescriptors); static DefaultParameterContext create(List<ParameterDescriptor> parameterDescriptors); @Override String getParameterNameByPosition(int position); @Override BindingParameterInvoker getBindingParameterInvoker(BindingParameter bindingParameter); @Override List<ParameterDescriptor> getParameterDescriptors(); @Override @Nullable BindingParameter tryExpandBindingParameter(BindingParameter bindingParameter); }
DefaultParameterContext implements ParameterContext { @Override @Nullable public BindingParameter tryExpandBindingParameter(BindingParameter bindingParameter) { if (!nameToTypeMap.containsKey(bindingParameter.getParameterName())) { BindingParameter newBindingParameter = bindingParameter.rightShift(); List<String> parameterNames = new ArrayList<String>(); for (Map.Entry<String, Type> entry : nameToTypeMap.entrySet()) { Type type = entry.getValue(); try { FunctionalBindingParameterInvoker.create(type, newBindingParameter); } catch (BindingException e) { continue; } parameterNames.add(entry.getKey()); } int num = parameterNames.size(); if (num > 0) { if (num != 1) { throw new BindingException("Root parameters " + transToBindingParameters(parameterNames) + " has the same property '" + newBindingParameter.getPropertyPath() + "', so can't auto expand"); } return BindingParameter.create( parameterNames.get(0), newBindingParameter.getPropertyPath(), newBindingParameter.getJdbcType()); } } return null; } private  DefaultParameterContext(List<ParameterDescriptor> parameterDescriptors); static DefaultParameterContext create(List<ParameterDescriptor> parameterDescriptors); @Override String getParameterNameByPosition(int position); @Override BindingParameterInvoker getBindingParameterInvoker(BindingParameter bindingParameter); @Override List<ParameterDescriptor> getParameterDescriptors(); @Override @Nullable BindingParameter tryExpandBindingParameter(BindingParameter bindingParameter);  }