diff --git a/pom.xml b/pom.xml index cd1b866..4e34caa 100644 --- a/pom.xml +++ b/pom.xml @@ -40,6 +40,13 @@ + + com.microsoft.sqlserver + mssql-jdbc + 9.4.0.jre8 + test + + io.ebean ebean-test diff --git a/src/main/java/org/example/domain/Customer.java b/src/main/java/org/example/domain/Customer.java index 0d3da1f..33592e1 100644 --- a/src/main/java/org/example/domain/Customer.java +++ b/src/main/java/org/example/domain/Customer.java @@ -2,9 +2,11 @@ import io.ebean.Model; +import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.Version; +import java.time.ZonedDateTime; @Entity public class Customer extends Model { @@ -16,6 +18,9 @@ public class Customer extends Model { String notes; + @Column(name = "MyDate", nullable = false) + ZonedDateTime mydate; + @Version Long version; @@ -26,36 +31,25 @@ public Customer(String name) { public Customer() { } - public Long getId() { + public Long id() { return id; } - public void setId(Long id) { + public void id(Long id) { this.id = id; } - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getNotes() { - return notes; - } - - public void setNotes(String notes) { + public void notes(String notes) { this.notes = notes; } - public Long getVersion() { - return version; + public ZonedDateTime mydate() { + return mydate; } - public void setVersion(Long version) { - this.version = version; + public Customer mydate(ZonedDateTime mydate) { + this.mydate = mydate; + return this; } } diff --git a/src/test/java/org/example/domain/CustomerTest.java b/src/test/java/org/example/domain/CustomerTest.java index 29e66e4..ffc273f 100644 --- a/src/test/java/org/example/domain/CustomerTest.java +++ b/src/test/java/org/example/domain/CustomerTest.java @@ -4,6 +4,8 @@ import io.ebean.Database; import org.junit.jupiter.api.Test; +import java.time.ZonedDateTime; + import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -22,11 +24,12 @@ public class CustomerTest { public void insert_via_database() { Customer rob = new Customer("Rob"); + rob.mydate(ZonedDateTime.now()); Database server = DB.getDefault(); server.save(rob); - assertNotNull(rob.getId()); + assertNotNull(rob.id()); } /** @@ -36,9 +39,10 @@ public void insert_via_database() { public void insert_via_model() { Customer jim = new Customer("Jim"); + jim.mydate(ZonedDateTime.now()); jim.save(); - assertNotNull(jim.getId()); + assertNotNull(jim.id()); } @@ -49,13 +53,14 @@ public void insert_via_model() { public void updateRob() { Customer newBob = new Customer("Bob"); + newBob.mydate(ZonedDateTime.now()); newBob.save(); Customer bob = DB.find(Customer.class) .where().eq("name", "Bob") .findOne(); - bob.setNotes("Doing an update"); + bob.notes("Doing an update"); bob.save(); } @@ -66,11 +71,12 @@ public void updateRob() { public void statelessUpdate() { Customer newMob = new Customer("Mob"); + newMob.mydate(ZonedDateTime.now()); newMob.save(); Customer upd = new Customer(); - upd.setId(newMob.getId()); - upd.setNotes("Update without a fetch"); + upd.id(newMob.id()); + upd.notes("Update without a fetch"); upd.update(); } diff --git a/src/test/resources/application-test.yaml b/src/test/resources/application-test.yaml index 49adf3b..01d5737 100644 --- a/src/test/resources/application-test.yaml +++ b/src/test/resources/application-test.yaml @@ -2,6 +2,9 @@ ebean: test: # useDocker: false # shutdown: stop # stop | remove - platform: h2 # h2, postgres, mysql, oracle, sqlserver, sqlite + platform: sqlserver # h2, postgres, mysql, oracle, sqlserver, sqlite ddlMode: dropCreate # none | dropCreate | create | migration | createOnly | migrationDropCreate dbName: myapp + + databasePlatformName: sqlserver17 + allQuotedIdentifiers: true