The following item descriptor definition creates an enumerated property named transactionType
. The definition provides a list of valid String values; the SQL repository generates the corresponding integer codes when the template is initialized:
<!-- The "transaction" item type --> <item-descriptor name="transaction"> <table name="transaction" id-column-names="xact_id"> <property name="amount" data-type="int"/> <property name="transactionType" data-type="enumerated"> <option value="credit"/> <option value="debit"/> <option value="purchase"/> </property> </table> </item-descriptor>
Setting Integer Codes
You can explicitly specify the integer codes with the <option>
tag’s code
attribute:
<property name="transactionType" data-type="enumerated"> <option value="credit" code="200"/> <option value="debit" code="201"/> <option value="purchase" code="202"/> </property>
Reserved Enumerated Property Integer Codes
Avoid assigning integer codes to enumerated properties that collide with integer codes that are used or reserved for future use by Oracle Commerce Platform products. In general, it is safe to assign enumerated properties integer codes within the range of 101-999 (some older Oracle Commerce Platform versions use integer code values between 0-100). You can also safely use negative integers.
The following option codes are reserved for use by Oracle Commerce Platform modules and products:
Module/Product | Reserved Option Code Values |
---|---|
DAF | 1000 - 1999 |
DPS | 2000 - 2999 |
DSS | 3000 - 3999 |
Core Commerce | 4000 - 4999 |
Core Commerce B2B | 5000 - 5999 |
ATG Portal | 6000 - 6999 |
ATG Content Administration | 8000 - 8999 |
ATG Ticketing | 9000 - 9999 |
Oracle Commerce Service Center | 11000 - 11999 |
Oracle Commerce Platform | 12000 - 12999 |
Agent | 14000 - 14999 |
Future Oracle Commerce Platform use | 16000 + |
Converting Integer Codes to Strings
By default, an enumerated property returns its value as an integer code. You can configure an enumerated property so the repository converts the integer code into a string value by setting the useCodeForValue
attribute to false
. For example, you might modify the previous definition as follows:
<property name="transactionType" data-type="enumerated"> <attribute name="useCodeForValue" value="false"/> <option value="credit" code="200"/> <option value="debit" code="201"/> <option value="purchase" code="202"/> </property>
Given this definition, the string value credit
, debit
, or purchase
is returned when you get the transactionType
property.
Conversely, if useCodeForValue
is set to true
(the default), the integer code is returned. If an enumerated property returns an integer code, you can get the property editor for an enumerated property and use it to create a property editor that can convert between string and integer codes. See the JavaBeans specification for a description of PropertyEditors
.