.where(eq("k", 2)) .onlyIf(eq("a", 1)) .and(eq("b", 2)); row = session().execute(update).one(); assertFalse(row.getBool("[applied]")); .where(eq("k", 1)) .onlyIf(eq("a", 2)) .and(eq("b", 2)); row = session().execute(update).one(); assertTrue(row.getBool("[applied]")); .and(set("b", 4)) .onlyIf(eq("a", 2)) .and(eq("b", 2)) .where(eq("k", 1)); row = session().execute(update).one(); .and(set("b", 4)) .onlyIf(eq("a", 3)) .and(eq("b", 3)) .where(eq("k", 1)); row = session().execute(update).one();
/** * Adds {@code PutIf}-specific conditions to the statement * * @param condition {@code PutIf} condition */ @Override public void visit(PutIf condition) { Update.Where update = (Update.Where) statement; List<ConditionalExpression> expressions = condition.getExpressions(); Update.Conditions cond = update.onlyIf(createClauseWith(expressions.get(0))); IntStream.range(1, expressions.size()) .forEach( i -> { cond.and(createClauseWith(expressions.get(i))); }); }
update("foo").onlyIf().and(contains("developers", "datastax")).where(eq("good", "drivers")), update("foo").onlyIf(contains("developers", "datastax")).with(set("v", 0)), update("foo").with(set("v", 0)).onlyIf(contains("hello", "world")),
update("foo").onlyIf().and(contains("developers", "datastax")).where(eq("good", "drivers")), update("foo").onlyIf(contains("developers", "datastax")).with(set("v", 0)), update("foo").with(set("v", 0)).onlyIf(contains("hello", "world")),
.where(eq("k", 2)) .onlyIf(eq("a", 1)) .and(eq("b", 2)); row = session().execute(update).one(); assertFalse(row.getBool("[applied]")); .where(eq("k", 1)) .onlyIf(eq("a", 2)) .and(eq("b", 2)); row = session().execute(update).one(); assertTrue(row.getBool("[applied]")); .and(set("b", 4)) .onlyIf(eq("a", 2)) .and(eq("b", 2)) .where(eq("k", 1)); row = session().execute(update).one(); .and(set("b", 4)) .onlyIf(eq("a", 3)) .and(eq("b", 3)) .where(eq("k", 1)); row = session().execute(update).one();
/** * Adds a conditions clause (IF) to this statement. * <p/> * This is a shorter/more readable version for {@code onlyIf().and(condition)}. * <p/> * This will configure the statement as non-idempotent, see {@link com.datastax.driver.core.Statement#isIdempotent()} * for more information. * * @param condition the condition to add. * @return the conditions of this query to which more conditions can be added. */ public Conditions onlyIf(Clause condition) { return conditions.and(condition); }
/** * Adds a conditions clause (IF) to this statement. * <p/> * This is a shorter/more readable version for {@code onlyIf().and(condition)}. * <p/> * This will configure the statement as non-idempotent, see {@link com.datastax.driver.core.Statement#isIdempotent()} * for more information. * * @param condition the condition to add. * @return the conditions of this query to which more conditions can be added. */ public Conditions onlyIf(Clause condition) { return conditions.and(condition); }
/** * Adds a conditions clause (IF) to this statement. * <p/> * This is a shorter/more readable version for {@code onlyIf().and(condition)}. * <p/> * This will configure the statement as non-idempotent, see {@link com.datastax.driver.core.Statement#isIdempotent()} * for more information. * * @param condition the condition to add. * @return the conditions of this query to which more conditions can be added. */ public Conditions onlyIf(Clause condition) { return conditions.and(condition); }
/** * Adds a conditions clause (IF) to this statement. * <p> * This is a shorter/more readable version for {@code onlyIf().and(condition)}. * * @param condition the condition to add. * @return the conditions of this query to which more conditions can be added. */ public Conditions onlyIf(Clause condition) { return conditions.and(condition); }
/** * Adds a conditions clause (IF) to this statement. * * <p>This is a shorter/more readable version for {@code onlyIf().and(condition)}. * * <p>This will configure the statement as non-idempotent, see {@link * com.datastax.driver.core.Statement#isIdempotent()} for more information. * * @param condition the condition to add. * @return the conditions of this query to which more conditions can be added. */ public Conditions onlyIf(Clause condition) { return conditions.and(condition); }