openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Patrick Linskey (JIRA)" <>
Subject [jira] Commented: (OPENJPA-473) Add support for joda-time
Date Sat, 22 Dec 2007 15:19:43 GMT


Patrick Linskey commented on OPENJPA-473:

Generally, this should be pretty straightforward to implement.

What are the primary Joda-Time types that a user would want to store in a database? For each
type, could you also provide the following info:

1. should the type map to a single column or to multiple columns?
2. is the type mutable?
3. is the type final?

Is Joda-Time available in Maven?

To make this happen totally transparently with existing versions of OpenJPA, all within the
Joda-Time codebase:

1. create an implementation of org.apache.openjpa.lib.conf.ProductDerivation. Probably easiest
to just extend AbstractProductDerivation.

2. in beforeConfigurationLoad(), do something like this:

public boolean beforeConfigurationLoad(Configuration conf) {
    if (!(conf instanceof JDBCConfiguration))
        return false;

    MappingDefaults defs = ((JDBCConfiguration) conf).getMappingDefaults();
    if (!(defs instanceof MappingDefaultsImpl))
        return false;
    ((MappingDefaultsImpl) defs).setFieldStrategy(YourFieldType.class.getName(),
    // repeat for other types
    return true;

3. Create a ValueHandler for each field type that should be supported. You can see a sample
ValueHandler in the OpenJPA dist; search for 'PointHandler'.

Yes, you should pass the ValueHandler class name to the setFieldStrategy() method call. The
name 'setFieldStrategy()' is the tragic result of a refactoring that didn't quite make it
all the way through the codebase. I've just created new 'setValueHandler()' and 'getValueHandler()'
methods and deprecated the other ones.

4. create a 'META-INF/services/org.apache.openjpa.lib.conf.ProductDerivation' file in your
dist and put the full class name of your ProductDerivation into the file. This will make OpenJPA
automatically load your ProductDerivation when it starts up with the Joda-Time classes in
the classpath.

The advantage of doing this rather than putting the code into the OpenJPA build itself is
that it will work with all versions of OpenJPA, even ones that have already been released,
since the ProductDerivation will get loaded if both Joda-Time and OpenJPA are in the classpath.

> Add support for joda-time
> -------------------------
>                 Key: OPENJPA-473
>                 URL:
>             Project: OpenJPA
>          Issue Type: Improvement
>            Reporter: Tobias Bergman
> It would be great to have support for Joda-Time types in Entity classes, there are many
users that use Joda-Time instead of the JDK date time types today.

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

View raw message