ORMLite Date in MySQL/MariaDB with millisecond precision -
ormlite question. have set of pojos used both android app , java web service persist info (to sqlite , mariadb, respectively). since 5.3, believe, mariadb supports timestamps/datetimes length, expands precision of field microseconds (mysql supporting in new dev 5.6 release).
however, haven't been able ormlite persist date field millisecond precision, if manually modify field command line set column datetime(6). understand utilize datatype of date_long or date_string in pojo, i'd utilize actual datetime type in mariadb.
is there way can millisecond precision?
have comments under question understand what's happening here...basically need new databasetype (if working mariadb, subclass mysql one):
public class mariadbtype extends mysqldatabasetype { private final static string database_url_portion = "mysql"; private final static string driver_class_name = "org.mariadb.jdbc.driver"; private final static string database_name = "mariadb"; @override public boolean isdatabaseurlthistype(string url, string dbtypepart) { homecoming database_url_portion.equals(dbtypepart); } @override protected string getdriverclassname() { homecoming driver_class_name; } @override public string getdatabasename() { homecoming database_name; } @override protected void appenddatetype(stringbuilder sb, fieldtype fieldtype, int fieldwidth) { /** * timestamp in mysql funky stuff last-modification time. values 'not null' default * automatic default of current_timestamp. unusual design decision. */ if (isdatetimefieldwidthsupported()) { sb.append("datetime(").append(fieldwidth).append(")"); } else { sb.append("datetime"); } } public boolean isdatetimefieldwidthsupported() { homecoming true; } }
now can utilize date datatype normal , millisecond or microsecond precision...in case, used gray's existing annotation param width (good case this, need millisecond precision, not microseconds).
@databasefield(columnname = constants.timestamp, datatype = datatype.date, width = 3) private date timestamp;
finally, if you're trying solve specific issue, don't forget fractional seconds flag:
private static jdbcpooledconnectionsource csource = new jdbcpooledconnectionsource(); csource.setdatabasetype(new mariadbtype()); csource.seturl("jdbc:mysql://localhost:3306/database?usefractionalseconds=true"); csource.setusername("username"); csource.setpassword("password");
ormlite mariadb
No comments:
Post a Comment