-
-
Notifications
You must be signed in to change notification settings - Fork 213
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
Any plans to support Java 8 Time API? #154
Comments
@graynk sounds like a good idea! |
However, doing it the usual way would mean upping the target for the project from 1.6 to 1.8, which I'm not sure is acceptable, since it's being used for Android development. And I'm not that familiar with reflection, nor do I see the reason to make custom persisters based on reflection for my use cases. |
That would require the approval of the maintainer, @j256. |
I already had a basic implementation but it all maps to |
As for the Android situation, you'll probably be able to avoid reflection for the most part (JDK 8 itself is fine if set to compile to 1.7 bytecode) but you will still need some sort of runtime check. Perhaps something in I think |
Yeah, I bumped into that already, the naming is a bit misleading. Not even sure how to name this new
You're right, it compiled just fine with 1.6 source and target, thanks |
Officially, it’s a standard of JDBC 4.2. Although you don’t need to restrict things 4.2, personally I’d argue it’s acceptable as that standard is officially a part of Java SE 8.
That works, but if you are using JDBC 4.2 the new, more direct API for it is |
Something also to consider is whether we also need Note that |
Okay, thanks for that. At first I made it work via conversions from/to
Well, it doesn't seem particularly challenging, just more of the same, so I'd say it's worth to support the whole java.time API, not just part of it. I may be wrong though.
Looking at H2 documentation again, they map both
Also about that -- considering there're backports like ThreeTen to both Java 6 and Android, it can't be just a simple JRE version check, I'd need to check if there's an appropriate class in classpath. Something like |
I fear that there will be differences between implementations on this, some using timezone and some not, particularly without guidance of a standard in JDBC.
Yep, I think that's fine. Other package names will not work out-of-the-box anyway without any check. |
Not sure I understand what this means. If JDBC driver complies with 4.2, then it supports mapping What worries me, is the actual compliance with JDBC 4.2 on the driver side. PostgreSQL is 4.2 "compliant", but then the documentation says:
But then there's this driver that follows 4.2 exactly. Derby says that it's 4.2 compliant, but all I could find in their docs point to java.sql types and this 4 year old unresolved JIRA issue. MySQL types "can always be converted" to java.sql types, but it also "follows JDBC specification where appropriate" (what? I'm guessing that's, again, because they don't have |
Sorry, I worded that extremely poorly and yeah, we can't guarantee much in regards to other JPA ORMs. That was already out of the window anyway with byte array.
PostgreSQL is correct for No idea about the situation of Derby but it just seems no-one there is interested in actually making it 4.2 compliant. I have to say it's hard to follow progress at Apache sometimes. Some libraries they have just seem abandoned before jumping back to life after several years.
MySQL's documentation is a load of hot trash. But I believe it does support
This is important to note. If a database does not support Any decision above may be relevant to PostgreSQL. On the topic of PostgreSQL, I believe you may find the reason for not supporting
On the point of
This could perhaps be because SQLite doesn't actually support date or time types. You just store them as strings, integers or reals. So in short, it seems to be actual database-level issues apart from Derby which is just pure non-compliance. Perhaps that is one too many though. |
Can't we use
Well, their current driver is compliant to some older specification of JDBC, it's able to return java.sql.Date and java.sql.Timestamp, so why not java.time? We shouldn't really care what they use internally and how the driver transforms Java objects to it's internals, as long as it exposes an interface, compliant with the specification. In the ideal world, that is. I presume the situation there is the same as with Derby, no one really wants to implement 4.2. So, my hacky suggestion is thus: we make two persistors for the troublesome (Offset/Instant) classes. One is the pure java.time, the other is a converter from java.time to java.sql types. Then we override |
True, you'll likely need to create a field converter for it.
Ultimately that's probably the only solution. You'll probably be unable to save the timezone like PostgreSQL & H2 but it seems like the support for timezones is pretty poor anyway across different DBs. |
I would also like to understand the reasoning behind
They all fail on this part, because
What I don't understand is why are we testing dates for this and why There are a bunch of new failed tests as well (for I'd also like to understand what |
I pushed base changes to my fork, but I haven't yet fixed issues described above, and haven't even begun adding support to java.sql conversions https://github.com/graynk/ormlite-core/tree/jsr310-persister-pr |
Java 8 has come and already almost gone, java.time (JSR-310) is now part of JDK and the recommended datetime API that is meant to replace old and clunky java.util.time in new projects (since they can't really deprecate it even if they'd love to). Are the any plans to support it? I saw a few StackOverflow questions about it with the answers that recommended to write custom persisters, but haven't found any in the wild. I'll start writing my own and will make a PR if I feel that my implementation is good enough to be used by general public, but aren't there any implementations that have already been tested?
The text was updated successfully, but these errors were encountered: