@Override public void bind(SQLStatement<?> q, Bind bind, Collection<String> arg) { Array a = null; if (arg != null) { try { a = q.getContext().getConnection().createArrayOf("varchar",arg.toArray()); } catch (SQLException se) { throw new RuntimeException(String.format("Unable to bind collection {%s} to a SQL array: (%s) %s", Joiner.on(" ,").join(arg), se.getClass(), se.getMessage()),se); } } q.bindBySqlType(bind.value(),a, Types.ARRAY); } }
@Override public Binder build(Annotation annotation) { return (Binder<BindSource, Source>) (sql, bindSource, source) -> { sql.bind("source", source.getUrl().toString()); sql.bind("frontpage", source.isFrontpage()); if (CollectionUtils.isNotEmpty(source.getTags())) { Array array = null; try { array = sql.getContext().getConnection().createArrayOf("text", source.getTags().toArray()); } catch (SQLException e) {} sql.bindBySqlType("authors", array, Types.ARRAY); } }; } }
@Override public Binder build(Annotation annotation) { return (Binder<BindArticle, Article>) (sql, bindArticle, article) -> { sql.bind("title", article.getTitle()); sql.bind("date", article.getPublicationDate()); sql.bind("description", truncate(article.getDescription(), 150)); sql.bind("url", article.getUrl()); sql.bind("channelTitle", truncate(article.getChannelTitle(), 50)); sql.bind("channelUrl", article.getChannelUrl()); Array array = null; try { array = sql.getContext().getConnection().createArrayOf("text", article.getAuthors().toArray()); } catch (SQLException e) { e.printStackTrace(); } sql.bindBySqlType("authors", array, Types.ARRAY); }; }