Skip to content

Commit 1b4d4d7

Browse files
committed
OK
1 parent 989a62a commit 1b4d4d7

32 files changed

+399
-199
lines changed

README.MD

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,19 @@
66

77
[![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=clun_astra-db-java&metric=security_rating)](https://sonarcloud.io/summary/new_code?id=clun_db-java)
88
[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=clun_astra-db-java&metric=sqale_rating)](https://sonarcloud.io/summary/overall?id=clun_astra-db-java)
9-
[![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=clun_astra-db-java&metric=vulnerabilities)](https://sonarcloud.io/summary/overall?id=clun_astra-db-java)
9+
[![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=clun_astra-db-java&metric=reliability_rating)](https://sonarcloud.io/summary/new_code?id=clun_astra-db-java)
1010

1111
[![Bugs](https://sonarcloud.io/api/project_badges/measure?project=clun_astra-db-java&metric=bugs)](https://sonarcloud.io/summary/new_code?id=clun_astra-db-java)
12-
[![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=clun_astra-db-java&metric=reliability_rating)](https://sonarcloud.io/summary/new_code?id=clun_astra-db-java)
12+
[![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=clun_astra-db-java&metric=vulnerabilities)](https://sonarcloud.io/summary/overall?id=clun_astra-db-java)
13+
![GitHub issues](https://img.shields.io/github/issues/datastax/astra-db-java)
14+
[![Duplicated Lines (%)](https://sonarcloud.io/api/project_badges/measure?project=clun_astra-db-java&metric=duplicated_lines_density)](https://sonarcloud.io/summary/new_code?id=clun_astra-db-java)
15+
1316
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=clun_astra-db-java&metric=coverage)](https://sonarcloud.io/summary/new_code?id=clun_astra-db-java)
14-
[![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=clun_astra-db-java&metric=reliability_rating)](https://sonarcloud.io/summary/new_code?id=clun_astra-db-java)
17+
18+
19+
[![Maven Central](https://img.shields.io/maven-central/v/com.datastax.astra/astra-db-java)](https://search.maven.org/artifact/com.datastax.astra/astra-db-java)
20+
21+
1522

1623
This client library provides a simplified way to interact with Data API for AstraDB or local instances. For detailed documentation, each operation comes with a detailed description and examples.
1724

astra-db-java/src/main/java/com/datastax/astra/client/Collection.java

Lines changed: 128 additions & 89 deletions
Large diffs are not rendered by default.

astra-db-java/src/main/java/com/datastax/astra/client/DataAPIOptions.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,14 +194,16 @@ public static class HttpClientOptions {
194194
/**
195195
* Default constructor.
196196
*/
197-
public HttpClientOptions() {}
197+
public HttpClientOptions() {
198+
// left blanks as default values are set
199+
}
198200

199201
}
200202

201203
/**
202204
* Subclass to represent an http proxy.
203205
*/
204-
@Data @AllArgsConstructor
206+
@Data
205207
public static class HttpProxy {
206208

207209
/** hostname of the proxy. */
@@ -212,8 +214,16 @@ public static class HttpProxy {
212214

213215
/**
214216
* Default constructor.
217+
*
218+
* @param hostname
219+
* host name
220+
* @param port
221+
* roxy port
215222
*/
216-
public HttpProxy() {}
223+
public HttpProxy(String hostname, int port) {
224+
this.hostname = hostname;
225+
this.port = port;
226+
}
217227
}
218228

219229

@@ -258,7 +268,9 @@ public static class DataAPIClientOptionsBuilder {
258268
/**
259269
* Default constructor.
260270
*/
261-
public DataAPIClientOptionsBuilder() {}
271+
public DataAPIClientOptionsBuilder() {
272+
// left blanks as default values are set
273+
}
262274

263275
/**
264276
* Builder pattern, update caller information.

astra-db-java/src/main/java/com/datastax/astra/client/Database.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ public Database(String apiEndpoint, String token, String namespace, DataAPIOptio
137137
dbApiEndPointBuilder.append("/api/json");
138138
}
139139
break;
140+
default:
141+
// left blank as local deployments does not require any change
142+
break;
140143
}
141144
this.apiEndpoint = dbApiEndPointBuilder
142145
.append("/")

astra-db-java/src/main/java/com/datastax/astra/client/admin/DataAPIDatabaseAdmin.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@
4444
@Getter
4545
public class DataAPIDatabaseAdmin extends AbstractCommandRunner implements DatabaseAdmin {
4646

47+
/** parameters names. */
48+
private static final String ARG_NAMESPACE = "namespaceName";
49+
4750
/** Version of the API. */
4851
protected final DataAPIOptions options;
4952

@@ -85,21 +88,21 @@ public Set<String> listNamespaceNames() {
8588
/** {@inheritDoc} */
8689
@Override
8790
public Database getDatabase(String namespaceName) {
88-
Assert.hasLength(namespaceName, "namespaceName");
91+
Assert.hasLength(namespaceName, ARG_NAMESPACE);
8992
return new Database(apiEndPoint, token, namespaceName, options);
9093
}
9194

9295
/** {@inheritDoc} */
9396
@Override
9497
public Database getDatabase(String namespaceName, String userToken) {
95-
Assert.hasLength(namespaceName, "namespaceName");
98+
Assert.hasLength(namespaceName, ARG_NAMESPACE);
9699
Assert.hasLength(userToken, "userToken");
97100
return new Database(apiEndPoint, userToken, namespaceName, options);
98101
}
99102

100103
/** {@inheritDoc} */
101104
public void createNamespace(String namespace) {
102-
Assert.hasLength(namespace, "namespace");
105+
Assert.hasLength(namespace, ARG_NAMESPACE);
103106
createNamespace(namespace, NamespaceOptions.simpleStrategy(1));
104107
}
105108

@@ -112,7 +115,7 @@ public void createNamespace(String namespace) {
112115
* options to create a namespace
113116
*/
114117
public void createNamespace(String namespace, NamespaceOptions options) {
115-
hasLength(namespace, "namespace");
118+
hasLength(namespace, ARG_NAMESPACE);
116119
notNull(options, "options");
117120
Command createNamespace = Command
118121
.create("createNamespace")
@@ -124,7 +127,7 @@ public void createNamespace(String namespace, NamespaceOptions options) {
124127

125128
/** {@inheritDoc} */
126129
public void dropNamespace(String namespace) {
127-
hasLength(namespace, "namespace");
130+
hasLength(namespace, ARG_NAMESPACE);
128131
Command dropNamespace = Command
129132
.create("dropNamespace")
130133
.append("name", namespace);

astra-db-java/src/main/java/com/datastax/astra/client/model/BulkWriteOptions.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ public final class BulkWriteOptions {
4141
/**
4242
* Default constructor.
4343
*/
44-
public BulkWriteOptions() {}
44+
public BulkWriteOptions() {
45+
// left blank attributes have default values
46+
}
4547

4648
}

astra-db-java/src/main/java/com/datastax/astra/client/model/CollectionIdTypes.java

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,59 @@
2020
* #L%
2121
*/
2222

23+
import lombok.Getter;
24+
2325
/**
2426
* List of possible types for the collection 'defaultId'.
2527
*/
28+
@Getter
2629
public enum CollectionIdTypes {
2730

28-
/** represent a bson ObjectId. */
29-
objectId,
31+
/**
32+
* Represent a BSON ObjectId.
33+
*/
34+
OBJECT_ID("objectId"),
35+
36+
/**
37+
* UUID in version v6 allowing natural ordering.
38+
*/
39+
UUIDV6("uuidv6"),
40+
41+
/**
42+
* UUID in version v7, random and time-based.
43+
*/
44+
UUIDV7("uuidv7"),
45+
46+
/**
47+
* UUID v4, the default random UUID.
48+
*/
49+
UUID("uuid");
3050

31-
/** uuid in version v6 allowing natural ordering. */
32-
uuidv6,
51+
private final String value;
3352

34-
/** uuid in version v7 random and time-based. */
35-
uuidv7,
53+
/**
54+
* Constructor.
55+
*
56+
* @param value
57+
* value to the types
58+
*/
59+
CollectionIdTypes(String value) {
60+
this.value = value;
61+
}
3662

37-
/** uuid v4, the default random uuid, */
38-
uuid
63+
/**
64+
* Creates a CollectionIdTypes from its string value.
65+
*
66+
* @param value The string value to look for.
67+
* @return The corresponding CollectionIdTypes enum constant.
68+
* @throws IllegalArgumentException if the value does not correspond to any CollectionIdTypes.
69+
*/
70+
public static CollectionIdTypes fromValue(String value) {
71+
for (CollectionIdTypes type : values()) {
72+
if (type.getValue().equals(value)) {
73+
return type;
74+
}
75+
}
76+
throw new IllegalArgumentException("Unknown value: " + value);
77+
}
3978
}

astra-db-java/src/main/java/com/datastax/astra/client/model/CollectionOptions.java

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class CollectionOptions {
3737
/**
3838
* The 'defaultId' to allow working with different types of identifiers.
3939
*/
40-
private Map<String, CollectionIdTypes> defaultId;
40+
private DefaultIdOptions defaultId;
4141

4242
/**
4343
* Vector options.
@@ -52,7 +52,36 @@ public class CollectionOptions {
5252
/**
5353
* Default constructor.
5454
*/
55-
public CollectionOptions() {}
55+
public CollectionOptions() {
56+
// left blank on purpose, built with builder
57+
}
58+
59+
/**
60+
* Subclass representing the indexing options.
61+
*/
62+
@Data
63+
public static class DefaultIdOptions {
64+
65+
/** Type for the default id. */
66+
private String type;
67+
68+
/**
69+
* Default constructor.
70+
*/
71+
public DefaultIdOptions() {
72+
// marshalled by jackson
73+
}
74+
75+
/**
76+
* Default constructor.
77+
*
78+
* @param type
79+
* type for the default id
80+
*/
81+
public DefaultIdOptions(String type) {
82+
this.type = type;
83+
}
84+
}
5685

5786
/**
5887
* Subclass representing the indexing options.
@@ -190,7 +219,7 @@ public static class CollectionOptionsBuilder {
190219
/**
191220
* Options for Default Id
192221
*/
193-
CollectionIdTypes defaultId;
222+
String defaultId;
194223

195224
/**
196225
* Access the vector options.
@@ -231,8 +260,8 @@ public CollectionOptionsBuilder() {}
231260
* @return
232261
* self reference
233262
*/
234-
public CollectionOptionsBuilder defaultId(CollectionIdTypes idType) {
235-
this.defaultId = idType;
263+
public CollectionOptionsBuilder defaultIdType(CollectionIdTypes idType) {
264+
this.defaultId = idType.getValue();
236265
return this;
237266
}
238267

@@ -327,7 +356,7 @@ public CollectionOptions build() {
327356
req.vector = this.vector;
328357
req.indexing = this.indexing;
329358
if (defaultId != null) {
330-
req.defaultId = Map.of("type", this.defaultId);
359+
req.defaultId = new DefaultIdOptions(defaultId);
331360
}
332361
return req;
333362
}

astra-db-java/src/main/java/com/datastax/astra/client/model/FilterKeyword.java renamed to astra-db-java/src/main/java/com/datastax/astra/client/model/DataAPIKeywords.java

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,39 @@
3636
* #L%
3737
*/
3838

39+
import lombok.Getter;
40+
3941
/**
4042
* Constants in the JSON API.
4143
*/
42-
public enum FilterKeyword {
44+
@Getter
45+
public enum DataAPIKeywords {
46+
47+
/**
48+
* ID.
49+
*/
50+
ID("_id"),
4351

4452
/**
4553
* ALL.
4654
*/
4755
ALL("$all"),
4856

57+
/**
58+
* ALL.
59+
*/
60+
DATE("$date"),
61+
62+
/**
63+
* UUID
64+
*/
65+
UUID("$uuid"),
66+
67+
/**
68+
* OBJECT_ID.
69+
*/
70+
OBJECT_ID("$objectId"),
71+
4972
/**
5073
* SIZE.
5174
*/
@@ -82,16 +105,7 @@ public enum FilterKeyword {
82105
* @param op
83106
* current operator
84107
*/
85-
FilterKeyword(String op) {
108+
DataAPIKeywords(String op) {
86109
this.keyword = op;
87110
}
88-
89-
/**
90-
* Gets keyword
91-
*
92-
* @return value of keyword
93-
*/
94-
public String getKeyword() {
95-
return keyword;
96-
}
97111
}

astra-db-java/src/main/java/com/datastax/astra/client/model/DeleteOneOptions.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ public class DeleteOneOptions {
3737
/**
3838
* Default constructor.
3939
*/
40-
public DeleteOneOptions() {}
40+
public DeleteOneOptions() {
41+
// Left blank as sort is populated in static way
42+
}
4143

4244
/**
4345
* Syntax sugar as delete option is only a sort

0 commit comments

Comments
 (0)