Author: amarkhel
Date: 2009-05-04 14:04:24 -0400 (Mon, 04 May 2009)
New Revision: 14012
Modified:
trunk/examples/photoalbum/source/ejb/src/main/java/org/richfaces/photoalbum/domain/Comment.java
trunk/examples/photoalbum/source/ejb/src/main/java/org/richfaces/photoalbum/service/AlbumAction.java
trunk/examples/photoalbum/source/ejb/src/main/java/org/richfaces/photoalbum/service/ImageAction.java
trunk/examples/photoalbum/source/ejb/src/main/java/org/richfaces/photoalbum/service/ShelfAction.java
Log:
Modified:
trunk/examples/photoalbum/source/ejb/src/main/java/org/richfaces/photoalbum/domain/Comment.java
===================================================================
---
trunk/examples/photoalbum/source/ejb/src/main/java/org/richfaces/photoalbum/domain/Comment.java 2009-05-04
18:04:16 UTC (rev 14011)
+++
trunk/examples/photoalbum/source/ejb/src/main/java/org/richfaces/photoalbum/domain/Comment.java 2009-05-04
18:04:24 UTC (rev 14012)
@@ -20,15 +20,8 @@
*/
package org.richfaces.photoalbum.domain;
-import org.hibernate.validator.Length;
-import org.hibernate.validator.NotEmpty;
-import org.hibernate.validator.NotNull;
-import org.hibernate.annotations.OnDelete;
-import org.hibernate.annotations.OnDeleteAction;
-import org.hibernate.annotations.ForeignKey;
-import org.jboss.seam.ScopeType;
-import org.jboss.seam.annotations.Name;
-import org.jboss.seam.annotations.Scope;
+import java.io.Serializable;
+import java.util.Date;
import javax.persistence.CascadeType;
import javax.persistence.Column;
@@ -40,8 +33,15 @@
import javax.persistence.ManyToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
-import java.io.Serializable;
-import java.util.Date;
+
+import org.hibernate.annotations.OnDelete;
+import org.hibernate.annotations.OnDeleteAction;
+import org.hibernate.validator.Length;
+import org.hibernate.validator.NotEmpty;
+import org.hibernate.validator.NotNull;
+import org.jboss.seam.ScopeType;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Scope;
/**
* Class for representing Comment Entity. EJB3 Entity Bean
*
@@ -64,7 +64,7 @@
@JoinColumn(nullable = false)
private Image image;
- @ManyToOne(fetch = FetchType.LAZY)
+ @ManyToOne(cascade = CascadeType.REMOVE, fetch = FetchType.LAZY)
@OnDelete(action = OnDeleteAction.CASCADE)
@JoinColumn(nullable = true)
private User author;
Modified:
trunk/examples/photoalbum/source/ejb/src/main/java/org/richfaces/photoalbum/service/AlbumAction.java
===================================================================
---
trunk/examples/photoalbum/source/ejb/src/main/java/org/richfaces/photoalbum/service/AlbumAction.java 2009-05-04
18:04:16 UTC (rev 14011)
+++
trunk/examples/photoalbum/source/ejb/src/main/java/org/richfaces/photoalbum/service/AlbumAction.java 2009-05-04
18:04:24 UTC (rev 14012)
@@ -67,15 +67,18 @@
* @throws PhotoAlbumException
*/
public void deleteAlbum(Album album) throws PhotoAlbumException {
- final Shelf shelf = album.getShelf();
+ Shelf parentShelf = album.getShelf();
try {
+ if(parentShelf == null){
+ return;
+ }
album.setCoveringImage(null);
-
+ //Remove from previous shelf
+ parentShelf.removeAlbum(album);
em.remove(album);
em.flush();
-
- em.refresh(shelf);
} catch (Exception e) {
+ parentShelf.addAlbum(album);
throw new PhotoAlbumException(e.getMessage());
}
}
Modified:
trunk/examples/photoalbum/source/ejb/src/main/java/org/richfaces/photoalbum/service/ImageAction.java
===================================================================
---
trunk/examples/photoalbum/source/ejb/src/main/java/org/richfaces/photoalbum/service/ImageAction.java 2009-05-04
18:04:16 UTC (rev 14011)
+++
trunk/examples/photoalbum/source/ejb/src/main/java/org/richfaces/photoalbum/service/ImageAction.java 2009-05-04
18:04:24 UTC (rev 14012)
@@ -32,6 +32,7 @@
import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
+import org.richfaces.photoalbum.domain.Album;
import org.richfaces.photoalbum.domain.Comment;
import org.richfaces.photoalbum.domain.Image;
import org.richfaces.photoalbum.domain.MetaTag;
@@ -55,13 +56,15 @@
* @throws PhotoAlbumException
*/
public void deleteImage(Image image) throws PhotoAlbumException {
+ Album parentAlbum = image.getAlbum();
try{
- image.getAlbum().removeImage(image);
+ parentAlbum.removeImage(image);
image.setImageTags(null);
em.remove(image);
em.flush();
} catch(Exception e){
+ parentAlbum.addImage(image);
throw new PhotoAlbumException(e.getMessage());
}
}
Modified:
trunk/examples/photoalbum/source/ejb/src/main/java/org/richfaces/photoalbum/service/ShelfAction.java
===================================================================
---
trunk/examples/photoalbum/source/ejb/src/main/java/org/richfaces/photoalbum/service/ShelfAction.java 2009-05-04
18:04:16 UTC (rev 14011)
+++
trunk/examples/photoalbum/source/ejb/src/main/java/org/richfaces/photoalbum/service/ShelfAction.java 2009-05-04
18:04:24 UTC (rev 14012)
@@ -56,10 +56,10 @@
*/
public void addShelf(Shelf shelf) throws PhotoAlbumException {
try{
- em.persist(shelf);
- //Add reference to user
- user.addShelf(shelf);
- em.flush();
+ em.persist(shelf);
+ //Add reference to user
+ user.addShelf(shelf);
+ em.flush();
}
catch(Exception e){
throw new PhotoAlbumException(e.getMessage());
@@ -74,11 +74,12 @@
public void deleteShelf(Shelf shelf) throws PhotoAlbumException {
try{
//Remove reference from user
- user.removeShelf(shelf);
- em.remove(shelf);
- em.flush();
+ user.removeShelf(shelf);
+ em.remove(shelf);
+ em.flush();
}
catch(Exception e){
+ user.addShelf(shelf);
throw new PhotoAlbumException(e.getMessage());
}
}
@@ -90,7 +91,7 @@
*/
public void editShelf(Shelf shelf) throws PhotoAlbumException {
try{
- em.flush();
+ em.flush();
}
catch(Exception e){
throw new PhotoAlbumException(e.getMessage());
Show replies by date