Skip to content

Instantly share code, notes, and snippets.

@jkbbwr
Created December 30, 2015 14:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jkbbwr/3f6fdca5d74f7c584fa7 to your computer and use it in GitHub Desktop.
Save jkbbwr/3f6fdca5d74f7c584fa7 to your computer and use it in GitHub Desktop.
@BindingAnnotation(BindBytes.BytesBinderFactory.class)
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.PARAMETER})
public @interface BindBytes {
String value();
class BytesBinderFactory implements BinderFactory {
public Binder build(final Annotation annotation) {
return new Binder<BindBytes, byte[]>() {
public void bind(SQLStatement q, BindBytes bind, byte[] arg) {
String name = ((BindBytes) annotation).value();
q.bind(name, UtilKt.hexify(arg));
}
};
}
}
}
@BindingAnnotation(BindBytes.BytesBinderFactory::class)
@Retention(RetentionPolicy.RUNTIME)
@Target(AnnotationTarget.VALUE_PARAMETER)
annotation class BindBytes(val value: String)
class BytesBinderFactory : BinderFactory {
override fun build(annotation: Annotation): Binder<BindBytes, ByteArray> {
return Binder { q, bind, arg ->
val name = (annotation as BindBytes).value
q.bind(name, arg.hexify())
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment