Note
This is a developer preview, not yet ready for production use, but with future releases planned. We encourage feedback from the Aerospike developer community through GitHub issues.
A higher-level API for Aerospike that provides type-safe, fluent interfaces for working with Aerospike databases.
This project provides a modern, type-safe API for Aerospike operations, including:
- DataSet: A fluent API for creating and managing Aerospike keys
- InfoParser & InfoCommands: High-level info command execution and parsing
- TransactionalSession: Transactional operations with automatic retry logic
- DSL (Domain Specific Language): A type-safe query builder with compile-time checking
- Type Safety: Compile-time validation to prevent runtime errors
- Fluent APIs: Chainable method calls for better readability
The DataSet
class represents a collection of records within an Aerospike namespace. It provides a fluent API for creating Aerospike keys with various identifier types.
- Multiple Key Types: Support for String, Integer, Long, and byte array keys
- Batch Operations: Create multiple keys at once
- Type Safety: Compile-time validation of key types
- Fluent API: Chainable method calls for better readability
// Create a dataset
DataSet users = DataSet.of("test", "users");
// Create single keys
Key userKey = users.id("user123");
Key userId = users.id(12345L);
// Create multiple keys
List<Key> userKeys = users.ids("user1", "user2", "user3");
List<Key> userIds = users.ids(1, 2, 3, 4, 5);
Key key = users.id("user123");
List<Key> keys = users.ids("user1", "user2", "user3");
// Integer keys
Key key = users.id(123);
List<Key> keys = users.ids(1, 2, 3, 4, 5);
// Long keys
Key key = users.id(12345L);
List<Key> keys = users.ids(1L, 2L, 3L, 4L, 5L);
byte[] id = {1, 2, 3, 4};
Key key = users.id(id);
// Using subset of byte array
Key key = users.id(id, 1, 2); // Uses bytes at offset 1, length 2
// Automatically determines the appropriate key type
Key key1 = users.idForObject("user123"); // String key
Key key2 = users.idForObject(123); // Integer key
Key key3 = users.idForObject(12345L); // Long key
Key key4 = users.idForObject(new byte[]{1,2,3}); // Byte array key
DataSet.of(String namespace, String set)
- Creates a new DataSet instance
id(String id)
- Creates a key with String identifierid(int id)
- Creates a key with Integer identifierid(long id)
- Creates a key with Long identifierid(byte[] id)
- Creates a key with byte array identifierid(byte[] id, int offset, int length)
- Creates a key with subset of byte arrayidForObject(Object object)
- Creates a key from any supported object type
ids(String... ids)
- Creates multiple String keysids(int... ids)
- Creates multiple Integer keysids(long... ids)
- Creates multiple Long keysids(byte[]... ids)
- Creates multiple byte array keysids(List<? extends Object> ids)
- Creates keys from a list of objects
getNamespace()
- Returns the namespace namegetSet()
- Returns the set name
The idForObject()
method throws IllegalArgumentException
if the object type is not supported. Supported types are:
- String
- Integer, Long, Byte, Short (converted to Long)
- byte[] arrays
DataSet users = DataSet.of("app", "users");
// Create keys for different user types
Key adminKey = users.id("admin");
Key guestKey = users.id("guest");
Key numericKey = users.id(1001);
// Batch operations
List<Key> userKeys = users.ids("user1", "user2", "user3", "user4");
List<Key> userIds = users.ids(1001, 1002, 1003, 1004);
DataSet sessions = DataSet.of("app", "sessions");
// Create session keys
Key sessionKey = sessions.id("session_abc123");
Key sessionId = sessions.id(987654321L);
// Batch session operations
List<Key> sessionKeys = sessions.ids("session1", "session2", "session3");
The InfoParser
class provides functionality to parse Aerospike info command responses and convert them into structured Java objects.
- Multiple Response Types: Handles both single-item and multiple-item info responses
- Node Aggregation: Merges data from multiple nodes in a cluster
- Type Safety: Converts raw strings to strongly-typed Java objects
- Error Handling: Graceful handling of parsing errors and node failures
Key-value pairs separated by semicolons:
key1=value1;key2=value2;key3=value3
Multiple records separated by semicolons, each containing key-value pairs separated by colons:
key1=value1:key2=value2;key3=value3:key4=value4
InfoParser parser = new InfoParser();
// Parse single item info
Optional<NamespaceDetail> namespace = parser.getInfoForSingleItem(session, NamespaceDetail.class, "namespace/test");
// Parse multiple items info
List<Sindex> indexes = parser.getInfoForMultipleItems(session, Sindex.class, "sindex-list");
// Get per-node results
Map<Node, Optional<NamespaceDetail>> perNode = parser.getInfoForSingleItemPerNode(session, NamespaceDetail.class, "namespace/test");
getInfoForSingleItem(Session, Class<T>, String)
- Gets and merges single item from all nodesgetInfoForSingleItemPerNode(Session, Class<T>, String)
- Gets single item from each node separately
getInfoForMultipleItems(Session, Class<T>, String)
- Gets and merges multiple items from all nodesgetInfoForMultipleItemsPerNode(Session, Class<T>, String)
- Gets multiple items from each node separately
mergeCommaSeparatedLists(Session, String)
- Merges comma-separated lists from all nodes
The InfoCommands
class provides high-level methods to execute common Aerospike info commands.
- Common Commands: Encapsulates frequently used info commands
- Dual Modes: Supports both aggregated and per-node results
- Type Safety: Returns strongly-typed objects instead of raw strings
- Convenience Methods: Overloaded methods for different parameter types
- Build Information: Get build details from all nodes
- Namespace Details: Get detailed information about specific namespaces
- Set Information: Get information about all sets
- Secondary Index Information: Get details about secondary indexes
InfoCommands commands = new InfoCommands(session);
// Get all namespaces
Set<String> namespaces = commands.namespaces();
// Get namespace details
Optional<NamespaceDetail> nsDetail = commands.namespaceDetails("test");
// Get all secondary indexes
List<Sindex> indexes = commands.secondaryIndexes();
// Get per-node results
Map<Node, List<SetDetail>> setsPerNode = commands.setsPerNode();
namespaces()
- Get all namespace namesnamespaceDetails(String)
- Get detailed namespace information (merged)namespaceDetailsPerNode(String)
- Get namespace details per node
sets()
- Get all set information (merged)setsPerNode()
- Get set information per node
secondaryIndexes()
- Get all secondary indexes (merged)secondaryIndexesPerNode()
- Get secondary indexes per nodesecondaryIndexDetails(String, String)
- Get specific index details (merged)secondaryIndexDetailsPerNode(String, String)
- Get index details per nodesecondaryIndexDetails(Sindex)
- Get index details using Sindex objectsecondaryIndexDetailsPerNode(Sindex)
- Get index details per node using Sindex object
build()
- Get build information from all nodes
The TransactionalSession
class extends the base Session to provide transactional operations with automatic retry logic.
- Automatic Retry: Retries on transient failures (MRT_BLOCKED, MRT_VERSION_MISMATCH, TXN_FAILED)
- Nested Transactions: Supports nested transaction calls without creating multiple contexts
- Resource Cleanup: Automatically aborts transactions on exceptions
- Dual Operations: Supports both void and value-returning operations
The following Aerospike result codes trigger automatic retry:
MRT_BLOCKED
- Multi-record transaction blockedMRT_VERSION_MISMATCH
- Multi-record transaction version mismatchTXN_FAILED
- Transaction failed
TransactionalSession session = new TransactionalSession(cluster, behavior);
// Void transaction
session.doInTransaction(txSession -> {
// Perform operations within transaction
txSession.put(key, bin);
});
// Value-returning transaction
String result = session.doInTransaction(txSession -> {
Record record = txSession.get(key);
return record.getString("value");
});
doInTransaction(Transactional<T>)
- Execute a value-returning transactiondoInTransaction(TransactionalVoid)
- Execute a void transactiongetCurrentTransaction()
- Get the current transaction object
- Retryable Errors: Automatically retried with exponential backoff
- Non-Retryable Errors: Thrown immediately without retry
- Resource Cleanup: Transactions are automatically aborted on any exception
The project also includes a comprehensive DSL for building type-safe queries with compile-time checking. See the DSL examples in the com.aerospike.dsl
package for more information.
# Compile the project
mvn compile
# Run tests
mvn test
# Generate Javadoc
mvn javadoc:javadoc
- Java 8 or higher
- Aerospike Java Client
- Maven for build management
[Add your license information here]