Issue Details (XML | Word | Printable)

Key: NUCCORE-437
Type: Improvement Improvement
Status: Closed Closed
Resolution: Fixed
Priority: Minor Minor
Assignee: Unassigned
Reporter: Erik Bengtson
Votes: 2
Watchers: 2
Operations

If you were logged in you would be able to see more operations.
DataNucleus Core

Support arbitrary enum values to be persisted

Created: 20/Apr/07 09:17 PM   Updated: 11/Jun/10 01:38 PM   Resolved: 04/Jun/10 04:18 PM
Component/s: None
Affects Version/s: None
Fix Version/s: 2.1.0.release


 Description  « Hide
Enum usage is normally a combination of name and ordinal values. Currently JPOX supports persisting the name or ordinal values, but should be allowed to persist arbitrary values. See the example:

public enum Test {
    RED(1), BLUE(5);
    
    private final int value;
    
    Test(int v)
    {
        this.value = v;
    }
    
    public final int getValue()
    {
        return this.value;
    }
    
    public final static Enum getEnum(int i)
    {
        switch(i)
        {
            case 1: return Test.RED;
            case 5: return Test.BLUE;
        }
        return null;
    }
}


<jdo>
    <package name="org.jpox.samples.jdo.enums">
        <class name="Palette">
            <field name="color" persistence-modifier="persistent" serialized="false">
             <column>
<extension vendor-name="jpox" key="enum-persistence-value-getter" value="getValue"/>
<extension vendor-name="jpox" key="enum-enum-value-getter" value="getEnum"/>
             </column>
            </field>
        </class>
    </package>
</jdo>

enum-enum-value-getter is the getter name for a static method that returns the Enum instance for the corresponding value.
enum-persistence-value-getter is the getter name for an instance method that returns the value to be persisted

Sort Order: Ascending order - Click to sort in descending order
Andy Jefferson added a comment - 24/Apr/07 11:28 AM
Moving to beta-3 since beta-2 release is tomorrow.

Andy Jefferson added a comment - 02/Jul/07 06:27 AM
Moved to next release since no comment on the status of this

Andy Jefferson added a comment - 08/Jan/08 05:30 PM
Not part of JDO2.1/JPA1 so moving to JPOX 1.3

Andy Jefferson added a comment - 04/Jun/10 04:18 PM
Use of extensions "enum-value-getter" (to get the value from an Enum) and "enum-getter-by-value" (to get the Enum from the value) are supported in SVN trunk. Extensions should be specified on field (1-1 relation) or on element, key, value (1-N relation).