PageRenderTime 49ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/org.itbelts.domain/src/main/java/org/itbelts/dao/mongolab/UserExamDAOImpl.java

https://bitbucket.org/itbelts/itbelts
Java | 55 lines | 28 code | 14 blank | 13 comment | 0 complexity | 2b848fc807fe6316c12401eac0c6562f MD5 | raw file
  1. package org.itbelts.dao.mongolab;
  2. import java.lang.reflect.Type;
  3. import java.net.URL;
  4. import java.util.List;
  5. import org.itbelts.dao.IUserExamDAO;
  6. import org.itbelts.domain.UserExam;
  7. import com.google.gson.reflect.TypeToken;
  8. /**
  9. * MongoDB implementation for the IUserExamDAO. <br>
  10. * <br>
  11. * <u><i>Version History</i></u>
  12. *
  13. * <pre>
  14. * v2013.12.0 05-nov.-2013 - DKBR813 - initial release
  15. *
  16. * </pre>
  17. *
  18. * @version v2013.12.0 05-nov.-2013
  19. * @author <a href=\"mailto:koenbruyndonckx@gmail.com\"> Koen Bruyndonckx </a>
  20. */
  21. public class UserExamDAOImpl extends AbstractMongoLabDAO implements IUserExamDAO {
  22. private static final String PATH = "collections/userexams";
  23. @Override
  24. public List<UserExam> getExamsForUser( String aUserId ) {
  25. URL url = buildUrl( PATH, "q={\"userId\":\"" + aUserId + "\"}" );
  26. Type theListType = new TypeToken<List<UserExam>>(){}.getType();
  27. return readFrom( url, theListType );
  28. }
  29. @Override
  30. public UserExam getUserExam( String aUserExamId ) {
  31. URL url = buildUrl( PATH, "q={\"_id\":\"" + aUserExamId + "\"}" );
  32. Type theListType = new TypeToken<List<UserExam>>(){}.getType();
  33. List<UserExam> theList = readFrom( url, theListType );
  34. return theList.get( 0 );
  35. }
  36. @Override
  37. public UserExam saveUserExam( UserExam aUserExam ) {
  38. sendTo( buildUrl( PATH ), aUserExam );
  39. return aUserExam;
  40. }
  41. }