1 7 package org.jfox.petstore.dao; 8 9 import java.sql.SQLException ; 10 import java.util.List ; 11 import javax.ejb.Local ; 12 import javax.ejb.Stateless ; 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 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 39 @Local 40 public class CategoryDAOImpl extends DAOSupport implements CategoryDAO{ 41 42 public static final String GET_CATEGORY = "getCategory"; 43 public static final String 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 categoryId) throws SQLException { 53 return (Category)createNamedNativeQuery(GET_CATEGORY).setParameter("id",categoryId).getSingleResult(); 54 } 55 56 public List <Category> getCategoryList() throws SQLException { 57 return (List <Category>)createNamedNativeQuery(GET_CATEGORY_LIST).getResultList(); 58 } 59 60 } 61 | Popular Tags |