private void decrementCounterInStorage( String queueName, DatabaseQueueMessage.Type type, long decrement ) { 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, decrement ) ); cassandraClient.getQueueMessageSession().execute( update ); }
/** * Decrementation of a counter column. * * <p>This will generate: {@code name = name - 1}. * * @param name the column name to decrement * @return the correspond assignment (to use in an update query) */ public static Assignment decr(String name) { return decr(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.decr( COLUMN_COUNTER_VALUE, value ) ); cassandraClient.getQueueMessageSession().execute( update );
/** * Decrementation of a counter column. * <p/> * This will generate: {@code name = name - 1}. * * @param name the column name to decrement * @return the correspond assignment (to use in an update query) */ public static Assignment decr(String name) { return decr(name, 1L); }
/** * Decrementation of a counter column. * <p/> * This will generate: {@code name = name - 1}. * * @param name the column name to decrement * @return the correspond assignment (to use in an update query) */ public static Assignment decr(String name) { return decr(name, 1L); }
/** * Decrementation of a counter column. * <p/> * This will generate: {@code name = name - 1}. * * @param name the column name to decrement * @return the correspond assignment (to use in an update query) */ public static Assignment decr(String name) { return decr(name, 1L); }
/** * Decrementation of a counter column. * <p> * This will generate: {@code name = name - 1}. * * @param name the column name to decrement * @return the correspond assignment (to use in an update query) */ public static Assignment decr(String name) { return decr(name, 1L); }
/** * Generate an UPDATE FROM ... <strong>SET simpleCounter = simpleCounter - 1</strong> */ public final EntityWithComplexCounters_Update.Cols Decr() { where.with(QueryBuilder.decr("count")); return EntityWithComplexCounters_Update.Cols.this; }
/** * Generate an UPDATE FROM ... <strong>SET staticCounter = staticCounter - 1</strong> */ public final EntityWithComplexCounters_UpdateStatic.Cols Decr() { where.with(QueryBuilder.decr("static_count")); return EntityWithComplexCounters_UpdateStatic.Cols.this; }
/** * Generate an UPDATE FROM ... <strong>SET count = count - 1</strong> */ public final EntityWithCounterColumn_Update.Cols Decr() { where.with(QueryBuilder.decr("count")); return EntityWithCounterColumn_Update.Cols.this; }
batch = batch() .add(update("foo").with(decr("a", 1))) .add(update("foo").with(decr("b", 2))) .add(update("foo").with(decr("c", 3))) .using(timestamp(42)); assertEquals(batch.toString(), query); batch = batch() .add(update("foo").with(decr("a"))) .add(update("foo").with(decr("b"))) .add(update("foo").with(decr("c"))) .using(timestamp(42)); assertEquals(batch.toString(), query); batch = 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)); assertEquals(batch.toString(), query);
/** * Generate an UPDATE FROM ... <strong>SET count = count - 1</strong> */ public final EntityWithCounterColumn_Update.Cols Decr() { where.with(QueryBuilder.decr("count")); return new EntityWithCounterColumn_Update.Cols(where, cassandraOptions); }
/** * Generate an UPDATE FROM ... <strong>SET simpleCounter = simpleCounter - 1</strong> */ public final EntityWithComplexCounters_Update.Cols Decr() { where.with(QueryBuilder.decr("count")); return new EntityWithComplexCounters_Update.Cols(where, cassandraOptions); }
/** * 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; } }
/** * Generate an UPDATE FROM ... <strong>SET staticCount = staticCount - ?</strong> */ @SuppressWarnings("static-access") public final EntityWithStaticCounterColumn_UpdateStatic.Cols Decr(final Long staticCount_decrement) { where.with(QueryBuilder.decr("static_count", QueryBuilder.bindMarker("static_count"))); boundValues.add(staticCount_decrement); encodedValues.add(meta.staticCount.encodeFromJava(staticCount_decrement, Optional.of(cassandraOptions))); return EntityWithStaticCounterColumn_UpdateStatic.Cols.this; } }
/** * Generate an UPDATE FROM ... <strong>SET staticCount = staticCount - ?</strong> */ @SuppressWarnings("static-access") public final EntityWithStaticCounterColumn_Update.Cols Decr(final Long staticCount_decrement) { where.with(QueryBuilder.decr("static_count", QueryBuilder.bindMarker("static_count"))); boundValues.add(staticCount_decrement); encodedValues.add(meta.staticCount.encodeFromJava(staticCount_decrement, Optional.of(cassandraOptions))); return EntityWithStaticCounterColumn_Update.Cols.this; } }
/** * Generate an UPDATE FROM ... <strong>SET simpleCounter = simpleCounter - ?</strong> */ @SuppressWarnings("static-access") public final EntityWithComplexCounters_Update.Cols Decr(final long simpleCounter_decrement) { where.with(QueryBuilder.decr("count", QueryBuilder.bindMarker("count"))); boundValues.add(simpleCounter_decrement); encodedValues.add(meta.simpleCounter.encodeFromJava(simpleCounter_decrement, Optional.of(cassandraOptions))); return new EntityWithComplexCounters_Update.Cols(where, cassandraOptions); } }
/** * Generate an UPDATE FROM ... <strong>SET count = count - ?</strong> */ @SuppressWarnings("static-access") public final EntityWithStaticCounterColumn_Update.Cols Decr(final Long count_decrement) { where.with(QueryBuilder.decr("count", QueryBuilder.bindMarker("count"))); boundValues.add(count_decrement); encodedValues.add(meta.count.encodeFromJava(count_decrement, Optional.of(cassandraOptions))); return new EntityWithStaticCounterColumn_Update.Cols(where, cassandraOptions); } }
/** * Generate an UPDATE FROM ... <strong>SET staticCount = staticCount - ?</strong> */ @SuppressWarnings("static-access") public final EntityWithStaticCounterColumn_UpdateStatic.Cols Decr(final Long staticCount_decrement) { where.with(QueryBuilder.decr("static_count", QueryBuilder.bindMarker("static_count"))); boundValues.add(staticCount_decrement); encodedValues.add(meta.staticCount.encodeFromJava(staticCount_decrement, Optional.of(cassandraOptions))); return new EntityWithStaticCounterColumn_UpdateStatic.Cols(where, cassandraOptions); } }