/layers-store/src/main/java/org/ala/layers/dao/FieldDAOImpl.java

http://alageospatialportal.googlecode.com/ · Java · 77 lines · 47 code · 10 blank · 20 comment · 5 complexity · cae305e88913135cc040812d2a418b42 MD5 · raw file

  1. /**************************************************************************
  2. * Copyright (C) 2010 Atlas of Living Australia
  3. * All Rights Reserved.
  4. *
  5. * The contents of this file are subject to the Mozilla Public
  6. * License Version 1.1 (the "License"); you may not use this file
  7. * except in compliance with the License. You may obtain a copy of
  8. * the License at http://www.mozilla.org/MPL/
  9. *
  10. * Software distributed under the License is distributed on an "AS
  11. * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  12. * implied. See the License for the specific language governing
  13. * rights and limitations under the License.
  14. ***************************************************************************/
  15. package org.ala.layers.dao;
  16. import java.util.List;
  17. import javax.annotation.Resource;
  18. import javax.sql.DataSource;
  19. import org.ala.layers.dto.Field;
  20. import org.apache.log4j.Logger;
  21. import org.springframework.jdbc.core.simple.ParameterizedBeanPropertyRowMapper;
  22. import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
  23. import org.springframework.stereotype.Service;
  24. /**
  25. *
  26. * @author ajay
  27. */
  28. @Service("fieldDao")
  29. public class FieldDAOImpl implements FieldDAO {
  30. /** log4j logger */
  31. private static final Logger logger = Logger.getLogger(FieldDAOImpl.class);
  32. private SimpleJdbcTemplate jdbcTemplate;
  33. @Resource(name = "layerIntersectDao")
  34. private LayerIntersectDAO layerIntersectDao;
  35. @Resource(name = "dataSource")
  36. public void setDataSource(DataSource dataSource) {
  37. this.jdbcTemplate = new SimpleJdbcTemplate(dataSource);
  38. }
  39. @Override
  40. public List<Field> getFields() {
  41. logger.info("Getting a list of all enabled fields");
  42. String sql = "select * from fields where enabled=true";
  43. return jdbcTemplate.query(sql, ParameterizedBeanPropertyRowMapper.newInstance(Field.class));
  44. }
  45. @Override
  46. public Field getFieldById(String id) {
  47. logger.info("Getting enabled field info for id = " + id);
  48. String sql = "select * from fields where enabled=true and id = ?";
  49. List<Field> l = jdbcTemplate.query(sql, ParameterizedBeanPropertyRowMapper.newInstance(Field.class), id);
  50. if (l.size() > 0) {
  51. return l.get(0);
  52. } else {
  53. return null;
  54. }
  55. }
  56. @Override
  57. public List<Field> getFieldsByDB() {
  58. if(layerIntersectDao.getConfig().getLayerIndexUrl() != null) {
  59. return layerIntersectDao.getConfig().getFieldsByDB();
  60. } else {
  61. //return hibernateTemplate.find("from Field where enabled=true and indb=true");
  62. logger.info("Getting a list of all enabled fields with indb");
  63. String sql = "select * from fields where enabled=TRUE and indb=TRUE";
  64. return jdbcTemplate.query(sql, ParameterizedBeanPropertyRowMapper.newInstance(Field.class));
  65. }
  66. }
  67. }