Comprehensive guide for AI agents working with the AstraDB Java SDK codebase
The AstraDB Java SDK provides a unified client for interacting with:
- Astra DB Serverless (cloud-native database)
- HCD (Hyper-Converged Database)
- DSE (DataStax Enterprise)
- Apache Cassandra with Data API
Supports both document-oriented (MongoDB-style) and relational (table-based) data models with vector search capabilities.
astra-db-java/ # ⭐ Core SDK (primary development module)
├── client/ # Public API surface
├── internal/ # Implementation details (not public)
└── test/ # Unit and integration tests
astra-sdk-devops/ # Astra DevOps API client
integrations/
├── langchain4j-astradb/ # LangChain4j vector store integration
├── data-api-spring-boot-3x-*/ # Spring Boot starters
└── skills/ # Reusable skill templates
tools/
├── data-api-tools/ # CLI utilities
└── data-api-tools-csv/ # CSV import/export
samples/ # Example applications
DataAPIClient # Entry point (token + options)
└── Database # Database-level operations
├── Collection<T> # Document collections (schemaless)
└── Table<T> # Relational tables (schema-defined)
Admin Hierarchy:
AstraDBAdmin # Organization-level operations
└── AstraDBDatabaseAdmin # Astra database admin
DataAPIDatabaseAdmin # Local/HCD database admin
Public API (com.datastax.astra.client.*):
client/
├── DataAPIClient.java # Main entry point
├── DataAPIClients.java # Factory methods
├── DataAPIDestination.java # Enum: ASTRA | HCD | DSE | CASSANDRA
├── databases/Database.java # Database operations
├── collections/Collection.java # Document operations
├── tables/Table.java # Table operations
├── admin/ # Admin interfaces
├── core/ # Query builders, options, auth
├── exceptions/ # 14 exception types
└── model/ # Data models (Document, Row)
Internal Implementation (com.datastax.astra.internal.*):
internal/
├── http/RetryHttpClient.java # HTTP client with retry logic
├── serdes/ # Jackson serializers/deserializers
├── command/ # Command execution engine
├── api/ # API endpoint routing
└── utils/ # Helper utilities
# Clone repository
git clone https://github.com/datastax/astra-db-java.git
cd astra-db-java
# Build without tests
mvn clean install -DskipTests
# Build core module only
mvn clean install -pl astra-db-java -DskipTests# Using Docker Compose
docker-compose up -dcd $DATA_API_FOLDER
# Required environment variables
export STARGATE_DATA_STORE_SAI_ENABLED=true
export STARGATE_DATA_STORE_VECTOR_SEARCH_ENABLED=true
export STARGATE_JSONAPI_OPERATIONS_VECTORIZE_ENABLED=true
export STARGATE_DATA_STORE_IGNORE_BRIDGE=true
export STARGATE_JSONAPI_OPERATIONS_DATABASE_CONFIG_LOCAL_DATACENTER=dc1
export STARGATE_JSONAPI_OPERATIONS_DATABASE_CONFIG_CASSANDRA_END_POINTS=localhost
# Start in dev mode
mvn quarkus:dev# Copy templates
cp src/test/resources/test-config-astra.properties.template \
src/test/resources/test-config-astra.properties
cp src/test/resources/test-config-embedding-providers.properties.template \
src/test/resources/test-config-embedding-providers.properties
# Edit and add your tokens/API keys
# ⚠️ These files are gitignored - never commit them!Astra DB Serverless:
DataAPIClient client = new DataAPIClient("AstraCS:...");
Database db = client.getDatabase("https://01234567-....apps.astra.datastax.com");Local HCD/DSE:
TokenProvider tp = new UsernamePasswordTokenProvider("cassandra", "cassandra");
DataAPIClient client = new DataAPIClient(tp);
Database db = client.getDatabase("http://localhost:8181");Default local token: Cassandra:Y2Fzc2FuZHJh:Y2Fzc2FuZHJh (cassandra/cassandra)
src/test/java/com/datastax/astra/test/
├── unit/ # Unit tests (no external dependencies)
│ ├── core/ # Filters, sorts, projections
│ ├── collections/ # Document serialization
│ ├── tables/ # Row builders, table definitions
│ └── admin/ # API endpoint parsing
│
└── integration/ # Integration tests
├── AbstractDataAPITest.java # Base class for all ITs
├── Abstract*IT.java # Abstract test suites
├── local/ # Local*IT (HCD/DSE tests)
└── astra/ # Astra*IT (cloud tests)
Every integration test class:
- Extends
AbstractDataAPITest(providesgetDatabase(), config access) - Uses
@TestInstance(TestInstance.Lifecycle.PER_CLASS) - Cleans up in
@BeforeAllwithdropAllCollections()+dropAllTables() - Uses
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)with@Order
Exception: AbstractDatabaseAdminIT skips cleanup to avoid premature database creation.
# All tests against local HCD/DSE
mvn clean verify -pl astra-db-java -Plocal
# All tests against Astra DEV
mvn clean verify -pl astra-db-java -Pastra-dev
# All tests against Astra PROD
mvn clean verify -pl astra-db-java -Pastra-prod
# Single test class
mvn test -pl astra-db-java -Dtest="LocalCollectionIT"
# With coverage report
mvn clean test jacoco:report -pl astra-db-java -Pastra-prodCoverage report: astra-db-java/target/site/jacoco/index.html
| Profile | Environment | Cloud | Region | Description |
|---|---|---|---|---|
local |
local |
GCP | us-east1 | Local HCD/DSE |
astra-dev |
astra_dev |
GCP | us-central1 | Astra development |
astra-prod |
astra_prod |
AWS | us-east-2 | Astra production |
skip-tests |
- | - | - | Skip all tests |
Files in src/test/resources/:
| File | Purpose | Committed |
|---|---|---|
test-config.properties |
Default settings | ✅ Yes |
test-config-local.properties |
Local overrides | ✅ Yes |
test-config-astra.properties |
Astra credentials | ❌ No (gitignored) |
test-config-embedding-providers.properties |
API keys | ❌ No (gitignored) |
junit-platform.properties |
JUnit 5 config | ✅ Yes |
logback-test.xml |
Test logging | ✅ Yes |
Configuration priority: Environment variables > System properties > Config files
@EnabledIfLocalAvailable // Skip if local HCD unreachable
@EnabledIfAstra // Skip if no Astra token or wrong environmentTests for unavailable environments are skipped (not failed).
| Variable | Description |
|---|---|
ASTRA_DB_APPLICATION_TOKEN |
Astra PROD token |
ASTRA_DB_APPLICATION_TOKEN_DEV |
Astra DEV token |
ASTRA_DB_JAVA_TEST_ENV |
local | astra_dev | astra_prod |
ASTRA_CLOUD_PROVIDER |
AWS | GCP | AZURE |
ASTRA_CLOUD_REGION |
e.g. us-east1, eu-west-1 |
Step-by-step:
-
Define options class
- Location:
client/collections/commands/orclient/tables/commands/ - Use
@Getter,@Setter,@Builder(Lombok) - Follow fluent builder pattern
- Location:
-
Add method to Collection/Table
- Location:
Collection.javaorTable.java - Use options pattern for parameters
- Return appropriate result type
- Location:
-
Add serialization (if needed)
- Location:
internal/serdes/collections/orinternal/serdes/tables/ - Register in
DataAPISerializer.javaorDatabaseSerializer.java
- Location:
-
Write unit test
- Location:
test/unit/collections/ortest/unit/tables/ - Test serialization, validation, edge cases
- Location:
-
Write integration tests
- Create abstract test class extending appropriate base
- Add concrete implementations in
local/andastra/ - Use
@Orderannotations for test sequence
-
Verify
mvn clean install -DskipTests mvn test -pl astra-db-java -Dtest="YourTestClass"
Template:
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public abstract class AbstractYourFeatureIT extends AbstractDataAPITest {
@BeforeAll
public void setup() {
dropAllCollections();
dropAllTables();
// Your setup code
}
@Test
@Order(1)
public void testFeature() {
// Test implementation
}
}Concrete implementations:
// Local version
@EnabledIfLocalAvailable
public class LocalYourFeatureIT extends AbstractYourFeatureIT {
}
// Astra version
@EnabledIfAstra
public class AstraYourFeatureIT extends AbstractYourFeatureIT {
}Extend the appropriate base:
public class YourProviderVectorizeIT extends AbstractVectorizeApiHeaderIT {
@Override
protected String getEmbeddingProviderId() {
return "yourProvider";
}
@Override
protected String getApiKey() {
return testConfig.getEmbeddingApiKey("YOUR_PROVIDER_KEY");
}
@Override
protected Map<String, Object> getAuthenticationParameters() {
return Map.of("apiKey", getApiKey());
}
}For non-standard auth (e.g., AWS Bedrock), override getEmbeddingAuthProvider().
internal/http/RetryHttpClient.java
Changes here affect every API call. Test thoroughly:
- Retry behavior
- Timeout handling
- Error responses
- Connection pooling
- Proxy support
- Lombok everywhere:
@Getter,@Setter,@Slf4j,@Builder - Fluent builders for all configuration/options classes
- Options pattern: Each operation has dedicated options class
- Public vs Internal: Public API in
client/, implementation ininternal/ - No style enforcement: Convention-based (no checkstyle/spotless)
- License headers: Enforced via
license-maven-plugin
Collections (Document-oriented):
Collection<T>stores flexible JSON documentsDocumentisMap<String, Object>with two access modes:- Plain:
put/get(literal keys) - Escaping-aware:
append/read(dot-notation for nested maps)
- Plain:
- Supports vector search, vectorize, hybrid search
Tables (Relational):
Table<T>stores rows with defined schemaRowprovides typed column access- Requires
TableDefinitionwith column types and partition key - POJO mapping via Jackson annotations
test-config-astra.properties(contains tokens)test-config-embedding-providers.properties(contains API keys).envfiles- Any file with tokens, passwords, or API keys
Gitignored patterns:
.env
.astrarc
sec/
*.log
test-config-astra.properties
test-config-embedding-providers.properties
| Library | Version | Purpose |
|---|---|---|
| Jackson | 2.20.1 | JSON serialization |
| Apache HttpClient 5 | 5.5.1 | HTTP transport |
| SLF4J | 2.0.17 | Logging API |
| Logback | 1.5.21 | Logging implementation |
| Lombok | 1.18.42 | Boilerplate reduction |
| Retry4j | 0.15.0 | Retry logic |
| Library | Version | Purpose |
|---|---|---|
| LangChain4j | 1.10.0 | AI framework integration |
| Spring Boot | 3.x | Spring integration |
| Library | Version | Purpose |
|---|---|---|
| JUnit Jupiter | 5.14.1 | Testing framework |
| AssertJ | 3.27.6 | Fluent assertions |
| JaCoCo | - | Code coverage |
# Prepare release (updates versions, creates tag)
mvn -pl astra-db-java,langchain4j-astradb -am release:prepare -DskipTests=true
# Perform release (builds and deploys)
mvn -pl astra-db-java,langchain4j-astradb -am release:perform -DskipTests=truePublishing:
- Artifacts published to Maven Central
- Via Sonatype Central Publishing
- GPG signing required
GitHub Actions (.github/workflows/):
| Workflow | Target | Purpose |
|---|---|---|
ci-astra-dev.yml |
Astra DEV | Full test suite |
ci-astra-dev-collection.yml |
Astra DEV | Collection operations |
ci-astra-dev-database.yml |
Astra DEV | Database operations |
ci-astra-dev-databaseadmin.yml |
Astra DEV | Database admin |
ci-astra-dev-vectorize-*.yml |
Astra DEV | Provider-specific vectorize |
ci-astra-prod-devops.yml |
Astra PROD | DevOps API |
Entry Points:
DataAPIClient- Main clientDataAPIClients- Factory methodsDatabase- Database operationsCollection<T>- Document operationsTable<T>- Table operations
Core Types:
Document- Document containerRow- Table row containerFilter- Query filter builderProjection- Field projection builderSort- Sort specification builder
Admin:
AstraDBAdmin- Org-level adminAstraDBDatabaseAdmin- Astra database adminDataAPIDatabaseAdmin- Local database admin
Exceptions:
DataAPIException- Base exception- 14 specific exception types for different error scenarios
# Build everything
mvn clean install -DskipTests
# Build core only
mvn clean install -pl astra-db-java -DskipTests
# Run specific test
mvn test -pl astra-db-java -Dtest="TestClassName"
# Generate coverage report
mvn clean test jacoco:report -pl astra-db-java
# Check for dependency updates
mvn versions:display-dependency-updates
# Format license headers
mvn license:format- Documentation: docs.datastax.com
- Issues: GitHub Issues
- Community: DataStax Community
Last updated: 2026-05-06
