DATACASS-735 - Fix integer overflow in Update.increment/decrement.
We now avoid integer downcasting for increment/decrement operations and use the long value instead.
This commit is contained in:
@@ -785,9 +785,9 @@ public class StatementFactory {
|
||||
|
||||
private static Assignment getAssignment(IncrOp incrOp, TermFactory termFactory) {
|
||||
|
||||
return incrOp.getValue().intValue() > 0
|
||||
? Assignment.increment(incrOp.toCqlIdentifier(), termFactory.create(Math.abs(incrOp.getValue().intValue())))
|
||||
: Assignment.decrement(incrOp.toCqlIdentifier(), termFactory.create(Math.abs(incrOp.getValue().intValue())));
|
||||
return incrOp.getValue().longValue() > 0
|
||||
? Assignment.increment(incrOp.toCqlIdentifier(), termFactory.create(Math.abs(incrOp.getValue().longValue())))
|
||||
: Assignment.decrement(incrOp.toCqlIdentifier(), termFactory.create(Math.abs(incrOp.getValue().longValue())));
|
||||
}
|
||||
|
||||
private static Assignment getAssignment(SetOp updateOp, TermFactory termFactory) {
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.core;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.Collections;
|
||||
@@ -419,6 +419,16 @@ public class StatementFactoryUnitTests {
|
||||
assertThat(update.build(ParameterHandling.INLINE).getQuery()).isEqualTo("UPDATE person SET number+=1");
|
||||
}
|
||||
|
||||
@Test // DATACASS-735
|
||||
public void shouldCreateIncrementLongUpdate() {
|
||||
|
||||
StatementBuilder<com.datastax.oss.driver.api.querybuilder.update.Update> update = statementFactory
|
||||
.update(Query.empty(), Update.empty().increment("number", Long.MAX_VALUE), personEntity);
|
||||
|
||||
assertThat(update.build(ParameterHandling.INLINE).getQuery())
|
||||
.isEqualTo("UPDATE person SET number+=" + Long.MAX_VALUE);
|
||||
}
|
||||
|
||||
@Test // DATACASS-343
|
||||
public void shouldCreateDecrementUpdate() {
|
||||
|
||||
@@ -428,6 +438,16 @@ public class StatementFactoryUnitTests {
|
||||
assertThat(update.build(ParameterHandling.INLINE).getQuery()).isEqualTo("UPDATE person SET number-=1");
|
||||
}
|
||||
|
||||
@Test // DATACASS-735
|
||||
public void shouldCreateDecrementLongUpdate() {
|
||||
|
||||
StatementBuilder<com.datastax.oss.driver.api.querybuilder.update.Update> update = statementFactory
|
||||
.update(Query.empty(), Update.empty().decrement("number", Long.MAX_VALUE), personEntity);
|
||||
|
||||
assertThat(update.build(ParameterHandling.INLINE).getQuery())
|
||||
.isEqualTo("UPDATE person SET number-=" + Long.MAX_VALUE);
|
||||
}
|
||||
|
||||
@Test // DATACASS-569
|
||||
public void shouldCreateSetUpdateIfExists() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user