/connect-dao/src/main/java/org/osforce/connect/dao/commons/impl/VoteRecordDaoImpl.java

http://focus-sns.googlecode.com/ · Java · 38 lines · 25 code · 6 blank · 7 comment · 2 complexity · c5a2328ad753d9085b27aff4d36e747a MD5 · raw file

  1. package org.osforce.connect.dao.commons.impl;
  2. import org.apache.commons.lang.StringUtils;
  3. import org.osforce.connect.dao.commons.VoteRecordDao;
  4. import org.osforce.connect.entity.commons.VoteRecord;
  5. import org.osforce.spring4me.dao.AbstractDao;
  6. import org.springframework.stereotype.Repository;
  7. /**
  8. *
  9. * @author <a href="mailto:haozhonghu@hotmail.com">gavin</a>
  10. * @since 1.1.1
  11. * @create Jun 3, 2011 - 10:05:02 AM
  12. * <a href="http://www.opensourceforce.org">????</a>
  13. */
  14. @Repository
  15. public class VoteRecordDaoImpl extends AbstractDao<VoteRecord>
  16. implements VoteRecordDao {
  17. public VoteRecordDaoImpl() {
  18. super(VoteRecord.class);
  19. }
  20. static final String JPQL0 = "FROM VoteRecord AS vr WHERE vr.linkedId = ?1 AND vr.entity = ?2 AND vr.user.id = ?3";
  21. public VoteRecord findVoteRecord(Long linkedId, String entity, Long userId) {
  22. return findOne(JPQL0, linkedId, entity, userId);
  23. }
  24. static final String JPQL1 = "SELECT COUNT(*) FROM VoteRecord AS vr WHERE vr.linkedId = ?1 AND vr.entity = ?2 %s";
  25. public Long countVoteRecords(String code, Long linkedId, String entity) {
  26. if(StringUtils.isBlank(code)) {
  27. return count(String.format(JPQL1, ""), linkedId, entity);
  28. } else {
  29. return count(String.format(JPQL1, " AND vr.code = ?3"), linkedId, entity, code);
  30. }
  31. }
  32. }