mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-17 22:56:28 +00:00
#1272 - ENH: Add built in support for Joda Period and java time Period
This commit is contained in:
1 parent
265bda8cf2
commit
75462e7410
5 files changed
+107
-5
No files matched your search
@@ -838,6 +838,7 @@ public final class DefaultTypeManager implements TypeManager {
|
||||
|
||||
if (config.getClassLoadConfig().isJavaTimePresent()) {
|
||||
logger.debug("Registering java.time data types");
|
||||
typeMap.put(java.time.Period.class, new ScalarTypePeriod());
|
||||
typeMap.put(java.time.LocalDate.class, new ScalarTypeLocalDate());
|
||||
typeMap.put(java.time.LocalDateTime.class, new ScalarTypeLocalDateTime(mode));
|
||||
typeMap.put(OffsetDateTime.class, new ScalarTypeOffsetDateTime(mode));
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package io.ebeaninternal.server.type;
|
||||
|
||||
import java.time.Period;
|
||||
|
||||
/**
|
||||
* ScalarType for Joda Period stored as DB VARCHAR
|
||||
*/
|
||||
public class ScalarTypePeriod extends ScalarTypeBaseVarchar<Period> {
|
||||
|
||||
public ScalarTypePeriod() {
|
||||
super(Period.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLength() {
|
||||
return 20;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String formatValue(Period v) {
|
||||
return v.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Period parse(String value) {
|
||||
return Period.parse(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Period convertFromDbString(String dbValue) {
|
||||
return Period.parse(dbValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String convertToDbString(Period beanValue) {
|
||||
return beanValue.toString();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user