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:
@@ -541,9 +541,9 @@ public class StatementFactory {
|
||||
|
||||
private static Assignment getAssignment(IncrOp incrOp) {
|
||||
|
||||
return incrOp.getValue().intValue() > 0
|
||||
? QueryBuilder.incr(incrOp.getColumnName().toCql(), Math.abs(incrOp.getValue().intValue()))
|
||||
: QueryBuilder.decr(incrOp.getColumnName().toCql(), Math.abs(incrOp.getValue().intValue()));
|
||||
return incrOp.getValue().longValue() > 0
|
||||
? QueryBuilder.incr(incrOp.getColumnName().toCql(), Math.abs(incrOp.getValue().longValue()))
|
||||
: QueryBuilder.decr(incrOp.getColumnName().toCql(), Math.abs(incrOp.getValue().longValue()));
|
||||
}
|
||||
|
||||
private static Assignment getAssignment(SetOp updateOp) {
|
||||
|
||||
@@ -241,6 +241,14 @@ public class StatementFactoryUnitTests {
|
||||
assertThat(update.toString()).isEqualTo("UPDATE person SET number=number+1;");
|
||||
}
|
||||
|
||||
@Test // DATACASS-735
|
||||
public void shouldCreateIncrementLongUpdate() {
|
||||
|
||||
Statement update = statementFactory.update(Query.empty(), Update.empty().increment("number", Long.MAX_VALUE), personEntity);
|
||||
|
||||
assertThat(update.toString()).isEqualTo("UPDATE person SET number=number+" + Long.MAX_VALUE+";");
|
||||
}
|
||||
|
||||
@Test // DATACASS-343
|
||||
public void shouldCreateDecrementUpdate() {
|
||||
|
||||
@@ -249,6 +257,14 @@ public class StatementFactoryUnitTests {
|
||||
assertThat(update.toString()).isEqualTo("UPDATE person SET number=number-1;");
|
||||
}
|
||||
|
||||
@Test // DATACASS-735
|
||||
public void shouldCreateDecrementLongUpdate() {
|
||||
|
||||
Statement update = statementFactory.update(Query.empty(), Update.empty().decrement("number", Long.MAX_VALUE), personEntity);
|
||||
|
||||
assertThat(update.toString()).isEqualTo("UPDATE person SET number=number-" + Long.MAX_VALUE+";");
|
||||
}
|
||||
|
||||
@Test // DATACASS-569
|
||||
public void shouldCreateSetUpdateIfExists() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user