Notifications
Clear all

[Solved] Dynamic Enumeration

3 Posts
2 Users
2 Reactions
1,054 Views
1
Topic starter

What's the purpose of dynamic enumeration and when it should be used? any documentation also welcome.

1 Answer
1

A static enumeration is one where it doesn't make sense for instance-specific entries to be added (e.g. add to logistics.onenetwork.com but not parcels.onenetwork.com), because the code itself may rely on the exact values in the enumeration. For example, in an enumeration like "SortDirection", our code is keenly aware of only two options: ASC and DESC. It doesn't make sense for someone to go to the database and add another sort type, because the code won't be able to honor it in any meaningful way. Our legacy assumption is that enumerations are static by default.

A dynamic enumeration is one where the code doesn't really care what values are in the enum. It is either used for information only, or any behavior around it is parameterized. For example, we have a number of predefined LoadType enum entries, but our code doesn't do anything with them. It's just used to limit the user's options and it could be changed on a per-implementation basis. Enumerations can be made dynamic through an attribute on the enum definition:

<Enumeration type="LoadType" dynamic="true">
  ...
</Enumeration>

On startup, Platform always updates the ENUMERATION table to match the .enums file for static enums ... if there are missing values we insert them, and if there are unexpected values we delete them. For dynamic enumerations, platform realizes there may be added or removed values in the DB, so as long as there is at least one value in the DB for the enum type, it will not automatically add or remove any entries.

Sergey Soshnikov Topic starter 2014-09-16 09:09:00

on a last point .. does that mean that dynamic enumerations can't effectively have more than 1 "static" value? otherwise platform would never add them to database after the very first jboss startup and you have to do it manually in either case.

GregMerrill 2014-09-16 10:09:00

If the enum is empty in the DB, Platform will add all entries that it finds in the enums file for that dynamic enum. So generally speaking it works well for initialization of an empty DB, but doesn't work well if you add more static values over time - those have to be pulled in manually.