Search in sources :

Example 1 with BindIn

use of org.skife.jdbi.v2.unstable.BindIn in project killbill by killbill.

the class EntitySqlDaoWrapperInvocationHandler method retrieveEntityIdsFromArguments.

private List<String> retrieveEntityIdsFromArguments(final Method method, final Object[] args) {
    final Annotation[][] parameterAnnotations = getAnnotations(method);
    int i = -1;
    for (final Object arg : args) {
        i++;
        // This is true for e.g. create calls
        if (arg instanceof Entity) {
            return ImmutableList.<String>of(((Entity) arg).getId().toString());
        }
        // For Batch calls, the first argument will be of type List<Entity>
        if (arg instanceof Iterable) {
            final Builder<String> entityIds = extractEntityIdsFromBatchArgument((Iterable) arg);
            if (entityIds != null) {
                return entityIds.build();
            }
        }
        for (final Annotation annotation : parameterAnnotations[i]) {
            if (arg instanceof String && Bind.class.equals(annotation.annotationType()) && ("id").equals(((Bind) annotation).value())) {
                return ImmutableList.<String>of((String) arg);
            } else if (arg instanceof Collection && BindIn.class.equals(annotation.annotationType()) && ("ids").equals(((BindIn) annotation).value())) {
                return ImmutableList.<String>copyOf((Collection) arg);
            }
        }
    }
    return ImmutableList.<String>of();
}
Also used : Entity(org.killbill.billing.util.entity.Entity) Bind(org.skife.jdbi.v2.sqlobject.Bind) BindIn(org.skife.jdbi.v2.unstable.BindIn) Collection(java.util.Collection) Annotation(java.lang.annotation.Annotation)

Aggregations

Annotation (java.lang.annotation.Annotation)1 Collection (java.util.Collection)1 Entity (org.killbill.billing.util.entity.Entity)1 Bind (org.skife.jdbi.v2.sqlobject.Bind)1 BindIn (org.skife.jdbi.v2.unstable.BindIn)1