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

http://thoughtsite.googlecode.com/ · Java · 71 lines · 40 code · 9 blank · 22 comment · 1 complexity · a7558baf94879b3e9bc82ebc7262e69d 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.IdeaCategoryDao;
  17. import com.google.ie.business.domain.IdeaCategory;
  18. import org.springframework.transaction.annotation.Propagation;
  19. import org.springframework.transaction.annotation.Transactional;
  20. import java.util.ArrayList;
  21. import java.util.Collection;
  22. import java.util.Date;
  23. import java.util.List;
  24. /**
  25. * A JDO implementation object for IdeaCategoryDao.
  26. *
  27. * @author Sachneet
  28. *
  29. */
  30. public class IdeaCategoryDaoImpl extends BaseDaoImpl implements IdeaCategoryDao {
  31. @Override
  32. public List<IdeaCategory> getIdeaCategories() {
  33. Collection<IdeaCategory> results = getJdoTemplate().find(
  34. IdeaCategory.class);
  35. /* Detach the result */
  36. results = getJdoTemplate().detachCopyAll(results);
  37. return new ArrayList<IdeaCategory>(results);
  38. }
  39. @Override
  40. @Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)
  41. public IdeaCategory saveIdeaCategory(IdeaCategory category) {
  42. Date date = new Date();
  43. category.setCreatedOn(date);
  44. category.setUpdatedOn(date);
  45. IdeaCategory savedCategory = getJdoTemplate().makePersistent(category);
  46. return savedCategory;
  47. }
  48. @Override
  49. public IdeaCategory getCategoryByName(String categoryName) {
  50. Collection<IdeaCategory> results = getJdoTemplate().find(
  51. IdeaCategory.class,
  52. "name == categoryName", "String categoryName", categoryName);
  53. /* Detach the result */
  54. results = getJdoTemplate().detachCopyAll(results);
  55. List<IdeaCategory> list = new ArrayList<IdeaCategory>(results);
  56. if (list.size() > DaoConstants.ZERO) {
  57. IdeaCategory category = list.get(DaoConstants.ZERO);
  58. return category;
  59. }
  60. return null;
  61. }
  62. }