Skip to content

Commit 0765f2e

Browse files
committed
feat: KV has also txId, builders "with" standard methods, version bump to 0.9.0.4
1 parent 9588a6a commit 0765f2e

File tree

9 files changed

+46
-21
lines changed

9 files changed

+46
-21
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ Just include immudb4j as a dependency in your project:
5555
<dependency>
5656
<groupId>io.codenotary</groupId>
5757
<artifactId>immudb4j</artifactId>
58-
<version>0.9.0.3</version>
58+
<version>0.9.0.4</version>
5959
</dependency>
6060
```
6161
- if using Gradle:
6262
```groovy
63-
compile 'io.codenotary:immudb4j:0.9.0.3'
63+
compile 'io.codenotary:immudb4j:0.9.0.4'
6464
```
6565

6666
`immudb4j` is currently hosted on both [Maven Central] and [Github Packages].
@@ -103,19 +103,19 @@ Using default configuration:
103103
Setting `immudb` url and port:
104104
```java
105105
ImmuClient immuClient = ImmuClient.newBuilder()
106-
.setServerUrl("localhost")
107-
.setServerPort(3322)
106+
.withServerUrl("localhost")
107+
.withServerPort(3322)
108108
.build();
109109
```
110110

111111
Customizing the `State Holder`:
112112
```java
113113
FileImmuStateHolder stateHolder = FileImmuStateHolder.newBuilder()
114-
.setStatesFolder("./my_immuapp_roots")
114+
.withStatesFolder("./my_immuapp_states")
115115
.build();
116116

117117
ImmuClient immuClient = ImmuClient.newBuilder()
118-
.setStateHolder(stateHolder)
118+
.withStateHolder(stateHolder)
119119
.build();
120120
```
121121

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ apply plugin: 'signing'
3838

3939
group = 'io.codenotary'
4040
archivesBaseName = 'immudb4j'
41-
version = '0.9.0.3'
41+
version = '0.9.0.4'
4242

4343
sourceCompatibility = 1.8
4444
targetCompatibility = 1.8

src/main/java/io/codenotary/immudb4j/FileImmuStateHolder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public FileImmuStateHolder build() throws IOException, IllegalStateException {
115115
return new FileImmuStateHolder(this);
116116
}
117117

118-
public Builder setStatesFolder(String statesFolder) {
118+
public Builder withStatesFolder(String statesFolder) {
119119
this.statesFolder = statesFolder;
120120
return this;
121121
}

src/main/java/io/codenotary/immudb4j/ImmuClient.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,7 @@ public String getServerUrl() {
951951
return this.serverUrl;
952952
}
953953

954-
public Builder setServerUrl(String serverUrl) {
954+
public Builder withServerUrl(String serverUrl) {
955955
this.serverUrl = serverUrl;
956956
return this;
957957
}
@@ -960,7 +960,7 @@ public int getServerPort() {
960960
return serverPort;
961961
}
962962

963-
public Builder setServerPort(int serverPort) {
963+
public Builder withServerPort(int serverPort) {
964964
this.serverPort = serverPort;
965965
return this;
966966
}
@@ -969,7 +969,7 @@ public boolean isWithAuthToken() {
969969
return withAuthToken;
970970
}
971971

972-
public Builder setWithAuthToken(boolean withAuthToken) {
972+
public Builder withAuthToken(boolean withAuthToken) {
973973
this.withAuthToken = withAuthToken;
974974
return this;
975975
}
@@ -978,7 +978,7 @@ public ImmuStateHolder getStateHolder() {
978978
return stateHolder;
979979
}
980980

981-
public Builder setStateHolder(ImmuStateHolder stateHolder) {
981+
public Builder withStateHolder(ImmuStateHolder stateHolder) {
982982
this.stateHolder = stateHolder;
983983
return this;
984984
}

src/main/java/io/codenotary/immudb4j/KV.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public interface KV {
1919

2020
byte[] getKey();
2121
byte[] getValue();
22+
long getTxId();
2223

2324
byte[] digest();
2425

src/main/java/io/codenotary/immudb4j/KVPair.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,35 @@ public class KVPair implements KV {
2828

2929
private final byte[] key;
3030
private final byte[] value;
31+
private final long txId;
3132

3233
public static KV from(ImmudbProto.Entry entry) {
33-
return new KVPair(entry.getKey().toByteArray(), entry.getValue().toByteArray());
34+
return new KVPair(entry.getKey().toByteArray(),
35+
entry.getValue().toByteArray(),
36+
entry.getTx()
37+
);
3438
}
3539

3640
public static KV from(ImmudbProto.ZEntry zEntry) {
3741
return KVPair.from(zEntry.getEntry());
3842
}
3943

40-
public KVPair(byte[] key, byte[] value) {
44+
public KVPair(byte[] key, byte[] value, long txId) {
4145
this.key = key;
4246
this.value = value;
47+
this.txId = txId;
4348
}
4449

4550
public KVPair(String key, byte[] value) {
4651
this.key = key.getBytes(StandardCharsets.UTF_8);
4752
this.value = value;
53+
this.txId = 0;
54+
}
55+
56+
public KVPair(byte[] key, byte[] value) {
57+
this.key = key;
58+
this.value = value;
59+
this.txId = 0;
4860
}
4961

5062
@Override
@@ -57,6 +69,11 @@ public byte[] getValue() {
5769
return this.value;
5870
}
5971

72+
@Override
73+
public long getTxId() {
74+
return this.txId;
75+
}
76+
6077
@Override
6178
public byte[] digest() {
6279
byte[] b = new byte[key.length + Consts.SHA256_SIZE];

src/test/java/io/codenotary/immudb4j/FileImmuStateHolderTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import java.nio.charset.StandardCharsets;
99
import java.nio.file.Files;
1010
import java.nio.file.Path;
11-
import java.nio.file.attribute.FileAttribute;
1211

1312
public class FileImmuStateHolderTest {
1413

@@ -24,7 +23,7 @@ public void t1() {
2423
// Write some fake "state_..." into "current_state" file.
2524
Files.write(currStateFile.toPath(), "state_fake".getBytes(StandardCharsets.UTF_8));
2625

27-
FileImmuStateHolder.newBuilder().setStatesFolder(statesDir.getAbsolutePath()).build();
26+
FileImmuStateHolder.newBuilder().withStatesFolder(statesDir.getAbsolutePath()).build();
2827

2928
cleanupDir(statesDir);
3029
Assert.fail("stateHolder creation must have fail, but it didn't.");

src/test/java/io/codenotary/immudb4j/ImmuClientIntegrationTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ public abstract class ImmuClientIntegrationTest {
2727
@BeforeClass
2828
public static void beforeClass() throws IOException {
2929
FileImmuStateHolder stateHolder = FileImmuStateHolder.newBuilder()
30-
.setStatesFolder("immudb/states")
30+
.withStatesFolder("immudb/states")
3131
.build();
3232

3333
immuClient = ImmuClient.newBuilder()
34-
.setStateHolder(stateHolder)
35-
.setServerUrl("localhost")
36-
.setServerPort(3322)
37-
.setWithAuthToken(true)
34+
.withStateHolder(stateHolder)
35+
.withServerUrl("localhost")
36+
.withServerPort(3322)
37+
.withAuthToken(true)
3838
.build();
3939
}
4040

src/test/java/io/codenotary/immudb4j/KVPairTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public class KVPairTest {
99

1010
@Test
1111
public void t1() {
12+
1213
byte[] key = "someKey".getBytes(StandardCharsets.UTF_8);
1314
byte[] val = "someVal".getBytes(StandardCharsets.UTF_8);
1415

@@ -18,9 +19,16 @@ public void t1() {
1819
Assert.assertEquals(kv1.getKey(), key);
1920
Assert.assertEquals(kv1.getValue(), val);
2021
Assert.assertEquals(kv1.hashCode(), kv2.hashCode());
22+
Assert.assertEquals(kv1.getTxId(), kv2.getTxId());
23+
2124
Assert.assertEquals(kv1, kv2);
2225

2326
Assert.assertEquals(kv1.digest().length, Consts.SHA256_SIZE);
27+
28+
long txId = 123;
29+
KV kv3 = new KVPair(key, val, txId);
30+
Assert.assertEquals(kv3.getTxId(), txId);
31+
2432
}
2533

2634
}

0 commit comments

Comments
 (0)