Skip to content

Commit b51b499

Browse files
committed
Optimization
1 parent bcf7ed8 commit b51b499

File tree

2 files changed

+4
-10
lines changed

2 files changed

+4
-10
lines changed

src/test/java/examples/sharding/ShardingTest.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,13 +156,9 @@ private SelectStatementProvider buildSelect(int id) {
156156

157157
private TableCodes calculateTable(int id) {
158158
if (id % 2 == 0) {
159-
return shards.computeIfAbsent("even", this::newTableInstance);
159+
return shards.computeIfAbsent("even", k -> tableCodes); // tableCodes_even is the default
160160
} else {
161-
return shards.computeIfAbsent("odd", this::newTableInstance);
161+
return shards.computeIfAbsent("odd", k -> tableCodes.withName("tableCodes_odd"));
162162
}
163163
}
164-
165-
private TableCodes newTableInstance(String suffix) {
166-
return tableCodes.withName("tableCodes_" + suffix);
167-
}
168164
}

src/test/kotlin/examples/kotlin/mybatis3/sharding/KShardingTest.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,8 @@ class KShardingTest {
134134

135135
private fun calculateTable(id: Int) =
136136
if (id % 2 == 0) {
137-
shards.computeIfAbsent("even", this::newTableInstance)
137+
shards.computeIfAbsent("even") { tableCodes } // tableCodes_even is default
138138
} else {
139-
shards.computeIfAbsent("odd", this::newTableInstance)
139+
shards.computeIfAbsent("odd") { tableCodes.withName("tableCodes_odd") }
140140
}
141-
142-
private fun newTableInstance(suffix: String)= tableCodes.withName("tableCodes_$suffix")
143141
}

0 commit comments

Comments
 (0)