### Begin Transaction - Java Source: https://javadoc.io/doc/in.arcadelabs.labaide/database-aide/1.0/in/arcadelabs/labaide/database/strategy/OdmStrategy Starts a new database transaction, allowing for atomic operations. The returned transaction object must be used within a try-with-resources block for proper cleanup. Throws DatabaseException if creation fails. ```java public Transaction beginTransaction() throws DatabaseException ``` -------------------------------- ### Build and Execute a Database Query with QueryBuilder Source: https://javadoc.io/doc/in.arcadelabs.labaide/database-aide/1.0/in/arcadelabs/labaide/database/query/QueryBuilder Demonstrates how to use the QueryBuilder interface to construct a query with filtering, sorting, and limiting, and then execute it to retrieve a list of entities. This example showcases method chaining for a readable query construction. ```java List activeUsers = database.query() .where("status", Operator.EQUALS, "ACTIVE") .orderBy("lastLogin", Direction.DESCENDING) .limit(50) .execute(); ``` -------------------------------- ### beginTransaction - Start a transaction Source: https://javadoc.io/doc/in.arcadelabs.labaide/database-aide/1.0/in/arcadelabs/labaide/database/strategy/json/StreamingJsonStrategy Begins a new database transaction. ```APIDOC ## beginTransaction ### Description Begins a new database transaction. ### Method `POST` (Conceptual - typically no direct HTTP mapping for internal methods) ### Endpoint N/A (Internal method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```java // Example usage (conceptual) Transaction transaction = null; try { transaction = strategy.beginTransaction(); // perform database operations within the transaction // transaction.commit(); } catch (DatabaseException e) { // if (transaction != null) transaction.rollback(); // handle exception } ``` ### Response #### Success Response (Transaction) - **Transaction** - A new Transaction object. #### Response Example (Returns a Transaction object, not a direct data response) ### Throws - `DatabaseException` - if the transaction cannot be started ``` -------------------------------- ### Execute Query and Get Results (Java) Source: https://javadoc.io/doc/in.arcadelabs.labaide/database-aide/1.0/in/arcadelabs/labaide/database/query/OdmQueryBuilder Executes the constructed query and returns a list of entities that match the specified criteria. The results are sorted and paginated as configured. Throws DatabaseException if execution fails. ```java public List execute() throws DatabaseException ``` -------------------------------- ### Begin Database Transaction (Java) Source: https://javadoc.io/doc/in.arcadelabs.labaide/database-aide/1.0/in/arcadelabs/labaide/database/strategy/PersistenceStrategy Begins a new database transaction, allowing multiple operations to be grouped atomically. This ensures data consistency, as all operations within the transaction either succeed or fail together. A DatabaseException may be thrown if the transaction cannot be started. ```java Transaction beginTransaction() throws DatabaseException; ``` -------------------------------- ### Manage Database Transactions Source: https://javadoc.io/doc/in.arcadelabs.labaide/database-aide/1.0/in/arcadelabs/labaide/database/strategy/InMemoryStrategy Provides methods to control database transactions. Supports starting a new transaction and closing the persistence strategy, releasing all associated resources. ```java Transaction beginTransaction() void close() ``` -------------------------------- ### Handle DatabaseException in Java Source: https://javadoc.io/doc/in.arcadelabs.labaide/database-aide/1.0/in/arcadelabs/labaide/database/exception/DatabaseException Example of how to catch and handle DatabaseException in Java. It demonstrates using a switch statement on the error type to perform specific error handling logic. ```java try { databaseAide.create(entity); } catch (DatabaseException e) { switch (e.getType()) { case CONNECTION_FAILED: // Handle connection issues (retry, failover) break; case VALIDATION_ERROR: // Handle data validation issues break; case DUPLICATE_KEY: // Handle unique constraint violations break; default: // Handle other database errors break; } } ``` -------------------------------- ### Usage Example for StreamingJsonStrategy Source: https://javadoc.io/doc/in.arcadelabs.labaide/database-aide/1.0/in/arcadelabs/labaide/database/strategy/json/StreamingJsonStrategy Demonstrates how to configure and use StreamingJsonStrategy to process a large JSON dataset. It sets up the DatabaseConfig for JSON streaming, creates a DatabaseAide instance, and then streams entities to filter and process error logs. ```java DatabaseConfig config = new DatabaseConfig() .setHandlerType(DatabaseConfig.HandlerType.JSON_STREAM) .getJsonConfig() .setJsonFilePath("./data/large-dataset.json"); DatabaseAide db = new DatabaseAide<>(LogEntry.class, Long.class, config); try (Stream stream = db.streamAll()) { stream.filter(entry -> entry.getLevel() == Level.ERROR) .forEach(this::processError); } ``` -------------------------------- ### Configure ORM Database Connection Source: https://javadoc.io/doc/in.arcadelabs.labaide/database-aide/1.0/in/arcadelabs/labaide/database/config/DatabaseConfig Example of configuring an ORM database connection using the DatabaseConfig class. This demonstrates setting the JDBC URL, username, password, and maximum pool size for an ORM handler. ```java DatabaseConfig config = new DatabaseConfig() .setHandlerType(DatabaseConfig.HandlerType.ORM) .getOrmConfig() .setJdbcUrl("jdbc:h2:./data/test") .setUsername("admin") .setPassword("password") .setMaximumPoolSize(20); ``` -------------------------------- ### Build DatabaseAide Instance Source: https://javadoc.io/doc/in.arcadelabs.labaide/database-aide/1.0/in/arcadelabs/labaide/database/DatabaseBuilder Builds and returns a configured DatabaseAide instance. ```APIDOC ## POST /api/database/builder/{builderId}/build ### Description Builds and returns a configured DatabaseAide instance. This method validates the configuration and creates a new DatabaseAide instance with the specified settings. The configuration is validated before attempting to create the database connection. ### Method POST ### Endpoint /api/database/builder/{builderId}/build ### Parameters #### Path Parameters - **builderId** (String) - Required - The ID of the builder instance. ### Response #### Success Response (200) - **databaseAide** (Object) - The configured DatabaseAide instance. #### Response Example ```json { "databaseAide": { "entityClass": "com.example.MyEntity", "idClass": "java.lang.Long", "persistenceType": "ORM", "config": { "url": "jdbc:mysql://localhost:3306/mydb" } } } ``` #### Error Response (400) - **error** (String) - Description of the validation or creation failure. #### Error Response Example ```json { "error": "Configuration validation failed: Missing database URL." } ``` ``` -------------------------------- ### Get Direction Enum Constants (Java) Source: https://javadoc.io/doc/in.arcadelabs.labaide/database-aide/1.0/in/arcadelabs/labaide/database/query/class-use/Direction Demonstrates how to retrieve Direction enum constants by name or get all available constants. This is useful for dynamically configuring query sorting. ```java Direction directionByName = Direction.valueOf("ASC"); Direction[] allDirections = Direction.values(); ``` -------------------------------- ### Usage Example: Filtering Database Queries with Operator Enum (Java) Source: https://javadoc.io/doc/in.arcadelabs.labaide/database-aide/1.0/in/arcadelabs/labaide/database/query/Operator Demonstrates how to use the Operator enum with the QueryBuilder to filter database results. Shows examples for finding users based on age and role. ```java // Find users with age greater than 18 List adults = databaseAide.query() .where("age", Operator.GREATER_THAN, 18) .execute(); // Find users in specific roles List admins = databaseAide.query() .where("role", Operator.IN, Arrays.asList("ADMIN", "MODERATOR")) .execute(); ``` -------------------------------- ### DatabaseAide Strategy Creation and CRUD Operations (Java) Source: https://javadoc.io/doc/in.arcadelabs.labaide/database-aide/1.0/in/arcadelabs/labaide/database/strategy/PersistenceStrategy Demonstrates how to create a PersistenceStrategy using DatabaseAide and perform basic CRUD operations. This strategy abstracts database interactions, handling entity persistence based on configuration. It requires the entity class and its ID type for strategy creation. ```java // Implementations are created by DatabaseAide based on configuration PersistenceStrategy strategy = DatabaseAide.createStrategy(config, User.class, Long.class); // CRUD operations User user = new User("john", "john@example.com"); strategy.create(user); Optional found = strategy.read(user.getId()); found.ifPresent(u -> strategy.update(u)); strategy.deleteById(user.getId()); strategy.close(); ``` -------------------------------- ### Initialize OrmStrategy with Database Configuration Source: https://javadoc.io/doc/in.arcadelabs.labaide/database-aide/1.0/in/arcadelabs/labaide/database/strategy/OrmStrategy Demonstrates how to configure and initialize the DatabaseAide with the OrmStrategy. This involves setting up database connection details and specifying the entity and ID types. ```java DatabaseConfig config = DatabaseConfig.builder() .setHandlerType(DatabaseConfig.HandlerType.ORM) .getOrmConfig() .setJdbcUrl("jdbc:h2:./data/mydb") .setUsername("admin") .setPassword("password") .setMaximumPoolSize(20); DatabaseAide db = new DatabaseAide<>(User.class, Long.class, config); // ORM strategy is automatically selected and initialized ``` -------------------------------- ### Create Transaction with Try-with-Resources Source: https://javadoc.io/doc/in.arcadelabs.labaide/database-aide/1.0/in/arcadelabs/labaide/database/strategy/PersistenceStrategy Demonstrates how to create a new Transaction instance using a try-with-resources block for automatic cleanup. This ensures that multiple operations are executed atomically and resources are properly managed. It may throw a DatabaseException if creation fails. ```java try (Transaction transaction = database.newTransaction()) { // Perform operations within the transaction } catch (DatabaseException e) { // Handle exception } ``` -------------------------------- ### StreamingJsonStrategy Overview Source: https://javadoc.io/doc/in.arcadelabs.labaide/database-aide/1.0/in/arcadelabs/labaide/database/strategy/json/StreamingJsonStrategy Provides an overview of the StreamingJsonStrategy, its features, limitations, and a usage example. ```APIDOC ## StreamingJsonStrategy ### Description Streaming JSON persistence strategy implementation. This strategy provides read-only access to large JSON datasets using streaming parsing. Unlike `JsonStrategy`, it does not load the entire file into memory, making it suitable for processing very large files. ### Key Features: * Memory-efficient streaming of large JSON files * Support for Java Stream API * Automatic resource management via Stream.onClose() * Fast sequential access ### Limitations: * Read-only access (write operations throw UnsupportedOperationException) * No random access (read by ID is not supported) * No transaction support ### Usage Example: ```java DatabaseConfig config = new DatabaseConfig() .setHandlerType(DatabaseConfig.HandlerType.JSON_STREAM) .getJsonConfig() .setJsonFilePath("./data/large-dataset.json"); DatabaseAide db = new DatabaseAide<>(LogEntry.class, Long.class, config); try (Stream stream = db.streamAll()) { stream.filter(entry -> entry.getLevel() == Level.ERROR) .forEach(this::processError); } ``` ### Constructor Summary #### `StreamingJsonStrategy(DatabaseConfig config, Class entityClass)` * Constructor for StreamingJsonStrategy. ### Method Summary #### Instance Methods - **`close()`** (void): Closes the persistence strategy and releases all resources. - **`create(E entity)`** (void): Creates a new entity in the persistent storage. (Throws UnsupportedOperationException) - **`createBatch(Collection entities)`** (void): Creates multiple entities in a single batch operation. (Throws UnsupportedOperationException) - **`createOrUpdate(E entity)`** (void): Creates a new entity or updates an existing one based on its ID. (Throws UnsupportedOperationException) - **`delete(E entity)`** (void): Deletes an entity from the persistent storage. (Throws UnsupportedOperationException) - **`deleteById(ID id)`** (void): Deletes an entity by its unique identifier. (Throws UnsupportedOperationException) - **`healthCheck()`** (boolean): Performs a health check on the persistence layer. - **`query()`** (QueryBuilder): Creates a query builder for constructing complex database queries. - **`read(ID id)`** (Optional): Reads an entity by its unique identifier. (Throws UnsupportedOperationException) - **`readAll()`** (List): Reads all entities from the persistent storage. (Throws UnsupportedOperationException) - **`streamAll()`** (Stream): Returns a stream of all entities for memory-efficient processing. - **`update(E entity)`** (void): Updates an existing entity in the persistent storage. (Throws UnsupportedOperationException) ### See Also: * `PersistenceStrategy` * `JsonStrategy` ``` -------------------------------- ### Transaction Management Source: https://javadoc.io/doc/in.arcadelabs.labaide/database-aide/1.0/index-all APIs for managing database transactions, including starting, committing, and closing transactions. ```APIDOC ## Transaction Management ### Description APIs for managing database transactions, including starting, committing, and closing transactions. ### Methods - **beginTransaction()** - **Description**: Begins a new database transaction. - **Method**: POST (Conceptual) - **Endpoint**: /transactions/begin - **commit()** - **Description**: Commits the transaction, making all changes permanent. - **Method**: POST (Conceptual) - **Endpoint**: /transactions/commit - **close()** - **Description**: Closes the transaction and releases associated resources. - **Method**: POST (Conceptual) - **Endpoint**: /transactions/close ### Parameters None for these operations as they operate on the current transaction context. ### Response #### Success Response (200) - **Transaction** - Represents the active transaction object. - **boolean** - Indicates success or failure of commit/close operations. #### Response Example ```json { "transactionId": "txn_abc123", "status": "active" } ``` ``` -------------------------------- ### DatabaseBuilder Initialization Source: https://javadoc.io/doc/in.arcadelabs.labaide/database-aide/1.0/in/arcadelabs/labaide/database/DatabaseBuilder This section covers the static factory method for creating a new DatabaseBuilder instance. ```APIDOC ## POST /api/database/builder ### Description Initializes a new DatabaseBuilder instance with specified entity and ID classes. ### Method POST ### Endpoint /api/database/builder ### Parameters #### Query Parameters - **entityClass** (Class) - Required - The class of the entity to be managed. - **idClass** (Class) - Required - The class of the entity's ID. ### Request Example ```json { "entityClass": "com.example.MyEntity", "idClass": "java.lang.Long" } ``` ### Response #### Success Response (200) - **builderId** (String) - A unique identifier for the created builder instance. #### Response Example ```json { "builderId": "builder-12345" } ``` ``` -------------------------------- ### Database Aide Configuration Source: https://javadoc.io/doc/in.arcadelabs.labaide/database-aide/1.0/index-all Details on configuring different database strategies, including JSON and streaming JSON persistence, using the `DatabaseBuilder`. ```APIDOC ## Database Aide Configuration ### Description Methods for configuring persistence strategies within the `DatabaseBuilder`. ### Endpoints #### `json(Consumer)` - DatabaseBuilder Configures simple flat-file JSON persistence. #### `jsonStream(Consumer)` - DatabaseBuilder Configures streaming JSON persistence for large datasets. ### Parameters #### Query Parameters - **configConsumer** (Consumer) - Required - A consumer to configure JSON specific settings. ### Request Example ```java DatabaseAide.builder() .json(jsonConfig -> { // Configure JSON settings here jsonConfig.setPath("data.json"); }) .build(); ``` ### Response #### Success Response (200) - **databaseAide** (DatabaseAide) - An instance of the configured DatabaseAide. #### Response Example ```json // Response is typically the configured DatabaseAide object, not a JSON representation. ``` ``` -------------------------------- ### Get DatabaseConfig.HandlerType enum constants (Java) Source: https://javadoc.io/doc/in.arcadelabs.labaide/database-aide/1.0/in/arcadelabs/labaide/database/config/class-use/DatabaseConfig.HandlerType Retrieves all declared constants of the DatabaseConfig.HandlerType enum. This is useful for iterating through all possible handler types. ```java DatabaseConfig.HandlerType[] handlerTypes = DatabaseConfig.HandlerType.values(); ``` -------------------------------- ### Get DatabaseConfig.HandlerType by name (Java) Source: https://javadoc.io/doc/in.arcadelabs.labaide/database-aide/1.0/in/arcadelabs/labaide/database/config/class-use/DatabaseConfig.HandlerType Retrieves a specific DatabaseConfig.HandlerType enum constant by its name. This method is case-sensitive and will throw an IllegalArgumentException if the name does not match any constant. ```java String handlerName = "MY_HANDLER"; DatabaseConfig.HandlerType handlerType = DatabaseConfig.HandlerType.valueOf(handlerName); ``` -------------------------------- ### Persistence Strategy Implementations Source: https://javadoc.io/doc/in.arcadelabs.labaide/database-aide/1.0/in/arcadelabs/labaide/database/strategy/class-use/PersistenceStrategy Overview of the different persistence strategy implementations available in the Database Aide library. ```APIDOC ## Persistence Strategy Implementations ### Description This section lists the available concrete implementations of the `PersistenceStrategy` interface, each offering a different approach to data persistence. ### Method N/A (Class Overview) ### Endpoint N/A (Class Overview) ### Parameters None ### Request Example None ### Response #### Success Response (200) - **InMemoryStrategy** (class) - An in-memory persistence strategy. - **JsonStrategy** (class) - A JSON file-based persistence strategy implementation. - **OdmStrategy** (class) - An Object-Document Mapping persistence strategy. - **OrmStrategy** (class) - An Object-Relational Mapping persistence strategy implementation. - **StreamingJsonStrategy** (class) - A streaming JSON persistence strategy implementation. #### Response Example None ``` -------------------------------- ### Database Aide Constructor with Custom Strategy Source: https://javadoc.io/doc/in.arcadelabs.labaide/database-aide/1.0/in/arcadelabs/labaide/database/strategy/class-use/PersistenceStrategy This section details the constructor for DatabaseAide that allows for the injection of a custom PersistenceStrategy and ExecutorService. ```APIDOC ## DatabaseAide Constructor with Custom Strategy ### Description Constructs a new DatabaseAide with a custom persistence strategy and executor service. ### Method CONSTRUCTOR ### Endpoint N/A (Class Constructor) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```java DatabaseAide databaseAide = new DatabaseAide<>(MyEntity.class, MyId.class, config, customStrategy, executorService); ``` ### Response #### Success Response (200) N/A (Constructor) #### Response Example N/A (Constructor) ``` -------------------------------- ### Get Operator Enum Constants (Java) Source: https://javadoc.io/doc/in.arcadelabs.labaide/database-aide/1.0/in/arcadelabs/labaide/database/query/class-use/Operator Retrieves all declared constants of the Operator enum. This is useful for iterating through all possible operators or for obtaining an array of all enum values. ```java static Operator[] Operator.values() Returns an array containing the constants of this enum class, in the order they are declared. ``` -------------------------------- ### Get All Database Error Types (Java) Source: https://javadoc.io/doc/in.arcadelabs.labaide/database-aide/1.0/in/arcadelabs/labaide/database/exception/DatabaseException.ErrorType Retrieves all the defined error types within the DatabaseException.ErrorType enum. This method is useful for iterating through all possible database error states. ```java public static DatabaseException.ErrorType[] values() Returns an array containing the constants of this enum class, in the order they are declared. ``` -------------------------------- ### Database Aide Core API Source: https://javadoc.io/doc/in.arcadelabs.labaide/database-aide/1.0/in/arcadelabs/labaide/database/package-summary The `DatabaseAide` class provides a unified entry point for all database operations, abstracting away the underlying persistence strategy. It supports CRUD operations, batch operations, query building, and transactions. ```APIDOC ## Database Aide Core API ### Description The `DatabaseAide` class is the central component for interacting with the database. It offers a consistent API regardless of the chosen persistence strategy (ORM, ODM, flat-file JSON, streaming JSON). ### Method N/A (This is a class-level documentation, not a specific endpoint) ### Endpoint N/A ### Parameters N/A (Class-level documentation) ### Request Example N/A ### Response N/A #### Success Response (200) N/A #### Response Example N/A ``` -------------------------------- ### Get Specific Database Error Type by Name (Java) Source: https://javadoc.io/doc/in.arcadelabs.labaide/database-aide/1.0/in/arcadelabs/labaide/database/exception/DatabaseException.ErrorType Retrieves a specific DatabaseException.ErrorType enum constant by its name. This method is case-sensitive and throws an exception if the name does not match any constant. ```java public static DatabaseException.ErrorType valueOf(String name) Returns the enum constant of this class with the specified name. The string must match _exactly_ an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.) Parameters: `name` - the name of the enum constant to be returned. Returns: the enum constant with the specified name Throws: `IllegalArgumentException` - if this enum class has no constant with the specified name `NullPointerException` - if the argument is null ``` -------------------------------- ### Initialize OrmStrategy Source: https://javadoc.io/doc/in.arcadelabs.labaide/database-aide/1.0/in/arcadelabs/labaide/database/strategy/OrmStrategy Constructs a new OrmStrategy with the specified configuration and entity class. This constructor initializes the ORM strategy by setting up the connection pool, creating database tables if they don't exist, and preparing the DAO for operations. ```java public OrmStrategy(DatabaseConfig config, Class entityClass) throws DatabaseException ``` -------------------------------- ### Get Operator Enum Constant by Name (Java) Source: https://javadoc.io/doc/in.arcadelabs.labaide/database-aide/1.0/in/arcadelabs/labaide/database/query/class-use/Operator Retrieves a specific enum constant of the Operator class by its name. This method is case-sensitive and throws an IllegalArgumentException if the specified name does not match any constant. ```java static Operator Operator.valueOf(String name) Returns the enum constant of this class with the specified name. ``` -------------------------------- ### Database Configuration API Source: https://javadoc.io/doc/in.arcadelabs.labaide/database-aide/1.0/in/arcadelabs/labaide/database/config/class-use/DatabaseConfig.OdmConfig This section details how to configure NoSQL document databases, such as MongoDB, using the Database Aide library. ```APIDOC ## POST /api/database/configure ### Description Configures a NoSQL document database (e.g., MongoDB) using a provided configurator. ### Method POST ### Endpoint /api/database/configure ### Parameters #### Request Body - **odmConfigurator** (Consumer) - Required - A consumer function to configure the ODM (Object-Document Mapper) settings. ### Request Example ```json { "odmConfigurator": "(config) -> config.setDatabaseName(\"myDatabase\").setCollectionName(\"myCollection\")" } ``` ### Response #### Success Response (200) - **status** (string) - Indicates the success of the configuration. #### Response Example ```json { "status": "Configuration successful" } ``` ``` -------------------------------- ### DatabaseAide Constructors Source: https://javadoc.io/doc/in.arcadelabs.labaide/database-aide/1.0/in/arcadelabs/labaide/database/config/class-use/DatabaseConfig This section details the constructors for the DatabaseAide class, highlighting how DatabaseConfig is used for initialization. ```APIDOC ## DatabaseAide Constructors ### Description Constructors for the `DatabaseAide` class that accept a `DatabaseConfig` object. ### Method `DatabaseAide(Class entityClass, Class idClass, DatabaseConfig config)` ### Method `DatabaseAide(Class entityClass, Class idClass, DatabaseConfig config, PersistenceStrategy strategy, ExecutorService executorService)` ### Method `DatabaseAide(Class entityClass, Class idClass, DatabaseConfig config, ExecutorService executorService)` ### Parameters * **entityClass** (Class) - The class of the entity. * **idClass** (Class) - The class of the entity's ID. * **config** (DatabaseConfig) - Configuration settings for database connections and behavior. * **strategy** (PersistenceStrategy) - The persistence strategy to use (optional for some constructors). * **executorService** (ExecutorService) - The executor service to use (optional for some constructors). ### Request Example ```json { "entityClass": "com.example.MyEntity", "idClass": "java.lang.Long", "config": { "url": "jdbc:mysql://localhost:3306/mydb", "username": "user", "password": "password" } } ``` ### Response #### Success Response (200) * **DatabaseAide instance** - A newly created DatabaseAide object configured with the provided settings. ``` -------------------------------- ### DatabaseAide Constructors Source: https://javadoc.io/doc/in.arcadelabs.labaide/database-aide/1.0/in/arcadelabs/labaide/database/DatabaseAide Constructors for initializing the DatabaseAide class with different configurations. ```APIDOC ## DatabaseAide Constructors ### Description Constructors for initializing the DatabaseAide class with different configurations. ### Constructor `DatabaseAide(Class entityClass, Class idClass, DatabaseConfig config)` **Description:** Constructs a new DatabaseAide with default executor service. ### Constructor `DatabaseAide(Class entityClass, Class idClass, DatabaseConfig config, PersistenceStrategy strategy, ExecutorService executorService)` **Description:** Constructs a new DatabaseAide with custom strategy and executor. ### Constructor `DatabaseAide(Class entityClass, Class idClass, DatabaseConfig config, ExecutorService executorService)` **Description:** Constructs a new DatabaseAide with custom executor service. ``` -------------------------------- ### Database Configuration API Source: https://javadoc.io/doc/in.arcadelabs.labaide/database-aide/1.0/in/arcadelabs/labaide/database/config/package-use This section outlines the configuration classes available in the Database Aide library. It covers general database configuration, specific settings for JSON, ODM, ORM persistence, and retry policies. ```APIDOC ## Database Configuration Classes ### Description Provides configuration POJOs for database connections and retry behavior. ### Method N/A (Configuration Classes) ### Endpoint N/A (Configuration Classes) ### Parameters N/A (Configuration Classes) ### Request Example N/A (Configuration Classes) ### Response N/A (Configuration Classes) ## DatabaseConfig ### Description Configuration class for database connections and persistence strategies. ### Method N/A ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ## DatabaseConfig.JsonConfig ### Description Configuration for JSON file-based persistence. ### Method N/A ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ## DatabaseConfig.OdmConfig ### Description Configuration for Object-Document Mapping (ODM) database connections. ### Method N/A ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ## DatabaseConfig.OrmConfig ### Description Configuration for Object-Relational Mapping (ORM) database connections. ### Method N/A ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ## DatabaseConfig.RetryConfig ### Description Configuration for retry policies and backoff strategies. ### Method N/A ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ## DatabaseConfig.BackoffStrategy ### Description Enumeration of backoff strategies for retry operations. ### Method N/A ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ## DatabaseConfig.HandlerType ### Description Enumeration of supported database handler types. ### Method N/A ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### DatabaseAide.query() Source: https://javadoc.io/doc/in.arcadelabs.labaide/database-aide/1.0/in/arcadelabs/labaide/database/query/class-use/QueryBuilder The `query()` method in `DatabaseAide` is the entry point for creating a `QueryBuilder` instance for complex database operations. ```APIDOC ## DatabaseAide.query() ### Description This method initiates the creation of a `QueryBuilder` for constructing complex database queries. ### Method `QueryBuilder query()` ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) - **QueryBuilder** (QueryBuilder) - An instance of `QueryBuilder` for the specified entity type `E`. #### Response Example N/A ``` -------------------------------- ### Database Persistence Configuration Source: https://javadoc.io/doc/in.arcadelabs.labaide/database-aide/1.0/in/arcadelabs/labaide/database/DatabaseBuilder Methods for configuring different database persistence strategies. ```APIDOC ## PUT /api/database/builder/{builderId}/orm ### Description Configures a SQL database (MySQL, PostgreSQL, etc) using ORMLite. Throws if you try to set multiple handlers. ### Method PUT ### Endpoint /api/database/builder/{builderId}/orm ### Parameters #### Path Parameters - **builderId** (String) - Required - The ID of the builder instance. #### Request Body - **ormConfigurator** (Consumer) - Required - A consumer for configuring ORM settings. ### Response #### Success Response (200) - **builderId** (String) - The ID of the updated builder instance. #### Response Example ```json { "builderId": "builder-12345" } ``` ## PUT /api/database/builder/{builderId}/odm ### Description Configures a NoSQL document database (MongoDB) using Morphia. Throws if you try to set multiple handlers. ### Method PUT ### Endpoint /api/database/builder/{builderId}/odm ### Parameters #### Path Parameters - **builderId** (String) - Required - The ID of the builder instance. #### Request Body - **odmConfigurator** (Consumer) - Required - A consumer for configuring ODM settings. ### Response #### Success Response (200) - **builderId** (String) - The ID of the updated builder instance. #### Response Example ```json { "builderId": "builder-12345" } ``` ## PUT /api/database/builder/{builderId}/json ### Description Configures simple flat-file JSON persistence. Good for small datasets/prototyping. ### Method PUT ### Endpoint /api/database/builder/{builderId}/json ### Parameters #### Path Parameters - **builderId** (String) - Required - The ID of the builder instance. #### Request Body - **jsonConfigurator** (Consumer) - Required - A consumer for configuring JSON settings. ### Response #### Success Response (200) - **builderId** (String) - The ID of the updated builder instance. #### Response Example ```json { "builderId": "builder-12345" } ``` ## PUT /api/database/builder/{builderId}/jsonStream ### Description Configures streaming JSON persistence. Use this for larger datasets that don't fit in memory, but still need to be files. ### Method PUT ### Endpoint /api/database/builder/{builderId}/jsonStream ### Parameters #### Path Parameters - **builderId** (String) - Required - The ID of the builder instance. #### Request Body - **jsonConfigurator** (Consumer) - Required - A consumer for configuring JSON streaming settings. ### Response #### Success Response (200) - **builderId** (String) - The ID of the updated builder instance. #### Response Example ```json { "builderId": "builder-12345" } ``` ``` -------------------------------- ### Constructor: JsonStrategy Source: https://javadoc.io/doc/in.arcadelabs.labaide/database-aide/1.0/in/arcadelabs/labaide/database/strategy/JsonStrategy Initializes a new instance of the JsonStrategy class with the specified database configuration, entity class, ID class, and ID field. ```APIDOC ## Constructor: JsonStrategy ### Description Initializes a new instance of the JsonStrategy class. ### Method CONSTRUCTOR ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) None #### Response Example None ### Throws `DatabaseException` - if initialization fails. ``` -------------------------------- ### Persistence Strategy Constructors using DatabaseConfig Source: https://javadoc.io/doc/in.arcadelabs.labaide/database-aide/1.0/in/arcadelabs/labaide/database/config/class-use/DatabaseConfig This section outlines the constructors for various persistence strategy implementations that utilize the DatabaseConfig. ```APIDOC ## Persistence Strategy Constructors with DatabaseConfig ### Description Constructors for persistence strategy classes that require a `DatabaseConfig` object for initialization. ### Method `JsonStrategy(DatabaseConfig config, Class entityClass, Class idClass, Field idField)` ### Method `OdmStrategy(DatabaseConfig config, Class entityClass)` ### Method `OrmStrategy(DatabaseConfig config, Class entityClass)` ### Method `StreamingJsonStrategy(DatabaseConfig config, Class entityClass)` ### Parameters * **config** (DatabaseConfig) - Configuration settings for the database connection. * **entityClass** (Class) - The class of the entity being persisted. * **idClass** (Class) - The class of the entity's ID (used in JsonStrategy). * **idField** (Field) - The field representing the entity's ID (used in JsonStrategy). ### Request Example ```json { "config": { "url": "mongodb://localhost:27017/mydatabase" }, "entityClass": "com.example.User" } ``` ### Response #### Success Response (200) * **Strategy instance** - A newly created instance of the specific persistence strategy (JsonStrategy, OdmStrategy, OrmStrategy, StreamingJsonStrategy) configured with the provided database settings and entity class. ``` -------------------------------- ### Persistence Strategy Implementations Source: https://javadoc.io/doc/in.arcadelabs.labaide/database-aide/1.0/in/arcadelabs/labaide/database/strategy/package-summary Details the various persistence strategy implementations available in the `in.arcadelabs.labaide.database.strategy` package. These strategies define how data is stored and retrieved from different backends. ```APIDOC ## Persistence Strategies Overview ### Description This section details the different persistence strategy implementations provided by the `in.arcadelabs.labaide.database.strategy` package. These strategies are responsible for interacting with specific data storage backends. ### Strategies * **`OrmStrategy`**: Implements SQL persistence using ORMLite. * **`OdmStrategy`**: Implements MongoDB persistence using Morphia. * **`JsonStrategy`**: Implements persistence by reading and writing to JSON files on disk. * **`StreamingJsonStrategy`**: Implements JSON persistence, but streams large datasets instead of loading everything into memory. * **`InMemoryStrategy`**: Implements an in-memory persistence strategy that stores data in a `ConcurrentHashMap`. Data is lost when the JVM shuts down. ### Core Interface * **`PersistenceStrategy`**: The core interface that defines the contract for all persistence strategies. ``` -------------------------------- ### JsonQueryBuilder Constructor Source: https://javadoc.io/doc/in.arcadelabs.labaide/database-aide/1.0/in/arcadelabs/labaide/database/query/JsonQueryBuilder Constructs a new JsonQueryBuilder with a source list. ```APIDOC ## JsonQueryBuilder Constructor ### Description Constructs a new JsonQueryBuilder. ### Method CONSTRUCTOR ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```java List sourceList = ...; JsonQueryBuilder builder = new JsonQueryBuilder<>(sourceList); ``` ### Response #### Success Response (200) N/A #### Response Example N/A ``` -------------------------------- ### OdmConfig Constructor - Java Source: https://javadoc.io/doc/in.arcadelabs.labaide/database-aide/1.0/in/arcadelabs/labaide/database/config/DatabaseConfig.OdmConfig Initializes a new instance of the OdmConfig class. This constructor does not take any arguments and sets up default configurations for ODM database connections. ```java public OdmConfig() ``` -------------------------------- ### Query Builder Implementations Source: https://javadoc.io/doc/in.arcadelabs.labaide/database-aide/1.0/index-all Documentation for specific query builder implementations, including `JsonQueryBuilder`, `OdmQueryBuilder`, and `OrmQueryBuilder`. ```APIDOC ## Query Builder Implementations ### Classes - **JsonQueryBuilder**: Handles queries for JSON data. - **OdmQueryBuilder**: Morphia implementation of `QueryBuilder` for ODM databases. - **Constructor**: `OdmQueryBuilder(Datastore, Class)` - **OrmQueryBuilder**: ORMLite implementation of `QueryBuilder` for ORM databases. - **Constructor**: `OrmQueryBuilder(Dao)` ### Methods (Common to multiple builders) - **offset(int)**: Sets the number of results to skip. - **orderBy(String, Direction)**: Adds sorting to the query results. ``` -------------------------------- ### Database Configuration Source: https://javadoc.io/doc/in.arcadelabs.labaide/database-aide/1.0/index-all Details about accessing and managing database configuration settings. ```APIDOC ## Database Configuration ### Description Provides access to configuration settings for database connections and behavior. ### Methods - **getConfig()** - **Description**: Retrieves the current database configuration. - **Method**: GET - **Endpoint**: /config - **updateConfig(DatabaseConfig config)** - **Description**: Updates the database configuration. - **Method**: PUT - **Endpoint**: /config ### Parameters #### Query Parameters None. #### Request Body - **config** (DatabaseConfig) - Required - The new configuration object. ### Response #### Success Response (200) - **config** (DatabaseConfig) - The database configuration object. #### Response Example ```json { "connectionUrl": "jdbc:h2:mem:testdb", "username": "sa", "password": "" } ``` ``` -------------------------------- ### Database Configuration and Builders Source: https://javadoc.io/doc/in.arcadelabs.labaide/database-aide/1.0/index-all This section covers database configuration options and builders, including settings for NoSQL document databases (ODM) and SQL databases (ORM). ```APIDOC ## Database Configuration and Builders ### Methods - **DatabaseBuilder.odm(Consumer)**: Configures a NoSQL document database (MongoDB) using Morphia. - **DatabaseBuilder.orm(Consumer)**: Configures a SQL database (MySQL, PostgreSQL, etc) using ORMLite. ### Enums - **DatabaseConfig.HandlerType.ODM**: Object-Document Mapping for document databases. - **DatabaseConfig.HandlerType.ORM**: Object-Relational Mapping for relational databases. - **DatabaseConfig.BackoffStrategy.NONE**: No delay between retry attempts. ``` -------------------------------- ### Initialize JsonConfig (Java) Source: https://javadoc.io/doc/in.arcadelabs.labaide/database-aide/1.0/in/arcadelabs/labaide/database/config/DatabaseConfig.JsonConfig This constructor initializes a new instance of the JsonConfig class. It does not require any parameters and sets up default configurations for JSON file persistence. ```java public JsonConfig() ``` -------------------------------- ### Initialize JsonStrategy with DatabaseConfig Source: https://javadoc.io/doc/in.arcadelabs.labaide/database-aide/1.0/in/arcadelabs/labaide/database/strategy/JsonStrategy Demonstrates how to configure and initialize the JsonStrategy for JSON file-based persistence. It specifies the entity type, ID type, and the path to the JSON file. ```java DatabaseConfig config = new DatabaseConfig() .setHandlerType(DatabaseConfig.HandlerType.JSON) .getJsonConfig() .setJsonFilePath("./data/users.json"); DatabaseAide db = new DatabaseAide<>(User.class, UUID.class, config); ``` -------------------------------- ### OrmQueryBuilder Constructor Source: https://javadoc.io/doc/in.arcadelabs.labaide/database-aide/1.0/in/arcadelabs/labaide/database/query/OrmQueryBuilder Constructs a new OrmQueryBuilder with the provided DAO. ```APIDOC ## Constructor OrmQueryBuilder ### Description Constructs a new OrmQueryBuilder. ### Method CONSTRUCTOR ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```json { "dao": ">" } ``` ### Response #### Success Response (200) None (Constructor) #### Response Example None ``` -------------------------------- ### Persistence Strategy Implementations Source: https://javadoc.io/doc/in.arcadelabs.labaide/database-aide/1.0/index-all Details on concrete implementations of the `PersistenceStrategy` interface, such as `InMemoryStrategy`, `StreamingJsonStrategy`, `JsonStrategy`, `OdmStrategy`, and `OrmStrategy`. ```APIDOC ## Persistence Strategy Implementations ### Classes - **InMemoryStrategy**: In-memory persistence strategy. - **StreamingJsonStrategy**: Persistence strategy for streaming JSON data. - **JsonStrategy**: Persistence strategy for JSON data. - **OdmStrategy**: Persistence strategy for ODM databases. - **Constructor**: `OdmStrategy(Datastore, Class)`, `OdmStrategy(DatabaseConfig, Class)` - **OrmStrategy**: Object-Relational Mapping (ORM) persistence strategy implementation. - **Constructor**: `OrmStrategy(DatabaseConfig, Class)` ### Methods - **query()**: Creates a query builder for constructing complex database queries. ``` -------------------------------- ### Database Aide Query Operations Source: https://javadoc.io/doc/in.arcadelabs.labaide/database-aide/1.0/in/arcadelabs/labaide/database/exception/class-use/DatabaseException Information on executing queries and counting entities using the Database Aide library. ```APIDOC ## DatabaseAide Query Operations ### Description Allows for executing queries to retrieve filtered lists of entities and counting entities. ### Method GET (Implicit for execute and count) ### Endpoint N/A (These are library methods, not REST endpoints) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **QueryBuilder/OrmQueryBuilder/OdmQueryBuilder** - Required - The query object to be executed or counted. ### Request Example ```json { "example": "QueryBuilder query = new QueryBuilder(...);" } ``` ### Response #### Success Response (200) - **List** - Returns a list of entities matching the query criteria. - **long** - Returns the count of entities matching the query criteria. #### Response Example ```json { "example": "List of entities" } ``` ```json { "example": "count = 10" } ``` ``` -------------------------------- ### OdmQueryBuilder Constructor Source: https://javadoc.io/doc/in.arcadelabs.labaide/database-aide/1.0/in/arcadelabs/labaide/database/query/OdmQueryBuilder Constructs a new OdmQueryBuilder instance. It requires a Datastore object for database operations and the Class object representing the entity type. ```java public OdmQueryBuilder(Datastore datastore, Class entityClass) ``` -------------------------------- ### Database Configuration API Source: https://javadoc.io/doc/in.arcadelabs.labaide/database-aide/1.0/in/arcadelabs/labaide/database/config/class-use/DatabaseConfig.OrmConfig This section details the configuration of SQL databases (MySQL, PostgreSQL, etc.) using ORMLite within the Database Aide library. ```APIDOC ## Database Configuration using ORMLite ### Description This endpoint allows for the configuration of SQL databases such as MySQL and PostgreSQL using the ORMLite framework. It utilizes a `DatabaseBuilder` to set up the ORM configuration. ### Method N/A (This is a library configuration, not a direct API endpoint) ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```java DatabaseBuilder builder = new DatabaseBuilder<>(); builder.orm(ormConfigurator -> { // Configure ORMLite settings here // Example: ormConfigurator.withDatabaseUrl("jdbc:mysql://localhost:3306/mydb"); // Example: ormConfigurator.withUsername("user"); // Example: ormConfigurator.withPassword("password"); }); ``` ### Response #### Success Response (N/A) N/A #### Response Example N/A ``` -------------------------------- ### JsonStrategy Constructor Source: https://javadoc.io/doc/in.arcadelabs.labaide/database-aide/1.0/in/arcadelabs/labaide/database/strategy/JsonStrategy Details the constructor for the JsonStrategy class. ```APIDOC ## Constructor Summary ### `JsonStrategy(DatabaseConfig config, Class entityClass, Class idClass, Field idField)` **Description:** Initializes a new instance of the `JsonStrategy` with the specified configuration, entity class, ID class, and ID field. ``` -------------------------------- ### PersistenceStrategy.query() Source: https://javadoc.io/doc/in.arcadelabs.labaide/database-aide/1.0/in/arcadelabs/labaide/database/query/class-use/QueryBuilder The `query()` method within `PersistenceStrategy` and its subclasses provides a way to obtain a `QueryBuilder` specific to the underlying storage strategy. ```APIDOC ## PersistenceStrategy.query() ### Description This method, available in `PersistenceStrategy` and its implementations (like `InMemoryStrategy`, `JsonStrategy`, `OdmStrategy`, `OrmStrategy`), returns a `QueryBuilder` tailored for the specific persistence mechanism. ### Method `QueryBuilder query()` ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) - **QueryBuilder** (QueryBuilder) - A `QueryBuilder` instance configured for the specific persistence strategy. #### Response Example N/A ``` -------------------------------- ### Persistence Strategy API Source: https://javadoc.io/doc/in.arcadelabs.labaide/database-aide/1.0/in/arcadelabs/labaide/database/strategy/InMemoryStrategy This section details the core methods provided by the PersistenceStrategy interface for interacting with a database. ```APIDOC ## POST /entities ### Description Creates a new entity in the persistent storage. ### Method POST ### Endpoint /entities ### Parameters #### Request Body - **entity** (E) - Required - The entity to create (must not be null) ### Response #### Success Response (200) - **message** (string) - Indicates successful creation. #### Response Example ```json { "message": "Entity created successfully" } ``` ## POST /entities/batch ### Description Creates multiple entities in a single batch operation. This method provides better performance for bulk operations compared to individual create calls. ### Method POST ### Endpoint /entities/batch ### Parameters #### Request Body - **entities** (Collection) - Required - The collection of entities to create (must not be null or empty) ### Response #### Success Response (200) - **message** (string) - Indicates successful batch creation. #### Response Example ```json { "message": "Entities created successfully in batch" } ``` ## GET /entities/{id} ### Description Reads an entity by its unique identifier. ### Method GET ### Endpoint /entities/{id} ### Parameters #### Path Parameters - **id** (ID) - Required - The unique identifier of the entity (must not be null) ### Response #### Success Response (200) - **entity** (E) - The entity if found, otherwise an empty response. #### Response Example ```json { "entity": { ... } } ``` ## GET /entities ### Description Reads all entities from the persistent storage. ### Method GET ### Endpoint /entities ### Response #### Success Response (200) - **entities** (List) - A list containing all entities. #### Response Example ```json { "entities": [ { ... }, { ... } ] } ``` ## GET /entities/stream ### Description Returns a stream of all entities for memory-efficient processing. This method is useful for processing large datasets without loading all entities into memory at once. ### Method GET ### Endpoint /entities/stream ### Response #### Success Response (200) - **stream** (Stream) - A stream of all entities. ### Response Example (Stream response handling depends on client implementation) ## PUT /entities ### Description Updates an existing entity in the persistent storage. ### Method PUT ### Endpoint /entities ### Parameters #### Request Body - **entity** (E) - Required - The entity to update (must not be null and must have a valid ID) ### Response #### Success Response (200) - **message** (string) - Indicates successful update. #### Response Example ```json { "message": "Entity updated successfully" } ``` ## DELETE /entities ### Description Deletes an entity from the persistent storage. ### Method DELETE ### Endpoint /entities ### Parameters #### Request Body - **entity** (E) - Required - The entity to delete (must not be null and must have a valid ID) ### Response #### Success Response (200) - **message** (string) - Indicates successful deletion. #### Response Example ```json { "message": "Entity deleted successfully" } ``` ## DELETE /entities/{id} ### Description Deletes an entity by its unique identifier. ### Method DELETE ### Endpoint /entities/{id} ### Parameters #### Path Parameters - **id** (ID) - Required - The unique identifier of the entity to delete (must not be null) ### Response #### Success Response (200) - **message** (string) - Indicates successful deletion. #### Response Example ```json { "message": "Entity deleted by ID successfully" } ``` ## POST /entities/createOrUpdate ### Description Creates a new entity or updates an existing one based on its ID. If an entity with the same ID exists, it will be updated. Otherwise, a new entity will be created. ### Method POST ### Endpoint /entities/createOrUpdate ### Parameters #### Request Body - **entity** (E) - Required - The entity to create or update (must not be null) ### Response #### Success Response (200) - **message** (string) - Indicates successful creation or update. #### Response Example ```json { "message": "Entity created or updated successfully" } ``` ## POST /query ### Description Creates a query builder for constructing complex database queries. The query builder provides a fluent API for building queries with filtering, sorting, pagination, and aggregation. ### Method POST ### Endpoint /query ### Response #### Success Response (200) - **queryBuilder** (QueryBuilder) - A new QueryBuilder instance for this entity type. ### Response Example (Query builder object structure depends on implementation) ## POST /transactions/begin ### Description Begins a new database transaction. Transactions allow multiple operations to be executed atomically. The returned transaction object should be used in a try-with-resources block to ensure proper cleanup. ### Method POST ### Endpoint /transactions/begin ### Response #### Success Response (200) - **transaction** (Transaction) - A new Transaction instance. ### Response Example (Transaction object structure depends on implementation) ## GET /health ### Description Performs a health check on the database connection and persistence strategy. ### Method GET ### Endpoint /health ### Response #### Success Response (200) - **status** (boolean) - True if the health check passes, false otherwise. #### Response Example ```json { "status": true } ``` ``` -------------------------------- ### Configure Simple JSON Persistence with DatabaseBuilder Source: https://javadoc.io/doc/in.arcadelabs.labaide/database-aide/1.0/in/arcadelabs/labaide/database/config/class-use/DatabaseConfig.JsonConfig Configures simple flat-file JSON persistence using DatabaseConfig.JsonConfig. This method takes a consumer to configure the JsonConfig object. ```java DatabaseBuilder json(Consumer jsonConfigurator) ```