mirror of
https://github.com/querydsl/querydsl.git
synced 2026-07-03 21:07:49 +08:00
Merge pull request #712 from mysema/i711
Improve DateTime serialization for SQLite
This commit is contained in:
commit
41fd638f85
@ -13,9 +13,8 @@
|
||||
*/
|
||||
package com.mysema.query.sql;
|
||||
|
||||
import org.joda.time.ReadableInstant;
|
||||
|
||||
import com.mysema.query.types.Ops;
|
||||
import org.joda.time.*;
|
||||
|
||||
/**
|
||||
* SQLiteTemplates is a SQL dialect for SQLite
|
||||
@ -92,8 +91,13 @@ public class SQLiteTemplates extends SQLTemplates {
|
||||
if (o instanceof java.util.Date) {
|
||||
return String.valueOf(((java.util.Date)o).getTime());
|
||||
} else if (o instanceof ReadableInstant) {
|
||||
return String.valueOf(((ReadableInstant)o).getMillis());
|
||||
// TODO ReadablePartial
|
||||
return String.valueOf(((ReadableInstant) o).getMillis());
|
||||
} else if (o instanceof LocalDate) {
|
||||
return String.valueOf(((LocalDate) o).toDateTimeAtStartOfDay(DateTimeZone.UTC).getMillis());
|
||||
} else if (o instanceof LocalDateTime) {
|
||||
return String.valueOf(((LocalDateTime) o).toDateTime(DateTimeZone.UTC).getMillis());
|
||||
} else if (o instanceof LocalTime) {
|
||||
return String.valueOf(((LocalTime) o).getMillisOfDay());
|
||||
} else {
|
||||
return super.asLiteral(o);
|
||||
}
|
||||
|
||||
@ -13,35 +13,13 @@
|
||||
*/
|
||||
package com.mysema.query;
|
||||
|
||||
import static com.mysema.query.Constants.survey;
|
||||
import static com.mysema.query.Constants.survey2;
|
||||
import static com.mysema.query.Target.CUBRID;
|
||||
import static com.mysema.query.Target.DERBY;
|
||||
import static com.mysema.query.Target.HSQLDB;
|
||||
import static com.mysema.query.Target.MYSQL;
|
||||
import static com.mysema.query.Target.ORACLE;
|
||||
import static com.mysema.query.Target.SQLSERVER;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import com.mysema.query.sql.domain.QDateTest;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.mysema.query.QueryFlag.Position;
|
||||
import com.mysema.query.sql.SQLSubQuery;
|
||||
import com.mysema.query.sql.dml.DefaultMapper;
|
||||
import com.mysema.query.sql.dml.Mapper;
|
||||
import com.mysema.query.sql.dml.SQLInsertClause;
|
||||
import com.mysema.query.sql.domain.Employee;
|
||||
import com.mysema.query.sql.domain.QDateTest;
|
||||
import com.mysema.query.sql.domain.QEmployee;
|
||||
import com.mysema.query.sql.domain.QSurvey;
|
||||
import com.mysema.query.support.Expressions;
|
||||
@ -50,6 +28,20 @@ import com.mysema.query.types.PathImpl;
|
||||
import com.mysema.query.types.expr.Param;
|
||||
import com.mysema.testutil.ExcludeIn;
|
||||
import com.mysema.testutil.IncludeIn;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import static com.mysema.query.Constants.survey;
|
||||
import static com.mysema.query.Constants.survey2;
|
||||
import static com.mysema.query.Target.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class InsertBase extends AbstractBaseTest {
|
||||
|
||||
@ -71,6 +63,7 @@ public class InsertBase extends AbstractBaseTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@ExcludeIn(SQLITE) // https://bitbucket.org/xerial/sqlite-jdbc/issue/133/prepstmtsetdate-int-date-calendar-seems
|
||||
public void Insert_Dates() {
|
||||
QDateTest dateTest = QDateTest.qDateTest;
|
||||
LocalDate localDate = new LocalDate(1978, 1, 2);
|
||||
@ -91,7 +84,7 @@ public class InsertBase extends AbstractBaseTest {
|
||||
assertEquals(Integer.valueOf(2), result.get(2, Integer.class));
|
||||
|
||||
DateTime dateTime = result.get(dateTimeProperty);
|
||||
assertEquals(dateTime, localDate.toDateTimeAtStartOfDay());
|
||||
assertEquals(localDate.toDateTimeAtStartOfDay(), dateTime);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Loading…
Reference in New Issue
Block a user