@Test(groups = "unit") public void should_handle_nested_collections() { String query; Statement statement; query = "UPDATE foo SET l=[[1],[2]] WHERE k=1;"; ImmutableList<ImmutableList<Integer>> list = ImmutableList.of(ImmutableList.of(1), ImmutableList.of(2)); statement = update("foo").with(set("l", list)).where(eq("k", 1)); assertThat(statement.toString()).isEqualTo(query); query = "UPDATE foo SET m={1:[[1],[2]],2:[[1],[2]]} WHERE k=1;"; statement = update("foo").with(set("m", ImmutableMap.of(1, list, 2, list))).where(eq("k", 1)); assertThat(statement.toString()).isEqualTo(query); query = "UPDATE foo SET m=m+{1:[[1],[2]],2:[[1],[2]]} WHERE k=1;"; statement = update("foo").with(putAll("m", ImmutableMap.of(1, list, 2, list))).where(eq("k", 1)); assertThat(statement.toString()).isEqualTo(query); query = "UPDATE foo SET l=[[1]]+l WHERE k=1;"; statement = update("foo").with(prepend("l", ImmutableList.of(1))).where(eq("k", 1)); assertThat(statement.toString()).isEqualTo(query); query = "UPDATE foo SET l=[[1],[2]]+l WHERE k=1;"; statement = update("foo").with(prependAll("l", list)).where(eq("k", 1)); assertThat(statement.toString()).isEqualTo(query); }
@Test(groups = "unit", expectedExceptions = InvalidQueryException.class) public void should_now_allow_bind_marker_for_prepend() { update("foo").with(prepend("l", bindMarker())).where(eq("k", 1)); }
update("foo") .with() .and(prepend("b", 3)) .and(append("c", "a")) .and(appendAll("d", Arrays.asList(1, 2, 3)))
@Override public UpdateBuilder<T> preAddList(String name, Object value) { update.with(QueryBuilder.prepend(classBean.toColumn(name), value)); return this; } @Override
public static BoundStatement preparePrependItemToList(Object id, Class<?> clazz, String propertyName, Object item, WriteOptions options, String keyspace, Session session) { EntityTypeMetadata emeta = EntityTypeParser.getEntityMetadata(clazz); EntityFieldMetaData fmeta = emeta.getFieldMetadata(propertyName); Update update = QueryBuilder.update(keyspace, emeta.getTableName()); if (item instanceof List<?> && fmeta.getType() == List.class) { List<?> list = (List<?>) item; if (list.size() == 0) return null; update.with(QueryBuilder.prependAll(fmeta.getColumnName(), list)); } else if (fmeta.getType() == List.class) { update.with(QueryBuilder.prepend(fmeta.getColumnName(), item)); } applyOptions(options, update, null); return prepareUpdate(id, emeta, update, session); }
private ImmutableList<BuiltStatement> nonIdempotentBuiltStatements() { return ImmutableList.of( update("foo").with(append("l", 1)).where(eq("k", 1)), // append to list update("foo").with(set("v", 1)).and(prepend("l", 1)).where(eq("k", 1)), // prepend to list update("foo").with(incr("c")).where(eq("k", 1)), // counter update
@Test(groups = "unit") public void should_handle_nested_collections() { String query; Statement statement; query = "UPDATE foo SET l=[[1],[2]] WHERE k=1;"; ImmutableList<ImmutableList<Integer>> list = ImmutableList.of(ImmutableList.of(1), ImmutableList.of(2)); statement = update("foo").with(set("l", list)).where(eq("k", 1)); assertThat(statement.toString()).isEqualTo(query); query = "UPDATE foo SET m={1:[[1],[2]],2:[[1],[2]]} WHERE k=1;"; statement = update("foo").with(set("m", ImmutableMap.of(1, list, 2, list))).where(eq("k", 1)); assertThat(statement.toString()).isEqualTo(query); query = "UPDATE foo SET m=m+{1:[[1],[2]],2:[[1],[2]]} WHERE k=1;"; statement = update("foo").with(putAll("m", ImmutableMap.of(1, list, 2, list))).where(eq("k", 1)); assertThat(statement.toString()).isEqualTo(query); query = "UPDATE foo SET l=[[1]]+l WHERE k=1;"; statement = update("foo").with(prepend("l", ImmutableList.of(1))).where(eq("k", 1)); assertThat(statement.toString()).isEqualTo(query); query = "UPDATE foo SET l=[[1],[2]]+l WHERE k=1;"; statement = update("foo").with(prependAll("l", list)).where(eq("k", 1)); assertThat(statement.toString()).isEqualTo(query); }
@Test(groups = "unit", expectedExceptions = InvalidQueryException.class) public void should_now_allow_bind_marker_for_prepend() { update("foo").with(prepend("l", bindMarker())).where(eq("k", 1)); }
update("foo") .with() .and(prepend("b", 3)) .and(append("c", "a")) .and(appendAll("d", Arrays.asList(1, 2, 3)))
private ImmutableList<BuiltStatement> nonIdempotentBuiltStatements() { return ImmutableList.of( update("foo").with(append("l", 1)).where(eq("k", 1)), // append to list update("foo").with(set("v", 1)).and(prepend("l", 1)).where(eq("k", 1)), // prepend to list update("foo").with(incr("c")).where(eq("k", 1)), // counter update