Skip to content

Commit

Permalink
Missing java.time tests in agrest-cayenne
Browse files Browse the repository at this point in the history
  • Loading branch information
andrus committed Sep 29, 2024
1 parent e418cc3 commit 6d96161
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,27 @@ public void sqlTimestamp() {
.queryParam("include", "cTimestamp")
.post("{\"cTimestamp\":\"2015-03-14T19:00:00.000\"}")
.wasCreated()
// TODO: why is time returned back without a "T" prefix?
.bodyEquals(1, "{\"cTimestamp\":\"2015-03-14T19:00:00\"}");
}

@Test
public void localDate() {
tester.target("e16")
.queryParam("include", "cLocalDate")
.post("{\"cLocalDate\":\"2015-03-14\"}")
.wasCreated()
.bodyEquals(1, "{\"cLocalDate\":\"2015-03-14\"}");
}

@Test
public void localDateTime() {
tester.target("e16")
.queryParam("include", "cLocalDateTime")
.post("{\"cLocalDateTime\":\"2015-03-14T19:00:00.000\"}")
.wasCreated()
.bodyEquals(1, "{\"cLocalDateTime\":\"2015-03-14T19:00:00\"}");
}

@Test
public void byteArray() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import java.sql.Date;
import java.sql.Time;
import java.sql.Timestamp;
import java.time.LocalDate;
import java.time.LocalDateTime;

import org.apache.cayenne.BaseDataObject;
import org.apache.cayenne.exp.property.DateProperty;
Expand All @@ -24,10 +26,14 @@ public abstract class _E16 extends BaseDataObject {
public static final String ID_PK_COLUMN = "id";

public static final DateProperty<Date> C_DATE = PropertyFactory.createDate("cDate", Date.class);
public static final DateProperty<LocalDate> C_LOCAL_DATE = PropertyFactory.createDate("cLocalDate", LocalDate.class);
public static final DateProperty<LocalDateTime> C_LOCAL_DATE_TIME = PropertyFactory.createDate("cLocalDateTime", LocalDateTime.class);
public static final DateProperty<Time> C_TIME = PropertyFactory.createDate("cTime", Time.class);
public static final DateProperty<Timestamp> C_TIMESTAMP = PropertyFactory.createDate("cTimestamp", Timestamp.class);

protected Date cDate;
protected LocalDate cLocalDate;
protected LocalDateTime cLocalDateTime;
protected Time cTime;
protected Timestamp cTimestamp;

Expand All @@ -42,6 +48,26 @@ public Date getCDate() {
return this.cDate;
}

public void setCLocalDate(LocalDate cLocalDate) {
beforePropertyWrite("cLocalDate", this.cLocalDate, cLocalDate);
this.cLocalDate = cLocalDate;
}

public LocalDate getCLocalDate() {
beforePropertyRead("cLocalDate");
return this.cLocalDate;
}

public void setCLocalDateTime(LocalDateTime cLocalDateTime) {
beforePropertyWrite("cLocalDateTime", this.cLocalDateTime, cLocalDateTime);
this.cLocalDateTime = cLocalDateTime;
}

public LocalDateTime getCLocalDateTime() {
beforePropertyRead("cLocalDateTime");
return this.cLocalDateTime;
}

public void setCTime(Time cTime) {
beforePropertyWrite("cTime", this.cTime, cTime);
this.cTime = cTime;
Expand Down Expand Up @@ -71,6 +97,10 @@ public Object readPropertyDirectly(String propName) {
switch(propName) {
case "cDate":
return this.cDate;
case "cLocalDate":
return this.cLocalDate;
case "cLocalDateTime":
return this.cLocalDateTime;
case "cTime":
return this.cTime;
case "cTimestamp":
Expand All @@ -90,6 +120,12 @@ public void writePropertyDirectly(String propName, Object val) {
case "cDate":
this.cDate = (Date)val;
break;
case "cLocalDate":
this.cLocalDate = (LocalDate)val;
break;
case "cLocalDateTime":
this.cLocalDateTime = (LocalDateTime)val;
break;
case "cTime":
this.cTime = (Time)val;
break;
Expand All @@ -113,6 +149,8 @@ private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundE
protected void writeState(ObjectOutputStream out) throws IOException {
super.writeState(out);
out.writeObject(this.cDate);
out.writeObject(this.cLocalDate);
out.writeObject(this.cLocalDateTime);
out.writeObject(this.cTime);
out.writeObject(this.cTimestamp);
}
Expand All @@ -121,6 +159,8 @@ protected void writeState(ObjectOutputStream out) throws IOException {
protected void readState(ObjectInputStream in) throws IOException, ClassNotFoundException {
super.readState(in);
this.cDate = (Date)in.readObject();
this.cLocalDate = (LocalDate)in.readObject();
this.cLocalDateTime = (LocalDateTime)in.readObject();
this.cTime = (Time)in.readObject();
this.cTimestamp = (Timestamp)in.readObject();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public abstract class _E32 extends BaseDataObject {

private static final long serialVersionUID = 1L;

public static final String S_ID_PK_COLUMN = "s_id";
public static final String P_ID_PK_COLUMN = "p_id";
public static final String S_ID_PK_COLUMN = "s_id";
public static final String T_ID_PK_COLUMN = "t_id";

public static final StringProperty<String> NAME = PropertyFactory.createString("name", String.class);
Expand Down
4 changes: 4 additions & 0 deletions agrest-cayenne/src/test/resources/main/datamap.map.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
</db-entity>
<db-entity name="e16">
<db-attribute name="c_date" type="DATE"/>
<db-attribute name="c_local_date" type="DATE"/>
<db-attribute name="c_local_date_time" type="TIMESTAMP"/>
<db-attribute name="c_time" type="TIME"/>
<db-attribute name="c_timestamp" type="TIMESTAMP"/>
<db-attribute name="id" type="INTEGER" isPrimaryKey="true" isGenerated="true" isMandatory="true"/>
Expand Down Expand Up @@ -234,6 +236,8 @@
<obj-entity name="E15E1" className="io.agrest.cayenne.cayenne.main.E15E1" dbEntityName="e15_e1"/>
<obj-entity name="E16" className="io.agrest.cayenne.cayenne.main.E16" dbEntityName="e16">
<obj-attribute name="cDate" type="java.sql.Date" db-attribute-path="c_date"/>
<obj-attribute name="cLocalDate" type="java.time.LocalDate" db-attribute-path="c_local_date"/>
<obj-attribute name="cLocalDateTime" type="java.time.LocalDateTime" db-attribute-path="c_local_date_time"/>
<obj-attribute name="cTime" type="java.sql.Time" db-attribute-path="c_time"/>
<obj-attribute name="cTimestamp" type="java.sql.Timestamp" db-attribute-path="c_timestamp"/>
</obj-entity>
Expand Down
2 changes: 1 addition & 1 deletion agrest-cayenne/src/test/resources/main/schema-derby.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ CREATE TABLE "e15" ("long_id" BIGINT NOT NULL, "name" VARCHAR (100), PRIMARY KE
CREATE TABLE "e14" ("e15_id" BIGINT , "long_id" BIGINT NOT NULL, "name" VARCHAR (100), PRIMARY KEY ("long_id"))
;

CREATE TABLE "e16" ("c_date" DATE , "c_time" TIME , "c_timestamp" TIMESTAMP , "id" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY, PRIMARY KEY ("id"))
CREATE TABLE "e16" ("c_date" DATE , "c_time" TIME , "c_timestamp" TIMESTAMP , "c_local_date" DATE , "c_local_date_time" TIMESTAMP , "id" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY, PRIMARY KEY ("id"))
;

CREATE TABLE "e10" ("c_boolean" BOOLEAN , "c_date" DATE , "c_decimal" DECIMAL (10, 2), "c_int" INTEGER , "c_time" TIME , "c_timestamp" TIMESTAMP , "c_varchar" VARCHAR (100), "id" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY, PRIMARY KEY ("id"))
Expand Down

0 comments on commit 6d96161

Please sign in to comment.