R2D1 / MODULAR JAVA PERSISTENCE

Document storage and indexed queries for Java.

Choose one DocumentStore for complete documents and one IndexStore for indexed lookup. R2D1 keeps the collection API the same across the supported backends and integrations.

Latest stable: 1.8.0

R2D1ONE COLLECTION API
IMPLEMENTATIONS

Choose your implementation.

Use the Java library from Maven Central or the TypeScript package with Node.js and Cloudflare Workers.

JAVA / MAVEN CENTRAL

Java

Java modules for Cloudflare R2 and D1, local storage, JDBC, and framework integrations.

Java documentation →
TYPESCRIPT / NPM

TypeScript

A TypeScript package for Node.js and Cloudflare Workers with Java-compatible storage contracts.

TypeScript overview →
SUPPORTED BACKENDS

Choose the two halves first.

R2D1 combines one DocumentStore with one IndexStore. Select one backend from each column, follow its setup guide, and then use the shared collection API.

DOCUMENT STORE

Complete documents

Authoritative serialized content, reads by identifier, and the document list.

R2

CLOUDFLARE

Cloudflare R2 through the asynchronous AWS SDK client.

R2 setup →
INDEX STORE

Indexed lookup

Document identifiers and explicitly indexed fields for filtering and sorting.

D1

CLOUDFLARE

Cloudflare D1 through the Java asynchronous REST client.

D1 setup →

JDBC

H2 / HSQLDB / SQLITE

Application-owned DataSource and JDBC execution boundary.

JDBC setup →
COMMON API

Configure once, use the same API.

Once the two backends are configured, every pairing uses the same annotations, collection lifecycle, mutation methods, and indexed query builder.

@Document("users")
record User(@Id String id, @Index String country, @Index long score) {}

R2D1 database = R2D1.builder()
    .collectionFactory(new PersistenceCollectionFactory(
        documentStore, indexStore, documentCodec, indexStore::initialize))
    .build();

R2D1Collection<User> users = database.collection(User.class);
users.put(new User("user-123", "NZ", 42));

Page<User> page = users.query()
    .where("country").eq("NZ")
    .sortBy("score", SortDirection.DESC)
    .limit(20)
    .fetch();

The complete setup, adapter choices, and lifecycle rules are covered in Getting Started.

MODULES & INTEGRATIONS

Modules and framework integrations.

R2D1 1.8.0 includes the Quarkus extension alongside the core API, storage adapters, Micronaut, and Spring Boot integrations.

CORE + CLOUDFLARE

R2D1

dev.nexcraft:r2d1

Common collection API plus the R2 DocumentStore and D1 IndexStore adapters.

Module setup →
INDEX STORE

R2D1-JDBC

dev.nexcraft:r2d1-jdbc

H2, HSQLDB, and local SQLite indexes behind an application-owned DataSource.

JDBC setup →
DOCUMENT STORE

R2D1-FILESYSTEM

dev.nexcraft:r2d1-filesystem

Canonical local document files with atomic replacement and explicit executor ownership.

Filesystem setup →
FRAMEWORK INTEGRATION

R2D1-MICRONAUT

dev.nexcraft:r2d1-micronaut

Micronaut 5 bean configuration around the same framework-neutral collection API.

Micronaut setup →
FRAMEWORK INTEGRATION

R2D1-SPRING-BOOT-STARTER

dev.nexcraft:r2d1-spring-boot-starter

Spring Boot 4 starter with separately published auto-configuration on Maven Central.

Spring Boot setup →
FRAMEWORK INTEGRATION

R2D1-QUARKUS

dev.nexcraft:r2d1-quarkus

Quarkus 3.39.5 extension with CDI configuration and application-owned resources, included in R2D1 1.8.0.

Quarkus setup →

Choose backends, then use one API.

Set up one document store, one index store, define the metadata, and open the collection.

READ GETTING STARTED