Пример #1
0
 @Override
 public String bindMany(Object value, QueryContext context) {
   List<String> keys;
   CommandParameters params = context.getParameters();
   if (value instanceof Iterable) {
     keys = addParameters((Iterable) value, params);
   } else {
     Object[] arr = asObjectArray(value);
     if (arr != null) {
       keys = addParameters(Arrays.asList(arr), params);
     } else {
       keys = addParameters(Arrays.asList(value), params);
     }
   }
   return joiner.join(keys).toString();
 }
Пример #2
0
/** @author enlo */
@Data
public class NamedParameterBinder implements ParameterBinder {

  private static final StringJoiner joiner = StringJoiner.valueOf(", ");
  private static final long serialVersionUID = 1L;

  private String prefix;

  public NamedParameterBinder(String prefix) {
    this.prefix = prefix;
  }

  @Override
  public String bind(Object value, QueryContext context) {
    return context.getParameters().addValueWithPrefix(prefix, value);
  }

  @Override
  public String bindMany(Object value, QueryContext context) {
    List<String> keys;
    CommandParameters params = context.getParameters();
    if (value instanceof Iterable) {
      keys = addParameters((Iterable) value, params);
    } else {
      Object[] arr = asObjectArray(value);
      if (arr != null) {
        keys = addParameters(Arrays.asList(arr), params);
      } else {
        keys = addParameters(Arrays.asList(value), params);
      }
    }
    return joiner.join(keys).toString();
  }

  public List<String> addParameters(Iterable<?> items, CommandParameters params) {
    List<String> keys = new ArrayList<>();
    for (Object item : items) {
      String key = params.addValueWithPrefix(prefix, item);
      keys.add(key);
    }
    return keys;
  }
}