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, extending BaseOptions 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 Details

  • Constructor Details

    • AbstractCommandRunner

      protected AbstractCommandRunner()
      Default constructor.
    • AbstractCommandRunner

      public AbstractCommandRunner(String apiEndpoint, OPTIONS options)
      Constructor with the API endpoint and default options.
      Parameters:
      apiEndpoint - the API endpoint
      options - the default options
  • Method Details

    • runCommand

      public DataAPIResponse runCommand(Command command, BaseOptions<?> overridingOptions)
      Command to return the payload as a Map.
      Specified by:
      runCommand in interface CommandRunner
      Parameters:
      command - command to execute
      overridingOptions - options when running the command
      Returns:
      result as a document map
    • runCommand

      public <DOC> DOC runCommand(Command command, BaseOptions<?> options, Class<DOC> documentClass)
      Extension point to run any command with typing constraints.
      Specified by:
      runCommand in interface CommandRunner
      Type Parameters:
      DOC - document type to use
      Parameters:
      command - command as a json Payload
      options - options when running the command
      documentClass - 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

      protected DataAPISerializer getSerializer()
      Gets the serializer currently in place to parse inputs and outputs.
      Returns:
      the serializer
    • unmarshall

      protected <DOC> DOC unmarshall(DataAPIResponse api, Class<DOC> documentClass)
      Document Mapping.
      Type Parameters:
      DOC - document type
      Parameters:
      api - api response
      documentClass - document class
      Returns:
      document
    • getApiEndpoint

      public String getApiEndpoint()
      Gets apiEndpoint
      Returns:
      value of apiEndpoint
    • getOptions

      public OPTIONS getOptions()
      Gets commandOptions
      Returns:
      value of commandOptions