Class AbstractCommandRunner<OPTIONS extends BaseOptions<?>>
java.lang.Object
com.datastax.astra.internal.command.AbstractCommandRunner<OPTIONS>
- Type Parameters:
OPTIONS
- the type of options used by the command runner, extendingBaseOptions
Example usage:public class MyCommandRunner extends AbstractCommandRunner<MyOptions> { @Override protected void runCommand(MyOptions options) { // Implement the command execution logic here } @Override protected void parseResults() { // Implement result parsing logic here } } MyCommandRunner runner = new MyCommandRunner(); runner.execute(new MyOptions());
- All Implemented Interfaces:
CommandRunner
- Direct Known Subclasses:
AstraDBDatabaseAdmin
,Collection
,DataAPIDatabaseAdmin
,Database
,Table
public abstract class AbstractCommandRunner<OPTIONS extends BaseOptions<?>>
extends Object
implements CommandRunner
Abstract base class for executing commands and handling their results.
This class provides a template for implementing a command runner that executes commands
with specific options and parses their results. It ensures consistent error handling by
throwing a DataAPIResponseException
when necessary.
Subclasses must implement the command execution logic as required by the specific context.
-
Field Summary
Modifier and TypeFieldDescriptionprotected String
Api Endpoint for the API.protected static final String
parameters names.protected static final String
parameters names.protected static final String
parameters names.protected static final String
parameters names.protected RetryHttpClient
Http client reused when properties not override.protected static final String
json inputsprotected static final String
json inputsprotected static final String
json inputsprotected static final String
json inputsprotected static final String
json inputsprotected static final String
json inputsprotected static final String
json inputsprotected OPTIONS
Default command options when not override.protected static final String
parsing output jsonprotected static final String
parsing output jsonprotected static final String
parameters names.protected static final String
parsing output jsonprotected static final String
parsing output jsonprotected static final String
parsing output jsonprotected static final String
parsing output json -
Constructor Summary
ModifierConstructorDescriptionprotected
Default constructor.AbstractCommandRunner
(String apiEndpoint, OPTIONS options) Constructor with the API endpoint and default options. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Validates that the current options are configured for Astra.Gets apiEndpointGets commandOptionsprotected DataAPISerializer
Gets the serializer currently in place to parse inputs and outputs.runCommand
(Command command, BaseOptions<?> overridingOptions) Command to return the payload as a Map.<DOC> DOC
runCommand
(Command command, BaseOptions<?> options, Class<DOC> documentClass) Extension point to run any command with typing constraints.protected <DOC> DOC
unmarshall
(DataAPIResponse api, Class<DOC> documentClass) Document Mapping.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.datastax.astra.client.core.commands.CommandRunner
runCommand, runCommand
-
Field Details
-
ARG_DATABASE
parameters names.- See Also:
-
ARG_OPTIONS
parameters names.- See Also:
-
ARG_UPDATE
parameters names.- See Also:
-
ARG_CLAZZ
parameters names.- See Also:
-
RESULT_INSERTED_IDS
parameters names.- See Also:
-
RESULT_DELETED_COUNT
parsing output json- See Also:
-
RESULT_MATCHED_COUNT
parsing output json- See Also:
-
RESULT_MODIFIED_COUNT
parsing output json- See Also:
-
RESULT_UPSERTED_ID
parsing output json- See Also:
-
RESULT_MORE_DATA
parsing output json- See Also:
-
RESULT_COUNT
parsing output json- See Also:
-
INPUT_INCLUDE_SIMILARITY
json inputs- See Also:
-
INPUT_INCLUDE_SORT_VECTOR
json inputs- See Also:
-
INPUT_UPSERT
json inputs- See Also:
-
INPUT_RETURN_DOCUMENT
json inputs- See Also:
-
INPUT_ORDERED
json inputs- See Also:
-
INPUT_RETURN_DOCUMENT_RESPONSES
json inputs- See Also:
-
INPUT_PAGE_STATE
json inputs- See Also:
-
httpClient
Http client reused when properties not override. -
apiEndpoint
Api Endpoint for the API. -
options
Default command options when not override.
-
-
Constructor Details
-
AbstractCommandRunner
protected AbstractCommandRunner()Default constructor. -
AbstractCommandRunner
Constructor with the API endpoint and default options.- Parameters:
apiEndpoint
- the API endpointoptions
- the default options
-
-
Method Details
-
runCommand
Command to return the payload as a Map.- Specified by:
runCommand
in interfaceCommandRunner
- Parameters:
command
- command to executeoverridingOptions
- options when running the command- Returns:
- result as a document map
-
runCommand
Extension point to run any command with typing constraints.- Specified by:
runCommand
in interfaceCommandRunner
- Type Parameters:
DOC
- document type to use- Parameters:
command
- command as a json Payloadoptions
- options when running the commanddocumentClass
- document class to use for marshalling- Returns:
- instance of expecting type.
-
assertIsAstra
protected void assertIsAstra()Validates that the current options are configured for Astra.This method ensures that the operation is being performed in an Astra environment. If the options are not set for Astra, it throws an exception with details about the restriction.
- Throws:
IllegalStateException
- if the configuration is not set for Astra
-
getSerializer
Gets the serializer currently in place to parse inputs and outputs.- Returns:
- the serializer
-
unmarshall
Document Mapping.- Type Parameters:
DOC
- document type- Parameters:
api
- api responsedocumentClass
- document class- Returns:
- document
-
getApiEndpoint
Gets apiEndpoint- Returns:
- value of apiEndpoint
-
getOptions
Gets commandOptions- Returns:
- value of commandOptions
-