-
-
Notifications
You must be signed in to change notification settings - Fork 100
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
Support for java.time #37
base: main
Are you sure you want to change the base?
Changes from 6 commits
678b0c1
559a93e
e86d9c8
ed1adcb
3eb089b
11d1d9f
5569c60
2f47ff5
4805f2e
ab77ff7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,10 @@ | |
import java.util.List; | ||
|
||
import com.j256.ormlite.field.FieldType; | ||
import com.j256.ormlite.field.SqlType; | ||
import com.j256.ormlite.field.DataType; | ||
import com.j256.ormlite.field.DataPersister; | ||
import com.j256.ormlite.field.FieldConverter; | ||
|
||
/** | ||
* H2 database type information used to create the tables, etc.. | ||
|
@@ -52,6 +56,20 @@ public void appendLimitValue(StringBuilder sb, long limit, Long offset) { | |
sb.append(limit).append(' '); | ||
} | ||
|
||
@Override | ||
public void appendOffsetTimeType(StringBuilder sb, FieldType fieldType, int fieldWidth) { | ||
sb.append("TIMESTAMP WITH TIME ZONE"); | ||
} | ||
|
||
@Override | ||
public FieldConverter getFieldConverter(DataPersister dataPersister, FieldType fieldType) { | ||
// H2 doesn't support TIME WITH TIME ZONE | ||
if (dataPersister.getSqlType() == SqlType.OFFSET_TIME) | ||
return DataType.OFFSET_TIME_SQL.getDataPersister(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Following the change in -core, this should now be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
// default is to use the dataPersister itself | ||
return dataPersister; | ||
} | ||
|
||
@Override | ||
public boolean isOffsetLimitArgument() { | ||
return true; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,10 @@ | |
import java.util.List; | ||
|
||
import com.j256.ormlite.field.FieldType; | ||
import com.j256.ormlite.field.SqlType; | ||
import com.j256.ormlite.field.DataType; | ||
import com.j256.ormlite.field.DataPersister; | ||
import com.j256.ormlite.field.FieldConverter; | ||
|
||
/** | ||
* Postgres database type information used to create the tables, etc.. | ||
|
@@ -127,4 +131,18 @@ public boolean isCreateIfNotExistsSupported() { | |
return super.isCreateIfNotExistsSupported(); | ||
} | ||
} | ||
|
||
@Override | ||
public void appendOffsetTimeType(StringBuilder sb, FieldType fieldType, int fieldWidth) { | ||
sb.append("TIMESTAMP WITH TIME ZONE"); | ||
} | ||
|
||
@Override | ||
public FieldConverter getFieldConverter(DataPersister dataPersister, FieldType fieldType) { | ||
// H2 doesn't support TIME WITH TIME ZONE | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor: this should refer to Postgres - not H2. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed, thanks |
||
if (dataPersister.getSqlType() == SqlType.OFFSET_TIME) | ||
return DataType.OFFSET_TIME_SQL.getDataPersister(); | ||
// default is to use the dataPersister itself | ||
return dataPersister; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This pattern is going to cause problems. Returning null leads to hard-to-debug NullPointerExceptions within ORMLite.
We have two options here I can think of:
Throw a friendly exception. It'll be a bit messy to take this into account in the tests though.
Make a best effort at converting. We should be able to easily emulate the behaviour of PostgreSQL and H2. They, at database level, just convert the timestamp to UTC and store it as such. On converting back it uses the system timezone. The timezone is never actually stored, so the
WITH TIMEZONE
didn't actually mean much in the first place. We could do the same here using aFieldConverter
toLocalTime
/LocalDateTime
. We want to takeInstant
into account too (which doesn't have its own SQL type because it rightly doesn't need one) so perhaps aFieldConverter
wrapper around the data persister would work better than just creating a newDataPersister
. It gives more flexibility for custom persisters too (say if you wanted to create persisters for ThreeTen for example). See Fixed exceptions in some JDBC drivers when working with chars #40 for an approach I took in another situation. I think this approach will work best. We won't be doing any worse than PostgreSQL and H2's efforts.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, haven't had a lot of free time on my hands. I'll be taking a vacation somewhere in the end of January/beginning of February and will do my best to catch up on both PRs then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, no problem. I’ll test everything again when you manage to take a look.