Refine search
/** * @return cql query statement to update the total_tasks in a shard for a workflow in the "workflows" table */ public String getUpdateTotalTasksStatement() { return QueryBuilder.update(keyspace, TABLE_WORKFLOWS) .with(set(TOTAL_TASKS_KEY, bindMarker())) .where(eq(WORKFLOW_ID_KEY, bindMarker())) .and(eq(SHARD_ID_KEY, bindMarker())) .getQueryString(); }
private void incrementCounterInStorage( String queueName, DatabaseQueueMessage.Type type, long increment ) { Statement update = QueryBuilder.update( TABLE_MESSAGE_COUNTERS ) .where( QueryBuilder.eq( COLUMN_QUEUE_NAME, queueName ) ) .and( QueryBuilder.eq( COLUMN_MESSAGE_TYPE, type.toString() ) ) .with( QueryBuilder.incr( COLUMN_COUNTER_VALUE, increment ) ); cassandraClient.getQueueMessageSession().execute( update ); }
update = update("foo").where().and(eq("k", 2)).with(set("b", null)); assertEquals(update.toString(), query); .with(setIdx("a", 2, "foo")) .and(eq("l", "foo")) .and(lt("m", 4)) .and(gte("n", 1)); assertEquals(update.toString(), query); .and(eq("k", 2)) .and(eq("l", "foo")) .with(prependAll("b", Arrays.asList(3, 2, 1))) .and(eq("k", 2)) .and(eq("l", "foo")) .using(timestamp(42)) .and(eq("l", "foo")) .with(prependAll("b", Arrays.asList(3, 2, 1))); assertEquals(update.toString(), query); update = update("foo").with(set("x", 4)).where(eq("k", 0)).onlyIf(eq("x", 1)); assertEquals(update.toString(), query); update = update("foo").with(set("x", 3)).where(eq("k", 2)).ifExists(); assertThat(update.toString()).isEqualTo("UPDATE foo SET x=3 WHERE k=2 IF EXISTS;");
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 update("foo").where(eq("is", "charlie?")).ifExists(), update("foo").where(eq("good", "drivers")).onlyIf(contains("developers", "datastax")), update("foo").onlyIf().and(contains("developers", "datastax")).where(eq("good", "drivers")), update("foo").onlyIf(contains("developers", "datastax")).with(set("v", 0)),
/** * Generate an ... <strong>IF tuple = ?</strong> */ @SuppressWarnings("static-access") public final EntityWithComplexTuple_Update.E Eq(final Tuple2<Integer, Map<Integer, List<String>>> tuple) { boundValues.add(tuple); encodedValues.add(meta.tuple.encodeFromJava(tuple, Optional.of(cassandraOptions))); where.onlyIf(QueryBuilder.eq("tuple", QueryBuilder.bindMarker("tuple"))); return EntityWithComplexTuple_Update.E.this; }
@Override public String updateEvent(EventKey eventKey, @Nullable RecordedEvent newEventData, @Nullable EventState newEventState, @Nullable String newEventType) throws EventStoreException { Update update = QueryBuilder.update(tableName); update.where(QueryBuilder.eq(ENTITY_ID, eventKey.getEntityId())) .and(QueryBuilder.eq(VERSION, eventKey.getVersion())) .ifExists(); if (newEventData != null) update.with(QueryBuilder.set(EVENT_DATA, createEventStr(newEventData))); if (newEventState != null) update.with(QueryBuilder.set(STATUS, newEventState.name())); if (newEventType != null) update.with(QueryBuilder.set(EVENT_TYPE, newEventType)); try { ResultSet execute = cassandraSession.execute(update); log.debug("Update Event, Result:" + execute.toString() + " Update: " + update.toString()); return execute.toString(); } catch (Exception e) { log.warn(e.getMessage(), e); throw new EventStoreException(e.getMessage(), e); } }
Update update = QueryBuilder.update(columnFamilyName); update.with(QueryBuilder.incr("value", entry.getCount())); update.where(QueryBuilder.eq("metricname", metricName)) .and(QueryBuilder.eq("groupid", entry.getGroupId())) .and(QueryBuilder.eq("metrictime", entry.getMetricTime())); update.where(QueryBuilder.eq(entryInTag.getKey(), entryInTag.getValue()));
@Inject public CassandraSieveDAO(Session session) { this.cassandraAsyncExecutor = new CassandraAsyncExecutor(session); insertScriptStatement = session.prepare( insertInto(TABLE_NAME) .value(USER_NAME, bindMarker(USER_NAME)) .value(SCRIPT_NAME, bindMarker(SCRIPT_NAME)) .value(SCRIPT_CONTENT, bindMarker(SCRIPT_CONTENT)) .value(IS_ACTIVE, bindMarker(IS_ACTIVE)) .value(SIZE, bindMarker(SIZE))); selectScriptsStatement = session.prepare(getScriptsQuery()); selectScriptStatement = session.prepare(getScriptsQuery() .and(eq(SCRIPT_NAME, bindMarker(SCRIPT_NAME)))); updateScriptActivationStatement = session.prepare( update(TABLE_NAME) .with(set(IS_ACTIVE, bindMarker(IS_ACTIVE))) .where(eq(USER_NAME, bindMarker(USER_NAME))) .and(eq(SCRIPT_NAME, bindMarker(SCRIPT_NAME))) .ifExists()); deleteScriptStatement = session.prepare( delete() .from(TABLE_NAME) .where(eq(USER_NAME, bindMarker(USER_NAME))) .and(eq(SCRIPT_NAME, bindMarker(SCRIPT_NAME))) .ifExists()); }
private T updateLocked(T entity) { long version = (entity.getVersion() == null) ? 0L : entity.getVersion(); Assignments assigns = update(getColumnFamilyName()) .onlyIf(eq(OPT_LOCK, version)) .with(set(OPT_LOCK, version + 1)); CassandraEntityMapper<T> entityMapper = CassandraEntityMapper.getEntityMapperForClass( getColumnFamilyClass(), cassandraClient); if (whereClauses.length > 1) { for (int i = 1; i < whereClauses.length; i++) { query = query.and(whereClauses[i]); query.setConsistencyLevel(getWriteConsistencyLevel()); ResultSet res = execute(query); if (!res.wasApplied()) {
@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); }
/** * Generate an ... <strong>IF udt < ?</strong> */ @SuppressWarnings("static-access") public final EntityWithCaseSensitivePK_Update.E Lt(final UDTWithNoKeyspace udt) { boundValues.add(udt); encodedValues.add(meta.udt.encodeFromJava(udt, Optional.of(cassandraOptions))); where.onlyIf(QueryBuilder.lt("\"udtWithNoKeyspace\"", QueryBuilder.bindMarker("\"udtWithNoKeyspace\""))); return EntityWithCaseSensitivePK_Update.E.this; }
/** * Generate an ... <strong>IF list <= ?</strong> */ @SuppressWarnings("static-access") public final EntityWithCaseSensitivePK_Update.E Lte(final List<String> list) { boundValues.add(list); encodedValues.add(meta.list.encodeFromJava(list, Optional.of(cassandraOptions))); where.onlyIf(QueryBuilder.lte("\"listString\"", QueryBuilder.bindMarker("\"listString\""))); return EntityWithCaseSensitivePK_Update.E.this; }
/** * Generate an UPDATE FROM ... <strong>SET value = ?</strong> */ @SuppressWarnings("static-access") public final EntityWithBeanValidation_Update.Cols Set(final String value) { where.with(NonEscapingSetAssignment.of("value", QueryBuilder.bindMarker("value"))); boundValues.add(value); encodedValues.add(meta.value.encodeFromJava(value, Optional.of(cassandraOptions))); return EntityWithBeanValidation_Update.Cols.this; } }
/** * Generate an ... <strong>IF list > ?</strong> */ @SuppressWarnings("static-access") public final EntityWithBeanValidation_Update.E Gt(final List<String> list) { boundValues.add(list); encodedValues.add(meta.list.encodeFromJava(list, Optional.of(cassandraOptions))); where.onlyIf(QueryBuilder.gt("list", QueryBuilder.bindMarker("list"))); return EntityWithBeanValidation_Update.E.this; }
/** * Generate an UPDATE FROM ... <strong>SET list[index] = null</strong> */ public final EntityWithBeanValidation_Update.Cols RemoveAtIndex(final int index) { where.with(QueryBuilder.setIdx("list", index, QueryBuilder.bindMarker("list"))); boundValues.add(null); encodedValues.add(null); return EntityWithBeanValidation_Update.Cols.this; }
/** * Generate an UPDATE FROM ... <strong>SET listofoptional = listofoptional + [?]</strong> */ @SuppressWarnings("static-access") public final EntityWithComplexTypes_Update.Cols AppendTo(final Optional<String> listOfOptional_element) { where.with(QueryBuilder.appendAll("listofoptional", QueryBuilder.bindMarker("listofoptional"))); boundValues.add(Arrays.asList(listOfOptional_element)); encodedValues.add(meta.listOfOptional.encodeFromJava(Arrays.asList(listOfOptional_element), Optional.of(cassandraOptions))); return new EntityWithComplexTypes_Update.Cols(where, cassandraOptions); }
/** * Generate an UPDATE FROM ... <strong>SET collectionIndex = collectionIndex - ?</strong> */ @SuppressWarnings("static-access") public final EntityWithComplexIndices_Update.Cols RemoveAllFrom(final List<String> collectionIndex_element) { where.with(QueryBuilder.discardAll("collectionindex", QueryBuilder.bindMarker("collectionindex"))); boundValues.add(collectionIndex_element); encodedValues.add(meta.collectionIndex.encodeFromJava(collectionIndex_element, Optional.of(cassandraOptions))); return EntityWithComplexIndices_Update.Cols.this; }
/** * Generate an ... <strong>IF indexOnMapValue >= ?</strong> */ @SuppressWarnings("static-access") public final EntityWithComplexIndices_Update.E Gte(final Map<Integer, String> indexOnMapValue) { boundValues.add(indexOnMapValue); encodedValues.add(meta.indexOnMapValue.encodeFromJava(indexOnMapValue, Optional.of(cassandraOptions))); where.onlyIf(QueryBuilder.gte("indexonmapvalue", QueryBuilder.bindMarker("indexonmapvalue"))); return EntityWithComplexIndices_Update.E.this; }
/** * Generate an UPDATE FROM ... <strong>SET "mapIntString"[?] = ?</strong> */ public final EntityWithCaseSensitivePK_Update.Cols PutTo(final Integer map_key, final String map_value) { where.with(QueryBuilder.put("\"mapIntString\"", QueryBuilder.bindMarker("map_key"), QueryBuilder.bindMarker("map_value"))); boundValues.add(map_key); boundValues.add(map_value); encodedValues.add(meta.map.keyProperty.encodeFromJava(map_key, Optional.of(cassandraOptions))); encodedValues.add(meta.map.valueProperty.encodeFromJava(map_value, Optional.of(cassandraOptions))); return EntityWithCaseSensitivePK_Update.Cols.this; }
/** * Generate an UPDATE FROM ... <strong>SET staticCounter = staticCounter - ?</strong> */ @SuppressWarnings("static-access") public final EntityWithComplexCounters_Update.Cols Decr(final Long staticCounter_decrement) { where.with(QueryBuilder.decr("static_count", QueryBuilder.bindMarker("static_count"))); boundValues.add(staticCounter_decrement); encodedValues.add(meta.staticCounter.encodeFromJava(staticCounter_decrement, Optional.of(cassandraOptions))); return EntityWithComplexCounters_Update.Cols.this; } }