Skip to content

Commit 5e59f09

Browse files
committed
First stab to 2.0, removing namespaces, bulkwrite, add new headers
1 parent a111a44 commit 5e59f09

File tree

82 files changed

+833
-1366
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+833
-1366
lines changed

README.MD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ import com.datastax.astra.client.Database;
147147
import com.datastax.astra.client.model.Document;
148148
import com.datastax.astra.client.model.FindIterable;
149149
import java.util.List;
150-
import static com.datastax.astra.client.model.Filters.eq;
150+
import static com.datastax.astra.client.model.query.Filters.eq;
151151
import static com.datastax.astra.client.model.SimilarityMetric.cosine;
152152

153153
public class GettingStarted {

astra-db-java/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<parent>
99
<groupId>com.datastax.astra</groupId>
1010
<artifactId>astra-db-java-parent</artifactId>
11-
<version>1.5.3-SNAPSHOT</version>
11+
<version>2.0.0-SNAPSHOT</version>
1212
</parent>
1313

1414
<properties>

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

Lines changed: 16 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,16 @@
2323
import com.datastax.astra.client.exception.DataAPIFaultyResponseException;
2424
import com.datastax.astra.client.exception.DataApiException;
2525
import com.datastax.astra.client.exception.TooManyDocumentsToCountException;
26-
import com.datastax.astra.client.model.BulkWriteOptions;
27-
import com.datastax.astra.client.model.BulkWriteResult;
2826
import com.datastax.astra.client.model.CollectionIdTypes;
2927
import com.datastax.astra.client.model.CollectionInfo;
3028
import com.datastax.astra.client.model.CollectionOptions;
31-
import com.datastax.astra.client.model.Command;
32-
import com.datastax.astra.client.model.CommandOptions;
3329
import com.datastax.astra.client.model.CountDocumentsOptions;
34-
import com.datastax.astra.client.model.DataAPIKeywords;
3530
import com.datastax.astra.client.model.DeleteManyOptions;
3631
import com.datastax.astra.client.model.DeleteOneOptions;
3732
import com.datastax.astra.client.model.DeleteResult;
3833
import com.datastax.astra.client.model.DistinctIterable;
3934
import com.datastax.astra.client.model.Document;
4035
import com.datastax.astra.client.model.EstimatedCountDocumentsOptions;
41-
import com.datastax.astra.client.model.Filter;
42-
import com.datastax.astra.client.model.Filters;
4336
import com.datastax.astra.client.model.FindIterable;
4437
import com.datastax.astra.client.model.FindOneAndDeleteOptions;
4538
import com.datastax.astra.client.model.FindOneAndReplaceOptions;
@@ -51,16 +44,21 @@
5144
import com.datastax.astra.client.model.InsertManyResult;
5245
import com.datastax.astra.client.model.InsertOneOptions;
5346
import com.datastax.astra.client.model.InsertOneResult;
54-
import com.datastax.astra.client.model.ObjectId;
5547
import com.datastax.astra.client.model.Page;
5648
import com.datastax.astra.client.model.ReplaceOneOptions;
5749
import com.datastax.astra.client.model.ReturnDocument;
58-
import com.datastax.astra.client.model.UUIDv6;
59-
import com.datastax.astra.client.model.UUIDv7;
6050
import com.datastax.astra.client.model.Update;
6151
import com.datastax.astra.client.model.UpdateManyOptions;
6252
import com.datastax.astra.client.model.UpdateOneOptions;
6353
import com.datastax.astra.client.model.UpdateResult;
54+
import com.datastax.astra.client.model.command.Command;
55+
import com.datastax.astra.client.model.command.CommandOptions;
56+
import com.datastax.astra.client.model.query.Filter;
57+
import com.datastax.astra.client.model.query.Filters;
58+
import com.datastax.astra.client.model.types.DataAPIKeywords;
59+
import com.datastax.astra.client.model.types.ObjectId;
60+
import com.datastax.astra.client.model.types.UUIDv6;
61+
import com.datastax.astra.client.model.types.UUIDv7;
6462
import com.datastax.astra.internal.api.ApiResponse;
6563
import com.datastax.astra.internal.command.AbstractCommandRunner;
6664
import com.datastax.astra.internal.command.CommandObserver;
@@ -89,7 +87,7 @@
8987

9088
import static com.datastax.astra.client.exception.DataApiException.ERROR_CODE_INTERRUPTED;
9189
import static com.datastax.astra.client.exception.DataApiException.ERROR_CODE_TIMEOUT;
92-
import static com.datastax.astra.client.model.DataAPIKeywords.SORT_VECTOR;
90+
import static com.datastax.astra.client.model.types.DataAPIKeywords.SORT_VECTOR;
9391
import static com.datastax.astra.internal.utils.AnsiUtils.cyan;
9492
import static com.datastax.astra.internal.utils.AnsiUtils.green;
9593
import static com.datastax.astra.internal.utils.AnsiUtils.magenta;
@@ -260,32 +258,6 @@ protected Collection(Database db, String collectionName, CommandOptions<?> comma
260258
// --- Global Information ----
261259
// ----------------------------
262260

263-
/**
264-
* Retrieves the name of the parent namespace associated with this collection. A namespace in
265-
* this context typically refers to a higher-level categorization or grouping mechanism within
266-
* the database that encompasses one or more collections. This method allows for identifying
267-
* the broader context in which this collection exists, which can be useful for operations
268-
* requiring knowledge of the database structure or for dynamic database interaction patterns.
269-
*
270-
* @return A {@code String} representing the name of the parent namespace of the current
271-
* collection. This name serves as an identifier for the namespace and can be used
272-
* to navigate or query the database structure.
273-
*
274-
* <p>Example usage:</p>
275-
* <pre>
276-
* {@code
277-
* Collection myCollection = ... // assume myCollection is already initialized
278-
* String namespaceName = myCollection.getNamespaceName();
279-
* System.out.println("The collection belongs to the namespace: " + namespaceName);
280-
* }
281-
* </pre>
282-
* @deprecated use {@link #getKeyspaceName()} instead
283-
*/
284-
@Deprecated
285-
public String getNamespaceName() {
286-
return getDatabase().getKeyspaceName();
287-
}
288-
289261
/**
290262
* Retrieves the name of the parent keyspace associated with this collection. A keyspace in
291263
* this context typically refers to a higher-level categorization or grouping mechanism within
@@ -413,9 +385,9 @@ public String getName() {
413385
* at the collection definition level you can enforce property `defaultId` to work with specialize ids.</p>
414386
* <ul>
415387
* <li>If {@code defaultId} is set to {@code uuid}, ids will be uuid v4 {@link java.util.UUID}</li>
416-
* <li>If {@code defaultId} is set to {@code objectId}, ids will be an {@link com.datastax.astra.client.model.ObjectId}</li>
417-
* <li>If {@code defaultId} is set to {@code uuidv6}, ids will be an {@link com.datastax.astra.client.model.UUIDv6}</li>
418-
* <li>If {@code defaultId} is set to {@code uuidv7}, ids will be an {@link com.datastax.astra.client.model.UUIDv7}</li>
388+
* <li>If {@code defaultId} is set to {@code objectId}, ids will be an {@link ObjectId}</li>
389+
* <li>If {@code defaultId} is set to {@code uuidv6}, ids will be an {@link UUIDv6}</li>
390+
* <li>If {@code defaultId} is set to {@code uuidv7}, ids will be an {@link UUIDv7}</li>
419391
* </ul>
420392
*
421393
* <p>The method returns an {@code InsertOneResult} object, which provides details about the
@@ -470,9 +442,9 @@ public final InsertOneResult insertOne(T document) {
470442
* at the collection definition level you can enforce property `defaultId` to work with specialize ids.</p>
471443
* <ul>
472444
* <li>If {@code defaultId} is set to {@code uuid}, ids will be uuid v4 {@link java.util.UUID}</li>
473-
* <li>If {@code defaultId} is set to {@code objectId}, ids will be an {@link com.datastax.astra.client.model.ObjectId}</li>
474-
* <li>If {@code defaultId} is set to {@code uuidv6}, ids will be an {@link com.datastax.astra.client.model.UUIDv6}</li>
475-
* <li>If {@code defaultId} is set to {@code uuidv7}, ids will be an {@link com.datastax.astra.client.model.UUIDv7}</li>
445+
* <li>If {@code defaultId} is set to {@code objectId}, ids will be an {@link ObjectId}</li>
446+
* <li>If {@code defaultId} is set to {@code uuidv6}, ids will be an {@link UUIDv6}</li>
447+
* <li>If {@code defaultId} is set to {@code uuidv7}, ids will be an {@link UUIDv7}</li>
476448
* </ul>
477449
*
478450
* <p>The method returns an {@code InsertOneResult} object, which provides details about the
@@ -1924,7 +1896,7 @@ public UpdateResult replaceOne(Filter filter, T replacement, ReplaceOneOptions r
19241896
* @return
19251897
* command result
19261898
*/
1927-
private FindOneAndReplaceResult<T> executeFindOneAndReplace(Command cmd, CommandOptions options) {
1899+
private FindOneAndReplaceResult<T> executeFindOneAndReplace(Command cmd, CommandOptions<?> options) {
19281900
// Run Command
19291901
ApiResponse apiResponse = runCommand(cmd, options);
19301902
// Parse Command Result
@@ -2181,67 +2153,6 @@ public Optional<T> findOneAndDelete(Filter filter, FindOneAndDeleteOptions optio
21812153
return Optional.empty();
21822154
}
21832155

2184-
// ----------------------------
2185-
// --- Bulk Write ----
2186-
// ----------------------------
2187-
2188-
/**
2189-
* Executes a mix of inserts, updates, replaces, and deletes.
2190-
*
2191-
* @param commands
2192-
* list of commands to run
2193-
* @return
2194-
* the result of the bulk write
2195-
*/
2196-
@Deprecated(since = "1.3.0", forRemoval = true)
2197-
public BulkWriteResult bulkWrite(List<Command> commands) {
2198-
return bulkWrite(commands, new BulkWriteOptions());
2199-
}
2200-
2201-
/**
2202-
* Executes a mix of inserts, updates, replaces, and deletes.
2203-
*
2204-
* @param options
2205-
* if requests must be ordered or not
2206-
* @param commands
2207-
* list of commands to run
2208-
* @return
2209-
* the result of the bulk write
2210-
*/
2211-
@Deprecated(since = "1.3.0", forRemoval = true)
2212-
public BulkWriteResult bulkWrite(List<Command> commands, BulkWriteOptions options) {
2213-
notNull(commands, ARG_COMMANDS);
2214-
notNull(options, ARG_OPTIONS);
2215-
if (options.getConcurrency() > 1 && options.isOrdered()) {
2216-
throw new IllegalArgumentException("Cannot run ordered bulk_write concurrently.");
2217-
}
2218-
BulkWriteResult result = new BulkWriteResult(commands.size());
2219-
if (options.isOrdered()) {
2220-
result.setResponses(commands
2221-
.stream()
2222-
.map(cmd -> runCommand(cmd, options))
2223-
.collect(Collectors.toList()));
2224-
} else {
2225-
try {
2226-
ExecutorService executor = Executors.newFixedThreadPool(options.getConcurrency());
2227-
List<Future<ApiResponse>> futures = new ArrayList<>();
2228-
commands.forEach(req -> futures.add(executor.submit(() -> runCommand(req, options))));
2229-
executor.shutdown();
2230-
for (Future<ApiResponse> future : futures) {
2231-
result.getResponses().add(future.get());
2232-
}
2233-
} catch (InterruptedException e) {
2234-
Thread.currentThread().interrupt();
2235-
throw new IllegalStateException("Thread was interrupted while waiting for command results", e);
2236-
} catch (RuntimeException e) {
2237-
throw new IllegalStateException("Cannot access command results", e);
2238-
} catch (Exception e) {
2239-
throw new IllegalStateException("Error occurred during command execution", e.getCause());
2240-
}
2241-
}
2242-
return result;
2243-
}
2244-
22452156
/**
22462157
* Register a listener to execute commands on the collection. Please now use {@link CommandOptions}.
22472158
*

0 commit comments

Comments
 (0)