Author: andrei_exadel
Date: 2009-02-27 13:42:35 -0500 (Fri, 27 Feb 2009)
New Revision: 12777
Added:
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/ISearchAction.java
Modified:
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/SearchAction.java
Log:
Search Service
Added:
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/ISearchAction.java
===================================================================
---
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/ISearchAction.java
(rev 0)
+++
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/ISearchAction.java 2009-02-27
18:42:35 UTC (rev 12777)
@@ -0,0 +1,18 @@
+package org.richfaces.realworld.service;
+
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
+import org.richfaces.realworld.domain.Album;
+import org.richfaces.realworld.domain.Image;
+
+public interface ISearchAction {
+ public List<Image> searchByImage(String name, String description, String path,
Integer width, Integer height, Integer size, Date createdDate, Date uploadedDate);
+
+ public List<Image> searchByTags(Map<String, String> params);
+
+ public List<Album> searchByAlbum(String name, String description, String
ownerName, boolean shared );
+
+ public List<Image> searchByUsers(Map<String, String> params);
+}
Modified:
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/SearchAction.java
===================================================================
---
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/SearchAction.java 2009-02-27
18:42:30 UTC (rev 12776)
+++
trunk/test-applications/realworld2/ejb/src/main/java/org/richfaces/realworld/service/SearchAction.java 2009-02-27
18:42:35 UTC (rev 12777)
@@ -1,10 +1,12 @@
package org.richfaces.realworld.service;
+import java.util.Date;
import java.util.List;
import java.util.Map;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
+import javax.persistence.Query;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
@@ -15,7 +17,7 @@
@Name("searchAction")
@Stateless
-public class SearchAction {
+public class SearchAction implements ISearchAction {
@In(value="entityManager")
EntityManager em;
@@ -23,16 +25,89 @@
@In @Out
private User user;
- public List<Image> searchByImage(Map<String, String> params){
- return null;
+ public List<Image> searchByImage(String name, String description, String path,
Integer width, Integer height, Integer size, Date createdDate, Date uploadedDate){
+ StringBuffer b = new StringBuffer("from Image i where ");
+ if (name != null && name.length() > 0) {
+ b.append("i.name like :name");
+ }
+ if (description != null && description.length() > 0) {
+ b.append("i.description like :description");
+ }
+ if (path != null && path.length() > 0) {
+ b.append("i.path like :path");
+ }
+ if (width != null && width > 0) {
+ b.append("i.width =:width");
+ }
+ if (height != null && height > 0) {
+ b.append("i.height =:height)");
+ }
+ if (size != null && size > 0) {
+ b.append("i.size =:size");
+ }
+ if (createdDate != null) {
+ b.append("i.createdDate =:createdDate");
+ }
+ if (uploadedDate != null) {
+ b.append("i.uploadedDate =:uploadedDate");
+ }
+
+
+ Query q = em.createQuery(b.toString());
+
+ if (name != null && name.length() > 0) {
+ q.setParameter("name", name);
+ }
+ if (description != null && description.length() > 0) {
+ q.setParameter("description", description);
+ }
+ if (path != null && path.length() > 0) {
+ q.setParameter("path", path);
+ }
+ if (width != null && width > 0) {
+ q.setParameter("width", width);
+ }
+ if (height != null && height > 0) {
+ q.setParameter("height", height);
+ }
+ if (size != null && size > 0) {
+ q.setParameter("size", size);
+ }
+ if (createdDate != null) {
+ q.setParameter("createdDate", createdDate);
+ }
+ if (uploadedDate != null) {
+ q.setParameter("uploadedDate", uploadedDate);
+ }
+
+ return q.getResultList();
}
public List<Image> searchByTags(Map<String, String> params){
return null;
}
- public List<Album> searchByAlbum(Map<String, String> params){
- return null;
+ public List<Album> searchByAlbum(String name, String description, String
ownerName, boolean shared ){
+ StringBuffer b = new StringBuffer("from Album a where a.name like :name and
a.shared=:shared");
+ if (description != null && description.length() > 0) {
+ b.append("and a.description like :description ");
+ }
+ if (ownerName != null && ownerName.length() > 0) {
+ b.append("and a.owner.login like :ownewName");
+ }
+
+ Query q = em.createQuery(b.toString())
+ .setParameter("name", name)
+ .setParameter("shared", shared);
+ if (description != null && description.length() > 0) {
+ q.setParameter("description", description);
+ }
+
+ if (ownerName != null && ownerName.length() > 0) {
+ q.setParameter("ownewName", ownerName);
+ }
+
+ return q.getResultList();
}
public List<Image> searchByUsers(Map<String, String> params){