/src/main/java/com/google/ie/business/dao/impl/DeveloperDaoImpl.java

http://thoughtsite.googlecode.com/ · Java · 87 lines · 57 code · 10 blank · 20 comment · 4 complexity · 0903a41b192d8460eb67a52e93ef0c3f MD5 · raw file

  1. /* Copyright 2010 Google Inc.
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS.
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License
  14. */
  15. package com.google.ie.business.dao.impl;
  16. import com.google.ie.business.dao.DeveloperDao;
  17. import com.google.ie.business.domain.Developer;
  18. import com.google.ie.dto.RetrievalInfo;
  19. import java.util.HashMap;
  20. import java.util.List;
  21. import java.util.Map;
  22. import javax.jdo.Query;
  23. /**
  24. * A JDO implementation for DeveloperDao.
  25. *
  26. * @author gmaurya
  27. */
  28. public class DeveloperDaoImpl extends BaseDaoImpl implements DeveloperDao {
  29. @SuppressWarnings("unchecked")
  30. @Override
  31. public List<Developer> getDevelopersByProjectKey(String projectKey) {
  32. Map<String, Object> mapOfFilterValues = new HashMap<String, Object>();
  33. List<Developer> developers = null;
  34. Query query = null;
  35. try {
  36. query = getPersistenceManager()
  37. .newQuery(Developer.class);
  38. query.setFilter("projectKey == '" + projectKey + "'");
  39. mapOfFilterValues.put("projectKey", projectKey);
  40. developers = (List<Developer>) getJdoTemplate().find(query.toString(),
  41. mapOfFilterValues);
  42. /* Detach the list fetched from the attached persistence manager */
  43. developers = (List<Developer>) getJdoTemplate().detachCopyAll(developers);
  44. } finally {
  45. if (query != null) {
  46. query.closeAll();
  47. }
  48. }
  49. return developers;
  50. }
  51. @Override
  52. public Developer saveDeveloper(Developer developer) {
  53. developer = getJdoTemplate().makePersistent(developer);
  54. return developer;
  55. }
  56. @SuppressWarnings("unchecked")
  57. @Override
  58. public List<Developer> getDevelopersByUserKey(String userKey, RetrievalInfo retrievalInfo) {
  59. Map<String, Object> mapOfFilterValues = new HashMap<String, Object>();
  60. List<Developer> developers;
  61. Query query = null;
  62. try {
  63. query = getPersistenceManager().newQuery(Developer.class);
  64. query.setRange(retrievalInfo.getStartIndex(), retrievalInfo.getNoOfRecords()
  65. + retrievalInfo.getStartIndex());
  66. query.setFilter("userKey == '" + userKey + "'");
  67. mapOfFilterValues.put("userKey", userKey);
  68. developers = (List<Developer>) getJdoTemplate().find(query.toString(),
  69. mapOfFilterValues);
  70. } finally {
  71. if (query != null) {
  72. query.closeAll();
  73. }
  74. }
  75. return developers;
  76. }
  77. }