private SelectOffsetStep<Record1<byte[]>> getRangeQuery(DSLContext ctx, TableReference tableRef, RangeRequest rangeRequest, long timestamp, int maxRows) { boolean reverse = rangeRequest.isReverse(); byte[] start = rangeRequest.getStartInclusive(); byte[] end = rangeRequest.getEndExclusive(); Condition cond = R_TIMESTAMP.lessThan(timestamp); if (start.length > 0) { cond = cond.and(reverse ? R_ROW_NAME.lessOrEqual(start) : R_ROW_NAME.greaterOrEqual(start)); } if (end.length > 0) { cond = cond.and(reverse ? R_ROW_NAME.greaterThan(end) : R_ROW_NAME.lessThan(end)); } return ctx.selectDistinct(R_ROW_NAME) .from(atlasTable(tableRef).as(RANGE_TABLE)) .where(cond) .orderBy(reverse ? R_ROW_NAME.desc() : R_ROW_NAME.asc()) .limit(maxRows); }
private Condition getCompareCondition(Object value, BiPredicate<?, ?> biPredicate, Field<Object> field) { String predicateString = biPredicate.toString(); switch (predicateString) { case ("eq"): return field.eq(value); case ("neq"): return field.notEqual(value); case ("gt"): return field.greaterThan(value); case ("gte"): return field.greaterOrEqual(value); case ("lt"): return field.lessThan(value); case ("lte"): return field.lessOrEqual(value); case ("inside"): List items = (List) value; Object firstItem = items.get(0); Object secondItem = items.get(1); return field.between(firstItem, secondItem); default: throw new IllegalArgumentException("predicate not supported in has step: " + biPredicate.toString()); } }
return field.notEqual(convertToSqlDate(value.toString())); case ("gt"): return field.greaterThan(convertToSqlDate(value.toString())); case ("gte"): return field.greaterOrEqual(convertToSqlDate(value.toString()));
private int[] update(DSLContext tx, Connection conn, List<HostItem> hosts) throws SQLException { Field<Integer> currentStatusWeight = decodeStatus(choose(ANSIBLE_HOSTS.STATUS)); Field<Integer> newStatusWeight = decodeStatus(choose(value((String) null))); String update = tx.update(ANSIBLE_HOSTS) .set(ANSIBLE_HOSTS.DURATION, ANSIBLE_HOSTS.DURATION.plus(value((Integer) null))) .set(ANSIBLE_HOSTS.STATUS, when(currentStatusWeight.greaterThan(newStatusWeight), ANSIBLE_HOSTS.STATUS).otherwise(value((String) null))) .set(ANSIBLE_HOSTS.EVENT_SEQ, when(currentStatusWeight.greaterThan(newStatusWeight), ANSIBLE_HOSTS.EVENT_SEQ).otherwise(value((Long) null))) .where(ANSIBLE_HOSTS.INSTANCE_ID.eq(value((UUID) null)) .and(ANSIBLE_HOSTS.INSTANCE_CREATED_AT.eq(value((Timestamp) null)) .and(ANSIBLE_HOSTS.HOST.eq(value((String) null)) .and(ANSIBLE_HOSTS.HOST_GROUP.eq(value((String) null)))))) .getSQL(); try (PreparedStatement ps = conn.prepareStatement(update)) { for (HostItem h : hosts) { ps.setLong(1, h.duration()); ps.setString(2, h.status()); ps.setString(3, h.status()); ps.setString(4, h.status()); ps.setLong(5, h.eventSeq()); ps.setObject(6, h.key().instanceId()); ps.setTimestamp(7, h.key().instanceCreatedAt()); ps.setString(8, h.key().host()); ps.setString(9, h.key().hostGroup()); ps.addBatch(); } return ps.executeBatch(); } }
@SuppressWarnings("unchecked") @Override final Field<Integer> getFunction0(Configuration configuration) { switch (configuration.dialect()) { case SQLITE: return DSL .when(((Field<Integer>) argument).greaterThan(zero()), one()) .when(((Field<Integer>) argument).lessThan(zero()), one().neg()) .otherwise(zero()); default: return function("sign", getDataType(), argument); } } }
.when(first.greaterThan(other), DSL.greatest(first, remaining)) .otherwise(DSL.greatest(other, remaining)); .when(first.greaterThan(other), first) .otherwise(other);
@SuppressWarnings("unchecked") @Override final Field<Integer> getFunction0(Configuration configuration) { switch (configuration.dialect()) { /* [pro] xx xxxx xxxxxxx xxxxxx xxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxx xxxxxxxxxx xx [/pro] */ case SQLITE: return DSL.decode() .when(((Field<Integer>) argument).greaterThan(zero()), one()) .when(((Field<Integer>) argument).lessThan(zero()), one().neg()) .otherwise(zero()); default: return function("sign", getDataType(), argument); } } }
.when(first.greaterThan(other), DSL.greatest(first, remaining)) .otherwise(DSL.greatest(other, remaining)); .when(first.greaterThan(other), first) .otherwise(other);
@Override public Condition visit(IsGreaterQueryCriteria criteria, Boolean inArray) { String[] keys = translateArrayRef(criteria); Field field = DSL.field(databaseInterface.arraySerializer().getFieldName(keys)); Param<?> value; Condition typeCondition = null; if (!isInArrayValue(criteria.getAttributeReference(), inArray)) { value = translateValueToSQL(criteria.getValue()); } else { value = translateValueToArraySerialization(criteria.getValue()); typeCondition = databaseInterface.arraySerializer().typeof( field.getName(), getJsonType(criteria.getValue().getType()) ); } Condition criteriaCondition = field.greaterThan(value); if (typeCondition != null) { criteriaCondition = typeCondition.and(criteriaCondition); } return addArrayCondition(criteria, criteriaCondition, keys, inArray); }
.from(project_info) .join(project_cost).using(project_info.field("project_pid")) .where(total_cost.greaterThan(new BigDecimal(totalCostBoundary))) .groupBy(project_name, total_cost, company_name) .orderBy(company_name);