KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfox > petstore > dao > CategoryDAOImpl


1 /*
2  * JFox - The most lightweight Java EE Application Server!
3  * more details please visit http://www.huihoo.org/jfox or http://www.jfox.org.cn.
4  *
5  * JFox is licenced and re-distributable under GNU LGPL.
6  */

7 package org.jfox.petstore.dao;
8
9 import java.sql.SQLException JavaDoc;
10 import java.util.List JavaDoc;
11 import javax.ejb.Local JavaDoc;
12 import javax.ejb.Stateless JavaDoc;
13 import javax.persistence.EntityManager;
14 import javax.persistence.NamedNativeQueries;
15 import javax.persistence.NamedNativeQuery;
16 import javax.persistence.PersistenceContext;
17
18 import org.jfox.entity.dao.DAOSupport;
19 import org.jfox.petstore.entity.Category;
20
21 /**
22  * @author <a HREF="mailto:jfox.young@gmail.com">Young Yang</a>
23  */

24 @NamedNativeQueries(
25         {
26         @NamedNativeQuery(
27                 name = CategoryDAOImpl.GET_CATEGORY,
28                 query = "select catid, name, descn from category where catid = $id",
29                 resultClass = Category.class
30         ),
31         @NamedNativeQuery(
32                 name = CategoryDAOImpl.GET_CATEGORY_LIST,
33                 query = "select catid, name, descn from category",
34                 resultClass = Category.class
35         )
36                 }
37 )
38 @Stateless JavaDoc
39 @Local JavaDoc
40 public class CategoryDAOImpl extends DAOSupport implements CategoryDAO{
41
42     public static final String JavaDoc GET_CATEGORY = "getCategory";
43     public static final String JavaDoc GET_CATEGORY_LIST = "getCategoryList";
44
45     @PersistenceContext(unitName = "JPetstoreMysqlDS")
46     EntityManager em;
47
48     protected EntityManager getEntityManager() {
49         return em;
50     }
51
52     public Category getCategory(String JavaDoc categoryId) throws SQLException JavaDoc {
53         return (Category)createNamedNativeQuery(GET_CATEGORY).setParameter("id",categoryId).getSingleResult();
54     }
55
56     public List JavaDoc<Category> getCategoryList() throws SQLException JavaDoc {
57         return (List JavaDoc<Category>)createNamedNativeQuery(GET_CATEGORY_LIST).getResultList();
58     }
59
60 }
61
Popular Tags