Skip to content

Commit f12729e

Browse files
committed
chore(spanner): add helper methods
1 parent be71459 commit f12729e

File tree

1 file changed

+12
-9
lines changed
  • google-cloud-spanner/src/main/java/com/google/cloud/spanner

1 file changed

+12
-9
lines changed

google-cloud-spanner/src/main/java/com/google/cloud/spanner/Mutation.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -440,9 +440,7 @@ static com.google.spanner.v1.Mutation toProtoAndReturnRandomMutation(
440440
if (checkIfInsertMutationWithLargeValue(builtMutation, largestInsertMutation)) {
441441
largestInsertMutation = builtMutation;
442442
}
443-
if (!builtMutation.hasInsert()) {
444-
allMutationsExcludingInsert.add(builtMutation);
445-
}
443+
addMutationsExcludingInsert(builtMutation, allMutationsExcludingInsert);
446444
}
447445
proto = com.google.spanner.v1.Mutation.newBuilder();
448446
com.google.spanner.v1.Mutation.Delete.Builder delete =
@@ -469,9 +467,7 @@ static com.google.spanner.v1.Mutation toProtoAndReturnRandomMutation(
469467
if (checkIfInsertMutationWithLargeValue(builtMutation, largestInsertMutation)) {
470468
largestInsertMutation = builtMutation;
471469
}
472-
if (!builtMutation.hasInsert()) {
473-
allMutationsExcludingInsert.add(builtMutation);
474-
}
470+
addMutationsExcludingInsert(builtMutation, allMutationsExcludingInsert);
475471
}
476472
proto = com.google.spanner.v1.Mutation.newBuilder();
477473
switch (mutation.operation) {
@@ -503,9 +499,7 @@ static com.google.spanner.v1.Mutation toProtoAndReturnRandomMutation(
503499
if (checkIfInsertMutationWithLargeValue(builtMutation, largestInsertMutation)) {
504500
largestInsertMutation = builtMutation;
505501
}
506-
if (!builtMutation.hasInsert()) {
507-
allMutationsExcludingInsert.add(builtMutation);
508-
}
502+
addMutationsExcludingInsert(builtMutation, allMutationsExcludingInsert);
509503
}
510504

511505
// Select a random mutation based on the heuristic.
@@ -531,4 +525,13 @@ private static boolean checkIfInsertMutationWithLargeValue(
531525
&& mutation.getInsert().getValuesCount()
532526
> largestInsertMutation.getInsert().getValuesCount();
533527
}
528+
529+
// Stores all mutations that are not of type INSERT.
530+
private static void addMutationsExcludingInsert(
531+
com.google.spanner.v1.Mutation mutation,
532+
List<com.google.spanner.v1.Mutation> allMutationsExcludingInsert) {
533+
if (!mutation.hasInsert()) {
534+
allMutationsExcludingInsert.add(mutation);
535+
}
536+
}
534537
}

0 commit comments

Comments
 (0)