Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

How to load model static data into a database dictionary
xomega
#1 Posted : Wednesday, October 24, 2012 6:21:53 PM(UTC)
xomega



When you define static enumerations in your model and keep it as the primary source of the static data, you will be able to generate various artifacts that will allow you to get access to the enumerations and their values both in your code during development and in your application at runtime.

However, it is sometimes useful to be able to access enumerations in the database layer as well. For example, if you need to look up descriptions or additional properties of certain enumeration items in SQL queries or stored procedures. Therefore, it is useful to be able to store such data in the database in one or several dictionary tables. You will also be able to load the static data from database during runtime, as opposed to loading the cache from an XML file, by defining appropriate service operations to read the data and generating lookup cache loaders based on these operations.

Xomega allows you to easily generate an SQL script that will reload the enumeration data into your database tables. The following steps explain how to do that.

  1. Set up database dictionary objects in the model for storing your enumerations and their additional properties in the database. One of them can be marked as default, which will be used for enumerations that don't explicitly specify the dictionary object their values is stored in.
  2. For any enumeration that should not be stored in the default dictionary, if one exists, add a config element as a child of the enum element if necessary.
  3. Add a sql:enum-source element inside of the config element, where the sql prefix maps to the "http://www.xomega.net/sql" namespace. Note, that if your enumeration was imported from a database, this configuration will be automatically set up and you can skip the related steps.
  4. Set the items-object attribute to the name of the dictionary object that stores the items of the current enumeration.
  5. Set the item-properties-object attribute to the full dot-delimited name of the dictionary object or subobject that stores the additional properties for the current enumeration's items if applicable.
  6. Open the Properties tab of the Enumeration Reload SQL generator in the Static Data folder.
  7. Set the Output Path parameter to the target location of the generated SQL script.
  8. Run the generator and carefully review the generated script file to make sure it doesn't cause any negative side effects.
  9. If the script is fine, then run it against your database. The generated script is designed to be re-runnable, so that it would not fail or break something if you run it multiple times.

The following example demonstrates how to specify a source dictionary object for a model enumeration.
Code:
<enum name="marital status">
  <item name="Single" value="S"/>
  <item name="Married" value="M"/>
  <config>
    <sql:enum-source items-object="dictionary" item-properties-object="dictionary.property"/>
  </config>
</enum>
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.