点赞管理接口实现类
| 27 | * |
| 28 | */ |
| 29 | @Repository |
| 30 | @Transactional |
| 31 | public class LikeRepositoryImpl extends DaoSupport<Like> implements LikeRepository { |
| 32 | private static final Logger logger = LogManager.getLogger(LikeRepositoryImpl.class); |
| 33 | |
| 34 | @Resource LikeConfig likeConfig; |
| 35 | @Resource TopicLikeConfig topicLikeConfig; |
| 36 | @Resource CommentReplyLikeConfig commentReplyLikeConfig; |
| 37 | @Resource CommentLikeConfig commentLikeConfig; |
| 38 | @Resource QuestionLikeConfig questionLikeConfig; |
| 39 | @Resource AnswerLikeConfig answerLikeConfig; |
| 40 | @Resource AnswerReplyLikeConfig answerReplyLikeConfig; |
| 41 | |
| 42 | /** |
| 43 | * 根据Id查询点赞 |
| 44 | * @param likeId 点赞Id |
| 45 | * @return |
| 46 | */ |
| 47 | @Transactional(readOnly=true, propagation=Propagation.NOT_SUPPORTED) |
| 48 | public Like findById(String likeId){ |
| 49 | //表编号 |
| 50 | int tableNumber = likeConfig.likeIdRemainder(likeId); |
| 51 | |
| 52 | if(tableNumber == 0){//默认对象 |
| 53 | Query query = em.createQuery("select o from Like o where o.id=?1") |
| 54 | .setParameter(1, likeId); |
| 55 | List<Like> list = query.getResultList(); |
| 56 | for(Like p : list){ |
| 57 | return p; |
| 58 | } |
| 59 | |
| 60 | }else{//带下划线对象 |
| 61 | Query query = em.createQuery("select o from Like_"+tableNumber+" o where o.id=?1") |
| 62 | .setParameter(1, likeId); |
| 63 | List<?> like_List= query.getResultList(); |
| 64 | |
| 65 | try { |
| 66 | //带下划线对象 |
| 67 | Class<?> c = Class.forName("cms.model.like.Like_"+tableNumber); |
| 68 | //获取无参数构造函数 |
| 69 | Constructor<?> constructor = c.getDeclaredConstructor(); |
| 70 | |
| 71 | //使用构造函数创建新实例 |
| 72 | Object object = constructor.newInstance(); |
| 73 | BeanCopier copier = BeanCopier.create(object.getClass(),Like.class, false); |
| 74 | |
| 75 | for(int j = 0;j< like_List.size(); j++) { |
| 76 | Object obj = like_List.get(j); |
| 77 | Like like = new Like(); |
| 78 | copier.copy(obj,like, null); |
| 79 | return like; |
| 80 | } |
| 81 | |
| 82 | |
| 83 | } catch (ClassNotFoundException e) { |
| 84 | // TODO Auto-generated catch block |
| 85 | // e.printStackTrace(); |
| 86 | if (logger.isErrorEnabled()) { |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…