/connect-service/src/main/java/org/osforce/connect/service/commons/impl/VoteRecordServiceImpl.java

http://focus-sns.googlecode.com/ · Java · 76 lines · 54 code · 14 blank · 8 comment · 3 complexity · 9e6886e8966778b78e9e9962a88dfc37 MD5 · raw file

  1. package org.osforce.connect.service.commons.impl;
  2. import java.util.Date;
  3. import org.osforce.connect.dao.commons.VoteRecordDao;
  4. import org.osforce.connect.dao.system.UserDao;
  5. import org.osforce.connect.entity.commons.VoteRecord;
  6. import org.osforce.connect.entity.system.User;
  7. import org.osforce.connect.service.commons.VoteRecordService;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. import org.springframework.stereotype.Service;
  10. import org.springframework.transaction.annotation.Transactional;
  11. /**
  12. *
  13. * @author <a href="mailto:haozhonghu@hotmail.com">gavin</a>
  14. * @since 1.1.1
  15. * @create Jun 3, 2011 - 5:58:13 PM
  16. * <a href="http://www.opensourceforce.org">????</a>
  17. */
  18. @Service
  19. @Transactional
  20. public class VoteRecordServiceImpl implements VoteRecordService {
  21. private UserDao userDao;
  22. private VoteRecordDao voteRecordDao;
  23. public VoteRecordServiceImpl() {
  24. }
  25. @Autowired
  26. public void setUserDao(UserDao userDao) {
  27. this.userDao = userDao;
  28. }
  29. @Autowired
  30. public void setVoteRecordDao(VoteRecordDao voteRecordDao) {
  31. this.voteRecordDao = voteRecordDao;
  32. }
  33. public VoteRecord getVoteRecord(Long voteRecordId) {
  34. return voteRecordDao.get(voteRecordId);
  35. }
  36. public VoteRecord getVoteRecord(Long linkedId, String entity, User user) {
  37. return voteRecordDao.findVoteRecord(linkedId, entity, user.getId());
  38. }
  39. public void createVoteRecord(VoteRecord voteRecord) {
  40. updateVoteRecord(voteRecord);
  41. }
  42. public void updateVoteRecord(VoteRecord voteRecord) {
  43. if(voteRecord.getUserId()!=null) {
  44. User user = userDao.get(voteRecord.getUserId());
  45. voteRecord.setUser(user);
  46. }
  47. //
  48. Date now = new Date();
  49. if(voteRecord.getId()==null) {
  50. voteRecord.setEntered(now);
  51. voteRecordDao.save(voteRecord);
  52. } else {
  53. voteRecordDao.update(voteRecord);
  54. }
  55. }
  56. public void deleteVoteRecord(Long voteRecordId) {
  57. voteRecordDao.delete(voteRecordId);
  58. }
  59. public Long countVoteRecords(String code, Long linkedId, String entity) {
  60. return voteRecordDao.countVoteRecords(code, linkedId, entity);
  61. }
  62. }