17
17
import org .junit .jupiter .api .Test ;
18
18
import org .locationtech .jts .util .Assert ;
19
19
import org .nebula .contrib .ngbatis .models .data .NgPath ;
20
+ import org .nebula .contrib .ngbatis .models .data .NgTriplet ;
20
21
import org .nebula .contrib .ngbatis .utils .Page ;
21
22
import org .springframework .beans .factory .annotation .Autowired ;
22
23
import org .springframework .boot .test .context .SpringBootTest ;
@@ -60,15 +61,15 @@ public void selectBySelective() {
60
61
List <Person > people = repository .selectBySelective (person );
61
62
System .out .println (JSON .toJSONString (people ));
62
63
}
63
-
64
+
64
65
@ Test
65
66
public void selectBySelectiveWithBigDecimal () {
66
67
Person person = new Person ();
67
68
person .setHeight (new BigDecimal ("155.55555" ));
68
69
List <Person > people = repository .selectBySelective (person );
69
70
System .out .println (JSON .toJSONString (people ));
70
71
}
71
-
72
+
72
73
/**
73
74
* https://github.com/nebula-contrib/ngbatis/issues/35.
74
75
*/
@@ -107,7 +108,7 @@ public void selectIdBySelectiveStringLike() {
107
108
List <String > people = repository .selectIdBySelectiveStringLike (person );
108
109
System .out .println (people );
109
110
}
110
-
111
+
111
112
@ Test
112
113
public void selectByMap () {
113
114
Map <String , Object > query = new HashMap <>();
@@ -182,7 +183,7 @@ public void insertSelectiveWithBigDecimal() {
182
183
@ Test
183
184
public void insertBatch () {
184
185
long now = System .currentTimeMillis ();
185
-
186
+
186
187
Person person1 = new Person ();
187
188
person1 .setName ("IB" + now );
188
189
person1 .setGender ("M" );
@@ -192,17 +193,17 @@ public void insertBatch() {
192
193
person2 .setName ("IB" + (now + 1 ));
193
194
person2 .setAge (18 );
194
195
person2 .setBirthday (new Date ());
195
-
196
+
196
197
Person person3 = new Person ();
197
198
person3 .setName ("IB" + (now + 2 ));
198
199
person3 .setGender ("M" );
199
200
person3 .setBirthday (new Date ());
200
201
201
202
List <Person > people = new ArrayList <>();
202
203
people .add (person1 );
203
- people .add (person2 );;
204
+ people .add (person2 );
204
205
people .add (person3 );
205
-
206
+
206
207
repository .insertBatch (people );
207
208
}
208
209
// endregion
@@ -215,14 +216,14 @@ public void updateById() {
215
216
Person person = new Person ();
216
217
person .setName (name );
217
218
repository .insert (person );
218
-
219
+
219
220
Integer newAge = randomAge ();
220
221
person .setAge (newAge );
221
222
person .setGender ("F" );
222
223
repository .updateById (person );
223
-
224
+
224
225
Person personDb = repository .selectById (name );
225
-
226
+
226
227
Assert .isTrue (newAge .equals (personDb .getAge ()));
227
228
}
228
229
@@ -266,7 +267,7 @@ public void updateByIdBatch() {
266
267
267
268
List <Person > people = new ArrayList <>();
268
269
people .add (person1 );
269
- people .add (person2 );;
270
+ people .add (person2 );
270
271
people .add (person3 );
271
272
272
273
repository .insertBatch (people );
@@ -276,17 +277,17 @@ public void updateByIdBatch() {
276
277
277
278
Integer newAge2 = randomAge ();
278
279
person2 .setAge (newAge2 );
279
-
280
+
280
281
Integer newAge3 = randomAge ();
281
282
person3 .setAge (newAge3 );
282
-
283
+
283
284
repository .updateByIdBatchSelective (people );
284
-
285
+
285
286
List <String > ids = people .stream ().map (Person ::getName ).collect (Collectors .toList ());
286
287
List <Person > peopleDb = repository .selectByIds (ids );
287
288
288
289
Assert .isTrue (peopleDb .size () == 3 );
289
-
290
+
290
291
for (Person personDb : peopleDb ) {
291
292
for (Person person : people ) {
292
293
if (Objects .equals (personDb .getName (), person .getName ())) {
@@ -330,6 +331,31 @@ public void deleteById() {
330
331
int row = repository .deleteById ("赵小洋" );
331
332
System .out .println (row );
332
333
}
334
+
335
+ @ Test
336
+ public void deleteByIdBatch () {
337
+ long now = System .currentTimeMillis ();
338
+ Person person1 = new Person ();
339
+ person1 .setName ("UBB" + now );
340
+
341
+ Person person2 = new Person ();
342
+ person2 .setName ("UBB" + (now + 1 ));
343
+
344
+ Person person3 = new Person ();
345
+ person3 .setName ("UBB" + (now + 2 ));
346
+
347
+ List <Person > people = new ArrayList <>();
348
+ people .add (person1 );
349
+ people .add (person2 );
350
+ people .add (person3 );
351
+ repository .insertBatch (people );
352
+
353
+ List <String > peopleIds = new ArrayList <>();
354
+ peopleIds .add (person1 .getName ());
355
+ peopleIds .add (person2 .getName ());
356
+ peopleIds .add (person3 .getName ());
357
+ Assert .equals (repository .deleteByIdBatch (peopleIds ),1 );
358
+ }
333
359
// endregion
334
360
335
361
// region graph special
@@ -384,7 +410,7 @@ public void insertEdgeUseNodeId() {
384
410
like .setLikeness (0.202210171102 );
385
411
repository .insertEdge ("吴小极" , like , "刘小洲" );
386
412
}
387
-
413
+
388
414
@ Test
389
415
public void insertEdgeUseNodeId2 () {
390
416
LikeWithRank like = new LikeWithRank ();
@@ -425,6 +451,26 @@ public void insertEdgeSelective() {
425
451
repository .insertEdgeSelective (person1 , likeWithRank , person2 );
426
452
}
427
453
454
+ @ Test
455
+ public void insertEdgeBatch () {
456
+ List <NgTriplet <String >> ngTripletList = new ArrayList <>();
457
+ for (int i = 0 ; i < 3 ; i ++) {
458
+ Person person1 = new Person ();
459
+ person1 .setName ("p1_" + i );
460
+ repository .insertSelective (person1 );
461
+
462
+ Person person2 = new Person ();
463
+ person2 .setName ("p2_" + i );
464
+ repository .insertSelective (person2 );
465
+
466
+ Like like = new Like ();
467
+ like .setLikeness (0.87 );
468
+
469
+ ngTripletList .add (new NgTriplet <>(person1 ,like ,person2 ));
470
+ }
471
+ repository .insertEdgeBatch (ngTripletList );
472
+ }
473
+
428
474
@ Test
429
475
public void upsertEdgeSelective () {
430
476
Person person1 = new Person ();
@@ -460,7 +506,7 @@ public void startNode() {
460
506
Person whoIsStartForTest = repository .startNode (Like .class , "易小海" );
461
507
System .out .println (JSON .toJSONString (whoIsStartForTest ));
462
508
}
463
-
509
+
464
510
@ Test
465
511
public void shortestPath () {
466
512
List <NgPath <String >> ngPaths = repository .shortestPath ("吴小极" , "刘小洲" );
0 commit comments