This is an automated email from the ASF dual-hosted git repository.
panjuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new de14fb7 update PlaceholderPosition toJson function (#6591)
de14fb7 is described below
commit de14fb713f48d1ffc950c533091b3b3646a9307b
Author: 邱鹿 Lucas <[email protected]>
AuthorDate: Mon Aug 3 17:03:14 2020 +0800
update PlaceholderPosition toJson function (#6591)
Co-authored-by: qiulu3 <Lucas209910>
---
.../scaling/core/job/position/PrimaryKeyPosition.java | 9 +++++----
.../position/resume/AbstractResumablePositionManager.java | 12 ++++++++----
2 files changed, 13 insertions(+), 8 deletions(-)
diff --git
a/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/job/position/PrimaryKeyPosition.java
b/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/job/position/PrimaryKeyPosition.java
index f624855..589f0a0 100644
---
a/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/job/position/PrimaryKeyPosition.java
+++
b/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/job/position/PrimaryKeyPosition.java
@@ -57,7 +57,7 @@ public class PrimaryKeyPosition implements Position {
*/
public static PrimaryKeyPosition fromJson(final String json) {
List<Double> values = GSON.fromJson(json, List.class);
- if (values.size() == 2) {
+ if (2 == values.size()) {
return new PrimaryKeyPosition(values.get(0).longValue(),
values.get(1).longValue());
}
return new PlaceholderPosition();
@@ -79,9 +79,10 @@ public class PrimaryKeyPosition implements Position {
* Placeholder position for without primary key table.
*/
public static class PlaceholderPosition extends PrimaryKeyPosition {
-
- public PlaceholderPosition() {
- super(-1, -1);
+
+ @Override
+ public JsonElement toJson() {
+ return GSON.toJsonTree(new long[0]);
}
}
}
diff --git
a/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/job/position/resume/AbstractResumablePositionManager.java
b/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/job/position/resume/AbstractResumablePositionManager.java
index fb00cae..d6a19b7 100644
---
a/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/job/position/resume/AbstractResumablePositionManager.java
+++
b/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/job/position/resume/AbstractResumablePositionManager.java
@@ -47,6 +47,10 @@ public abstract class AbstractResumablePositionManager
implements ResumablePosit
private static final Gson GSON = new Gson();
+ private static final String UNFINISHED = "unfinished";
+
+ private static final String FINISHED = "finished";
+
private final Map<String, PositionManager<PrimaryKeyPosition>>
inventoryPositionManagerMap = Maps.newConcurrentMap();
private final Map<String, PositionManager> incrementalPositionManagerMap =
Maps.newConcurrentMap();
@@ -102,8 +106,8 @@ public abstract class AbstractResumablePositionManager
implements ResumablePosit
}
unfinished.add(entry.getKey(),
entry.getValue().getCurrentPosition().toJson());
}
- result.add("unfinished", unfinished);
- result.add("finished", GSON.toJsonTree(finished));
+ result.add(UNFINISHED, unfinished);
+ result.add(FINISHED, GSON.toJsonTree(finished));
return result.toString();
}
@@ -137,9 +141,9 @@ public abstract class AbstractResumablePositionManager
implements ResumablePosit
public static InventoryPosition fromJson(final String data) {
InventoryPosition result = new InventoryPosition();
JsonObject json = JsonParser.parseString(data).getAsJsonObject();
- Map<String, Object> unfinished =
GSON.fromJson(json.getAsJsonObject("unfinished"), Map.class);
+ Map<String, Object> unfinished =
GSON.fromJson(json.getAsJsonObject(UNFINISHED), Map.class);
result.setUnfinished(unfinished.entrySet().stream().collect(Collectors.toMap(Entry::getKey,
entry -> PrimaryKeyPosition.fromJson(entry.getValue().toString()))));
- result.setFinished(GSON.fromJson(json.getAsJsonArray("finished"),
Set.class));
+ result.setFinished(GSON.fromJson(json.getAsJsonArray(FINISHED),
Set.class));
return result;
}
}