/** * 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))); }); }
/** * Adds the provided condition for the update. * <p> * Note that while the query builder accept any type of {@code Clause} * as conditions, Cassandra currently only allow equality ones. * * @param condition the condition to add. * @return this {@code Conditions} clause. */ public Conditions and(Clause condition) { conditions.add(condition); checkForBindMarkers(condition); return this; }
Assignments assigns = update(getColumnFamilyName()) .onlyIf(eq(OPT_LOCK, version)) .with(set(OPT_LOCK, version + 1)); CassandraEntityMapper<T> entityMapper = CassandraEntityMapper.getEntityMapperForClass( getColumnFamilyClass(), cassandraClient);
.and(QueryBuilder.eq("tt_from", 0)) .onlyIf(QueryBuilder.eq("tt_to", 9223372036854775807l)) .with(QueryBuilder.set("tt_to", 20150101));
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")), insertInto("foo").value("k", 1).value("v", Sets.newHashSet(now())).ifNotExists(),
.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(); assertFalse(row.getBool("[applied]")); .and(set("b", 4)) .onlyIf(eq("a", 3)) .and(eq("b", 3)) .where(eq("k", 1)); row = session().execute(update).one(); assertTrue(row.getBool("[applied]"));
/** * Adds the provided condition for the update. * <p/> * Note that while the query builder accept any type of {@code Clause} * as conditions, Cassandra currently only allow equality ones. * * @param condition the condition to add. * @return this {@code Conditions} clause. */ public Conditions and(Clause condition) { statement.setNonIdempotentOps(); conditions.add(condition); checkForBindMarkers(condition); return this; }
/** * Adds the provided condition for the update. * <p/> * Note that while the query builder accept any type of {@code Clause} * as conditions, Cassandra currently only allow equality ones. * * @param condition the condition to add. * @return this {@code Conditions} clause. */ public Conditions and(Clause condition) { statement.setNonIdempotentOps(); conditions.add(condition); checkForBindMarkers(condition); return this; }
/** * 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 the provided condition for the update. * <p/> * Note that while the query builder accept any type of {@code Clause} * as conditions, Cassandra currently only allow equality ones. * * @param condition the condition to add. * @return this {@code Conditions} clause. */ public Conditions and(Clause condition) { statement.setNonIdempotentOps(); conditions.add(condition); checkForBindMarkers(condition); return this; }
/** * 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); }
Update(String keyspace, String table, List<Object> routingKeyValues, List<ColumnMetadata> partitionKey) { super(keyspace, partitionKey, routingKeyValues); this.table = table; this.assignments = new Assignments(this); this.where = new Where(this); this.usings = new Options(this); this.conditions = new Conditions(this); this.ifExists = false; }
private PreparedStatement prepareUpdate(Session session) { return session.prepare(update(TABLE_NAME) .onlyIf(eq(NEXT_MODSEQ, bindMarker(MOD_SEQ_CONDITION))) .with(set(NEXT_MODSEQ, bindMarker(NEXT_MODSEQ))) .where(eq(MAILBOX_ID, bindMarker(MAILBOX_ID)))); }
/** * 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); }
Update(String keyspace, String table, List<Object> routingKeyValues, List<ColumnMetadata> partitionKey) { super(keyspace, partitionKey, routingKeyValues); this.table = table; this.assignments = new Assignments(this); this.where = new Where(this); this.usings = new Options(this); this.conditions = new Conditions(this); this.ifExists = false; }
Update(String keyspace, String table, List<Object> routingKeyValues, List<ColumnMetadata> partitionKey) { super(keyspace, partitionKey, routingKeyValues); this.table = table; this.assignments = new Assignments(this); this.where = new Where(this); this.usings = new Options(this); this.conditions = new Conditions(this); this.ifExists = false; }
Update(TableMetadata table) { super(table); this.table = escapeId(table.getName()); this.assignments = new Assignments(this); this.where = new Where(this); this.usings = new Options(this); this.conditions = new Conditions(this); }
Update(String keyspace, String table) { super(keyspace); this.table = table; this.assignments = new Assignments(this); this.where = new Where(this); this.usings = new Options(this); this.conditions = new Conditions(this); }
private PreparedStatement prepareUpdate(Session session) { return session.prepare(update(TABLE_NAME) .onlyIf(eq(NEXT_UID, bindMarker(CONDITION))) .with(set(NEXT_UID, bindMarker(NEXT_UID))) .where(eq(MAILBOX_ID, bindMarker(MAILBOX_ID)))); }