@@ -53,7 +53,7 @@ public class ImmuClient {
5353
5454 private static final String AUTH_HEADER = "authorization" ;
5555 private final ImmuServiceGrpc .ImmuServiceBlockingStub stub ;
56- private final boolean withAuthToken ;
56+ private final boolean withAuth ;
5757 private final ImmuStateHolder stateHolder ;
5858 private ManagedChannel channel ;
5959 private String authToken ;
@@ -62,7 +62,7 @@ public class ImmuClient {
6262
6363 public ImmuClient (Builder builder ) {
6464 this .stub = createStubFrom (builder );
65- this .withAuthToken = builder .isWithAuthToken ();
65+ this .withAuth = builder .isWithAuth ();
6666 this .stateHolder = builder .getStateHolder ();
6767 }
6868
@@ -111,7 +111,7 @@ public synchronized boolean isShutdown() {
111111 }
112112
113113 private ImmuServiceGrpc .ImmuServiceBlockingStub getStub () {
114- if (!withAuthToken || authToken == null ) {
114+ if (!withAuth || authToken == null ) {
115115 return stub ;
116116 }
117117 Metadata metadata = new Metadata ();
@@ -377,18 +377,28 @@ public Entry verifiedGetSince(byte[] key, long txId) throws VerificationExceptio
377377 // ========== HISTORY ==========
378378 //
379379
380- public List <KV > history (String key , int limit , long offset , boolean reverse ) {
381- return history (key .getBytes (StandardCharsets .UTF_8 ), limit , offset , reverse );
380+
381+ public List <KV > history (String key , int limit , long offset , boolean desc ) {
382+ return history (key .getBytes (StandardCharsets .UTF_8 ), limit , offset , desc );
383+ }
384+
385+ public List <KV > history (byte [] key , int limit , long offset , boolean desc ) {
386+ return history (key , limit , offset , desc , 1 );
382387 }
383388
384- public List <KV > history (byte [] key , int limit , long offset , boolean reverse ) {
389+ public List <KV > history (String key , int limit , long offset , boolean desc , long sinceTxId ) {
390+ return history (key .getBytes (StandardCharsets .UTF_8 ), limit , offset , desc , sinceTxId );
391+ }
392+
393+ public List <KV > history (byte [] key , int limit , long offset , boolean desc , long sinceTxId ) {
385394 ImmudbProto .Entries entries ;
386395 try {
387396 entries = getStub ().history (ImmudbProto .HistoryRequest .newBuilder ()
388397 .setKey (ByteString .copyFrom (key ))
389398 .setLimit (limit )
390399 .setOffset (offset )
391- .setDesc (reverse )
400+ .setDesc (desc )
401+ .setSinceTx (sinceTxId )
392402 .build ()
393403 );
394404 } catch (StatusRuntimeException e ) {
@@ -401,26 +411,45 @@ public List<KV> history(byte[] key, int limit, long offset, boolean reverse) {
401411 // ========== SCAN ==========
402412 //
403413
404- public List <KV > scan (String key ) {
405- return scan (ByteString .copyFrom (key , StandardCharsets .UTF_8 ).toByteArray ());
414+ public List <KV > scan (String prefix ) {
415+ return scan (ByteString .copyFrom (prefix , StandardCharsets .UTF_8 ).toByteArray ());
416+ }
417+
418+ public List <KV > scan (String prefix , long sinceTxId , long limit , boolean desc ) {
419+ return scan (ByteString .copyFrom (prefix , StandardCharsets .UTF_8 ).toByteArray (), sinceTxId , limit , desc );
406420 }
407421
408- public List <KV > scan (String key , long sinceTxId , long limit , boolean reverse ) {
409- return scan (ByteString .copyFrom (key , StandardCharsets .UTF_8 ).toByteArray (), sinceTxId , limit , reverse );
422+ public List <KV > scan (String prefix , String seekKey , long sinceTxId , long limit , boolean desc ) {
423+ return scan (
424+ ByteString .copyFrom (prefix , StandardCharsets .UTF_8 ).toByteArray (),
425+ ByteString .copyFrom (seekKey , StandardCharsets .UTF_8 ).toByteArray (),
426+ sinceTxId , limit , desc );
410427 }
411428
412- public List <KV > scan (byte [] key ) {
413- ScanRequest req = ScanRequest .newBuilder ().setPrefix (ByteString .copyFrom (key )).build ();
429+ public List <KV > scan (byte [] prefix ) {
430+ ScanRequest req = ScanRequest .newBuilder ().setPrefix (ByteString .copyFrom (prefix )).build ();
414431 ImmudbProto .Entries entries = getStub ().scan (req );
415432 return buildList (entries );
416433 }
417434
418- public List <KV > scan (byte [] key , long sinceTxId , long limit , boolean reverse ) {
435+ public List <KV > scan (byte [] prefix , long sinceTxId , long limit , boolean desc ) {
419436 ScanRequest req = ScanRequest .newBuilder ()
420- .setPrefix (ByteString .copyFrom (key ))
437+ .setPrefix (ByteString .copyFrom (prefix ))
421438 .setLimit (limit )
422439 .setSinceTx (sinceTxId )
423- .setDesc (reverse )
440+ .setDesc (desc )
441+ .build ();
442+ ImmudbProto .Entries entries = getStub ().scan (req );
443+ return buildList (entries );
444+ }
445+
446+ public List <KV > scan (byte [] prefix , byte [] seekKey , long sinceTxId , long limit , boolean desc ) {
447+ ScanRequest req = ScanRequest .newBuilder ()
448+ .setPrefix (ByteString .copyFrom (prefix ))
449+ .setLimit (limit )
450+ .setSeekKey (ByteString .copyFrom (seekKey ))
451+ .setSinceTx (sinceTxId )
452+ .setDesc (desc )
424453 .build ();
425454 ImmudbProto .Entries entries = getStub ().scan (req );
426455 return buildList (entries );
@@ -800,12 +829,12 @@ public List<Tx> txScan(long initialTxId) {
800829 return buildList (txList );
801830 }
802831
803- public List <Tx > txScan (long initialTxId , int limit , boolean reverse ) {
832+ public List <Tx > txScan (long initialTxId , int limit , boolean desc ) {
804833 ImmudbProto .TxScanRequest req = ImmudbProto .TxScanRequest
805834 .newBuilder ()
806835 .setInitialTx (initialTxId )
807836 .setLimit (limit )
808- .setDesc (reverse )
837+ .setDesc (desc )
809838 .build ();
810839 ImmudbProto .TxList txList = getStub ().txScan (req );
811840 return buildList (txList );
@@ -892,6 +921,15 @@ public void changePassword(String user, String oldPassword, String newPassword)
892921 getStub ().changePassword (changePasswordRequest );
893922 }
894923
924+ //
925+ // ========== USER MGMT ==========
926+ //
927+
928+ public void cleanIndex () {
929+ //noinspection ResultOfMethodCallIgnored
930+ getStub ().cleanIndex (Empty .getDefaultInstance ());
931+ }
932+
895933 //
896934 // ========== INTERNAL UTILS ==========
897935 //
@@ -932,15 +970,15 @@ public static class Builder {
932970
933971 private int serverPort ;
934972
935- private boolean withAuthToken ;
973+ private boolean withAuth ;
936974
937975 private ImmuStateHolder stateHolder ;
938976
939977 private Builder () {
940978 this .serverUrl = "localhost" ;
941979 this .serverPort = 3322 ;
942980 this .stateHolder = new SerializableImmuStateHolder ();
943- this .withAuthToken = true ;
981+ this .withAuth = true ;
944982 }
945983
946984 public ImmuClient build () {
@@ -965,12 +1003,12 @@ public Builder withServerPort(int serverPort) {
9651003 return this ;
9661004 }
9671005
968- public boolean isWithAuthToken () {
969- return withAuthToken ;
1006+ public boolean isWithAuth () {
1007+ return withAuth ;
9701008 }
9711009
972- public Builder withAuthToken (boolean withAuthToken ) {
973- this .withAuthToken = withAuthToken ;
1010+ public Builder withAuth (boolean withAuth ) {
1011+ this .withAuth = withAuth ;
9741012 return this ;
9751013 }
9761014
0 commit comments