You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by "Jeremias Maerki (JIRA)" <ji...@apache.org> on 2009/08/13 11:45:14 UTC

[jira] Created: (CAY-1256) [PATCH] Easily subclassable ExtendedEnumType for reusing an existing Enum

[PATCH] Easily subclassable ExtendedEnumType for reusing an existing Enum
-------------------------------------------------------------------------

                 Key: CAY-1256
                 URL: https://issues.apache.org/jira/browse/CAY-1256
             Project: Cayenne
          Issue Type: Improvement
          Components: Cayenne Core Library
            Reporter: Jeremias Maerki


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.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (CAY-1256) [PATCH] Easily subclassable ExtendedEnumType for reusing an existing Enum

Posted by "Andrus Adamchik (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CAY-1256?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12742797#action_12742797 ] 

Andrus Adamchik commented on CAY-1256:
--------------------------------------

I don't understand the value of this approach. Writing a custom ExtendedType for a known enum is rather trivial as it is. Subclassing ExtendedEnumType doesn't seem to buy you much.

> [PATCH] Easily subclassable ExtendedEnumType for reusing an existing Enum
> -------------------------------------------------------------------------
>
>                 Key: CAY-1256
>                 URL: https://issues.apache.org/jira/browse/CAY-1256
>             Project: Cayenne
>          Issue Type: Improvement
>          Components: Cayenne Core Library
>            Reporter: Jeremias Maerki
>         Attachments: EasilySubclassableExtendedEnumType.diff
>
>
> 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.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (CAY-1256) [PATCH] Easily subclassable ExtendedEnumType for reusing an existing Enum

Posted by "Jeremias Maerki (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CAY-1256?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12742805#action_12742805 ] 

Jeremias Maerki commented on CAY-1256:
--------------------------------------

Sure, it's not difficult, but well, I don't have to implement the full ExtendedType interface including the lookup list for the enum values. Instead of  80+ lines I get away with 20 (where the actual meat on the bone is just three). Saves a lot of testing and most of all: time. I can put this in my own project but I thought it might be useful for someone else which is why I made the patch. If it doesn't help, it doesn't hurt, either. Right? ;-)

BTW, what I forgot to mention: there was this line:
statement.setString(pos, (String) e.getDatabaseValue());

Yes, the javadocs say it should be an Integer or a Character but If the return type is a Character rather than a String, it goes boom here. My patch uses toString() instead. Just in case.

> [PATCH] Easily subclassable ExtendedEnumType for reusing an existing Enum
> -------------------------------------------------------------------------
>
>                 Key: CAY-1256
>                 URL: https://issues.apache.org/jira/browse/CAY-1256
>             Project: Cayenne
>          Issue Type: Improvement
>          Components: Cayenne Core Library
>            Reporter: Jeremias Maerki
>         Attachments: EasilySubclassableExtendedEnumType.diff
>
>
> 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.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (CAY-1256) [PATCH] Easily subclassable ExtendedEnumType for reusing an existing Enum

Posted by "Jeremias Maerki (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CAY-1256?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jeremias Maerki updated CAY-1256:
---------------------------------

    Attachment: EasilySubclassableExtendedEnumType.diff

> [PATCH] Easily subclassable ExtendedEnumType for reusing an existing Enum
> -------------------------------------------------------------------------
>
>                 Key: CAY-1256
>                 URL: https://issues.apache.org/jira/browse/CAY-1256
>             Project: Cayenne
>          Issue Type: Improvement
>          Components: Cayenne Core Library
>            Reporter: Jeremias Maerki
>         Attachments: EasilySubclassableExtendedEnumType.diff
>
>
> 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.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.