Fix for #240 - Add support for using Joda LocalDateTime and DateTime with @CreatedTimestamp, @UpdatedTimestamp

This commit is contained in:
rbygrave
2015-02-02 20:39:06 +13:00
parent 36dd2bbee7
commit ace45a038e
7 changed files with 254 additions and 1 deletions
@@ -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);
}
}