mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-03 08:24:23 +00:00
Add support for java.time types for use with @CreatedTimestamp and @UpdatedTimestamp
This commit is contained in:
1 parent
8ea1f51c7f
commit
d5d6ac675b
8 files changed
+528
-39
No files matched your search
+56
@@ -0,0 +1,56 @@
|
||||
package com.avaje.ebeaninternal.server.deploy.generatedproperty;
|
||||
|
||||
import com.avaje.ebeaninternal.server.deploy.meta.DeployBeanProperty;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.OffsetDateTime;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class InsertTimestampFactoryTest {
|
||||
|
||||
InsertTimestampFactory factory = new InsertTimestampFactory();
|
||||
|
||||
@Test
|
||||
public void test_createdTimestamp_LocalDateTime() {
|
||||
|
||||
DeployBeanProperty prop = new DeployBeanProperty(null, LocalDateTime.class, null, null);
|
||||
|
||||
GeneratedProperty insertTimestamp = factory.createInsertTimestamp(prop);
|
||||
Object value = insertTimestamp.getInsertValue(null, null);
|
||||
assertTrue(value instanceof LocalDateTime);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_createdTimestamp_OffsetDateTime() {
|
||||
|
||||
DeployBeanProperty prop = new DeployBeanProperty(null, OffsetDateTime.class, null, null);
|
||||
|
||||
GeneratedProperty insertTimestamp = factory.createInsertTimestamp(prop);
|
||||
Object value = insertTimestamp.getInsertValue(null, null);
|
||||
assertTrue(value instanceof OffsetDateTime);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_createdTimestamp_Timestamp() {
|
||||
|
||||
DeployBeanProperty prop = new DeployBeanProperty(null, Timestamp.class, null, null);
|
||||
|
||||
GeneratedProperty insertTimestamp = factory.createInsertTimestamp(prop);
|
||||
Object value = insertTimestamp.getInsertValue(null, null);
|
||||
assertTrue(value instanceof Timestamp);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_createdTimestamp_utilDate() {
|
||||
|
||||
DeployBeanProperty prop = new DeployBeanProperty(null, java.util.Date.class, null, null);
|
||||
|
||||
GeneratedProperty insertTimestamp = factory.createInsertTimestamp(prop);
|
||||
Object value = insertTimestamp.getInsertValue(null, null);
|
||||
assertTrue(value instanceof java.util.Date);
|
||||
}
|
||||
|
||||
}
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
package com.avaje.ebeaninternal.server.deploy.generatedproperty;
|
||||
|
||||
import com.avaje.ebeaninternal.server.deploy.meta.DeployBeanProperty;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.OffsetDateTime;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class UpdateTimestampFactoryTest {
|
||||
|
||||
|
||||
UpdateTimestampFactory factory = new UpdateTimestampFactory();
|
||||
|
||||
@Test
|
||||
public void test_createdTimestamp_LocalDateTime() {
|
||||
|
||||
DeployBeanProperty prop = new DeployBeanProperty(null, LocalDateTime.class, null, null);
|
||||
|
||||
GeneratedProperty generatedProperty = factory.createUpdateTimestamp(prop);
|
||||
Object value = generatedProperty.getInsertValue(null, null);
|
||||
assertTrue(value instanceof LocalDateTime);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_createdTimestamp_OffsetDateTime() {
|
||||
|
||||
DeployBeanProperty prop = new DeployBeanProperty(null, OffsetDateTime.class, null, null);
|
||||
|
||||
GeneratedProperty generatedProperty = factory.createUpdateTimestamp(prop);
|
||||
Object value = generatedProperty.getInsertValue(null, null);
|
||||
assertTrue(value instanceof OffsetDateTime);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_createdTimestamp_Timestamp() {
|
||||
|
||||
DeployBeanProperty prop = new DeployBeanProperty(null, Timestamp.class, null, null);
|
||||
|
||||
GeneratedProperty generatedProperty = factory.createUpdateTimestamp(prop);
|
||||
Object value = generatedProperty.getInsertValue(null, null);
|
||||
assertTrue(value instanceof Timestamp);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_createdTimestamp_utilDate() {
|
||||
|
||||
DeployBeanProperty prop = new DeployBeanProperty(null, java.util.Date.class, null, null);
|
||||
|
||||
GeneratedProperty generatedProperty = factory.createUpdateTimestamp(prop);
|
||||
Object value = generatedProperty.getInsertValue(null, null);
|
||||
assertTrue(value instanceof java.util.Date);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.avaje.tests.generated;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.tests.model.EGenProps;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public class TestGeneratedProperties extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test_insert() {
|
||||
|
||||
EGenProps bean = new EGenProps();
|
||||
bean.setName("inserting");
|
||||
Ebean.save(bean);
|
||||
|
||||
assertNotNull(bean.getId());
|
||||
assertNotNull(bean.getVersion());
|
||||
assertNotNull(bean.getTsCreated());
|
||||
assertNotNull(bean.getTsUpdated());
|
||||
assertNotNull(bean.getLdtCreated());
|
||||
assertNotNull(bean.getLdtUpdated());
|
||||
assertNotNull(bean.getOdtCreated());
|
||||
assertNotNull(bean.getOdtUpdated());
|
||||
assertNotNull(bean.getZdtCreated());
|
||||
assertNotNull(bean.getZdtUpdated());
|
||||
assertNotNull(bean.getLongCreated());
|
||||
assertNotNull(bean.getLongUpdated());
|
||||
|
||||
bean.setName("updating...");
|
||||
Ebean.save(bean);
|
||||
|
||||
Ebean.delete(bean);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
package com.avaje.tests.model;
|
||||
|
||||
import com.avaje.ebean.annotation.CreatedTimestamp;
|
||||
import com.avaje.ebean.annotation.UpdatedTimestamp;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Version;
|
||||
import java.sql.Timestamp;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.time.ZonedDateTime;
|
||||
|
||||
@Entity
|
||||
public class EGenProps {
|
||||
|
||||
@Id
|
||||
Long id;
|
||||
|
||||
String name;
|
||||
|
||||
@Version
|
||||
Long version;
|
||||
|
||||
@CreatedTimestamp
|
||||
Timestamp tsCreated;
|
||||
|
||||
@UpdatedTimestamp
|
||||
Timestamp tsUpdated;
|
||||
|
||||
@CreatedTimestamp
|
||||
LocalDateTime ldtCreated;
|
||||
|
||||
@UpdatedTimestamp
|
||||
LocalDateTime ldtUpdated;
|
||||
|
||||
@CreatedTimestamp
|
||||
OffsetDateTime odtCreated;
|
||||
|
||||
@UpdatedTimestamp
|
||||
OffsetDateTime odtUpdated;
|
||||
|
||||
@CreatedTimestamp
|
||||
ZonedDateTime zdtCreated;
|
||||
|
||||
@UpdatedTimestamp
|
||||
ZonedDateTime zdtUpdated;
|
||||
|
||||
@CreatedTimestamp
|
||||
long longCreated;
|
||||
|
||||
@UpdatedTimestamp
|
||||
long longUpdated;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Long getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(Long version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public Timestamp getTsCreated() {
|
||||
return tsCreated;
|
||||
}
|
||||
|
||||
public void setTsCreated(Timestamp tsCreated) {
|
||||
this.tsCreated = tsCreated;
|
||||
}
|
||||
|
||||
public Timestamp getTsUpdated() {
|
||||
return tsUpdated;
|
||||
}
|
||||
|
||||
public void setTsUpdated(Timestamp tsUpdated) {
|
||||
this.tsUpdated = tsUpdated;
|
||||
}
|
||||
|
||||
public LocalDateTime getLdtCreated() {
|
||||
return ldtCreated;
|
||||
}
|
||||
|
||||
public void setLdtCreated(LocalDateTime ldtCreated) {
|
||||
this.ldtCreated = ldtCreated;
|
||||
}
|
||||
|
||||
public LocalDateTime getLdtUpdated() {
|
||||
return ldtUpdated;
|
||||
}
|
||||
|
||||
public void setLdtUpdated(LocalDateTime ldtUpdated) {
|
||||
this.ldtUpdated = ldtUpdated;
|
||||
}
|
||||
|
||||
public OffsetDateTime getOdtCreated() {
|
||||
return odtCreated;
|
||||
}
|
||||
|
||||
public void setOdtCreated(OffsetDateTime odtCreated) {
|
||||
this.odtCreated = odtCreated;
|
||||
}
|
||||
|
||||
public OffsetDateTime getOdtUpdated() {
|
||||
return odtUpdated;
|
||||
}
|
||||
|
||||
public void setOdtUpdated(OffsetDateTime odtUpdated) {
|
||||
this.odtUpdated = odtUpdated;
|
||||
}
|
||||
|
||||
public ZonedDateTime getZdtCreated() {
|
||||
return zdtCreated;
|
||||
}
|
||||
|
||||
public void setZdtCreated(ZonedDateTime zdtCreated) {
|
||||
this.zdtCreated = zdtCreated;
|
||||
}
|
||||
|
||||
public ZonedDateTime getZdtUpdated() {
|
||||
return zdtUpdated;
|
||||
}
|
||||
|
||||
public void setZdtUpdated(ZonedDateTime zdtUpdated) {
|
||||
this.zdtUpdated = zdtUpdated;
|
||||
}
|
||||
|
||||
public long getLongCreated() {
|
||||
return longCreated;
|
||||
}
|
||||
|
||||
public void setLongCreated(long longCreated) {
|
||||
this.longCreated = longCreated;
|
||||
}
|
||||
|
||||
public long getLongUpdated() {
|
||||
return longUpdated;
|
||||
}
|
||||
|
||||
public void setLongUpdated(long longUpdated) {
|
||||
this.longUpdated = longUpdated;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user