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.

R2D1ONE COLLECTION API
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.

PUBLIC MODULES

One set of modules. One collection API.

The core artifact covers the common API and Cloudflare backends. Add the module that supplies local files, JDBC indexing, or Micronaut wiring.

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 →

Choose backends, then use one API.

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

READ GETTING STARTED