PageRenderTime 362ms CodeModel.GetById 141ms app.highlight 7ms RepoModel.GetById 154ms app.codeStats 0ms

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

http://thoughtsite.googlecode.com/
Java | 91 lines | 56 code | 9 blank | 26 comment | 8 complexity | e2ae931c8cd4c29e92333e8d63f6e2ef 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.AdminRequestDao;
19import com.google.ie.business.domain.AdminRequest;
20import com.google.ie.dto.RetrievalInfo;
21
22import org.apache.commons.lang.StringUtils;
23import org.apache.log4j.Logger;
24import org.springframework.transaction.annotation.Propagation;
25import org.springframework.transaction.annotation.Transactional;
26
27import java.util.ArrayList;
28import java.util.Collection;
29import java.util.HashMap;
30import java.util.List;
31import java.util.Map;
32
33import javax.jdo.Query;
34
35/**
36 * A JDO implementation object for {@link AdminRequestDao}.
37 * 
38 * @author asirohi
39 * 
40 */
41public class AdminRequestDaoImpl extends BaseDaoImpl implements AdminRequestDao {
42    private static Logger logger = Logger.getLogger(AdminRequestDaoImpl.class);
43
44    @Override
45    @Transactional(readOnly = false, propagation = Propagation.REQUIRED)
46    public boolean saveRequest(AdminRequest adminRequest) {
47        adminRequest = getJdoTemplate().makePersistent(adminRequest);
48        if (adminRequest != null && !StringUtils.isBlank(adminRequest.getKey())) {
49            logger.info("Admin Request for " + adminRequest.getRequestType() + " "
50                            + adminRequest.getEntityType() + " saved successfully");
51            return true;
52        }
53        logger.error("Saving of AdminRequest object failed");
54        return false;
55    }
56
57    @SuppressWarnings("unchecked")
58    @Override
59    public List<AdminRequest> getAllAdminRequests(RetrievalInfo retrievalInfo) {
60        Query query = null;
61        try {
62            query = getJdoTemplate().getPersistenceManagerFactory()
63                            .getPersistenceManager().newQuery(AdminRequest.class);
64            /*
65             * Add the start index to the number of records required since
66             * internally the second argument is treated as the index up to
67             * which
68             * the entities are to be fetched
69             */
70            query.setRange(retrievalInfo.getStartIndex(), retrievalInfo.getStartIndex()
71                            + retrievalInfo.getNoOfRecords());
72            query.setFilter("status == '" + AdminRequest.STATUS_PENDING + "'");
73            Map<String, Object> mapOfFilterValues = new HashMap<String, Object>();
74            mapOfFilterValues.put("status", AdminRequest.STATUS_PENDING);
75            Collection<AdminRequest> collection = getJdoTemplate().find(query.toString(),
76                            mapOfFilterValues);
77            if (collection != null && collection.size() > DaoConstants.ZERO) {
78                logger.info(collection.size() + " admin requests found for the Idea or Comment");
79                List<AdminRequest> requestList = (new ArrayList<AdminRequest>(collection));
80                return requestList;
81            }
82        } finally {
83            if (query != null) {
84                query.closeAll();
85            }
86        }
87        logger.info("No admin requests for the Idea or Comment");
88        return null;
89    }
90}
91