PageRenderTime 129ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/itbelts/itbelts
Java | 56 lines | 25 code | 14 blank | 17 comment | 2 complexity | 62b200156d19ae5e636427a13832fd4c 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.IUserDAO;
  6. import org.itbelts.domain.User;
  7. import com.google.gson.reflect.TypeToken;
  8. /**
  9. * MongoDB implementation for the IUserDAO.
  10. * <br><br>
  11. * <u><i>Version History</i></u>
  12. * <pre>
  13. * v2013.10.0 20-okt.-2013 - DKBR813 - initial release
  14. *
  15. * </pre>
  16. *
  17. * @version v2013.10.0 20-okt.-2013
  18. * @author <a href=\"mailto:koenbruyndonckx@gmail.com\"> Koen Bruyndonckx </a>
  19. */
  20. public class UserDAOImpl extends AbstractMongoLabDAO implements IUserDAO {
  21. private static final String PATH = "collections/users";
  22. @Override
  23. public User getUser( String anId ) {
  24. URL url = buildUrl( PATH, "q={\"_id\":\"" + anId + "\"}" );
  25. Type theListType = new TypeToken<List<User>>(){}.getType();
  26. List<User> theList = readFrom( url, theListType );
  27. if ( theList.size() == 0 ) {
  28. return null;
  29. }
  30. return theList.get( 0 );
  31. }
  32. @Override
  33. public User saveUser( User aUser ) {
  34. sendTo( buildUrl( PATH ), aUser );
  35. return aUser;
  36. }
  37. // @Override
  38. // public User deleteUser( User aUser ) {
  39. // deleteFrom( buildUrl( PATH, "\"_id\":\"" + aUser.get_id() + "\"" ) );
  40. // return aUser;
  41. // }
  42. }