File tree Expand file tree Collapse file tree 2 files changed +4
-10
lines changed
kotlin/examples/kotlin/mybatis3/sharding Expand file tree Collapse file tree 2 files changed +4
-10
lines changed Original file line number Diff line number Diff line change @@ -156,13 +156,9 @@ private SelectStatementProvider buildSelect(int id) {
156
156
157
157
private TableCodes calculateTable (int id ) {
158
158
if (id % 2 == 0 ) {
159
- return shards .computeIfAbsent ("even" , this :: newTableInstance );
159
+ return shards .computeIfAbsent ("even" , k -> tableCodes ); // tableCodes_even is the default
160
160
} else {
161
- return shards .computeIfAbsent ("odd" , this :: newTableInstance );
161
+ return shards .computeIfAbsent ("odd" , k -> tableCodes . withName ( "tableCodes_odd" ) );
162
162
}
163
163
}
164
-
165
- private TableCodes newTableInstance (String suffix ) {
166
- return tableCodes .withName ("tableCodes_" + suffix );
167
- }
168
164
}
Original file line number Diff line number Diff line change @@ -134,10 +134,8 @@ class KShardingTest {
134
134
135
135
private fun calculateTable (id : Int ) =
136
136
if (id % 2 == 0 ) {
137
- shards.computeIfAbsent(" even" , this ::newTableInstance)
137
+ shards.computeIfAbsent(" even" ) { tableCodes } // tableCodes_even is default
138
138
} else {
139
- shards.computeIfAbsent(" odd" , this ::newTableInstance)
139
+ shards.computeIfAbsent(" odd" ) { tableCodes.withName( " tableCodes_odd " ) }
140
140
}
141
-
142
- private fun newTableInstance (suffix : String )= tableCodes.withName(" tableCodes_$suffix " )
143
141
}
You can’t perform that action at this time.
0 commit comments