File tree Expand file tree Collapse file tree
test/java/com/actionbazaar Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package com .actionbazaar .application ;
2+
3+ import com .actionbazaar .domain .Bid ;
4+
5+ public interface BidService {
6+ public void addBid (Bid bid );
7+
8+ public Bid getBid (Long id );
9+
10+ public void updateBid (Bid bid );
11+
12+ public void deleteBid (Bid bid );
13+ }
Original file line number Diff line number Diff line change 1+ package com .actionbazaar .application ;
2+
3+ import javax .ejb .Stateless ;
4+ import javax .inject .Inject ;
5+
6+ import com .actionbazaar .domain .Bid ;
7+ import com .actionbazaar .repository .BidDao ;
8+
9+ @ Stateless
10+ public class DefaultBidService implements BidService {
11+
12+ @ Inject
13+ private BidDao bidDao ;
14+
15+ @ Override
16+ public void addBid (Bid bid ) {
17+ bidDao .addBid (bid );
18+ }
19+
20+ @ Override
21+ public Bid getBid (Long id ) {
22+ return bidDao .getBid (id );
23+ }
24+
25+ @ Override
26+ public void updateBid (Bid bid ) {
27+ bidDao .updateBid (bid );
28+ }
29+
30+ @ Override
31+ public void deleteBid (Bid bid ) {
32+ bidDao .deleteBid (bid );
33+ }
34+ }
Original file line number Diff line number Diff line change 1+ package com .actionbazaar .interfaces .rest ;
2+
3+ import javax .ejb .EJB ;
4+ import javax .ejb .Stateless ;
5+ import javax .ws .rs .Consumes ;
6+ import javax .ws .rs .DELETE ;
7+ import javax .ws .rs .GET ;
8+ import javax .ws .rs .POST ;
9+ import javax .ws .rs .PUT ;
10+ import javax .ws .rs .Path ;
11+ import javax .ws .rs .Produces ;
12+ import javax .ws .rs .QueryParam ;
13+
14+ import com .actionbazaar .application .BidService ;
15+ import com .actionbazaar .domain .Bid ;
16+
17+ @ Stateless
18+ @ Path ("/bid" )
19+ public class BidRestService {
20+
21+ @ EJB
22+ private BidService bidService ;
23+
24+ @ POST
25+ @ Consumes ("text/xml" )
26+ public void addBid (Bid bid ) {
27+ bidService .addBid (bid );
28+ }
29+
30+ @ GET
31+ @ Produces ("text/xml" )
32+ public Bid getBid (@ QueryParam ("id" ) Long id ) {
33+ return bidService .getBid (id );
34+ }
35+
36+ @ PUT
37+ @ Consumes ("text/xml" )
38+ public void updateBid (@ QueryParam ("id" ) Long id , Bid bid ) {
39+ bidService .updateBid (bid );
40+ }
41+
42+ @ DELETE
43+ public void deleteBid (@ QueryParam ("id" ) Long id ) {
44+ Bid bid = bidService .getBid (id );
45+ bidService .deleteBid (bid );
46+ }
47+ }
Original file line number Diff line number Diff line change 1+ package com .actionbazaar .interfaces .web ;
2+
3+ import java .io .Serializable ;
4+
5+ import javax .enterprise .context .RequestScoped ;
6+ import javax .enterprise .inject .Produces ;
7+ import javax .inject .Inject ;
8+ import javax .inject .Named ;
9+
10+ import com .actionbazaar .application .BidService ;
11+ import com .actionbazaar .domain .Bid ;
12+
13+ @ Named
14+ @ RequestScoped
15+ public class AddBid implements Serializable {
16+ private static final long serialVersionUID = 1L ;
17+
18+ @ Inject
19+ private BidService bidService ;
20+
21+ @ Produces
22+ @ Named
23+ @ RequestScoped
24+ private Bid bid = new Bid ();
25+
26+ public String addBid () {
27+ bidService .addBid (bid );
28+
29+ return "confirm_bid.jsf" ;
30+ }
31+ }
Original file line number Diff line number Diff line change 1+ package com .actionbazaar .repository ;
2+
3+ import com .actionbazaar .domain .Bid ;
4+
5+ public interface BidDao {
6+ public void addBid (Bid bid );
7+
8+ public Bid getBid (Long id );
9+
10+ public void updateBid (Bid bid );
11+
12+ public void deleteBid (Bid bid );
13+ }
Original file line number Diff line number Diff line change 1+ package com .actionbazaar .repository ;
2+
3+ import javax .persistence .EntityManager ;
4+ import javax .persistence .PersistenceContext ;
5+
6+ import com .actionbazaar .domain .Bid ;
7+
8+ public class DefaultBidDao implements BidDao {
9+
10+ @ PersistenceContext
11+ private EntityManager entityManager ;
12+
13+ @ Override
14+ public void addBid (Bid bid ) {
15+ entityManager .persist (bid );
16+ }
17+
18+ @ Override
19+ public Bid getBid (Long id ) {
20+ return entityManager .find (Bid .class , id );
21+ }
22+
23+ @ Override
24+ public void updateBid (Bid bid ) {
25+ entityManager .merge (bid );
26+ }
27+
28+ @ Override
29+ public void deleteBid (Bid bid ) {
30+ entityManager .remove (entityManager .merge (bid ));
31+ }
32+ }
Load diff This file was deleted.
Original file line number Diff line number Diff line change 33 xmlns=" http://xmlns.jcp.org/xml/ns/persistence" xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
44 xsi:schemaLocation=" http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd" >
55 <persistence-unit name =" action-bazaar-unit" >
6- <jta-data-source >jdbc/ActionBazaarDB</jta-data-source >
6+ <jta-data-source >java:comp/env/ jdbc/ActionBazaarDB</jta-data-source >
77 <properties >
88 <property name =" javax.persistence.schema-generation.database.action"
99 value=" drop-and-create" />
Original file line number Diff line number Diff line change 1919 <welcome-file-list >
2020 <welcome-file >add_bid.jsf</welcome-file >
2121 </welcome-file-list >
22+ <data-source >
23+ <name >java:comp/env/jdbc/ActionBazaarDB</name >
24+ <class-name >org.apache.derby.jdbc.EmbeddedDriver</class-name >
25+ <url >jdbc:derby:/tmp/actionbazaar-database;create=true
26+ </url >
27+ </data-source >
2228</web-app >
Original file line number Diff line number Diff line change 1616 < h:outputLabel for ="amount "> Bid amount:</ h:outputLabel >
1717 < h:inputText id ="amount " value ="#{bid.amount} " />
1818 </ h:panelGrid >
19- < h:commandButton id ="add " value ="PlaceBid "
20- action ="#{placeBid.placeBid } " />
19+ < h:commandButton id ="add " value ="Add Bid "
20+ action ="#{addBid.addBid } " />
2121 </ h:form >
2222</ h:body >
2323</ html >
You can’t perform that action at this time.
0 commit comments