Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve EOAttribute's value factory method to accept numeric arguments #962

Commits on Nov 12, 2021

  1. Improve EOAttribute's value factory method to accept numeric arguments

    When creating custom prototypes, one can configure a factory method to convert the attribute's value from/to a string or byte array. It's not possible to use an integer or a float value as an argument/return type, though, even if you set a value type of integer ("i") or float ("f"). Trying to fetch/save an entity containing an attribute using this prototype will throw the following exception:
    
    ```
    Error encountered converting value of class MyEnum to type specified in attribute 'myEnumAttribute' of entity 'MyEntity'.
    Conversion exception is : EOAttribute adaptorValueByConvertingAttributeValue(Object):
    Unable to convert value of class java.lang.Integer for attribute 'enumAttribute' in entity 'MyEntity' to adaptor type EOAttribute.AdaptorBytesType.
    Check the signature of the conversion method MyEnum.toInteger().
    ```
    
    This pull request adds the ability to configure a factory method that receives numeric values as an argument and a conversion method that returns numeric values. For instance, it allows the creation of enum prototypes that translate from/to a number in the database.
    
    I'm testing this change using an Oracle database, and everything has been working fine so far. I'll try to test it on other databases as well.
    hprange committed Nov 12, 2021
    Configuration menu
    Copy the full SHA
    16fa5f6 View commit details
    Browse the repository at this point in the history

Commits on Jan 9, 2022

  1. Add support for custom types when fetching numeric values from the da…

    …tabase
    
    Complements the previous commit by converting numeric values from the database to custom types using an attribute's `valueFactoryClass` and `valueFactoryMethod` properties. The parameter type passed to the `valueFactoryMethod` adheres to the `valueType` configured in the EOModel. It must be a reference type (java.lang.Integer, java.lang.Long, etc.), not a primitive type.
    
    The `DateJDBCColumn` class was deprecated in favor of `ERXEnhancedJDBCColumn` to accommodate this change. I'm not sure about the impact of this change on Wonder users, but it doesn't seem too risky. Please, let me know if I'm overlooking something.
    hprange committed Jan 9, 2022
    Configuration menu
    Copy the full SHA
    6271713 View commit details
    Browse the repository at this point in the history

Commits on Jan 10, 2022

  1. Improve error message when value factory method is not found

    This is not the final solution. It would be great to fix it in the `NSSelector` class instead. 🤔
    hprange committed Jan 10, 2022
    Configuration menu
    Copy the full SHA
    e8db8ec View commit details
    Browse the repository at this point in the history