> ## Documentation Index
> Fetch the complete documentation index at: https://docs.activeviam.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Atoti What-If Components

## Components of the Atoti What-If library

<table><thead><tr><th>Component</th><th>Description</th></tr></thead><tbody><tr><td>IUniqueIdGenerator</td><td>Interface for the creation of unique ID generators.</td></tr><tr><td>IncrementalUniqueIdGenerator</td><td>Implementation of <code>IUniqueIdGenerator</code> which uses an incremental counter starting from the Epoch second.</td></tr><tr><td>DatabaseSimulationEngine</td><td>Internal component wrapping interactions with an <code>IDatabaseService</code>.</td></tr><tr><td>ISimulationPersistenceManager</td><td>Interface for CRUD operations on a persistence layer for simulations.</td></tr><tr><td>HibernateSimulationPersistenceManager</td><td>An implementation of <code>ISimulationPersistenceManager</code> using Hibernate for persistence in a database.</td></tr><tr><td>IDatabaseSimulationsWorkflow</td><td>Interface for a component handling the creation, execution, retrieval and deletion of simulations within an application server.</td></tr><tr><td>IDatabaseSimulationsSecurityManager</td><td>Interface for a component handling branch permissions related to simulations.</td></tr><tr><td>SpringDatabaseSimulationsSecurityManager</td><td>An implementation of <code>IDatabaseSimulationsSecurityManager</code> matching Spring authentication against Atoti Server user roles.</td></tr><tr><td>NoOpDatabaseSimulationsSecurityManager</td><td>An implementation of <code>IDatabaseSimulationsSecurityManager</code> that ignores the user attempting to execute simulations.</td></tr><tr><td>DatabaseSimulationsWorkflow</td><td>Implementation of <code>IDatabaseSimulationsWorkflow</code> using <code>DatabaseSimulationEngine</code>, <code>ISimulationPersistenceManager</code>, <code>IDatabaseSimulationsSecurityManager</code>, <code>IUniqueIdGenerator</code> and <code>IDatabaseService</code> objects to orchestrate the execution of database simulations.</td></tr><tr><td>ArithmeticUpdateProcedureFactory</td><td>Implementation of <code>IUpdateWhereProcedureFactory</code> for update-where procedures that apply an arithmetic operation to a table field.</td></tr><tr><td>UpdateWithFieldValuesProcedureFactory</td><td>Implementation of <code>IUpdateWhereProcedureFactory</code> for update-where procedures that accepts a map of field names and associated objects.</td></tr><tr><td>UpdateWithListOfValuesProcedureFactory</td><td>Implementation of <code>IUpdateWhereProcedureFactory</code> for update-where procedures that accepts a set of keys and updated rows as a list of value maps.</td></tr><tr><td>IDatabaseSimulationDefinition</td><td>Interface for the definition of simulations, an extension of <code>IExtendedPluginValue</code> with methods for retrieving definition parameters, the description, the list of changes made by the simulation and a <code>JsonDatabaseEdit</code> object to use with the <code>IDatabaseService</code>.</td></tr><tr><td>ADatabaseSimulationDefinition</td><td>A serializable abstract implementation of <code>IDatabaseSimulationDefinition</code> that converts the parameters map to a string map, and wraps an array of <code>JsonDatabaseAction</code> objects in a <code>JsonDatabaseEdit</code>.</td></tr><tr><td>DatabaseSimulationDefinitionDTO</td><td>A DTO for the type, parameters and description of a database simulation definition.</td></tr><tr><td>DatabaseSimulationDiffDTO</td><td>A DTO for the before/after values resulting from executing a simulation.</td></tr><tr><td>IDatabaseSimulation</td><td>Interface for simulations, with methods for retrieving information about a specific instance of a simulation.</td></tr><tr><td>DatabaseSimulation</td><td>A serializable implementation of <code>IDatabaseSimulation</code>.</td></tr><tr><td>DatabaseSimulationDTO</td><td>A DTO for the relevant information associated with a database simulation.</td></tr><tr><td>DatabaseSimulationsUtils</td><td>A utility class containing helper methods for the creation of <code>JsonDatabaseAction</code> objects, the creation of duplicate tuples and conversions to and from a <code>JsonNode</code>.</td></tr></tbody></table>

## Auto-configuration

When using the Spring Boot Starter, the following beans are created automatically. All auto-configuration classes are gated by `@ConditionalOnWhatIfEnabled`, so setting `atoti.what-if.enable: false` disables all of them.

| Bean                                  | Auto-configuration class   | Condition                                                                        |
| ------------------------------------- | -------------------------- | -------------------------------------------------------------------------------- |
| `DatabaseSimulationEngine`            | `WhatIfCoreConfig`         | Always                                                                           |
| `IUniqueIdGenerator`                  | `WhatIfCoreConfig`         | Always                                                                           |
| `ISimulationPersistenceManager`       | `WhatIfPersistenceConfig`  | `IWhatIfPersistenceProperties` bean present                                      |
| `IDatabaseSimulationsSecurityManager` | `WhatIfSecurityConfig`     | Based on `security.type` property                                                |
| `IDatabaseSimulationsWorkflow`        | `WhatIfWorkflowConfig`     | Always                                                                           |
| `DatabaseSimulationsRestService`      | `WhatIfRestConfig`         | Web application context                                                          |
| `IDistributedQueryResultsMerger`      | `WhatIfDistributionConfig` | `distribution.enabled: true`                                                     |
| `RestDistributedDatabaseService`      | `WhatIfDistributionConfig` | `distribution.enabled: true` and `distribution.create-distributed-service: true` |

### Auto-configuration classes

| Class                      | Description                                                |
| -------------------------- | ---------------------------------------------------------- |
| `WhatIfCoreConfig`         | Creates the simulation engine and ID generator.            |
| `WhatIfPersistenceConfig`  | Creates the Hibernate-based persistence manager.           |
| `WhatIfSecurityConfig`     | Creates the security manager based on the configured type. |
| `WhatIfWorkflowConfig`     | Creates the simulation workflow.                           |
| `WhatIfRestConfig`         | Creates the REST service for UI interactions.              |
| `WhatIfDistributionConfig` | Creates beans for distributed mode.                        |

### How to override auto-configured beans

All auto-configured beans use `@ConditionalOnMissingBean`, meaning your custom beans take precedence. Define a bean of the same type in your configuration:

```java theme={"languages":{"custom":["/engine/python-sdk/0.9/languages/pycon.tmLanguage.json"]}}
@Bean
public IUniqueIdGenerator customIdGenerator() {
    return new MyCustomIdGenerator();
}
```

See [How to customize auto-configured beans](./customize-beans) for more details and examples.

## Simulation and definition objects

In previous versions of Atoti What-If, definitions contained concrete parameters and abstract methods that directly operate on a datastore. Version 2.0 allows for free-form serializable parameters and methods that build objects to be passed to the `IDatastoreInstance`. The results of the simulation (diffs) are also omitted from the persistence of the simulations. They are now an optional implementation detail for definitions that require them.

DTOs are also provided for both object types, that is, for serialization and REST service implementations.
