We need the ability to map various types of entities to different types of hierarchical data in our web application. As an example, consider an entity called Vendor. We need the ability to map each instance of vendor to geographical areas. Geographical areas are in the following hierarchy:
- Post code - most granular geographical area; example, EC2
- Locality - formed of post codes; example, Kensington. Each post code will be part of exactly one locality, no more.
- Town - formed of localities; example London. Each locality will be part of exactly one town, no more.
- District - formed of towns; example, Columbia.
- Province - formed of districts (equivalent to a state in some countries); example, South Carolina.
- Region - formed of provinces; example, Northeast Provinces.
- Country - formed of regions.
- Zone - formed of countries; example Southeast Asia.
- Continent - formed of zones.
We have a complete database of post codes, localities, towns, districts, provinces, regions, countries, zones and continents. This currently exists as tables in an RDBMS.
Our use cases:
- Ability to associate a Vendor with multiple geographies, at any level. For example, we could map Nestle to Mainland Europe (a zone), California (a US province) and Greater London (a district in UK).
- Ability to exclude some parts of a geography from the mapping. For example, when mapping Nestle to California, we may want to exclude San Diego.
- If the composition of a geography changes, no changes should be required to the mappings of which the geography is a part. For example, if a post code is added to Greater London, the mapping with Nestle should not require a change.
- Ability to query the database for a Vendor and a geography level. For example, if we query the database for Nestle and post codes, we should get all the post codes for Greater London, California (minus post codes for San Diego) and Mainland Europe. If we query the database for Nestle and countries, we should get UK (country for Greater London), US and all countries in Mainland Europe.
There are many such mappings with many different types of hierarchical data, this is just one of the requirements.
Looking for suggestions on storing the hierarchical data and the mappings. Please do not post answers that involve storing the data and mappings in RDBMS tables, as I am already aware of the options using RDBMS.