@@ -464,16 +464,17 @@ public boolean exists(Get get) throws IOException {
464
464
465
465
@ Override
466
466
public boolean [] existsAll (List <Get > gets ) throws IOException {
467
- if (gets .isEmpty ()) {
468
- return new boolean [] {};
469
- }
470
- if (gets .size () == 1 ) {
471
- return new boolean [] { exists (gets .get (0 )) };
472
- }
473
- Result [] r = get (gets );
474
- boolean [] ret = new boolean [r .length ];
475
- for (int i = 0 ; i < gets .size (); ++i ) {
476
- ret [i ] = exists (gets .get (i ));
467
+ boolean [] ret = new boolean [gets .size ()];
468
+ if (CompatibilityUtil .isBatchSupport ()) {
469
+ Result [] results = new Result [gets .size ()];
470
+ batch (gets , results );
471
+ for (int i = 0 ; i < gets .size (); ++i ) {
472
+ ret [i ] = !results [i ].isEmpty ();
473
+ }
474
+ } else {
475
+ for (int i = 0 ; i < gets .size (); ++i ) {
476
+ ret [i ] = exists (gets .get (i ));
477
+ }
477
478
}
478
479
return ret ;
479
480
}
@@ -933,17 +934,21 @@ public Result call() throws IOException {
933
934
@ Override
934
935
public Result [] get (List <Get > gets ) throws IOException {
935
936
Result [] results = new Result [gets .size ()];
936
- List <Future <Result >> futures = new LinkedList <>();
937
- for (int i = 0 ; i < gets .size (); i ++) {
938
- int index = i ;
939
- Future <Result > future = executePool .submit (() -> get (gets .get (index )));
940
- futures .add (future );
941
- }
942
- for (int i = 0 ; i < gets .size (); i ++) {
943
- try {
944
- results [i ] = futures .get (i ).get ();
945
- } catch (Exception e ) {
946
- throw new RuntimeException ("gets occur error. index:{" + i + "}" , e );
937
+ if (CompatibilityUtil .isBatchSupport ()) { // get only supported in BatchSupport version
938
+ batch (gets , results );
939
+ } else {
940
+ List <Future <Result >> futures = new LinkedList <>();
941
+ for (int i = 0 ; i < gets .size (); i ++) {
942
+ int index = i ;
943
+ Future <Result > future = executePool .submit (() -> get (gets .get (index )));
944
+ futures .add (future );
945
+ }
946
+ for (int i = 0 ; i < gets .size (); i ++) {
947
+ try {
948
+ results [i ] = futures .get (i ).get ();
949
+ } catch (Exception e ) {
950
+ throw new RuntimeException ("gets occur error. index:{" + i + "}" , e );
951
+ }
947
952
}
948
953
}
949
954
return results ;
0 commit comments