Author: amarkhel
Date: 2009-04-10 13:21:04 -0400 (Fri, 10 Apr 2009)
New Revision: 13509
Added:
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/RealworldException.java
Modified:
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/domain/Image.java
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/AlbumAction.java
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/Constants.java
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/IImageAction.java
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/ImageAction.java
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/ShelfAction.java
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/UserAction.java
Log:
Modified:
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/domain/Image.java
===================================================================
---
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/domain/Image.java 2009-04-10
16:55:00 UTC (rev 13508)
+++
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/domain/Image.java 2009-04-10
17:21:04 UTC (rev 13509)
@@ -47,6 +47,7 @@
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
+import javax.persistence.UniqueConstraint;
import org.hibernate.validator.Length;
import org.hibernate.validator.NotEmpty;
@@ -69,8 +70,12 @@
@NamedQuery(
name = "user-shelves",
query = "select distinct s from Shelf s where (s.shared = true and
s.preDefined = true) or s.owner = :user order by s.name"
- ),
+ ),
@NamedQuery(
+ name = "image-exist",
+ query = "from Image i where i.path = :path and i.album = :album"
+ ),
+ @NamedQuery(
name = "tag-suggest",
query = "select m from MetaTag m where lower(m.tag) like :tag"
)
@@ -85,7 +90,9 @@
@Entity
@Name("image")
-@Table(name = "Images")
+@Table(name = "Images", uniqueConstraints = {
+ @UniqueConstraint(columnNames = "path"),
+ })
@Scope(ScopeType.CONVERSATION)
@AutoCreate
public class Image implements Serializable {
Modified:
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/AlbumAction.java
===================================================================
---
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/AlbumAction.java 2009-04-10
16:55:00 UTC (rev 13508)
+++
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/AlbumAction.java 2009-04-10
17:21:04 UTC (rev 13509)
@@ -50,10 +50,15 @@
* @param album - album to add
*/
public void addAlbum(Album album) {
+ try{
em.persist(album);
//Add to shelf
album.getShelf().addAlbum(album);
em.flush();
+ }
+ catch(Exception e){
+ throw new RealworldException(e.getMessage());
+ }
}
/**
@@ -61,6 +66,7 @@
* @param album - album to delete
*/
public void deleteAlbum(Album album){
+ try{
if(album.getShelf() == null){
return;
}
@@ -68,6 +74,10 @@
album.getShelf().removeAlbum(album);
em.remove(album);
em.flush();
+ }
+ catch(Exception e){
+ throw new RealworldException(e.getMessage());
+ }
}
/**
@@ -75,6 +85,11 @@
* @param album - album to Synchronize
*/
public void editAlbum(Album album){
+ try{
em.flush();
+ }
+ catch(Exception e){
+ throw new RealworldException(e.getMessage());
+ }
}
}
Modified:
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/Constants.java
===================================================================
---
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/Constants.java 2009-04-10
16:55:00 UTC (rev 13508)
+++
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/Constants.java 2009-04-10
17:21:04 UTC (rev 13509)
@@ -160,6 +160,8 @@
public static final String SEARCH_ALBUM_QUERY = "from Album a where lower(a.name)
like :name or lower(a.description) like :name";
public static final String USER_SHELVES_QUERY = "user-shelves";
public static final String SHELF_PARAMETER = "shelf";
+ public static final String PATH_PARAMETER = "path";
+ public static final String IMAGE_PATH_EXIST_QUERY = "image-exist";
private Constants(){
}
}
\ No newline at end of file
Modified:
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/IImageAction.java
===================================================================
---
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/IImageAction.java 2009-04-10
16:55:00 UTC (rev 13508)
+++
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/IImageAction.java 2009-04-10
17:21:04 UTC (rev 13509)
@@ -53,4 +53,6 @@
public List<MetaTag> getTagsLikeString(String suggest);
+ public boolean isImageWithThisPathExist(Image image);
+
}
\ No newline at end of file
Modified:
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/ImageAction.java
===================================================================
---
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/ImageAction.java 2009-04-10
16:55:00 UTC (rev 13508)
+++
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/ImageAction.java 2009-04-10
17:21:04 UTC (rev 13509)
@@ -54,12 +54,17 @@
* @param image - image to delete
*/
public void deleteImage(Image image) {
+ try{
if(image.getAlbum().getCoveringImage().equals(image)){
image.getAlbum().setCoveringImage(null);
}
image.getAlbum().removeImage(image);
em.remove(image);
em.flush();
+ }
+ catch(Exception e){
+ throw new RealworldException(e.getMessage());
+ }
}
/**
@@ -68,6 +73,7 @@
* @param metatagsChanged - boolean value, that indicates is metatags of this image
were changed(add new or delete older)
*/
public void editImage(Image image, boolean metatagsChanged) {
+ try{
if(metatagsChanged){
//Create cash of metatags early associated with image
List<MetaTag> removals = new
ArrayList<MetaTag>(image.getImageTags());
@@ -116,6 +122,10 @@
}
}
em.flush();
+ }
+ catch(Exception e){
+ throw new RealworldException(e.getMessage());
+ }
}
/**
@@ -123,9 +133,14 @@
* @param image - image to add
*/
public void addImage(Image image) {
- em.persist(image);
- image.getAlbum().addImage(image);
- em.flush();
+ try{
+ em.persist(image);
+ image.getAlbum().addImage(image);
+ em.flush();
+ }
+ catch(Exception e){
+ throw new RealworldException(e.getMessage());
+ }
}
/**
@@ -133,8 +148,13 @@
* @param comment - comment to remove
*/
public void deleteComment(Comment comment) {
- comment.getImage().removeComment(comment);
- em.flush();
+ try{
+ comment.getImage().removeComment(comment);
+ em.flush();
+ }
+ catch(Exception e){
+ throw new RealworldException(e.getMessage());
+ }
}
/**
@@ -142,8 +162,13 @@
* @param comment - comment to add
*/
public void addComment(Comment comment) {
- comment.getImage().addComment(comment);
- em.flush();
+ try{
+ comment.getImage().addComment(comment);
+ em.flush();
+ }
+ catch(Exception e){
+ throw new RealworldException(e.getMessage());
+ }
}
/**
@@ -180,4 +205,15 @@
public List<MetaTag> getTagsLikeString(String suggest) {
return (List<MetaTag>)
em.createNamedQuery(Constants.TAG_SUGGEST_QUERY).setParameter(Constants.TAG_PARAMETER,
suggest + Constants.PERCENT).getResultList();
}
+
+ /**
+ * Check if image with specified path already exist
+ * @return is image with specified path already exist
+ */
+ public boolean isImageWithThisPathExist(Image image) {
+ return em.createNamedQuery(Constants.IMAGE_PATH_EXIST_QUERY)
+ .setParameter(Constants.PATH_PARAMETER, image.getPath())
+ .setParameter(Constants.ALBUM_PARAMETER, image.getAlbum())
+ .getResultList().size() != 0;
+ }
}
Added:
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/RealworldException.java
===================================================================
---
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/RealworldException.java
(rev 0)
+++
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/RealworldException.java 2009-04-10
17:21:04 UTC (rev 13509)
@@ -0,0 +1,23 @@
+package org.richfaces.realworld.service;
+
+import org.jboss.seam.annotations.ApplicationException;
+
+@ApplicationException(rollback=false)
+public class RealworldException extends RuntimeException {
+
+ public RealworldException()
+ {
+ super();
+ }
+
+ public RealworldException(String message)
+ {
+ super(message);
+ }
+
+ public RealworldException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+}
+
Property changes on:
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/RealworldException.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Id Revision Date
Name: svn:eol-style
+ native
Modified:
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/ShelfAction.java
===================================================================
---
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/ShelfAction.java 2009-04-10
16:55:00 UTC (rev 13508)
+++
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/ShelfAction.java 2009-04-10
17:21:04 UTC (rev 13509)
@@ -56,10 +56,15 @@
* @param shelf - shelf to add
*/
public void addShelf(Shelf shelf) {
+ try{
em.persist(shelf);
//Add reference to user
user.addShelf(shelf);
em.flush();
+ }
+ catch(Exception e){
+ throw new RealworldException(e.getMessage());
+ }
}
/**
@@ -68,9 +73,14 @@
*/
public void deleteShelf(Shelf shelf) {
//Remove reference from user
+ try{
user.removeShelf(shelf);
em.remove(shelf);
em.flush();
+ }
+ catch(Exception e){
+ throw new RealworldException(e.getMessage());
+ }
}
/**
@@ -78,7 +88,12 @@
* @param shelf - shelf to Synchronize
*/
public void editShelf(Shelf shelf) {
+ try{
em.flush();
+ }
+ catch(Exception e){
+ throw new RealworldException(e.getMessage());
+ }
}
/**
Modified:
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/UserAction.java
===================================================================
---
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/UserAction.java 2009-04-10
16:55:00 UTC (rev 13508)
+++
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/UserAction.java 2009-04-10
17:21:04 UTC (rev 13509)
@@ -63,8 +63,13 @@
* @param user - user to register
*/
public void register(User user) {
+ try{
em.persist(user);
em.flush();
+ }
+ catch(Exception e){
+ throw new RealworldException(e.getMessage());
+ }
}
/**
@@ -72,7 +77,12 @@
* @return user if success
*/
public User updateUser() {
+ try{
em.flush();
+ }
+ catch(Exception e){
+ throw new RealworldException(e.getMessage());
+ }
return user;
}