Richie's Life

A Wonderfule Journey ...
posts - 3, comments - 4, trackbacks - 0, articles - 1
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

test

Posted on 2006-05-04 08:57 Richie@L 阅读(91) 评论(0)  编辑  收藏

The code below has been highlighted using the selected language:

HTML Source of Syntax Highlighted Code

This is the code that was generated by the highlighting engine:

1package richie.gt.ejb3.manager; 2 3import java.util.Collection; 4 5import javax.persistence.EntityManager; 6import javax.persistence.NamedQueries; 7import javax.persistence.NamedQuery; 8import javax.persistence.PersistenceContext; 9 10import richie.gt.ejb3.domain.User; 11import richie.gt.ejb3.service.UserMangerService; 12 13@NamedQueries( { 14 @NamedQuery(name = "findUserByName", query = "SELECT u FROM User u WHERE u.userName = : userName"), 15 @NamedQuery(name = "findUserById", query = "SELECT u FROM User u WHERE u.userID = : userID"), 16 @NamedQuery(name = "getAll", query = "SELECT u FROM User u "), 17 @NamedQuery(name = "findByServiceID", query = "SELECT u FROM User u JOIN u.myServices ms JOIN ms.service s WHERE s.serviceID = : serviceID"), 18 @NamedQuery(name = "findByServiceName", query = "SELECT u FROM User u JOIN u.myServices ms JOIN ms.service s WHERE s.serviceName = : serviceName") }) 19public class UserManager implements UserMangerService { 20 21 @PersistenceContext 22 protected EntityManager em; 23 24 /** 25 * 通过userName查找相应User对象,没有返回Null 26 */ 27 public User findByName(String userName) { 28 return (User) em.createNamedQuery("findUserByName").setParameter( 29 "userName", userName).getSingleResult(); 30 } 31 32 /** 33 * 通过userId查找相应User对象,没有返回Null 34 */ 35 public User findById(int id) { 36 return (User) em.createNamedQuery("findUserById").setParameter( 37 "userID", id).getSingleResult(); 38 39 } 40 41 /** 42 * 返回所有用户列表 43 */ 44 public Collection<User> getAll() { 45 return em.createNamedQuery("getAll").getResultList(); 46 } 47 48 /** 49 * 返回所有开通指定serviceId服务的User列表 50 */ 51 public Collection<User> findByServiceID(int serviceID) { 52 return em.createNamedQuery("findByServiceID").setParameter("serviceID", 53 serviceID).getResultList(); 54 55 } 56 57 /** 58 * 返回所有开通指定serviceName服务的User列表 59 */ 60 public Collection<User> findByServiceName(String serviceName) { 61 return em.createNamedQuery("findByServiceName").setParameter( 62 "serviceName", serviceName).getResultList(); 63 } 64 65 /** 66 * 持久化一个User对象 67 */ 68 public void save(User user) { 69 em.persist(user); 70 71 } 72 73 /** 74 * 删除一个User对象 75 */ 76 public void remove(User user) { 77 em.remove(user); 78 79 } 80 81 /** 82 * 获得现有User数量 83 */ 84 public int getCount() { 85 // TODO Auto-generated method stub 86 return 0; 87 } 88 89} 90

 


只有注册用户登录后才能发表评论。


网站导航: