mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Fix for #240 - Add support for using Joda LocalDateTime and DateTime with @CreatedTimestamp, @UpdatedTimestamp
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
package com.avaje.tests.model.joda;
|
||||
|
||||
import com.avaje.ebean.annotation.CreatedTimestamp;
|
||||
import com.avaje.ebean.annotation.UpdatedTimestamp;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.LocalDateTime;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Version;
|
||||
|
||||
@Entity
|
||||
public class BasicJodaEntity {
|
||||
|
||||
@Id
|
||||
Long id;
|
||||
|
||||
String name;
|
||||
|
||||
@CreatedTimestamp
|
||||
LocalDateTime created;
|
||||
|
||||
@UpdatedTimestamp
|
||||
DateTime updated;
|
||||
|
||||
@Version
|
||||
LocalDateTime version;
|
||||
|
||||
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 LocalDateTime getCreated() {
|
||||
return created;
|
||||
}
|
||||
|
||||
public void setCreated(LocalDateTime created) {
|
||||
this.created = created;
|
||||
}
|
||||
|
||||
public DateTime getUpdated() {
|
||||
return updated;
|
||||
}
|
||||
|
||||
public void setUpdated(DateTime updated) {
|
||||
this.updated = updated;
|
||||
}
|
||||
|
||||
public LocalDateTime getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(LocalDateTime version) {
|
||||
this.version = version;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.avaje.tests.model.joda;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.LocalDateTime;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertSame;
|
||||
|
||||
public class TestJodaInsertUpdate extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() throws InterruptedException {
|
||||
|
||||
BasicJodaEntity e0 = new BasicJodaEntity();
|
||||
e0.setName("foo");
|
||||
|
||||
Ebean.save(e0);
|
||||
|
||||
LocalDateTime created = e0.getCreated();
|
||||
DateTime updated = e0.getUpdated();
|
||||
LocalDateTime version = e0.getVersion();
|
||||
assertNotNull(created);
|
||||
assertNotNull(updated);
|
||||
assertNotNull(version);
|
||||
|
||||
Thread.sleep(10);
|
||||
e0.setName("bar");
|
||||
Ebean.save(e0);
|
||||
|
||||
LocalDateTime created1 = e0.getCreated();
|
||||
DateTime updated1 = e0.getUpdated();
|
||||
LocalDateTime version1 = e0.getVersion();
|
||||
|
||||
assertSame(created, created1);
|
||||
assertNotSame(updated, updated1);
|
||||
assertNotSame(version, version1);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user