r3704 - in trunk/pollen-persistence/src: main/java/org/chorem/pollen/business/persistence test/java/org/chorem/pollen/business/persistence
Author: tchemit Date: 2012-09-23 16:37:19 +0200 (Sun, 23 Sep 2012) New Revision: 3704 Url: http://chorem.org/repositories/revision/pollen/3704 Log: make sure we use talso the poll to get the pollAccount Modified: trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/VoteDAOImpl.java trunk/pollen-persistence/src/test/java/org/chorem/pollen/business/persistence/VoteDAOImplTest.java Modified: trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/VoteDAOImpl.java =================================================================== --- trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/VoteDAOImpl.java 2012-09-23 14:36:50 UTC (rev 3703) +++ trunk/pollen-persistence/src/main/java/org/chorem/pollen/business/persistence/VoteDAOImpl.java 2012-09-23 14:37:19 UTC (rev 3704) @@ -65,22 +65,25 @@ return result; } - public Vote findVoteByPollAndVotingId(Poll poll, String votingId) throws TopiaException { + public E findVoteByPollAndVotingId(Poll poll, String votingId) throws TopiaException { String hql = "SELECT e FROM VoteImpl e, PollImpl p WHERE " + "p = :p AND " + "e in elements(p.vote) AND " + "e.pollAccount.votingId = :v"; - Vote result = findByQuery(Vote.class, hql, "p", poll, "v", votingId); + E result = findByQuery(hql, "p", poll, "v", votingId); return result; } - public E findByAccountId(String accountId) throws TopiaException { + public E findByPollAndAccountId(Poll poll, String accountId) throws TopiaException { - String hql = "FROM VoteImpl e WHERE e.pollAccount.accountId = :a"; + String hql = "SELECT e FROM VoteImpl e, PollImpl p WHERE " + + "p = :p AND " + + "e in elements(p.vote) AND " + + "e.pollAccount.accountId = :a"; - E result = findByQuery(hql, "a", accountId); + E result = findByQuery(hql,"p", poll, "a", accountId); return result; } } Modified: trunk/pollen-persistence/src/test/java/org/chorem/pollen/business/persistence/VoteDAOImplTest.java =================================================================== --- trunk/pollen-persistence/src/test/java/org/chorem/pollen/business/persistence/VoteDAOImplTest.java 2012-09-23 14:36:50 UTC (rev 3703) +++ trunk/pollen-persistence/src/test/java/org/chorem/pollen/business/persistence/VoteDAOImplTest.java 2012-09-23 14:37:19 UTC (rev 3704) @@ -170,13 +170,20 @@ } @Test - public void findByAccountId() throws Exception { + public void findByPollAndAccountId() throws Exception { TopiaContext tx = beginTransaction(); + PollDAO pollDAO = PollenDAOHelper.getPollDAO(tx); + PollAccountDAO pollAccountDAO = PollenDAOHelper.getPollAccountDAO(tx); VoteDAO voteDAO = PollenDAOHelper.getVoteDAO(tx); - PollAccountDAO pollAccountDAO = PollenDAOHelper.getPollAccountDAO(tx); + + Poll poll1 = pollDAO.create(Poll.PROPERTY_POLL_ID, "pollId1"); + Poll poll2 = pollDAO.create(Poll.PROPERTY_POLL_ID, "pollId2", + Poll.PROPERTY_POLL_VOTE_VISIBILITY, + PollVoteVisibility.NOBODY); + String accountId1 = "accountId1"; PollAccount pollAccount1 = pollAccountDAO.create(PollAccount.PROPERTY_ACCOUNT_ID, accountId1); String accountId2 = "accountId2"; @@ -185,28 +192,29 @@ tx.commitTransaction(); Vote actual; - actual = voteDAO.findByAccountId(accountId1); + actual = voteDAO.findByPollAndAccountId(poll1, accountId1); Assert.assertNull(actual); - actual = voteDAO.findByAccountId(accountId2); + actual = voteDAO.findByPollAndAccountId(poll1, accountId2); Assert.assertNull(actual); // attach accountId1 to vote1 Vote vote1 = voteDAO.create(Vote.PROPERTY_POLL_ACCOUNT, pollAccount1); - + poll1.addVote(vote1); tx.commitTransaction(); - actual = voteDAO.findByAccountId(accountId1); + actual = voteDAO.findByPollAndAccountId(poll1, accountId1); Assert.assertNotNull(actual); Assert.assertEquals(vote1, actual); - actual = voteDAO.findByAccountId(accountId2); + actual = voteDAO.findByPollAndAccountId(poll1, accountId2); Assert.assertNull(actual); // attach accountId2 to vote2 Vote vote2 = voteDAO.create(Vote.PROPERTY_POLL_ACCOUNT, pollAccount2); + poll2.addVote(vote2); tx.commitTransaction(); - actual = voteDAO.findByAccountId(accountId2); + actual = voteDAO.findByPollAndAccountId(poll2, accountId2); Assert.assertNotNull(actual); Assert.assertEquals(vote2, actual); }
participants (1)
-
tchemit@users.chorem.org