Java tutorial
/* Copyright 2006 - 2010 Under Dusken Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package no.dusken.aranea.service; import no.dusken.aranea.model.*; import org.springframework.dao.DataAccessException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Isolation; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import java.util.*; /** * Implementation of ArticleService using JPA. */ @Service("articleService") @Transactional(propagation = Propagation.SUPPORTS, isolation = Isolation.DEFAULT, readOnly = true) public class ArticleServiceImpl extends AbstractPageServiceImpl<Article> implements ArticleService { public ArticleServiceImpl() { super(Article.class); } public List<Article> getArticlesByIssue(Issue issue) { List<Article> list = Collections.emptyList(); try { Map<String, Object> map = new HashMap<String, Object>(); map.put("issue", issue); list = genericDao.getByNamedQuery("article_byissue", map); } catch (DataAccessException dae) { log.info("Unable to get Articles", dae); } return list; } public List<Article> getArticlesByYear(int year, int number, int offset) { List<Article> list = Collections.emptyList(); try { Map<String, Object> map = new HashMap<String, Object>(); map.put("fromDate", new GregorianCalendar(year, 0, 1)); map.put("toDate", new GregorianCalendar(year, 11, 31)); list = genericDao.getByNamedQuery("article_byyear", map, offset, number); } catch (DataAccessException dae) { log.info("Unable to get Articles", dae); } return list; } public List<Article> getArticlesBySection(int number, int offset, Section section) { List<Article> list = Collections.emptyList(); try { if (section == null) { list = genericDao.getByNamedQuery("article_frontpage", null, offset, number); } else { Map<String, Object> map = new HashMap<String, Object>(); map.put("section", section); list = genericDao.getByNamedQuery("article_bysection", map, offset, number); } } catch (DataAccessException dae) { log.info("Unable to get Articles by section", dae); } return list; } public List<Article> getArticlesByTag(Tag tag) { List<Article> list = Collections.emptyList(); try { Map<String, Object> map = new HashMap<String, Object>(); map.put("tag", tag); list = genericDao.getByNamedQuery("article_bytag", map); } catch (DataAccessException dae) { log.info("Unable to get Articles", dae); } return list; } public List<Article> getArticlesByTitle(String title) { List<Article> list = Collections.emptyList(); try { Map<String, Object> map = new HashMap<String, Object>(); map.put("title", title); list = genericDao.getByNamedQuery("article_bytitle", map); } catch (DataAccessException dae) { log.info("Unable to get Articles", dae); } return list; } public List<Article> getArticles(int offset, int number) { List<Article> list = Collections.emptyList(); try { list = genericDao.getByNamedQuery("article_all", null, offset, number); } catch (DataAccessException dae) { log.info("Unable to get pages", dae); } return list; } public List<Article> getPublishedArticles(int offset, int number) { List<Article> list = Collections.emptyList(); try { list = genericDao.getByNamedQuery("article_all_published", null, offset, number); } catch (DataAccessException dae) { log.info("Unable to get pages", dae); } return list; } public List<Article> getPublishedArticlesByPerson(Person person) { List<Article> list = Collections.emptyList(); try { Map<String, Object> map = new HashMap<String, Object>(); map.put("person", person); list = genericDao.getByNamedQuery("article_published_byperson", map); } catch (DataAccessException dae) { log.info("Unable to get Articles", dae); } return list; } }