}) .using(ttl(24)) .and(timestamp(42)); assertEquals(insert.toString(), query);
@Test(groups = "unit") public void updateInjectionTest() throws Exception { String query; Statement update; query = "UPDATE foo.bar USING TIMESTAMP 42 SET a=12 WHERE k='2 OR 1=1';"; update = update("foo", "bar").using(timestamp(42)).with(set("a", 12)).where(eq("k", "2 OR 1=1")); assertEquals(update.toString(), query); query = "UPDATE foo SET b='null WHERE k=1; --comment' WHERE k=2;"; update = update("foo").where().and(eq("k", 2)).with(set("b", "null WHERE k=1; --comment")); assertEquals(update.toString(), query); query = "UPDATE foo USING TIMESTAMP 42 SET \"b WHERE k=1; --comment\"=[3,2,1]+\"b WHERE k=1; --comment\" WHERE k=2;"; update = update("foo") .where() .and(eq("k", 2)) .with(prependAll("b WHERE k=1; --comment", Arrays.asList(3, 2, 1))) .using(timestamp(42)); assertEquals(update.toString(), query); }
@Test(groups = "unit") public void statementForwardingTest() throws Exception { Update upd = update("foo"); upd.setConsistencyLevel(ConsistencyLevel.QUORUM); upd.enableTracing(); Statement query = upd.using(timestamp(42)).with(set("a", 12)).and(incr("c", 3)).where(eq("k", 2)); assertEquals(query.getConsistencyLevel(), ConsistencyLevel.QUORUM); assertTrue(query.isTracing()); }
delete = delete("a", "b", "c").from("foo").using(timestamp(0)).where(eq("k", 1)); assertEquals(delete.toString(), query); delete = delete().all().from("foo").using(timestamp(1240003134L)).where(eq("k", "value")); assertEquals(delete.toString(), query); delete = delete().from("foo").using(timestamp(1240003134L)).where(eq("k", "value")); assertEquals(delete.toString(), query); .where() .and(eq("k", 1)) .using(timestamp(1240003134L)); assertEquals(delete.toString(), query); delete().from("foo").using(timestamp(-1240003134L)); fail("Expected an IllegalArgumentException"); } catch (IllegalArgumentException e) {
batch_query += "INSERT INTO foo.bar (a) VALUES (123);"; batch_query += "APPLY BATCH;"; batch = batch().using(timestamp(42)).add(insertInto("foo", "bar").value("a", 123)); assertEquals(batch.getRoutingKey(protocolVersion, codecRegistry), null); assertEquals(batch.toString(), batch_query);
@Override public BatchBuilder withTimeStamp(long timeStamp) { batch.using(QueryBuilder.timestamp(timeStamp)); return this; }
@Override public InsertBuilder<T> withTimeStamp(long timeStamp) { insert.using(QueryBuilder.timestamp(timeStamp)); return this; }
@Test( groups = "unit", expectedExceptions = {IllegalArgumentException.class}) public void batchMixedCounterTest() throws Exception { batch() .add(update("foo").with(incr("a", 1))) .add(update("foo").with(set("b", 2))) .add(update("foo").with(incr("c", 3))) .using(timestamp(42)); }
@Override public DeleteBuilder<T> withTimeStamp(long timeStamp) { delete.using(QueryBuilder.timestamp(timeStamp)); return this; }
@Override public UpdateBuilder<T> withTimeStamp(long timeStamp) { update.using(QueryBuilder.timestamp(timeStamp)); return this; }
.using(timestamp(42)) .and(ttl(24)); assertEquals(insert.toString(), query); }) .using(ttl(24)) .and(timestamp(42)); assertEquals(insert.toString(), query); }) .using(ttl(bindMarker())) .and(timestamp(bindMarker())); assertEquals(insert.toString(), query); insert = insertInto("foo", "bar") .using(timestamp(42)) .values( new String[] {"a", "b"}, insert = insertInto("foo") .using(timestamp(42)) .value("c", 123) .values(
update = update("foo", "bar") .using(timestamp(42)) .with(set("a", 12)) .and(set("b", Arrays.asList(3, 2, 1))) .and(eq("l", "foo")) .with(prependAll("b", Arrays.asList(3, 2, 1))) .using(timestamp(42)); assertEquals(update.toString(), query); .and(eq("k", 2)) .and(eq("l", "foo")) .using(timestamp(42)) .with(prependAll("b", Arrays.asList(3, 2, 1))); assertEquals(update.toString(), query); .using(timestamp(42)) .where(eq("k", 2)) .and(eq("l", "foo"))
@Override public ReactiveCassandraBatchOperations withTimestamp(long timestamp) { assertNotExecuted(); batch.using(QueryBuilder.timestamp(timestamp)); return this; }
@Override public CassandraBatchOperations withTimestamp(long timestamp) { assertNotExecuted(); batch.using(QueryBuilder.timestamp(timestamp)); return this; }
.add(update("foo").with(incr("b", 2))) .add(update("foo").with(incr("c", 3))) .using(timestamp(42)); assertEquals(batch.toString(), query); .add(update("foo").with(incr("b"))) .add(update("foo").with(incr("c"))) .using(timestamp(42)); assertEquals(batch.toString(), query); .add(update("foo").with(decr("b", 2))) .add(update("foo").with(decr("c", 3))) .using(timestamp(42)); assertEquals(batch.toString(), query); .add(update("foo").with(decr("b"))) .add(update("foo").with(decr("c"))) .using(timestamp(42)); assertEquals(batch.toString(), query); .add(update("foo").with(incr("b", -2))) .add(update("foo").with(decr("c", 3))) .using(timestamp(42)); assertEquals(batch.toString(), query);
.from("foo") .where(eq("k", 1))) .using(timestamp(42)); assertEquals(batch.toString(), query);
@Override void modifyQueryString(BuiltStatement query) { if (query instanceof Insert) { ((Insert) query).using().and(QueryBuilder.timestamp(QueryBuilder.bindMarker())); } else if (query instanceof Delete) { ((Delete) query).using().and(QueryBuilder.timestamp(QueryBuilder.bindMarker())); } else { throw new AssertionError("Unexpected query type: " + query.getClass()); } }
private static String deleteQueryWithTimestamp(TableMetadata tableMetadata) { Delete delete = QueryBuilder.delete().from(tableMetadata); delete.using(QueryBuilder.timestamp(QueryBuilder.bindMarker())); Delete.Where where = delete.where(); List<ColumnMetadata> columns = tableMetadata.getPrimaryKey(); for(ColumnMetadata column : columns) { where.and(QueryBuilder.eq(column.getName(), QueryBuilder.bindMarker())); } return delete.toString(); }
@Test(groups = "unit") public void statementForwardingTest() throws Exception { Update upd = update("foo"); upd.setConsistencyLevel(ConsistencyLevel.QUORUM); upd.enableTracing(); Statement query = upd.using(timestamp(42)).with(set("a", 12)).and(incr("c", 3)).where(eq("k", 2)); assertEquals(query.getConsistencyLevel(), ConsistencyLevel.QUORUM); assertTrue(query.isTracing()); }
@Test( groups = "unit", expectedExceptions = {IllegalArgumentException.class}) public void batchMixedCounterTest() throws Exception { batch() .add(update("foo").with(incr("a", 1))) .add(update("foo").with(set("b", 2))) .add(update("foo").with(incr("c", 3))) .using(timestamp(42)); }