Permalink
Browse files

Introduce jpa.GenericModel.create() and update sample applications

  • Loading branch information...
1 parent 3b88620 commit 4de44b3e696ec5d4ffc16eb7b30401e7a435b1be @guillaumebort guillaumebort committed Nov 3, 2010
@@ -174,6 +174,13 @@ public boolean validateAndSave() {
}
/**
+ * store (ie insert) the entity.
+ */
+ public boolean create() {
+ return _create();
+ }
+
+ /**
* Refresh the entity state.
*/
public <T extends JPABase> T refresh() {
@@ -32,6 +32,15 @@
@MappedSuperclass
public class JPABase implements Serializable, play.db.Model {
+ public boolean _create() {
+ if (!em().contains(this)) {
+ em().persist(this);
+ PlayPlugin.postEvent("JPASupport.objectPersisted", this);
+ return true;
+ }
+ return false;
+ }
+
public void _save() {
if (!em().contains(this)) {
em().persist(this);
@@ -45,7 +45,7 @@ public static void saveUser(@Valid User user, String verifyPassword) {
if(validation.hasErrors()) {
render("@register", user, verifyPassword);
}
- user.save();
+ user.create();
session.put("user", user.username);
flash.success("Welcome, " + user.name);
Hotels.index();
@@ -60,7 +60,7 @@ public static void confirmBooking(Long id, Booking booking) {
// Confirm
if(params.get("confirm") != null) {
- booking.save();
+ booking.create();
flash.success("Thank you, %s, your confimation number for %s is %s", connected().name, hotel.name, booking.id);
index();
}
@@ -20,7 +20,7 @@
public Forum(String name, String description) {
this.name = name;
this.description = description;
- save();
+ create();
}
// ~~~~~~~~~~~~
@@ -28,7 +28,7 @@ public Post(Topic topic, User postedBy, String content) {
this.postedBy = postedBy;
this.content = content;
this.postedAt = new Date();
- save();
+ create();
}
}
@@ -25,7 +25,7 @@
public Topic(Forum forum, User by, String subject, String content) {
this.forum = forum;
this.subject = subject;
- save();
+ create();
new Post(this, by, content);
}
@@ -30,7 +30,7 @@ public User(String email, String password, String name) {
this.passwordHash = Codec.hexMD5(password);
this.name = name;
this.needConfirmation = Codec.UUID();
- save();
+ create();
}
// ~~~~~~~~~~~~

0 comments on commit 4de44b3

Please sign in to comment.