java - Persisting data suited for enums -


Most projects have some types of data that are essentially static between release and stability, such as for use in anonymous form, such as status, transaction type, error code etc. For example, I would only use a normal position value:

  public domain status {active (10, "active"); End (11, "expired"); / * Other conditions ... * / / * Constructors, Gates, etc. * /}  

I want to know what other people do in terms of persistence about data like these. I see some options, each of which has some obvious advantages and disadvantages:

  • Stamps to the possible conditions in the status table and all the possible status domain objects cache the use of the whole application
  • Use only one enum and do not issue a list of available conditions
  • to create a data organizational sacred war between me and my DBA
  • Stay in position And maintain an NM in the code, but do not create duplicated data

My priority is the second option, though my DBA claims that our end user is ready to make reports Due to access to data, and not the continuation of the situation, there will be an incomplete data model (counter-argument: it can be resolved with documentation).

Is there a conference that most people use here? What are the people's experiences with each and what are the other options?

Edit:

After thinking about it for a while, my real stubborn struggle comes with handling of ID values, Is tied. These values ​​will be inserted as default data when installing apps. At this point they have such aids that are eligible to use as a foreign key in another table, I think my code needs to know about these IDs so that I can easily recover the status object and We can assign them to other objects. What do I do about this? I can add another field, such as "code", to look at things, or to look at situations based on name, which is icky.

We store anonymous values ​​in the database using some explicit string or character values. Then to go from the database value back to the enum, we write to write a stable method on the enum square and find the right one.

If you expect a lot of enum values, you can use a static mapping to quickly translate the Hashampant & lt; String, Mynem & gt; .

Do not store the actual anonym name ("active" in your example), because it is easily rearranged by developers.


Comments