Uploaded image for project: 'Cayenne'
  1. Cayenne
  2. CAY-1256

[PATCH] Easily subclassable ExtendedEnumType for reusing an existing Enum

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Major
    • Resolution: Unresolved
    • None
    • Undefined future
    • Core Library
    • None

    Description

      I've had this enum class that has character codes that I use in a CHAR(1) field.

      public enum Status {
      NEW('N'), PENDING('P'), CANCELLED('X'), CLOSED('C');
      [..]

      I didn't want that enum class to introduce a dependency on Cayenne (through the ExtendedEnumeration interface. So I changed ExtendedEnumType a bit so you can support that enum class with just a few lines of code and without using ExtendedEnumeration.

      Please see the patch for an example. I've written a test case for this although this just covers the materialization.

      In the application code I can now simply do this to register the type:
      node.getAdapter().getExtendedTypes().registerType(new StatusExtendedEnumType());
      (my StatusExtendedEnumType is basically the same as the MockEnumWithCodeEnumType in the patch)

      I hope you find this useful, too. Patch is against Cayenne Trunk.

      Attachments

        Activity

          People

            Unassigned Unassigned
            jeremias@apache.org Jeremias Maerki
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated: