From 3de0cce47c0f64bacb93709f399d1cfaed83a5ee Mon Sep 17 00:00:00 2001 From: bananan Date: Wed, 8 Feb 2017 00:24:18 +0100 Subject: [PATCH] HHH-11468 - add Javadoc with java.time.* classes mentioned in Create/UpdateTimestamp --- .../annotations/CreationTimestamp.java | 14 +- .../annotations/UpdateTimestamp.java | 14 +- .../annotations/CreationTimestampTest.java | 190 ++++++++++++++++++ .../test/annotations/UpdateTimestampTest.java | 190 ++++++++++++++++++ 4 files changed, 404 insertions(+), 4 deletions(-) create mode 100644 hibernate-core/src/test/java/org/hibernate/test/annotations/CreationTimestampTest.java create mode 100644 hibernate-core/src/test/java/org/hibernate/test/annotations/UpdateTimestampTest.java diff --git a/hibernate-core/src/main/java/org/hibernate/annotations/CreationTimestamp.java b/hibernate-core/src/main/java/org/hibernate/annotations/CreationTimestamp.java index 386645be6b..9b5405f1de 100644 --- a/hibernate-core/src/main/java/org/hibernate/annotations/CreationTimestamp.java +++ b/hibernate-core/src/main/java/org/hibernate/annotations/CreationTimestamp.java @@ -6,11 +6,11 @@ */ package org.hibernate.annotations; +import org.hibernate.tuple.CreationTimestampGeneration; + import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; -import org.hibernate.tuple.CreationTimestampGeneration; - /** * Marks a property as the creation timestamp of the containing entity. The property value will be set to the current * VM date exactly once when saving the owning entity for the first time. @@ -22,6 +22,16 @@ import org.hibernate.tuple.CreationTimestampGeneration; *
  • {@link java.sql.Date}
  • *
  • {@link java.sql.Time}
  • *
  • {@link java.sql.Timestamp}
  • + *
  • {@link java.time.Instant}
  • + *
  • {@link java.time.LocalDate}
  • + *
  • {@link java.time.LocalDateTime}
  • + *
  • {@link java.time.LocalTime}
  • + *
  • {@link java.time.MonthDay}
  • + *
  • {@link java.time.OffsetDateTime}
  • + *
  • {@link java.time.OffsetTime}
  • + *
  • {@link java.time.Year}
  • + *
  • {@link java.time.YearMonth}
  • + *
  • {@link java.time.ZonedDateTime}
  • * * * @author Gunnar Morling diff --git a/hibernate-core/src/main/java/org/hibernate/annotations/UpdateTimestamp.java b/hibernate-core/src/main/java/org/hibernate/annotations/UpdateTimestamp.java index c8b86e74f0..c1635886da 100644 --- a/hibernate-core/src/main/java/org/hibernate/annotations/UpdateTimestamp.java +++ b/hibernate-core/src/main/java/org/hibernate/annotations/UpdateTimestamp.java @@ -6,11 +6,11 @@ */ package org.hibernate.annotations; +import org.hibernate.tuple.UpdateTimestampGeneration; + import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; -import org.hibernate.tuple.UpdateTimestampGeneration; - /** * Marks a property as the update timestamp of the containing entity. The property value will be set to the current VM * date whenever the owning entity is updated. @@ -22,6 +22,16 @@ import org.hibernate.tuple.UpdateTimestampGeneration; *
  • {@link java.sql.Date}
  • *
  • {@link java.sql.Time}
  • *
  • {@link java.sql.Timestamp}
  • + *
  • {@link java.time.Instant}
  • + *
  • {@link java.time.LocalDate}
  • + *
  • {@link java.time.LocalDateTime}
  • + *
  • {@link java.time.LocalTime}
  • + *
  • {@link java.time.MonthDay}
  • + *
  • {@link java.time.OffsetDateTime}
  • + *
  • {@link java.time.OffsetTime}
  • + *
  • {@link java.time.Year}
  • + *
  • {@link java.time.YearMonth}
  • + *
  • {@link java.time.ZonedDateTime}
  • * * * @author Gunnar Morling diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/CreationTimestampTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/CreationTimestampTest.java new file mode 100644 index 0000000000..0191e1bebe --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/CreationTimestampTest.java @@ -0,0 +1,190 @@ +package org.hibernate.test.annotations; + +import org.hibernate.annotations.CreationTimestamp; +import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; +import org.junit.Assert; +import org.junit.Test; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import java.sql.Time; +import java.sql.Timestamp; +import java.time.*; +import java.util.Calendar; +import java.util.Date; + +import static org.hibernate.testing.transaction.TransactionUtil.doInJPA; + +/** + * @author Borys Piela + */ +public class CreationTimestampTest extends BaseEntityManagerFunctionalTestCase { + + @Override + protected Class[] getAnnotatedClasses() { + return new Class[]{ + Event.class + }; + } + + @Entity(name = "Event") + private static class Event { + + @Id + @GeneratedValue + private Long id; + + @Column(name = "`date`") + @CreationTimestamp + private Date date; + + @Column(name = "`calendar`") + @CreationTimestamp + private Calendar calendar; + + @Column(name = "`sqlDate`") + @CreationTimestamp + private java.sql.Date sqlDate; + + @Column(name = "`time`") + @CreationTimestamp + private Time time; + + @Column(name = "`timestamp`") + @CreationTimestamp + private Timestamp timestamp; + + @Column(name = "`instant`") + @CreationTimestamp + private Instant instant; + + @Column(name = "`localDate`") + @CreationTimestamp + private LocalDate localDate; + + @Column(name = "`localDateTime`") + @CreationTimestamp + private LocalDateTime localDateTime; + + @Column(name = "`localTime`") + @CreationTimestamp + private LocalTime localTime; + + @Column(name = "`monthDay`") + @CreationTimestamp + private MonthDay monthDay; + + @Column(name = "`offsetDateTime`") + @CreationTimestamp + private OffsetDateTime offsetDateTime; + + @Column(name = "`offsetTime`") + @CreationTimestamp + private OffsetTime offsetTime; + + @Column(name = "`year`") + @CreationTimestamp + private Year year; + + @Column(name = "`yearMonth`") + @CreationTimestamp + private YearMonth yearMonth; + + @Column(name = "`zonedDateTime`") + @CreationTimestamp + private ZonedDateTime zonedDateTime; + + public Event() { + } + + public Long getId() { + return id; + } + + public Date getDate() { + return date; + } + + public Calendar getCalendar() { + return calendar; + } + + public java.sql.Date getSqlDate() { + return sqlDate; + } + + public Time getTime() { + return time; + } + + public Timestamp getTimestamp() { + return timestamp; + } + + public Instant getInstant() { + return instant; + } + + public LocalDate getLocalDate() { + return localDate; + } + + public LocalDateTime getLocalDateTime() { + return localDateTime; + } + + public LocalTime getLocalTime() { + return localTime; + } + + public MonthDay getMonthDay() { + return monthDay; + } + + public OffsetDateTime getOffsetDateTime() { + return offsetDateTime; + } + + public OffsetTime getOffsetTime() { + return offsetTime; + } + + public Year getYear() { + return year; + } + + public YearMonth getYearMonth() { + return yearMonth; + } + + public ZonedDateTime getZonedDateTime() { + return zonedDateTime; + } + } + + @Test + public void generatesCurrentTimestamp() { + doInJPA(this::entityManagerFactory, entityManager -> { + Event event = new Event(); + entityManager.persist(event); + entityManager.flush(); + Assert.assertNotNull(event.getDate()); + Assert.assertNotNull(event.getCalendar()); + Assert.assertNotNull(event.getSqlDate()); + Assert.assertNotNull(event.getTime()); + Assert.assertNotNull(event.getTimestamp()); + Assert.assertNotNull(event.getInstant()); + Assert.assertNotNull(event.getLocalDate()); + Assert.assertNotNull(event.getLocalDateTime()); + Assert.assertNotNull(event.getLocalTime()); + Assert.assertNotNull(event.getMonthDay()); + Assert.assertNotNull(event.getOffsetDateTime()); + Assert.assertNotNull(event.getOffsetTime()); + Assert.assertNotNull(event.getYear()); + Assert.assertNotNull(event.getYearMonth()); + Assert.assertNotNull(event.getZonedDateTime()); + }); + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/UpdateTimestampTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/UpdateTimestampTest.java new file mode 100644 index 0000000000..e207092f71 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/UpdateTimestampTest.java @@ -0,0 +1,190 @@ +package org.hibernate.test.annotations; + +import org.hibernate.annotations.UpdateTimestamp; +import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; +import org.junit.Assert; +import org.junit.Test; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import java.sql.Time; +import java.sql.Timestamp; +import java.time.*; +import java.util.Calendar; +import java.util.Date; + +import static org.hibernate.testing.transaction.TransactionUtil.doInJPA; + +/** + * @author Borys Piela + */ +public class UpdateTimestampTest extends BaseEntityManagerFunctionalTestCase { + + @Override + protected Class[] getAnnotatedClasses() { + return new Class[]{ + Event.class + }; + } + + @Entity(name = "Event") + private static class Event { + + @Id + @GeneratedValue + private Long id; + + @Column(name = "`date`") + @UpdateTimestamp + private Date date; + + @Column(name = "`calendar`") + @UpdateTimestamp + private Calendar calendar; + + @Column(name = "`sqlDate`") + @UpdateTimestamp + private java.sql.Date sqlDate; + + @Column(name = "`time`") + @UpdateTimestamp + private Time time; + + @Column(name = "`timestamp`") + @UpdateTimestamp + private Timestamp timestamp; + + @Column(name = "`instant`") + @UpdateTimestamp + private Instant instant; + + @Column(name = "`localDate`") + @UpdateTimestamp + private LocalDate localDate; + + @Column(name = "`localDateTime`") + @UpdateTimestamp + private LocalDateTime localDateTime; + + @Column(name = "`localTime`") + @UpdateTimestamp + private LocalTime localTime; + + @Column(name = "`monthDay`") + @UpdateTimestamp + private MonthDay monthDay; + + @Column(name = "`offsetDateTime`") + @UpdateTimestamp + private OffsetDateTime offsetDateTime; + + @Column(name = "`offsetTime`") + @UpdateTimestamp + private OffsetTime offsetTime; + + @Column(name = "`year`") + @UpdateTimestamp + private Year year; + + @Column(name = "`yearMonth`") + @UpdateTimestamp + private YearMonth yearMonth; + + @Column(name = "`zonedDateTime`") + @UpdateTimestamp + private ZonedDateTime zonedDateTime; + + public Event() { + } + + public Long getId() { + return id; + } + + public Date getDate() { + return date; + } + + public Calendar getCalendar() { + return calendar; + } + + public java.sql.Date getSqlDate() { + return sqlDate; + } + + public Time getTime() { + return time; + } + + public Timestamp getTimestamp() { + return timestamp; + } + + public Instant getInstant() { + return instant; + } + + public LocalDate getLocalDate() { + return localDate; + } + + public LocalDateTime getLocalDateTime() { + return localDateTime; + } + + public LocalTime getLocalTime() { + return localTime; + } + + public MonthDay getMonthDay() { + return monthDay; + } + + public OffsetDateTime getOffsetDateTime() { + return offsetDateTime; + } + + public OffsetTime getOffsetTime() { + return offsetTime; + } + + public Year getYear() { + return year; + } + + public YearMonth getYearMonth() { + return yearMonth; + } + + public ZonedDateTime getZonedDateTime() { + return zonedDateTime; + } + } + + @Test + public void generatesCurrentTimestamp() { + doInJPA(this::entityManagerFactory, entityManager -> { + Event event = new Event(); + entityManager.persist(event); + entityManager.flush(); + Assert.assertNotNull(event.getDate()); + Assert.assertNotNull(event.getCalendar()); + Assert.assertNotNull(event.getSqlDate()); + Assert.assertNotNull(event.getTime()); + Assert.assertNotNull(event.getTimestamp()); + Assert.assertNotNull(event.getInstant()); + Assert.assertNotNull(event.getLocalDate()); + Assert.assertNotNull(event.getLocalDateTime()); + Assert.assertNotNull(event.getLocalTime()); + Assert.assertNotNull(event.getMonthDay()); + Assert.assertNotNull(event.getOffsetDateTime()); + Assert.assertNotNull(event.getOffsetTime()); + Assert.assertNotNull(event.getYear()); + Assert.assertNotNull(event.getYearMonth()); + Assert.assertNotNull(event.getZonedDateTime()); + }); + } +}