-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #168 from CorvusYe/master
fix: #102 and clear time type mapping (v1.1.4)
- Loading branch information
Showing
15 changed files
with
293 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
ngbatis-demo/src/main/java/ye/weicheng/ngbatis/demo/pojo/TimeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package ye.weicheng.ngbatis.demo.pojo; | ||
|
||
// Copyright (c) 2022 All project authors. All rights reserved. | ||
// | ||
// This source code is licensed under Apache 2.0 License. | ||
|
||
import java.sql.Time; | ||
import java.sql.Timestamp; | ||
import java.time.Duration; | ||
import java.util.Date; | ||
import javax.persistence.Column; | ||
import javax.persistence.Id; | ||
import javax.persistence.Table; | ||
|
||
/** | ||
* @author yeweicheng | ||
* @since 2023-06-07 15:26 | ||
* <br>Now is history! | ||
*/ | ||
@Table(name = "time_test") | ||
public class TimeTest { | ||
@Id | ||
private String id; | ||
|
||
@Column(name = "t_date") | ||
private java.sql.Date date; | ||
|
||
@Column(name = "t_datetime") | ||
private Date datetime; | ||
|
||
@Column(name = "t_time") | ||
private java.sql.Time time; | ||
|
||
@Column(name = "t_timestamp") | ||
private java.sql.Timestamp timestamp; | ||
|
||
@Column(name = "t_duration") | ||
private Duration duration; | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
public void setId(String id) { | ||
this.id = id; | ||
} | ||
|
||
public java.sql.Date getDate() { | ||
return date; | ||
} | ||
|
||
public void setDate(java.sql.Date date) { | ||
this.date = date; | ||
} | ||
|
||
public Date getDatetime() { | ||
return datetime; | ||
} | ||
|
||
public void setDatetime(Date datetime) { | ||
this.datetime = datetime; | ||
} | ||
|
||
public Time getTime() { | ||
return time; | ||
} | ||
|
||
public void setTime(Time time) { | ||
this.time = time; | ||
} | ||
|
||
public Timestamp getTimestamp() { | ||
return timestamp; | ||
} | ||
|
||
public void setTimestamp(Timestamp timestamp) { | ||
this.timestamp = timestamp; | ||
} | ||
|
||
public Duration getDuration() { | ||
return duration; | ||
} | ||
|
||
public void setDuration(Duration duration) { | ||
this.duration = duration; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
ngbatis-demo/src/main/java/ye/weicheng/ngbatis/demo/repository/TimeTestDao.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package ye.weicheng.ngbatis.demo.repository; | ||
|
||
// Copyright (c) 2022 All project authors. All rights reserved. | ||
// | ||
// This source code is licensed under Apache 2.0 License. | ||
|
||
import java.time.Duration; | ||
import org.nebula.contrib.ngbatis.proxy.NebulaDaoBasic; | ||
import ye.weicheng.ngbatis.demo.pojo.TimeTest; | ||
|
||
/** | ||
* @author yeweicheng | ||
* @since 2023-06-07 17:17 | ||
* <br>Now is history! | ||
*/ | ||
public interface TimeTestDao extends NebulaDaoBasic<TimeTest, String> { | ||
Duration selectTenDaysTwoSec(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!-- | ||
Copyright (c) 2022 All project authors. All rights reserved. | ||
This source code is licensed under Apache 2.0 License. | ||
--> | ||
<mapper namespace="ye.weicheng.ngbatis.demo.repository.TimeTestDao"> | ||
|
||
<select id="selectTenDaysTwoSec"> | ||
RETURN duration({years: 0, months: 0, days: 10, hours: 0, minutes: 0, seconds: 2}) | ||
</select> | ||
|
||
</mapper> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
ngbatis-demo/src/test/java/ye/weicheng/ngbatis/demo/repository/TimeTestDaoTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package ye.weicheng.ngbatis.demo.repository; | ||
|
||
// Copyright (c) 2022 All project authors. All rights reserved. | ||
// | ||
// This source code is licensed under Apache 2.0 License. | ||
|
||
import java.time.Duration; | ||
import java.util.Date; | ||
import java.util.Objects; | ||
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation; | ||
import org.junit.jupiter.api.Order; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.TestMethodOrder; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.util.Assert; | ||
import ye.weicheng.ngbatis.demo.pojo.TimeTest; | ||
|
||
/** | ||
* @author yeweicheng | ||
* @since 2023-06-07 17:19 | ||
* <br>Now is history! | ||
*/ | ||
@SpringBootTest | ||
@TestMethodOrder(OrderAnnotation.class) | ||
class TimeTestDaoTest { | ||
|
||
static final String caseId = "time-test"; | ||
|
||
static final Date datetime = new Date(); | ||
|
||
static final java.sql.Date date = new java.sql.Date(datetime.getTime()); | ||
|
||
static final java.sql.Timestamp timestamp = new java.sql.Timestamp(datetime.getTime()); | ||
|
||
static final java.sql.Time time = new java.sql.Time(datetime.getTime()); | ||
|
||
@Autowired private TimeTestDao dao; | ||
|
||
@Test | ||
@Order(1) | ||
public void testInsert() { | ||
TimeTest test = new TimeTest(); | ||
test.setId(caseId); | ||
test.setDatetime(datetime); | ||
test.setDate(date); | ||
test.setTime(time); | ||
test.setTimestamp(timestamp); | ||
test.setDuration(java.time.Duration.ofMillis(2000)); | ||
dao.insert(test); | ||
} | ||
|
||
@Test | ||
@Order(2) | ||
public void selectById() { | ||
TimeTest timeTest = dao.selectById(caseId); | ||
Assert.isTrue( | ||
Objects.equals(timeTest.getDate().toString(), date.toString()), | ||
"Date must be equal to the value before insertion" | ||
); | ||
|
||
Assert.isTrue( | ||
Objects.equals(timeTest.getTime().toString(), time.toString()), | ||
"Time must be equal to the value before insertion" | ||
); | ||
|
||
Assert.isTrue( | ||
Objects.equals(timeTest.getDatetime().toString(), datetime.toString()), | ||
"Datetime must be equal to the value before insertion" | ||
); | ||
|
||
String dbTimestamp = String.valueOf(timeTest.getTimestamp().getTime()); | ||
// 毫秒精度丢失 | ||
String timestampInsertBefore = (timestamp.getTime() / 1000) + "000"; | ||
Assert.isTrue( | ||
Objects.equals(dbTimestamp, timestampInsertBefore), | ||
"Timestamp must be equal to the value before insertion" | ||
); | ||
|
||
Assert.isTrue( | ||
timeTest.getDuration().getSeconds() == 2, | ||
"2000ms must be equal 2s" | ||
); | ||
} | ||
|
||
@Test | ||
@Order(3) | ||
public void deleteById() { | ||
dao.deleteById(caseId); | ||
} | ||
|
||
@Test | ||
@Order(4) | ||
public void selectTenDaysTwoSec() { | ||
Duration o = dao.selectTenDaysTwoSec(); | ||
Assert.isTrue(o.getSeconds() == 864002, "10d 2s equals 864002s"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.