cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From abulat...@apache.org
Subject [cayenne] branch master updated: CAY-2557 Add java.time.Duration and java.time.Period to supported types
Date Tue, 11 Jun 2019 11:12:54 GMT
This is an automated email from the ASF dual-hosted git repository.

abulatski pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cayenne.git


The following commit(s) were added to refs/heads/master by this push:
     new 7f02a3e  CAY-2557 Add java.time.Duration and java.time.Period to supported types
7f02a3e is described below

commit 7f02a3e3c14903d055b34173ffc59b78a5fc052b
Author: Arseni Bulatski <ancarseni@gmail.com>
AuthorDate: Tue Jun 11 14:12:40 2019 +0300

    CAY-2557 Add java.time.Duration and java.time.Period to supported types
---
 .../apache/cayenne/access/types/DurationType.java  | 18 +---------
 .../apache/cayenne/access/types/Java8TimeIT.java   | 10 ------
 .../testdo/java8/auto/_DurationTestEntity.java     | 38 ----------------------
 cayenne-server/src/test/resources/java8.map.xml    | 28 +++++++---------
 4 files changed, 13 insertions(+), 81 deletions(-)

diff --git a/cayenne-server/src/main/java/org/apache/cayenne/access/types/DurationType.java
b/cayenne-server/src/main/java/org/apache/cayenne/access/types/DurationType.java
index ab2da3c..6f33abd 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/access/types/DurationType.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/access/types/DurationType.java
@@ -29,13 +29,9 @@ public class DurationType implements ExtendedType<Duration> {
             return val.toString();
         } else if(type == Types.LONGVARCHAR) {
             return val.toString();
-        } else if(type == Types.NVARCHAR) {
-            return val.toString();
-        } else if(type == Types.LONGNVARCHAR) {
-            return val.toString();
         } else {
             throw new IllegalArgumentException(
-                    "Only INTEGER, NUMERIC, DECIMAL, BIGINT, VARCHAR, LONGVARCHAR, NVARCHAR,
LONGNVARCHAR " +
+                    "Only INTEGER, NUMERIC, DECIMAL, BIGINT, VARCHAR, LONGVARCHAR " +
                             "can be mapped as '" + getClassName()
                             + "', got " + TypesMapping.getSqlNameByType(type));
         }
@@ -72,12 +68,6 @@ public class DurationType implements ExtendedType<Duration> {
             case Types.LONGVARCHAR:
                 val = Duration.parse(rs.getString(index));
                 break;
-            case Types.NVARCHAR:
-                val = Duration.parse(rs.getNString(index));
-                break;
-            case Types.LONGNVARCHAR:
-                val = Duration.parse(rs.getNString(index));
-                break;
         }
 
         if(rs.wasNull()) {
@@ -111,12 +101,6 @@ public class DurationType implements ExtendedType<Duration> {
             case Types.LONGVARCHAR:
                 val = Duration.parse(rs.getString(index));
                 break;
-            case Types.NVARCHAR:
-                val = Duration.parse(rs.getNString(index));
-                break;
-            case Types.LONGNVARCHAR:
-                val = Duration.parse(rs.getNString(index));
-                break;
         }
 
         if(rs.wasNull()) {
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/types/Java8TimeIT.java
b/cayenne-server/src/test/java/org/apache/cayenne/access/types/Java8TimeIT.java
index cf9611b..dd30dea 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/access/types/Java8TimeIT.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/access/types/Java8TimeIT.java
@@ -154,11 +154,9 @@ public class Java8TimeIT extends ServerCase {
 		durationTestEntity.setDurationBigInt(duration);
 		durationTestEntity.setDurationDecimal(duration);
 		durationTestEntity.setDurationInt(duration);
-		durationTestEntity.setDurationLongNVarchar(duration);
 		durationTestEntity.setDurationLongVarchar(duration);
 		durationTestEntity.setDurationNumeric(duration);
 		durationTestEntity.setDurationVarchar(duration);
-		durationTestEntity.setDurationNVarchar(duration);
 
 		context.commitChanges();
 
@@ -176,10 +174,6 @@ public class Java8TimeIT extends ServerCase {
 		assertEquals(Duration.class, testRead.getDurationInt().getClass());
 		assertEquals(duration, testRead.getDurationInt());
 
-		assertNotNull(testRead.getDurationLongNVarchar());
-		assertEquals(Duration.class, testRead.getDurationLongNVarchar().getClass());
-		assertEquals(duration, testRead.getDurationLongNVarchar());
-
 		assertNotNull(testRead.getDurationLongVarchar());
 		assertEquals(Duration.class, testRead.getDurationLongVarchar().getClass());
 		assertEquals(duration, testRead.getDurationLongVarchar());
@@ -191,10 +185,6 @@ public class Java8TimeIT extends ServerCase {
 		assertNotNull(testRead.getDurationVarchar());
 		assertEquals(Duration.class, testRead.getDurationVarchar().getClass());
 		assertEquals(duration, testRead.getDurationVarchar());
-
-		assertNotNull(testRead.getDurationNVarchar());
-		assertEquals(Duration.class, testRead.getDurationNVarchar().getClass());
-		assertEquals(duration, testRead.getDurationNVarchar());
 	}
 
 	@Test
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/testdo/java8/auto/_DurationTestEntity.java
b/cayenne-server/src/test/java/org/apache/cayenne/testdo/java8/auto/_DurationTestEntity.java
index 3b9d018..f0d5c72 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/testdo/java8/auto/_DurationTestEntity.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/testdo/java8/auto/_DurationTestEntity.java
@@ -26,8 +26,6 @@ public abstract class _DurationTestEntity extends BaseDataObject {
     public static final BaseProperty<Duration> DURATION_NUMERIC = PropertyFactory.createBase("durationNumeric",
Duration.class);
     public static final BaseProperty<Duration> DURATION_DECIMAL = PropertyFactory.createBase("durationDecimal",
Duration.class);
     public static final BaseProperty<Duration> DURATION_LONG_VARCHAR = PropertyFactory.createBase("durationLongVarchar",
Duration.class);
-    public static final BaseProperty<Duration> DURATION_NVARCHAR = PropertyFactory.createBase("durationNVarchar",
Duration.class);
-    public static final BaseProperty<Duration> DURATION_LONG_NVARCHAR = PropertyFactory.createBase("durationLongNVarchar",
Duration.class);
     public static final BaseProperty<Duration> DURATION_INT = PropertyFactory.createBase("durationInt",
Duration.class);
 
     protected Duration durationVarchar;
@@ -35,8 +33,6 @@ public abstract class _DurationTestEntity extends BaseDataObject {
     protected Duration durationNumeric;
     protected Duration durationDecimal;
     protected Duration durationLongVarchar;
-    protected Duration durationNVarchar;
-    protected Duration durationLongNVarchar;
     protected Duration durationInt;
 
 
@@ -90,26 +86,6 @@ public abstract class _DurationTestEntity extends BaseDataObject {
         return this.durationLongVarchar;
     }
 
-    public void setDurationNVarchar(Duration durationNVarchar) {
-        beforePropertyWrite("durationNVarchar", this.durationNVarchar, durationNVarchar);
-        this.durationNVarchar = durationNVarchar;
-    }
-
-    public Duration getDurationNVarchar() {
-        beforePropertyRead("durationNVarchar");
-        return this.durationNVarchar;
-    }
-
-    public void setDurationLongNVarchar(Duration durationLongNVarchar) {
-        beforePropertyWrite("durationLongNVarchar", this.durationLongNVarchar, durationLongNVarchar);
-        this.durationLongNVarchar = durationLongNVarchar;
-    }
-
-    public Duration getDurationLongNVarchar() {
-        beforePropertyRead("durationLongNVarchar");
-        return this.durationLongNVarchar;
-    }
-
     public void setDurationInt(Duration durationInt) {
         beforePropertyWrite("durationInt", this.durationInt, durationInt);
         this.durationInt = durationInt;
@@ -137,10 +113,6 @@ public abstract class _DurationTestEntity extends BaseDataObject {
                 return this.durationDecimal;
             case "durationLongVarchar":
                 return this.durationLongVarchar;
-            case "durationNVarchar":
-                return this.durationNVarchar;
-            case "durationLongNVarchar":
-                return this.durationLongNVarchar;
             case "durationInt":
                 return this.durationInt;
             default:
@@ -170,12 +142,6 @@ public abstract class _DurationTestEntity extends BaseDataObject {
             case "durationLongVarchar":
                 this.durationLongVarchar = (Duration)val;
                 break;
-            case "durationNVarchar":
-                this.durationNVarchar = (Duration)val;
-                break;
-            case "durationLongNVarchar":
-                this.durationLongNVarchar = (Duration)val;
-                break;
             case "durationInt":
                 this.durationInt = (Duration)val;
                 break;
@@ -200,8 +166,6 @@ public abstract class _DurationTestEntity extends BaseDataObject {
         out.writeObject(this.durationNumeric);
         out.writeObject(this.durationDecimal);
         out.writeObject(this.durationLongVarchar);
-        out.writeObject(this.durationNVarchar);
-        out.writeObject(this.durationLongNVarchar);
         out.writeObject(this.durationInt);
     }
 
@@ -213,8 +177,6 @@ public abstract class _DurationTestEntity extends BaseDataObject {
         this.durationNumeric = (Duration)in.readObject();
         this.durationDecimal = (Duration)in.readObject();
         this.durationLongVarchar = (Duration)in.readObject();
-        this.durationNVarchar = (Duration)in.readObject();
-        this.durationLongNVarchar = (Duration)in.readObject();
         this.durationInt = (Duration)in.readObject();
     }
 
diff --git a/cayenne-server/src/test/resources/java8.map.xml b/cayenne-server/src/test/resources/java8.map.xml
index 692cc77..b07d557 100644
--- a/cayenne-server/src/test/resources/java8.map.xml
+++ b/cayenne-server/src/test/resources/java8.map.xml
@@ -5,14 +5,12 @@
 	 project-version="10">
 	<property name="defaultPackage" value="org.apache.cayenne.testdo.java8"/>
 	<db-entity name="DURATION_TEST">
-		<db-attribute name="DurationBigInt" type="BIGINT"/>
-		<db-attribute name="DurationDecimal" type="DECIMAL"/>
-		<db-attribute name="DurationInt" type="INTEGER" length="100"/>
-		<db-attribute name="DurationLongNVarchar" type="LONGNVARCHAR" length="100"/>
-		<db-attribute name="DurationLongVarchar" type="LONGVARCHAR" length="100"/>
-		<db-attribute name="DurationNVarchar" type="NVARCHAR" length="100"/>
-		<db-attribute name="DurationNumeric" type="NUMERIC"/>
-		<db-attribute name="DurationVarchar" type="VARCHAR" length="100"/>
+		<db-attribute name="DURATION_BIG_INT" type="BIGINT"/>
+		<db-attribute name="DURATION_DECIMAL" type="DECIMAL" length="19" scale="2"/>
+		<db-attribute name="DURATION_INT" type="INTEGER"/>
+		<db-attribute name="DURATION_LONG_VARCHAR" type="LONGVARCHAR"/>
+		<db-attribute name="DURATION_NUMERIC" type="NUMERIC" length="19" scale="2"/>
+		<db-attribute name="DURATION_VARCHAR" type="VARCHAR" length="255"/>
 		<db-attribute name="ID" type="INTEGER" isPrimaryKey="true" isMandatory="true"/>
 	</db-entity>
 	<db-entity name="LOCAL_DATETIME_TEST">
@@ -32,14 +30,12 @@
 		<db-attribute name="PeriodField" type="VARCHAR" length="100"/>
 	</db-entity>
 	<obj-entity name="DurationTest" className="org.apache.cayenne.testdo.java8.DurationTestEntity"
dbEntityName="DURATION_TEST">
-		<obj-attribute name="durationVarchar" type="java.time.Duration" db-attribute-path="DurationVarchar"/>
-		<obj-attribute name="durationBigInt" type="java.time.Duration" db-attribute-path="DurationBigInt"/>
-		<obj-attribute name="durationNumeric" type="java.time.Duration" db-attribute-path="DurationNumeric"/>
-		<obj-attribute name="durationDecimal" type="java.time.Duration" db-attribute-path="DurationDecimal"/>
-		<obj-attribute name="durationLongVarchar" type="java.time.Duration" db-attribute-path="DurationLongVarchar"/>
-		<obj-attribute name="durationNVarchar" type="java.time.Duration" db-attribute-path="DurationNVarchar"/>
-		<obj-attribute name="durationLongNVarchar" type="java.time.Duration" db-attribute-path="DurationLongNVarchar"/>
-		<obj-attribute name="durationInt" type="java.time.Duration" db-attribute-path="DurationInt"/>
+		<obj-attribute name="durationVarchar" type="java.time.Duration" db-attribute-path="DURATION_VARCHAR"/>
+		<obj-attribute name="durationBigInt" type="java.time.Duration" db-attribute-path="DURATION_BIG_INT"/>
+		<obj-attribute name="durationNumeric" type="java.time.Duration" db-attribute-path="DURATION_NUMERIC"/>
+		<obj-attribute name="durationDecimal" type="java.time.Duration" db-attribute-path="DURATION_DECIMAL"/>
+		<obj-attribute name="durationLongVarchar" type="java.time.Duration" db-attribute-path="DURATION_LONG_VARCHAR"/>
+		<obj-attribute name="durationInt" type="java.time.Duration" db-attribute-path="DURATION_INT"/>
 	</obj-entity>
 	<obj-entity name="LocalDateTest" className="org.apache.cayenne.testdo.java8.LocalDateTestEntity"
dbEntityName="LOCAL_DATE_TEST">
 		<obj-attribute name="date" type="java.time.LocalDate" db-attribute-path="DateField"/>


Mime
View raw message