@Test(groups = "unit", expectedExceptions = InvalidQueryException.class) public void should_not_allow_bind_marker_for_add() { // This generates the query "UPDATE foo SET s = s + {?} WHERE k = 1", which is invalid in // Cassandra update("foo").with(add("s", bindMarker())).where(eq("k", 1)); }
update("foo") .with(discardAll("b", Arrays.asList(1, 2, 3))) .and(add("c", 1)) .and( addAll(
public static BoundStatement prepareAppendItemToCollection(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 Set<?> && fmeta.getType() == Set.class) { Set<?> set = (Set<?>) item; if (set.size() == 0) return null; update.with(QueryBuilder.addAll(fmeta.getColumnName(), set)); } else if (item instanceof List<?> && fmeta.getType() == List.class) { List<?> list = (List<?>) item; if (list.size() == 0) return null; update.with(QueryBuilder.appendAll(fmeta.getColumnName(), list)); } else if (item instanceof Map<?, ?>) { Map<?, ?> map = (Map<?, ?>) item; if (map.size() == 0) return null; update.with(QueryBuilder.putAll(fmeta.getColumnName(), map)); } else if (fmeta.getType() == Set.class) { update.with(QueryBuilder.add(fmeta.getColumnName(), item)); } else if (fmeta.getType() == List.class) { update.with(QueryBuilder.append(fmeta.getColumnName(), item)); } applyOptions(options, update, null); return prepareUpdate(id, emeta, update, session); }
public void insert(CassandraSessionPool.Session session, CassandraBackendEntry.Row entry) { Update update = QueryBuilder.update(this.table); update.with(QueryBuilder.add(ELEMENT_IDS, entry.id().asLong())); update.where(CassandraTable.formatEQ(HugeKeys.NAME, entry.column(HugeKeys.NAME))); session.add(update); }
update("foo") .with(discardAll("b", Arrays.asList(1, 2, 3))) .and(add("c", 1)) .and( addAll(
private Assignments addUserFlagsToQuery(Set<String> userFlags, Assignments updateQuery) { userFlags.forEach(userFlag -> updateQuery.and(add(USER_FLAGS, userFlag))); return updateQuery; }
@Override public UpdateBuilder<T> addSet(String name, Object value) { update.with(QueryBuilder.add(classBean.toColumn(name), value)); return this; } @Override
private Statement createStatementToAddDevice(String userId, MobileDevice mobileDevice) { UUID userUuid = UUID.fromString(userId); String serializedDevice = serializeMobileDevice(mobileDevice); return QueryBuilder .update(UserPreferences.TABLE_NAME) .with(add(UserPreferences.SERIALIZED_DEVICES, serializedDevice)) .where(eq(UserPreferences.USER_ID, userUuid)); }
private ImmutableList<BuiltStatement> idempotentBuiltStatements() { return ImmutableList.<BuiltStatement>of( update("foo").with(set("v", 1)).where(eq("k", 1)), // set simple value update("foo").with(add("s", 1)).where(eq("k", 1)), // add to set update("foo").with(put("m", "a", 1)).where(eq("k", 1)), // put in map // select statements should be idempotent even with function calls select().countAll().from("foo").where(eq("k", 1)), select().ttl("v").from("foo").where(eq("k", 1)), select().writeTime("v").from("foo").where(eq("k", 1)), select().fcall("token", "k").from("foo").where(eq("k", 1))); }
private List<RegularStatement> addJvm(Identifier accId, String analyseId, UUID jvmUUID, String jvmName, VMVersion version, GarbageCollectorType type, String headers, MemoryDetails memoryDetails) { UUID uuid = UUID.fromString(analyseId); String jvmId = jvmUUID.toString(); List<RegularStatement> batch = new ArrayList<>(); batch.add(updateTable(accId, uuid).with(add("jvm_ids", jvmId))); batch.add(updateTable(accId, uuid).with(put("jvm_names", jvmId, jvmName))); batch.add(updateTable(accId, uuid).with(put("jvm_headers", jvmId, headers))); batch.add(updateTable(accId, uuid).with(put("jvm_versions", jvmId, version.type()))); batch.add(updateTable(accId, uuid).with(put("jvm_gc_types", jvmId, type.type()))); if (memoryDetails != null) { insertMemoryDetails(accId, jvmId, memoryDetails, uuid, batch); } return batch; }
public void insert(CassandraSessionPool.Session session, CassandraBackendEntry.Row entry) { Update update = QueryBuilder.update(this.table); update.with(QueryBuilder.add(ELEMENT_IDS, entry.id().asLong())); update.where(CassandraTable.formatEQ(HugeKeys.NAME, entry.column(HugeKeys.NAME))); session.add(update); }
@Test(groups = "unit", expectedExceptions = InvalidQueryException.class) public void should_not_allow_bind_marker_for_add() { // This generates the query "UPDATE foo SET s = s + {?} WHERE k = 1", which is invalid in // Cassandra update("foo").with(add("s", bindMarker())).where(eq("k", 1)); }
private ImmutableList<BuiltStatement> idempotentBuiltStatements() { return ImmutableList.<BuiltStatement>of( update("foo").with(set("v", 1)).where(eq("k", 1)), // set simple value update("foo").with(add("s", 1)).where(eq("k", 1)), // add to set update("foo").with(put("m", "a", 1)).where(eq("k", 1)), // put in map // select statements should be idempotent even with function calls select().countAll().from("foo").where(eq("k", 1)), select().ttl("v").from("foo").where(eq("k", 1)), select().writeTime("v").from("foo").where(eq("k", 1)), select().fcall("token", "k").from("foo").where(eq("k", 1))); }