PageRenderTime 27ms CodeModel.GetById 17ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/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
16package com.google.ie.business.dao.impl;
17
18import com.google.ie.business.dao.DeveloperDao;
19import com.google.ie.business.domain.Developer;
20import com.google.ie.dto.RetrievalInfo;
21
22import java.util.HashMap;
23import java.util.List;
24import java.util.Map;
25
26import javax.jdo.Query;
27
28/**
29 * A JDO implementation for DeveloperDao.
30 * 
31 * @author gmaurya
32 */
33public class DeveloperDaoImpl extends BaseDaoImpl implements DeveloperDao {
34
35    @SuppressWarnings("unchecked")
36    @Override
37    public List<Developer> getDevelopersByProjectKey(String projectKey) {
38        Map<String, Object> mapOfFilterValues = new HashMap<String, Object>();
39        List<Developer> developers = null;
40        Query query = null;
41        try {
42            query = getPersistenceManager()
43                            .newQuery(Developer.class);
44            query.setFilter("projectKey == '" + projectKey + "'");
45            mapOfFilterValues.put("projectKey", projectKey);
46            developers = (List<Developer>) getJdoTemplate().find(query.toString(),
47                            mapOfFilterValues);
48            /* Detach the list fetched from the attached persistence manager */
49            developers = (List<Developer>) getJdoTemplate().detachCopyAll(developers);
50        } finally {
51            if (query != null) {
52                query.closeAll();
53            }
54        }
55        return developers;
56    }
57
58    @Override
59    public Developer saveDeveloper(Developer developer) {
60        developer = getJdoTemplate().makePersistent(developer);
61        return developer;
62    }
63
64    @SuppressWarnings("unchecked")
65    @Override
66    public List<Developer> getDevelopersByUserKey(String userKey, RetrievalInfo retrievalInfo) {
67        Map<String, Object> mapOfFilterValues = new HashMap<String, Object>();
68        List<Developer> developers;
69        Query query = null;
70        try {
71            query = getPersistenceManager().newQuery(Developer.class);
72            query.setRange(retrievalInfo.getStartIndex(), retrievalInfo.getNoOfRecords()
73                            + retrievalInfo.getStartIndex());
74            query.setFilter("userKey == '" + userKey + "'");
75            mapOfFilterValues.put("userKey", userKey);
76            developers = (List<Developer>) getJdoTemplate().find(query.toString(),
77                            mapOfFilterValues);
78        } finally {
79            if (query != null) {
80                query.closeAll();
81            }
82        }
83        return developers;
84    }
85
86}
87