@Test public void itWorksWithConditionProvider() { query.put("count__gt", "100"); ParsedQuery<Spec> parsed = parser.parse(query); BoundFilterEntry<Spec> bfe = parsed.getBoundFilterEntries().get(0); ConditionProvider<?> provider = bfe.getConditionProvider(fieldFactory); provider = bfe.getConditionProvider(fieldFactory); Param<?> value = provider.getParam(parsed.getBoundQuery().getCount(), "count"); assertThat(provider.getField().getName()).isEqualTo("count"); assertThat(provider.getField().getType()).isEqualTo(Long.class); assertThat(value.getValue()).isEqualTo(100L); }
public void sawClient(Client client) { Instant now = Instant.now(); Instant lastSeen = Optional.ofNullable(client.getLastSeen()).map(ls -> Instant.ofEpochSecond(ls.toEpochSecond())).orElse(null); // only update last seen if it's been more than `lastSeenThreshold` seconds // this way we can have less granularity on lastSeen and save db writes if (lastSeen == null || now.isAfter(lastSeen.plus(lastSeenThreshold, SECONDS))) { dslContext.transaction(configuration -> { Param<Long> val = DSL.val(now.getEpochSecond(), CLIENTS.LASTSEEN); DSL.using(configuration) .update(CLIENTS) .set(CLIENTS.LASTSEEN, DSL.when(CLIENTS.LASTSEEN.isNull(), val).otherwise(DSL.greatest(CLIENTS.LASTSEEN, val))) .where(CLIENTS.ID.eq(client.getId())) .execute(); }); } }
private JsonArray getBindValues(Query query) { JsonArray bindValues = new JsonArray(); for (Param<?> param : query.getParams().values()) { Object value = convertToDatabaseType(param); if(value==null){ bindValues.addNull(); }else{ bindValues.add(value); } } return bindValues; }
@Override public <T> ConditionProvider<T> getConditionProvider(final Field<T> field) { return new ConditionProvider<T>(field) { @Override public Condition getCondition(Param<T> value) { return field.contains(value); } }; }
@Override public <T> ConditionProvider<T> getConditionProvider(final Field<T> field) { return new ConditionProvider<T>(field) { @Override public Condition getCondition(Param<T> value) { return field.lt(value); } }; }
@Override public <T> ConditionProvider<T> getConditionProvider(Field<T> field) { return new ConditionProvider<T>(field) { @Override public Condition getCondition(Param<T> value) { return field.isNull(); } }; }
@Override public <T> ConditionProvider<T> getConditionProvider(final Field<T> field) { return new ConditionProvider<T>(field) { @Override public Condition getCondition(Param<T> value) { return field.eq(value); } }; }
@Override public <T> ConditionProvider<T> getConditionProvider(final Field<T> field) { return new ConditionProvider<T>(field) { @Override public Condition getCondition(Param<T> value) { return field.greaterOrEqual(value); } }; }
@Override public <T> ConditionProvider<T> getConditionProvider(final Field<T> field) { return new ConditionProvider<T>(field) { @Override public Condition getCondition(Param<T> value) { String originalValue = (String) value.getValue(); String escapedValue = ESCAPER.escape(originalValue); return field.likeIgnoreCase('%' + escapedValue + '%', '!'); } }; }
@Override public <T> ConditionProvider<T> getConditionProvider(final Field<T> field) { return new ConditionProvider<T>(field) { @Override public Condition getCondition(Param<T> value) { return field.isNull().or(field.notEqual(value)); } }; }
@Override public <T> ConditionProvider<T> getConditionProvider(final Field<T> field) { return new ConditionProvider<T>(field) { @Override public Condition getCondition(Param<T> value) { return field.lessOrEqual(value); } }; }
@Override public <T> ConditionProvider<T> getConditionProvider(Field<T> field) { return new ConditionProvider<T>(field) { @Override public Condition getCondition(Param<T> value) { return field.startsWith(value); } }; }
@Override public <T> ConditionProvider<T> getConditionProvider(Field<T> field) { return new ConditionProvider<T>(field) { @Override public Condition getCondition(Param<T> value) { return field.isNotNull(); } }; }
@Override public <T> ConditionProvider<T> getConditionProvider(final Field<T> field) { return new ConditionProvider<T>(field) { @Override public Condition getCondition(Param<T> value) { return field.gt(value); } }; }
static <T> Object convertToDatabaseType(Param<T> param) { return param.getBinding().converter().to(param.getValue()); }
@Override public Condition getCondition(Param<T> value) { throw new RuntimeException("Single-value getCondition() called for multi-value filter!"); }
public Param<T> getParam(Object value, String paramName) { Param<T> param = DSL.param(paramName, field.getType()); param.setConverted(value); return param; }
public abstract Condition getCondition(Param<T> value);