PageRenderTime 264ms CodeModel.GetById 140ms app.highlight 5ms RepoModel.GetById 116ms app.codeStats 0ms

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