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

Use Apache Commons FastDateFormat instead of SimpleDateFormat #41

Merged
merged 1 commit into from
Jul 27, 2015

Conversation

sanelson2000
Copy link

SimpleDateFormat's .parse() method does not treat format Strings the same as its .format() method does. This is a problem when dealing with dates created by ActiveRecord, which stores dates as strings with pseudo-microsecond precision in the following format: yyyy-MM-dd HH:mm:ss.SSS000 (It's actually stored with millisecond precision, but 000 is always appended to the string.

SimpleDateFormat will properly format a date given this format string, but it fails when trying to parse a date.

The FastDateFormat utility provided by Apache Commons Lang 3.x does not have this issue. As an added bonus, it is also faster and thread-safe.

This pull request uses FastDateFormat instead of SimpleDateFormat to get around this issue.

Unfortunately, it also has a few drawbacks.

  1. make is broken because it can't find the commons-lang3-3.4.jar file. This should be a simple fix, but I'm not familiar with make, so I'm not exactly sure where it's failing.
  2. It requires the user to include commons-lang3-3.4.jar with alongside sqlite-jdbc.jar in order to work. This may be a dealbreaker. I'm not sure if there is a way to include the contents of the jar inside of the sqlite jar when it's built, though. It seemed like it may be possible with Maven, but I'm not familiar with it, either.

@xerial
Copy link
Owner

xerial commented Jul 24, 2015

@sanelson2000
Thanks for the improvement. One of the design policy of sqlite-jdbc.jar is make it standalone-jar file.

Could you consider the followings?:

  • Extract a part of java files in commons-lang3-3.4 which is necessary to implement this feature, and add them to the src folder? This usage is valid under APL2
  • And also when embedding, rename the package org.apache.commons.lang3.time.FastDateFormat into org.sqlite.date etc. so that sqlite-jdbc can be used with other libraries that use commons-lang3.

@sanelson2000
Copy link
Author

Thanks for the suggestions. I'll look into it and update the PR when I get time.

@sanelson2000
Copy link
Author

@xerial
I've updated the PR with your suggested changes

@xerial
Copy link
Owner

xerial commented Jul 27, 2015

Looks good. Thanks for the contribution!

xerial added a commit that referenced this pull request Jul 27, 2015
Use Apache Commons FastDateFormat instead of SimpleDateFormat
@xerial xerial merged commit 5ac2541 into xerial:master Jul 27, 2015
@sanelson2000
Copy link
Author

No problem. Thanks for merging this!

@sanelson2000 sanelson2000 deleted the FastDateFormat branch July 27, 2015 20:35
@sanelson2000
Copy link
Author

@xerial Is there somewhere where I can download the latest build? I'm seeing this when I try to load the driver that I compiled in my production environment on Windows... I'm guessing because I compiled it incorrectly... Seems to be a problem with the native DLL

I, [2015-07-27T22:12:56.122000 #468]  INFO -- : Connecting to database: jdbc:sqlite:C:/consensus/Consensus_5.4.NIGHTLY.4953/consensus.db java.lang.UnsatisfiedLinkError: C:\Users\snelson\AppData\Local\Temp\sqlite-3.8.10.1-6038616b-b2e7-4e53-befe-d75da7b081fa-sqlitejdbc.dll: Can't find dependent libraries
E, [2015-07-27T22:12:56.247000 #468] ERROR -- : org.sqlite.core.NativeDB._open(Ljava/lang/String;I)V (Java::JavaLang::UnsatisfiedLinkError)
org.sqlite.core.NativeDB._open(Native Method)
org.sqlite.core.DB.open(org/sqlite/core/DB.java:161)

@xerial
Copy link
Owner

xerial commented Jul 28, 2015

Just released 3.8.10.2. Try this version.

@sanelson2000
Copy link
Author

Awesome. That works. Thanks!

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants