@Override public void bind(SQLStatement<?> sql, AccountBinder accountBinder, Account account) { try { String serialized = mapper.writeValueAsString(account); sql.bind(NUMBER, account.getNumber()); sql.bind(DATA, serialized); } catch (JsonProcessingException e) { throw new IllegalArgumentException(e); } } };
/** * Bind an argument positionally * * @param position position to bind the paramater at, starting at 0 * @param value to bind * * @return the same Query instance */ public final SelfType bind(int position, int value) { return bind(position, getForeman().waffle(int.class, value, getContext())); }
private void bindStatement(SQLStatement<?> q, String prefix, Map<String, Object> map) { for (Entry<String, Object> entry : map.entrySet()) { Object value = entry.getValue(); String name = prefix + entry.getKey(); if (value == null) { q.bind(name, (Object) null); } else { q.dynamicBind(value.getClass(), name, value); } } }
/** * Binds named parameters from JavaBean properties on o. * * @param o source of named parameter values to use as arguments * * @return modified statement */ public SelfType bindFromProperties(Object o) { return bindNamedArgumentFinder(new BeanPropertyArguments(o, getContext(), getForeman())); }
public void apply(SQLStatement q) throws SQLException { q.define(key, ns); } };
@Override public void apply(final SQLStatement q) throws SQLException { q.bindNamedArgumentFinder(new NamedArgumentFinder() { @Override public Argument find(String name) { Expression e = engine.createExpression(name); final Object it = e.evaluate(new MapContext(ImmutableMap.of(root_name, root))); if (it != null) { return q.getContext().getForeman().createArgument(it.getClass(), it, q.getContext()); } else { return null; } } }); } };
/** * Bind an argument by name * * @param name name to bind the paramater to * @param value to bind * * @return the same Query instance */ public final SelfType bind(String name, Integer value) { return bind(name, getForeman().waffle(Integer.class, value, getContext())); }
/** * Binds named parameters from JavaBean properties on o. * * @param o source of named parameter values to use as arguments * * @return modified statement */ public SelfType bindFromProperties(Object o) { return bindNamedArgumentFinder(new BeanPropertyArguments(o, getContext(), getForeman())); }
public void apply(SQLStatement q) { q.define(key, arg); } };
/** * Bind an argument positionally * * @param position position to bind the paramater at, starting at 0 * @param value to bind * * @return the same Query instance */ public final SelfType bind(int position, BigDecimal value) { return bind(position, getForeman().waffle(BigDecimal.class, value, getContext())); }
@Override public void bind(SQLStatement<?> sql, PreKeyBinder accountBinder, KeyRecord record) { sql.bind("id", record.getId()); sql.bind("number", record.getNumber()); sql.bind("device_id", record.getDeviceId()); sql.bind("key_id", record.getKeyId()); sql.bind("public_key", record.getPublicKey()); sql.bind("last_resort", record.isLastResort() ? 1 : 0); } };
/** * Binds named parameters from a map of String to Object instances * * @param args map where keys are matched to named parameters in order to bind arguments. * Can be null, in this case, the binding has no effect. * * @return modified statement */ @SuppressWarnings("unchecked") public SelfType bindFromMap(Map<String, ? extends Object> args) { if (args != null) { return bindNamedArgumentFinder(new MapArguments(getForeman(), getContext(), args)); } else { return (SelfType) this; } }
@Override public void apply(SQLStatement q) throws SQLException { q.define(key, ns); } };
/** * Bind an argument by name * * @param name token name to bind the paramater to * @param value to bind * * @return the same Query instance */ public final SelfType bind(String name, Blob value) { return bind(name, getForeman().waffle(Blob.class, value, getContext())); }
@Override public void bind(final SQLStatement<?> q, final EntityHistoryBinder bind, final EntityHistoryModelDao<M, E> history) { try { // Emulate @SmartBindBean final M arg = history.getEntity(); final BeanInfo infos = Introspector.getBeanInfo(arg.getClass()); final PropertyDescriptor[] props = infos.getPropertyDescriptors(); for (final PropertyDescriptor prop : props) { q.bind(prop.getName(), prop.getReadMethod().invoke(arg)); } q.bind("id", history.getId()); q.bind("targetRecordId", history.getTargetRecordId()); q.bind("changeType", history.getChangeType().toString()); } catch (IntrospectionException e) { logger.warn(e.getMessage()); } catch (InvocationTargetException e) { logger.warn(e.getMessage()); } catch (IllegalAccessException e) { logger.warn(e.getMessage()); } } };
/** * Binds named parameters from a map of String to Object instances * * @param args map where keys are matched to named parameters in order to bind arguments. * Can be null, in this case, the binding has no effect. * * @return modified statement */ @SuppressWarnings("unchecked") public SelfType bindFromMap(Map<String, ? extends Object> args) { if (args != null) { return bindNamedArgumentFinder(new MapArguments(getForeman(), getContext(), args)); } else { return (SelfType) this; } }
@Override public void apply(SQLStatement q) { q.define(key, arg); } };