Replacing immutable core API calls

Any typical ActivePivot implementation will define stores using two core API objects, the StoreDescriptionBuilder and ReferenceDescriptionBuilder. These objects are followed by a chain of fluent API calls that can be considered immutable - the chain is a complete definition of the store or reference configuration, and any partial (or iterative) definition is difficult due to the nested interfaces composing the fluent API.

The Datastore Helper API makes these fluent API chains mutable, by providing implementations that allow external customisations to be defined using the datastore configurator.

The MutableStoreDescriptionBuilder and MutableReferenceDescriptionBuilder objects can be instantiated manually using their public constructors, but using the factory methods provided in the configurator allows for non-breaking future changes in the implementation details of the Datastore Helper API.

A typical migration of an existing project would entail the following modifications.

MutableStoreDescriptionBuilder

The standard store definition

StoreDescription.builder()
    .withStoreName(TRADE_PNL_STORE_NAME)
    .withField(AS_OF_DATE, LOCAL_DATE).asKeyField()
    .withField(TRADE_PNL__TRADE_ID).asKeyField()
    .withField(TRADE_PNL__SCENARIO_SET).asKeyField()
    .withField(TRADE_PNL__CALCULATION_ID).asKeyField()
    .withField(TRADE_PNL__RISK_FACTOR).asKeyField()
    .withField(TRADE_PNL__RISK_CLASS)
    .withField(TRADE_PNL__RISK_FACTOR_TYPE)
    .withField(TRADE_PNL__LIQUIDITY_HORIZON, INT)
    .withField(TRADE_PNL__CCY)
    .withVectorField(TRADE_PNL__PNL_VECTOR, DOUBLE)
    .withModuloPartitioning(TRADE_PNL__TRADE_ID, NUM_HASH_PARTITIONS)
    .onDuplicateKeyWithinTransaction().logException()
    .build();

becomes

configurator.storeBuilder(PNL_SCHEMA)
    .withStoreName(TRADE_PNL_STORE_NAME)
    .withField(AS_OF_DATE, LOCAL_DATE).asKeyField()
    .withField(TRADE_PNL__TRADE_ID).asKeyField()
    .withField(TRADE_PNL__SCENARIO_SET).asKeyField()
    .withField(TRADE_PNL__CALCULATION_ID).asKeyField()
    .withField(TRADE_PNL__RISK_FACTOR).asKeyField()
    .withField(TRADE_PNL__RISK_CLASS)
    .withField(TRADE_PNL__RISK_FACTOR_TYPE)
    .withField(TRADE_PNL__LIQUIDITY_HORIZON, INT)
    .withField(TRADE_PNL__CCY)
    .withVectorField(TRADE_PNL__PNL_VECTOR, DOUBLE)
    .withModuloPartitioning(TRADE_PNL__TRADE_ID, NUM_HASH_PARTITIONS)
    .onDuplicateKeyWithinTransaction().logException()
    .build();

MutableReferenceDescriptionBuilder

The standard reference definition

ReferenceDescription.builder()
    .fromStore(COUNTERPARTY_STORE_NAME)
    .toStore(COUNTRY_STORE_NAME)
    .withName(COUNTERPARTY_TO_COUNTRY_RISK)
    .withMapping(COUNTERPARTY__COUNTRY_OF_RISK, COUNTRY__COUNTRY_CODE)
    .withMapping(AS_OF_DATE, AS_OF_DATE)
    .build();

becomes

configurator.referenceBuilder(PNL_SCHEMA)
    .fromStore(COUNTERPARTY_STORE_NAME)
    .toStore(COUNTRY_STORE_NAME)
    .withName(COUNTERPARTY_TO_COUNTRY_RISK)
    .withMapping(COUNTERPARTY__COUNTRY_OF_RISK, COUNTRY__COUNTRY_CODE)
    .withMapping(AS_OF_DATE, AS_OF_DATE)
    .build();