[jboss-cvs] jboss-seam/examples/seambay/src/org/jboss/seam/example/seambay ...
Shane Bryzak
sbryzak at redhat.com
Thu Mar 29 09:54:59 EDT 2007
User: sbryzak2
Date: 07/03/29 09:54:59
Modified: examples/seambay/src/org/jboss/seam/example/seambay
Auction.java AuctionSearchAction.java
AuctionService.java CategoryAction.java User.java
Added: examples/seambay/src/org/jboss/seam/example/seambay
AuctionImage.java
Log:
ongoing
Revision Changes Path
1.3 +50 -3 jboss-seam/examples/seambay/src/org/jboss/seam/example/seambay/Auction.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: Auction.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/examples/seambay/src/org/jboss/seam/example/seambay/Auction.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- Auction.java 24 Mar 2007 05:38:19 -0000 1.2
+++ Auction.java 29 Mar 2007 13:54:59 -0000 1.3
@@ -4,13 +4,17 @@
import java.util.Date;
import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
import javax.persistence.Id;
+import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
+import javax.persistence.OneToOne;
+import javax.persistence.Transient;
@Entity
public class Auction implements Serializable
{
- private static final long serialVersionUID = 1L;
+ private static final long serialVersionUID = -8349473227099432431L;
private Integer auctionId;
private User user;
@@ -18,8 +22,11 @@
private String title;
private String description;
private Date endDate;
+ private AuctionImage image;
+ private int bids;
+ private double price;
- @Id
+ @Id @GeneratedValue
public Integer getAuctionId()
{
return auctionId;
@@ -31,6 +38,7 @@
}
@ManyToOne
+ @JoinColumn(name = "USER_ID")
public User getUser()
{
return user;
@@ -42,6 +50,7 @@
}
@ManyToOne
+ @JoinColumn(name = "CATEGORY_ID")
public Category getCategory()
{
return category;
@@ -81,4 +90,42 @@
{
this.endDate = endDate;
}
+
+ @OneToOne
+ @JoinColumn(name = "IMAGE_ID")
+ public AuctionImage getImage()
+ {
+ return image;
+ }
+
+ public void setImage(AuctionImage image)
+ {
+ this.image = image;
+ }
+
+ public int getBids()
+ {
+ return bids;
+ }
+
+ public void setBids(int bids)
+ {
+ this.bids = bids;
+ }
+
+ @Transient
+ public String getTimeLeft()
+ {
+ return (endDate.getTime() - System.currentTimeMillis()) + "ms";
+ }
+
+ public double getPrice()
+ {
+ return price;
+ }
+
+ public void setPrice(double price)
+ {
+ this.price = price;
+ }
}
1.2 +48 -5 jboss-seam/examples/seambay/src/org/jboss/seam/example/seambay/AuctionSearchAction.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: AuctionSearchAction.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/examples/seambay/src/org/jboss/seam/example/seambay/AuctionSearchAction.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- AuctionSearchAction.java 22 Mar 2007 15:02:47 -0000 1.1
+++ AuctionSearchAction.java 29 Mar 2007 13:54:59 -0000 1.2
@@ -1,6 +1,10 @@
package org.jboss.seam.example.seambay;
+import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
import javax.persistence.EntityManager;
@@ -9,7 +13,6 @@
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
-import org.jboss.seam.annotations.datamodel.DataModel;
@Name("auctionSearch")
@Scope(ScopeType.SESSION)
@@ -22,20 +25,43 @@
private int page = 0;
private String searchTerm;
+ private Category searchCategory;
- @DataModel
private List<Auction> auctions;
+ private Map<Category,Long> searchCategories = new HashMap<Category,Long>();
+
+ @SuppressWarnings("unchecked")
public void queryAuctions()
{
- auctions = entityManager.createQuery(
- "from Auction a where lower(title) like #{pattern}")
+ String qry = null;
+
+ if (searchCategory == null)
+ {
+ qry = "from Auction a where lower(title) like #{searchPattern}";
+ }
+ else
+ {
+ qry = "from Auction a where lower(title) like #{searchPattern} and a.category = #{searchCategory}";
+ }
+
+ auctions = entityManager.createQuery(qry)
.setMaxResults(pageSize)
.setFirstResult( page * pageSize )
.getResultList();
+
+ searchCategories.clear();
+
+ for (Object[] result : (List<Object[]>) entityManager.createQuery(
+ "select a.category.categoryId, count(a) from Auction a " +
+ "where lower(a.title) like #{searchPattern} group by a.category.categoryId")
+ .getResultList())
+ {
+ searchCategories.put(entityManager.find(Category.class, result[0]), (Long) result[1]);
+ }
}
- @Factory(value="pattern", scope=ScopeType.EVENT)
+ @Factory(value="searchPattern", scope=ScopeType.EVENT)
public String getSearchPattern()
{
return searchTerm == null ?
@@ -76,4 +102,21 @@
{
return auctions;
}
+
+ public List<Entry> getSearchCategories()
+ {
+ return new ArrayList<Entry>(searchCategories.entrySet());
+ }
+
+ public void selectCategory(Category category)
+ {
+ this.searchCategory = category;
+ queryAuctions();
+ }
+
+ @Factory(value="searchCategory", scope=ScopeType.EVENT)
+ public Category getSearchCategory()
+ {
+ return searchCategory;
+ }
}
1.3 +2 -0 jboss-seam/examples/seambay/src/org/jboss/seam/example/seambay/AuctionService.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: AuctionService.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/examples/seambay/src/org/jboss/seam/example/seambay/AuctionService.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- AuctionService.java 24 Mar 2007 05:38:19 -0000 1.2
+++ AuctionService.java 29 Mar 2007 13:54:59 -0000 1.3
@@ -1,6 +1,7 @@
package org.jboss.seam.example.seambay;
import javax.ejb.Stateless;
+import javax.jws.HandlerChain;
import javax.jws.WebMethod;
import javax.jws.WebService;
@@ -8,6 +9,7 @@
@Stateless
@WebService
+ at HandlerChain(file="META-INF/handler-chain.xml")
public class AuctionService implements AuctionServiceRemote
{
@WebMethod
1.2 +1 -0 jboss-seam/examples/seambay/src/org/jboss/seam/example/seambay/CategoryAction.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: CategoryAction.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/examples/seambay/src/org/jboss/seam/example/seambay/CategoryAction.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- CategoryAction.java 24 Mar 2007 05:38:19 -0000 1.1
+++ CategoryAction.java 29 Mar 2007 13:54:59 -0000 1.2
@@ -18,6 +18,7 @@
@Out(required = false)
private List<Category> categories;
+ @SuppressWarnings("unchecked")
@Factory("categories")
public void loadCategories()
{
1.2 +2 -1 jboss-seam/examples/seambay/src/org/jboss/seam/example/seambay/User.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: User.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/examples/seambay/src/org/jboss/seam/example/seambay/User.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- User.java 22 Mar 2007 15:02:47 -0000 1.1
+++ User.java 29 Mar 2007 13:54:59 -0000 1.2
@@ -3,6 +3,7 @@
import java.io.Serializable;
import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
import javax.persistence.Id;
@Entity
@@ -14,7 +15,7 @@
private String username;
private String password;
- @Id
+ @Id @GeneratedValue
public Integer getUserId()
{
return userId;
1.1 date: 2007/03/29 13:54:59; author: sbryzak2; state: Exp;jboss-seam/examples/seambay/src/org/jboss/seam/example/seambay/AuctionImage.java
Index: AuctionImage.java
===================================================================
package org.jboss.seam.example.seambay;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
@Entity
public class AuctionImage implements Serializable
{
private static final long serialVersionUID = -1219357931402690891L;
private Integer imageId;
private Auction auction;
private byte[] data;
@Id @GeneratedValue
public Integer getImageId()
{
return imageId;
}
public void setImageId(Integer imageId)
{
this.imageId = imageId;
}
@ManyToOne
@JoinColumn(name = "AUCTION_ID")
public Auction getAuction()
{
return auction;
}
public void setAuction(Auction auction)
{
this.auction = auction;
}
@Lob
public byte[] getData()
{
return data;
}
public void setData(byte[] data)
{
this.data = data;
}
}
More information about the jboss-cvs-commits
mailing list