Skip to content

Commit 845b5e0

Browse files
authored
Merge pull request #251 from eclipse/update-api
Update API make it ready for Java 17/21
2 parents dd8ab21 + 662ecc5 commit 845b5e0

File tree

39 files changed

+140
-551
lines changed

39 files changed

+140
-551
lines changed

jnosql-cassandra/src/main/java/org/eclipse/jnosql/databases/cassandra/communication/CassandraConverter.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,17 @@ public static ColumnEntity toDocumentEntity(Row row) {
5858
private static Column getColumn(ColumnDefinition definition, Object result) {
5959

6060
final DataType type = definition.getType();
61-
switch (type.getProtocolCode()) {
62-
case ProtocolConstants.DataType.UDT:
63-
return Column.class.cast(result);
64-
case ProtocolConstants.DataType.LIST:
65-
case ProtocolConstants.DataType.SET:
61+
return switch (type.getProtocolCode()) {
62+
case ProtocolConstants.DataType.UDT -> Column.class.cast(result);
63+
case ProtocolConstants.DataType.LIST, ProtocolConstants.DataType.SET -> {
6664
if (isUDTIterable(result)) {
67-
return UDT.builder(getUserType(result)).withName(definition.getName().asInternal())
65+
yield UDT.builder(getUserType(result)).withName(definition.getName().asInternal())
6866
.addUDTs(getColumns(definition, result)).build();
6967
}
70-
return Column.of(definition.getName().asInternal(), Value.of(result));
71-
default:
72-
return Column.of(definition.getName().asInternal(), Value.of(result));
73-
}
68+
yield Column.of(definition.getName().asInternal(), Value.of(result));
69+
}
70+
default -> Column.of(definition.getName().asInternal(), Value.of(result));
71+
};
7472
}
7573

7674
static Object get(ColumnDefinition definition, Row row) {

jnosql-cassandra/src/main/java/org/eclipse/jnosql/databases/cassandra/communication/DefaultUDT.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,9 @@ public boolean equals(Object o) {
7777
if (this == o) {
7878
return true;
7979
}
80-
if (!(o instanceof UDT)) {
80+
if (!(o instanceof UDT udt)) {
8181
return false;
8282
}
83-
UDT udt = (UDT) o;
8483
return Objects.equals(name, udt.name()) &&
8584
Objects.equals(userType, udt.getUserType()) &&
8685
Objects.equals(columns, udt.get());

jnosql-cassandra/src/main/java/org/eclipse/jnosql/databases/cassandra/communication/IterableUDT.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,9 @@ public boolean equals(Object o) {
7575
if (this == o) {
7676
return true;
7777
}
78-
if (!(o instanceof UDT)) {
78+
if (!(o instanceof UDT udt)) {
7979
return false;
8080
}
81-
UDT udt = (UDT) o;
8281
return Objects.equals(name, udt.name()) &&
8382
Objects.equals(userType, udt.getUserType()) &&
8483
Objects.equals(columns, udt.get());

jnosql-cassandra/src/test/java/org/eclipse/jnosql/databases/cassandra/mapping/Address.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ public void setStreet(String street) {
4747
@Override
4848
public boolean equals(Object o) {
4949
if (this == o) return true;
50-
if (!(o instanceof Address)) return false;
51-
Address address = (Address) o;
50+
if (!(o instanceof Address address)) return false;
5251
return Objects.equals(city, address.city) &&
5352
Objects.equals(street, address.street);
5453
}

jnosql-cassandra/src/test/java/org/eclipse/jnosql/databases/cassandra/mapping/model/Money.java

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,7 @@
1818
import java.math.BigDecimal;
1919
import java.util.Objects;
2020

21-
public class Money {
22-
23-
private final String currency;
24-
25-
private final BigDecimal value;
26-
27-
public Money(String currency, BigDecimal value) {
28-
this.currency = currency;
29-
this.value = value;
30-
}
31-
32-
public String getCurrency() {
33-
return currency;
34-
}
35-
36-
public BigDecimal getValue() {
37-
return value;
38-
}
21+
public record Money(String currency, BigDecimal value) {
3922

4023
@Override
4124
public boolean equals(Object o) {

jnosql-couchbase/src/main/java/org/eclipse/jnosql/databases/couchbase/communication/DefaultCouchbaseDocumentManager.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public Stream<DocumentEntity> select(final DocumentQuery query) throws NullPoint
162162
List<JsonObject> jsons = new ArrayList<>();
163163
if (n1QLQuery.hasIds()) {
164164
Collection collection = bucket.collection(query.name());
165-
for (String id : n1QLQuery.getIds()) {
165+
for (String id : n1QLQuery.ids()) {
166166
try {
167167
GetResult result = collection.get(id);
168168
jsons.add(result.contentAsObject());
@@ -175,10 +175,10 @@ public Stream<DocumentEntity> select(final DocumentQuery query) throws NullPoint
175175
if (!n1QLQuery.hasOnlyIds()) {
176176
QueryResult result;
177177
if (n1QLQuery.hasParameter()) {
178-
result = cluster.query(n1QLQuery.getQuery());
178+
result = cluster.query(n1QLQuery.query());
179179
} else {
180-
result = cluster.query(n1QLQuery.getQuery(), QueryOptions
181-
.queryOptions().parameters(n1QLQuery.getParams()));
180+
result = cluster.query(n1QLQuery.query(), QueryOptions
181+
.queryOptions().parameters(n1QLQuery.params()));
182182
}
183183
jsons.addAll(result.rowsAsObject());
184184
}
@@ -194,7 +194,7 @@ public long count(String documentCollection) {
194194
.select("COUNT(*)").from(documentCollection).build();
195195
N1QLQuery n1QLQuery = N1QLBuilder
196196
.of(countQuery, database, bucket.defaultScope().name()).get();
197-
QueryResult query = cluster.query(n1QLQuery.getQuery());
197+
QueryResult query = cluster.query(n1QLQuery.query());
198198
List<JsonObject> result = query.rowsAsObject();
199199
var count = result.stream().findFirst()
200200
.map(data -> data.getNumber("$1"))

jnosql-couchbase/src/main/java/org/eclipse/jnosql/databases/couchbase/communication/N1QLQuery.java

Lines changed: 3 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,11 @@
1818

1919
import java.util.Collections;
2020
import java.util.List;
21-
import java.util.Objects;
2221

23-
final class N1QLQuery {
22+
record N1QLQuery(String query, JsonObject params, List<String> ids) {
2423

25-
private final String query;
26-
27-
private final JsonObject params;
28-
29-
private final List<String> ids;
30-
31-
N1QLQuery(String query, JsonObject params, List<String> ids) {
32-
this.query = query;
33-
this.params = params;
34-
this.ids = ids;
35-
}
36-
37-
public String getQuery() {
38-
return query;
39-
}
40-
41-
public JsonObject getParams() {
42-
return params;
43-
}
44-
45-
public List<String> getIds() {
24+
@Override
25+
public List<String> ids() {
4626
return Collections.unmodifiableList(ids);
4727
}
4828

@@ -58,24 +38,6 @@ public boolean hasIds() {
5838
return !this.ids.isEmpty();
5939
}
6040

61-
@Override
62-
public boolean equals(Object o) {
63-
if (this == o) {
64-
return true;
65-
}
66-
if (o == null || getClass() != o.getClass()) {
67-
return false;
68-
}
69-
N1QLQuery n1QLQuery = (N1QLQuery) o;
70-
return Objects.equals(query, n1QLQuery.query) && Objects.equals(params, n1QLQuery.params)
71-
&& Objects.equals(ids, n1QLQuery.ids);
72-
}
73-
74-
@Override
75-
public int hashCode() {
76-
return Objects.hash(query, params, ids);
77-
}
78-
7941
@Override
8042
public String toString() {
8143
return "N1QLQuery{" +

jnosql-database-commons/src/test/java/org/eclipse/jnosql/communication/driver/User.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,9 @@ public boolean equals(Object o) {
3636
if (this == o) {
3737
return true;
3838
}
39-
if (!(o instanceof User)) {
39+
if (!(o instanceof User user)) {
4040
return false;
4141
}
42-
User user = (User) o;
4342
return Objects.equals(name, user.name) &&
4443
Objects.equals(age, user.age);
4544
}

jnosql-dynamodb/src/main/java/org/eclipse/jnosql/databases/dynamodb/communication/DynamoDBBuilderASync.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ public void profile(String profile) {
5353

5454
public DynamoDbAsyncClient build() {
5555

56-
boolean accessKey = awsAccessKey != null && !awsAccessKey.equals("");
57-
boolean secretAccess = awsSecretAccess != null && !awsSecretAccess.equals("");
56+
boolean accessKey = awsAccessKey != null && !awsAccessKey.isEmpty();
57+
boolean secretAccess = awsSecretAccess != null && !awsSecretAccess.isEmpty();
5858

5959
if (accessKey && secretAccess) {
6060

jnosql-dynamodb/src/main/java/org/eclipse/jnosql/databases/dynamodb/communication/DynamoDBBuilderSync.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ public void profile(String profile) {
5353

5454
public DynamoDbClient build() {
5555

56-
boolean accessKey = awsAccessKey != null && !awsAccessKey.equals("");
57-
boolean secretAccess = awsSecretAccess != null && !awsSecretAccess.equals("");
56+
boolean accessKey = awsAccessKey != null && !awsAccessKey.isEmpty();
57+
boolean secretAccess = awsSecretAccess != null && !awsSecretAccess.isEmpty();
5858

5959

6060
if (accessKey && secretAccess) {

0 commit comments

Comments
 (0)