Datastore Helper Examples

This page provides a description of the functionality of Datastorehelper. It features multiple example of common use cases for modifications to the Reference Implementation. The techniques employed are generic examples that can be extended, adapted and repeated for any use case that we need. In all cases, we make minimal changes to the Reference Implementation.

All of the project customisations will be defined in the loadCustomisations() method in the DatastoreCustomisations class.

The DatastoreHelper class contains helper methods for

  • field customisations - inserting, appending, updating and removing fields from a datastore
  • reference mapping customisations - adding or removing pairs of fields
  • store configuration customisations - partitioning, chunk sizes, duplicate key within transaction behaviour, NUMA selector, etc.

Configuration options can be split into the following categories:

  1. D the CustomisableStoreDescriptionBuilder object.
  2. Custom global configuration - defined via the DatastoreHelper.addConfiguration() method, using the ConfigurationConstants.ALL_STORES constant as the store name. These options will apply to all customisable stores across the entire project.
  3. Multi-store custom configuration - defined via the DatastoreHelper.addConfiguration(), with a list of store names passed in. These options will apply to all the stores in the list.
  4. Individual custom configuration - defined via the DatastoreHelper.addConfiguration(), with a single store name.

Most store configuration options will follow a standard order of precedence (custom configuration for the store, custom global configuration, default store configuration), except for:

  • custom indexes: as multiple secondary indexes can be created for a store, the indexing calls are keyed by the input fields.
  • partitioning: all partitioning calls that accept a field (or more) as inputs are keyed by those fields.
  • individual properties: the calls are keyed by the property name, so for any given property name, the order of preference will be respected, however properties defined by default will be used unless overridden.

The order of precedence does not differentiate between configuration options defined as part of multi-store or individual custom configurations. If configuration options are defined multiple times for the same stores, the ordering will be chronological.

Inserting two fields into a TradeStore, after the TradeId field:

Map<String, CustomField> customFields = new HashMap<>();

customFields.put("TradeId", new CustomField("TradeLeg", ILiteralType.STRING).asKeyField());
customFields.add("TradeLeg", new CustomField("Theta", ILiteralType.DOUBLE).asNullable());

DatastoreHelper.insertFields("TradeStore", customFields);

Appending a vector field to the end of the Delta store:

DatastoreHelper.appendField("Delta", new CustomField("Interpolated Delta", ILiteralType.DOUBLE, new double[]{-1.0}).asVectorField().swap());
Removing the RiskClass field from the TradePnLs store:

Changing the TradeLeg field in the TradeStore from a String to a Double:

DatastoreHelper.updateField("TradeStore", new CustomField("TradeLeg", ILiteralType.DOUBLE).asKeyField());
Including a field into the reference between the TradeStore and the MarketDataStore:
DatastoreHelper.addReference("TradeStore", "MarketDataStore", new Pair("TradeLeg","TradeLeg"));

** Removing two fields from the reference between the TradeBase and the Delta stores:**

List<IPair<String, String>> referencesToRemove; referencesToRemove.add(new Pair("RiskClass", "RiskClass")); referencesToRemove.add(new Pair("RiskMeasure", "RiskMeasure")); DatastoreHelper.removeReferences("TradeBase", "Delta", referencesToRemove);

Adding an index on the Trade Attributes store. Setting a global config for the chunksize, overridden by the TradeAttributes configuration:

CustomisableStoreConfig config = new CustomisableStoreConfig(); config .withIndexOn(StoreFieldNames.INSTRUMENT_CLASS, StoreFieldNames.AS_OF_DATE); config .withChunkSize(2048); CustomisableStoreConfig globalConfig = new CustomisableStoreConfig(); globalConfig .withChunkSize(1024); DatastoreHelper.addConfiguration(StoreNames.TRADE_ATTRIBUTE_STORE_NAME, config); DatastoreHelper.addConfiguration(ConfigurationConstants.ALL_STORES, globalConfig);

For more usage examples, refer to the test classes in the package.