mirror of https://github.com/apache/openjpa.git
OPENJPA-2755 OPENJPA-2555 use scale to set Date fractions
This commit is contained in:
parent
9461ffdfcd
commit
3b4c2e6f42
|
@ -251,7 +251,7 @@ public class DynamicSchemaFactory
|
||||||
setSize(size);
|
setSize(size);
|
||||||
if (typeName != null)
|
if (typeName != null)
|
||||||
setTypeIdentifier(DBIdentifier.newColumnDefinition(typeName));
|
setTypeIdentifier(DBIdentifier.newColumnDefinition(typeName));
|
||||||
if (decimals >= 0)
|
if (decimals != 0)
|
||||||
setDecimalDigits(decimals);
|
setDecimalDigits(decimals);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,7 +99,7 @@ public class MySQLDictionary
|
||||||
supportsSelectStartIndex = true;
|
supportsSelectStartIndex = true;
|
||||||
supportsSelectEndIndex = true;
|
supportsSelectEndIndex = true;
|
||||||
|
|
||||||
|
datePrecision = MICRO;
|
||||||
|
|
||||||
concatenateFunction = "CONCAT({0},{1})";
|
concatenateFunction = "CONCAT({0},{1})";
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.openjpa.persistence.kernel;
|
package org.apache.openjpa.persistence.kernel;
|
||||||
|
|
||||||
|
import java.sql.Timestamp;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
@ -71,6 +72,15 @@ public class TestDateQueries extends BaseKernelTest {
|
||||||
startTx(_pm);
|
startTx(_pm);
|
||||||
AllFieldTypesTest test = new AllFieldTypesTest();
|
AllFieldTypesTest test = new AllFieldTypesTest();
|
||||||
test.setTestDate(_date);
|
test.setTestDate(_date);
|
||||||
|
|
||||||
|
// prepare scale test fields
|
||||||
|
Timestamp tst = new Timestamp(1000000000L);
|
||||||
|
tst.setNanos(123456789);
|
||||||
|
test.setTestDateMaxScale(tst);
|
||||||
|
test.setTestDateScale0(tst);
|
||||||
|
test.setTestDateScale3(tst);
|
||||||
|
test.setTestDateScale6(tst);
|
||||||
|
|
||||||
_pm.persist(test);
|
_pm.persist(test);
|
||||||
|
|
||||||
test = new AllFieldTypesTest();
|
test = new AllFieldTypesTest();
|
||||||
|
@ -81,6 +91,8 @@ public class TestDateQueries extends BaseKernelTest {
|
||||||
test.setTestDate(_after);
|
test.setTestDate(_after);
|
||||||
_pm.persist(test);
|
_pm.persist(test);
|
||||||
endTx(_pm);
|
endTx(_pm);
|
||||||
|
|
||||||
|
_pm.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testEquals() {
|
public void testEquals() {
|
||||||
|
@ -95,6 +107,21 @@ public class TestDateQueries extends BaseKernelTest {
|
||||||
assertEquals(2, vals.size());
|
assertEquals(2, vals.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testDateScale() {
|
||||||
|
Timestamp referenceTst = new Timestamp(1000000000L);
|
||||||
|
|
||||||
|
Collection vals = executeQuery("testDate = :date");
|
||||||
|
AllFieldTypesTest aft = (AllFieldTypesTest) vals.iterator().next();
|
||||||
|
assertNotNull(aft);
|
||||||
|
|
||||||
|
long time = aft.getTestDateMaxScale().getTime();
|
||||||
|
long nanos = aft.getTestDateMaxScale().getNanos();
|
||||||
|
|
||||||
|
// cut of the ms
|
||||||
|
assertEquals(referenceTst, time - (time%1000));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public void testBefore() {
|
public void testBefore() {
|
||||||
Collection vals = executeQuery("testDate < :date");
|
Collection vals = executeQuery("testDate < :date");
|
||||||
assertEquals(1, vals.size());
|
assertEquals(1, vals.size());
|
||||||
|
|
|
@ -20,10 +20,12 @@ package org.apache.openjpa.persistence.kernel.common.apps;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
|
import java.sql.Timestamp;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
|
import javax.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.GeneratedValue;
|
import javax.persistence.GeneratedValue;
|
||||||
import javax.persistence.GenerationType;
|
import javax.persistence.GenerationType;
|
||||||
|
@ -55,10 +57,28 @@ public class AllFieldTypesTest {
|
||||||
private char testchar;
|
private char testchar;
|
||||||
private String testString;
|
private String testString;
|
||||||
private String testBigString;
|
private String testBigString;
|
||||||
|
|
||||||
@Temporal(TemporalType.DATE)
|
@Temporal(TemporalType.DATE)
|
||||||
private Date testDate;
|
private Date testDate;
|
||||||
|
|
||||||
@Temporal(TemporalType.DATE)
|
@Temporal(TemporalType.DATE)
|
||||||
private Calendar testCalendar;
|
private Calendar testCalendar;
|
||||||
|
|
||||||
|
@Temporal(TemporalType.TIMESTAMP)
|
||||||
|
@Column(scale=-1)
|
||||||
|
private Timestamp testDateScale0;
|
||||||
|
|
||||||
|
@Temporal(TemporalType.TIMESTAMP)
|
||||||
|
@Column(scale=3)
|
||||||
|
private Timestamp testDateScale3;
|
||||||
|
|
||||||
|
@Temporal(TemporalType.TIMESTAMP)
|
||||||
|
@Column(scale=6)
|
||||||
|
private Timestamp testDateScale6;
|
||||||
|
|
||||||
|
@Temporal(TemporalType.TIMESTAMP)
|
||||||
|
private Timestamp testDateMaxScale;
|
||||||
|
|
||||||
private Object testObject;
|
private Object testObject;
|
||||||
private BigInteger testBigInteger;
|
private BigInteger testBigInteger;
|
||||||
private BigDecimal testBigDecimal;
|
private BigDecimal testBigDecimal;
|
||||||
|
@ -188,6 +208,39 @@ public class AllFieldTypesTest {
|
||||||
this.testBigDecimal = testBigDecimal;
|
this.testBigDecimal = testBigDecimal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Timestamp getTestDateScale0() {
|
||||||
|
return testDateScale0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTestDateScale0(Timestamp testDateScale0) {
|
||||||
|
this.testDateScale0 = testDateScale0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Timestamp getTestDateScale3() {
|
||||||
|
return testDateScale3;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTestDateScale3(Timestamp testDateScale3) {
|
||||||
|
this.testDateScale3 = testDateScale3;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Timestamp getTestDateScale6() {
|
||||||
|
return testDateScale6;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTestDateScale6(Timestamp testDateScale6) {
|
||||||
|
this.testDateScale6 = testDateScale6;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Timestamp getTestDateMaxScale() {
|
||||||
|
return testDateMaxScale;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTestDateMaxScale(Timestamp testDateMaxScale) {
|
||||||
|
this.testDateMaxScale = testDateMaxScale;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void randomize(boolean objects, boolean blobs) {
|
public void randomize(boolean objects, boolean blobs) {
|
||||||
testint = AbstractTestCase.randomInt().intValue();
|
testint = AbstractTestCase.randomInt().intValue();
|
||||||
testlong = AbstractTestCase.randomLong().longValue();
|
testlong = AbstractTestCase.randomLong().longValue();
|
||||||
|
|
Loading…
Reference in New Issue