mirror of https://github.com/apache/openjpa.git
OPENJPA-2856 improve MariaDB TIME handling
* java.sql.Time parameters must be on date Jan 1st 1970, otherwise MariaDB won't find anything in the DB * from > 10 onwards MariaDB supports up to 6 fractions in TIME as well.
This commit is contained in:
parent
76225267d9
commit
ab8090f556
|
@ -20,11 +20,15 @@ package org.apache.openjpa.jdbc.sql;
|
|||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DatabaseMetaData;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Time;
|
||||
import java.sql.Types;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -196,6 +200,13 @@ public class MariaDBDictionary extends DBDictionary {
|
|||
timestampTypeName = "DATETIME{0}";
|
||||
fixedSizeTypeNameSet.remove(timestampTypeName);
|
||||
fractionalTypeNameSet.add(timestampTypeName);
|
||||
|
||||
// also TIME type now has optional fraction digits
|
||||
|
||||
if (dateFractionDigits > 0 ) {
|
||||
timeTypeName = "TIME{0}";
|
||||
fractionalTypeNameSet.add(timeTypeName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -516,4 +527,16 @@ public class MariaDBDictionary extends DBDictionary {
|
|||
}
|
||||
buf.append(")");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTime(PreparedStatement stmnt, int idx, Time val, Calendar cal, Column col) throws SQLException {
|
||||
// nail down to Jan 1st 1970, because MariaDB uses getTime LONG and freaks out.
|
||||
final Date date = new Date(val.getTime());
|
||||
date.setYear(70);
|
||||
date.setMonth(0);
|
||||
date.setDate(1);
|
||||
val = new Time(date.getTime());
|
||||
|
||||
super.setTime(stmnt, idx, val, cal, col);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,6 +67,7 @@ public class TestTemporalTypeQueryParameterBinding extends SingleEMFTestCase {
|
|||
"openjpa.jdbc.DBDictionary", "(dateFractionDigits=6)",
|
||||
TimeKeeper.class, TimeEntity.class);
|
||||
em = emf.createEntityManager();
|
||||
em.getTransaction().begin();
|
||||
|
||||
TimeKeeper pc = new TimeKeeper();
|
||||
pc.setDate(VALUE_DATE);
|
||||
|
@ -83,7 +84,6 @@ public class TestTemporalTypeQueryParameterBinding extends SingleEMFTestCase {
|
|||
te.setUDate2Time(VALUE_DATE);
|
||||
te.setUDate2Timestamp(VALUE_DATE);
|
||||
|
||||
em.getTransaction().begin();
|
||||
em.persist(pc);
|
||||
em.persist(te);
|
||||
em.getTransaction().commit();
|
||||
|
|
4
pom.xml
4
pom.xml
|
@ -77,7 +77,7 @@
|
|||
<derby.version>10.14.2.0</derby.version>
|
||||
<hsqldb.version>2.4.1</hsqldb.version>
|
||||
<mysql.connector.version>5.1.47</mysql.connector.version>
|
||||
<mariadb.connector.version>2.2.0</mariadb.connector.version>
|
||||
<mariadb.connector.version>2.7.2</mariadb.connector.version>
|
||||
<postgresql.connector.version>42.2.9</postgresql.connector.version>
|
||||
<mssql.connector.version>9.2.1.jre8</mssql.connector.version>
|
||||
|
||||
|
@ -718,7 +718,7 @@
|
|||
<dbcp.maxIdle>5</dbcp.maxIdle>
|
||||
<dbcp.minIdle>0</dbcp.minIdle>
|
||||
|
||||
<mariadb.server.version>10.3</mariadb.server.version>
|
||||
<mariadb.server.version>10.5</mariadb.server.version>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
|
|
Loading…
Reference in New Issue