Migration notes 2.0.0

Migrating from versions 1.x

The 2.0 version of the Datastore Helper (DaSH) is not backwards-compatible with the 1.x versions. The required changes are listed in this section, together with improvement suggestions that are not mandatory for a successful migration.

Initial store definitions

Required

Replace any instantiation of a CustomisableStoreDescriptionBuilder by a MutableStoreDescriptionBuilder or the result of a configurator.storeBuilder(schemaName) call.

Initial reference definitions

Required

Replace any instantiation of a CustomisableReferenceDescriptionBuilder by a MutableStoreDescriptionBuilder or the result of a configurator.referenceBuilder(schemaName) call.

Datastore customisations configuration class

Required

The IDatastoreCustomisationsConfig interface has been renamed to IDatastoreConfiguratorSetup and now creates and exposes an instance of IDatastoreConfigurator as a Spring Bean by default.

Override the addModifications() and buildSchemas() methods, providing entrypoints for defining modifications to initial definitions and instantiating schema classes, respectively. For an example, see Datastore configuration classes/Optional.

Datastore configuration classes

Optional

Configuration classes can keep the standard pattern of defining individual stores and references, exposed as Collection Spring Beans autowired in the main datastore configuration class.

The preferred usage is for configuration classes to extend AConfigurableSchema and override the createStores() and createReferences() methods, adding the stores and references directly to the configurator object.

Instantiate the resulting classes individually, set the configurator object using setConfigurator() and call the aforementioned methods. This should be done in an instance of the IDatastoreConfiguratorSetup interface, which exposes the configurator Spring Bean for further use.

For example, a given schema:

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()
        );
    }
}

would then be instantiated:

@Configuration
public class DatastoreConfiguratorSetup implements IDatastoreConfiguratorSetup {
    /**
     * Adds all customisations 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);
    }
}

Defining customisations

Required

The DaSH 1.x DatastoreHelper class, providing static helper methods for customising datastore configurations, has been replaced with an IDatastoreConfigurator object. You need to make any calls to the DatastoreHelper methods on the configurator.

Optional

DaSH 2.0 introduces the concept of schemas when defining customisations. The migrated DatastoreHelper method calls can be performed as-is, with all customisations defined for the IConfigurableSchema.GLOBAL schema name. It is advisable to replace these calls with specific schema names, to allow more granular control over the datastore configuration.

All available methods include an option to define the schema name as the first parameter, e.g:

public IDatastoreConfigurator appendField(String storeName, CustomField field)
public IDatastoreConfigurator appendField(String schema, String storeName, CustomField field)

public IDatastoreConfigurator addConfiguration(String storeName, IMutableStore config)
public IDatastoreConfigurator addConfiguration(String schema, String storeName, IMutableStore config)

Additionally, customisation methods (adding new stores and references and modifying fields, references and store configurations) return the configurator object and therefore can be chained:

configurator
    .updateField(PnLDatastoreDescriptionConfig.SCHEMA, PNL_STORE_NAME, new CustomField(StoreFieldNames.TYPE).asKeyField())
    .insertField(PnLDatastoreDescriptionConfig.SCHEMA, PNL_STORE_NAME, DAILY, new CustomField(MONTHLY, ILiteralType.DOUBLE).asNullable())
    .insertField(PnLDatastoreDescriptionConfig.SCHEMA, PNL_STORE_NAME, MONTHLY, new CustomField(YEARLY, ILiteralType.DOUBLE).asNullable())
    .insertField(PnLDatastoreDescriptionConfig.SCHEMA, PNL_STORE_NAME, YEARLY, new CustomField(LIFETIME, ILiteralType.DOUBLE).asNullable());

Wiring into application configuration

Required

The IDatastoreCustomisations Spring Bean used in some DaSH 1.x projects has been replaced by a default IDatastoreConfigurator Spring Bean exposed by the IDatastoreConfiguratorSetup interface implementation. The main datastore configuration class will need to autowire an IDatastoreConfigurator object, to have access to enabled schemas and the stores/references defined for each of them:

configurator.getEnabledSchemas()
		.forEach(
				schema -> {
                    // For existing stores and reference lists
					stores.addAll(configurator.getCustomisations(schema).getAddedStores());
					refs.addAll(configurator.getCustomisations(schema).getAddedReferences());
				}
		);
IDatastoreSchemaDescription description	= new DatastoreSchemaDescription(stores, refs);

Optional

Previous versions of DaSH required autowiring an IDatastoreCustomisations Spring Bean to ensure the static DatastoreHelper class contained the required customisations, but the resulting object did not provide further functionality. Due to the common usage of store/reference Collection beans, bean ordering posed a potential problem as stores could be created prior to any customisations being defined.

To mitigate this issue when using DaSH 2.0, the IDatastoreConfiguratorSetup provides addModifications() and buildSchemas() methods that are called prior to exposing the IDatastoreConfigurator Spring Bean.

The required example assumes the older pattern of creating default lists of stores and references, on top of which configurator customisations are added. To reduce complexity, if you define all stores on the configurator (see adding stores or the optional datastore configuration migration), the configurator can create the IDatastoreSchemaDescription object directly:

IDatastoreSchemaDescription description = configurator.buildSchemaDescription();