Modifying an existing project configuration

A typical Atoti Server project will contain a DatastoreDescriptionConfig class providing a Spring Bean or static method that creates a DatastoreSchemaDescription object. Contributing stores and references to the creation of this object is usually done either directly in this class or via collections of stores and references exposed as Spring Beans in other DatastoreConfig classes.

The intended usage of the Datastore Helper API is to replace the logic in this configuration class with an @Autowired datastore configurator object and rely on the configurator’s buildSchemaDescription() method to provide the appropriate DatastoreSchemaDescription object.

Furthermore, DescriptionConfig classes that expose store and reference collections extend the AConfigurableSchema interface and add the stores and references directly to the configurator object. An implementation of the IDatastoreConfiguratorSetup class is then responsible for creating the datastore configurator Spring Bean.

An example migration would be:

@Configuration
public class DatastoreDescriptionConfig {

    public static IStoreDescription createTradesStoreDescription() {
        return StoreDescription.builder().withStoreName(StoreAndFieldConstants.TRADES_STORE_NAME)
                .withField(StoreAndFieldConstants.ASOFDATE, LOCAL_DATE).asKeyField()
                .withField(StoreAndFieldConstants.TRADES__TRADEID, STRING).asKeyField()
                .withField(StoreAndFieldConstants.TRADES__NOTIONAL, DOUBLE)
                .build();
    }

    public static Collection<IReferenceDescription> references() {
        final Collection<IReferenceDescription> references = new LinkedList<>();
        return references;
    }

    /**
     *
     * Provide the schema description of the datastore.
     * <p>
     * It is based on the descriptions of the stores in the datastore, the descriptions of the references
     * between those stores, and the optimizations and constraints set on the schema.
     *
     * @return schema description
     */
    public static IDatastoreSchemaDescription schemaDescription() {

        final Collection<IStoreDescription> stores = new LinkedList<>();
        stores.add(createTradesStoreDescription());

        return new DatastoreSchemaDescription(stores, references());
    }
}

where the schemaDescription() method is called statically in other configuration classes, to:

@Configuration
public class DatastoreConfiguratorSetup implements IDatastoreConfiguratorSetup {
    /**
     * Adds all customizations to the configurator.
     *
     * @param configurator The application datastore configurator.
     */
    @Override
    public void addModifications(IDatastoreConfigurator configurator) {

    }

    /**
     * Builds the datastores and references included in schemas. Must be called after {@link #addModifications}.
     *
     * @param configurator The application datastore configurator.
     */
    @Override
    public void buildSchemas(IDatastoreConfigurator configurator) {
        IConfigurableSchema schema = new DefaultSchema();
        schema.setConfigurator(configurator);
        schema.createStores();
        schema.createReferences();
        configurator.enableSchema(DefaultSchema.SCHEMA);
    }
}

together with

public class DefaultSchema extends AConfigurableSchema {

    public static final String SCHEMA = "Default";

    /**
     * {@inheritDoc}
     * If this method is not overridden in concrete implementation, it will not have any effect.
     */
    @Override
    public void createStores() {
        getConfigurator().addStore(SCHEMA,
                getConfigurator()
                        .storeBuilder(SCHEMA)
                        .withStoreName(StoreAndFieldConstants.TRADES_STORE_NAME)
                        .withField(StoreAndFieldConstants.ASOFDATE, LOCAL_DATE).asKeyField()
                        .withField(StoreAndFieldConstants.TRADES__TRADEID, STRING).asKeyField()
                        .withField(StoreAndFieldConstants.TRADES__NOTIONAL, DOUBLE)
                        .build()
        );
    }
}

where the DatastoreConfiguratorSetup class exposes an IDatastoreConfigurator object as a Spring Bean.