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 ); }
void incrementCounterInStorage( String queueName, Shard.Type type, long shardId, long increment ) { Statement update = QueryBuilder.update( TABLE_COUNTERS ) .where( QueryBuilder.eq( COLUMN_QUEUE_NAME, queueName ) ) .and( QueryBuilder.eq( COLUMN_SHARD_TYPE, type.toString() ) ) .and( QueryBuilder.eq( COLUMN_SHARD_ID, shardId ) ) .with( QueryBuilder.incr( COLUMN_COUNTER_VALUE, increment ) ); cassandraClient.getQueueMessageSession().execute( update ); }
/** * Incrementation of a counter column. * * <p>This will generate: {@code name = name + 1}. * * @param name the column name to increment * @return the correspond assignment (to use in an update query) */ public static Assignment incr(String name) { return incr(name, 1L); }
@Override public void resetCounter(String queueName, DatabaseQueueMessage.Type type) { // this sucks: "You cannot index, delete, or re-add a counter column" // https://docs.datastax.com/en/cql/3.1/cql/cql_using/use_counter_t.html // so instead we decrement or increment the counter to zero // get value first, before resetting in memory counter long value = getCounterValue( queueName, type ); String key = buildKey( queueName, type ); InMemoryCount inMemoryCount = inMemoryCounters.get( key ); if ( inMemoryCount != null ) { inMemoryCount.reset(); } if ( value < 0 ) { 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, -1 * value ) ); // incr must be positive cassandraClient.getQueueMessageSession().execute( update ); } else { Statement update = QueryBuilder.update( TABLE_MESSAGE_COUNTERS ) .where( QueryBuilder.eq( COLUMN_QUEUE_NAME, queueName ) ) .and( QueryBuilder.eq( COLUMN_MESSAGE_TYPE, type.toString() ) ) .with( QueryBuilder.decr( COLUMN_COUNTER_VALUE, value ) ); cassandraClient.getQueueMessageSession().execute( update ); } }
.and( QueryBuilder.eq( COLUMN_SHARD_TYPE, type.toString() ) ) .and( QueryBuilder.eq( COLUMN_SHARD_ID, shardId ) ) .with( QueryBuilder.incr( COLUMN_COUNTER_VALUE, -1 * value ) ); // incr must be positive cassandraClient.getQueueMessageSession().execute( update );
public void increaseCounter(CassandraSessionPool.Session session, HugeType type, long increment) { Update update = QueryBuilder.update(TABLE); update.with(QueryBuilder.incr(formatKey(HugeKeys.ID), increment)); update.where(formatEQ(HugeKeys.SCHEMA_TYPE, type.name())); session.execute(update); } }
update.with(QueryBuilder.incr("value", entry.getCount())); update.where(QueryBuilder.eq("metricname", metricName)) .and(QueryBuilder.eq("groupid", entry.getGroupId()))
/** * Incrementation of a counter column. * <p/> * This will generate: {@code name = name + 1}. * * @param name the column name to increment * @return the correspond assignment (to use in an update query) */ public static Assignment incr(String name) { return incr(name, 1L); }
@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()); }
/** * Generate an UPDATE FROM ... <strong>SET count = count + 1</strong> */ public final EntityWithComplexCounters_Update.Cols Incr() { where.with(QueryBuilder.incr("count")); return EntityWithComplexCounters_Update.Cols.this; }
/** * Generate an UPDATE FROM ... <strong>SET codec_count = codec_count + 1</strong> */ public final EntityWithComplexCounters_Update.Cols Incr() { where.with(QueryBuilder.incr("codec_count")); return EntityWithComplexCounters_Update.Cols.this; }
batch = batch() .add(update("foo").with(incr("a", 1))) .add(update("foo").with(incr("b", 2))) .add(update("foo").with(incr("c", 3))) .using(timestamp(42)); assertEquals(batch.toString(), query); batch = batch() .add(update("foo").with(incr("a"))) .add(update("foo").with(incr("b"))) .add(update("foo").with(incr("c"))) .using(timestamp(42)); assertEquals(batch.toString(), query); batch() .add(update("foo").with(decr("a", -1))) .add(update("foo").with(incr("b", -2))) .add(update("foo").with(decr("c", 3))) .using(timestamp(42));
/** * Generate an UPDATE FROM ... <strong>SET count = count + 1</strong> */ public final EntityWithStaticCounterColumn_Update.Cols Incr() { where.with(QueryBuilder.incr("count")); return new EntityWithStaticCounterColumn_Update.Cols(where, cassandraOptions); }
@Override public UpdateBuilder<T> incr(String name) { update.with(QueryBuilder.incr(classBean.toColumn(name))); return this; } @Override
.with(set("a", 12)) .and(set("b", Arrays.asList(3, 2, 1))) .and(incr("c", 3)) .where(eq("k", 2)); assertEquals(update.toString(), query);
/** * Generate an UPDATE FROM ... <strong>SET static_count = static_count + 1</strong> */ public final EntityWithComplexCounters_UpdateStatic.Cols Incr() { where.with(QueryBuilder.incr("static_count")); return new EntityWithComplexCounters_UpdateStatic.Cols(where, cassandraOptions); }
/** * Generate an UPDATE FROM ... <strong>SET simpleCounter = simpleCounter + ?</strong> */ @SuppressWarnings("static-access") public final EntityWithComplexCounters_Update.Cols Incr(final long simpleCounter_increment) { where.with(QueryBuilder.incr("count", QueryBuilder.bindMarker("count"))); boundValues.add(simpleCounter_increment); encodedValues.add(meta.simpleCounter.encodeFromJava(simpleCounter_increment, Optional.of(cassandraOptions))); return new EntityWithComplexCounters_Update.Cols(where, cassandraOptions); }
private Statement createUpdateForMessageCounterByTitle(Message message) { UUID appId = UUID.fromString(message.applicationId); return queryBuilder .update(Messages.TABLE_NAME_TOTALS_BY_TITLE) .where(eq(APP_ID, appId)) .and(eq(TITLE, message.title)) .with(incr(TOTAL_MESSAGES, 1)); }
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