PageRenderTime 21ms CodeModel.GetById 14ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/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 ***************************************************************************/
15package org.ala.layers.dao;
16
17import java.util.List;
18import javax.annotation.Resource;
19import javax.sql.DataSource;
20import org.ala.layers.dto.Field;
21import org.apache.log4j.Logger;
22import org.springframework.jdbc.core.simple.ParameterizedBeanPropertyRowMapper;
23import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
24import org.springframework.stereotype.Service;
25
26/**
27 *
28 * @author ajay
29 */
30@Service("fieldDao")
31public class FieldDAOImpl implements FieldDAO {
32
33    /** log4j logger */
34    private static final Logger logger = Logger.getLogger(FieldDAOImpl.class);
35
36    private SimpleJdbcTemplate jdbcTemplate;
37
38    @Resource(name = "layerIntersectDao")
39    private LayerIntersectDAO layerIntersectDao;
40
41    @Resource(name = "dataSource")
42    public void setDataSource(DataSource dataSource) {
43        this.jdbcTemplate = new SimpleJdbcTemplate(dataSource);
44    }
45
46    @Override
47    public List<Field> getFields() {
48        logger.info("Getting a list of all enabled fields");
49        String sql = "select * from fields where enabled=true";
50        return jdbcTemplate.query(sql, ParameterizedBeanPropertyRowMapper.newInstance(Field.class));
51    }
52
53    @Override
54    public Field getFieldById(String id) {
55        logger.info("Getting enabled field info for id = " + id);
56        String sql = "select * from fields where enabled=true and id = ?";
57        List<Field> l = jdbcTemplate.query(sql, ParameterizedBeanPropertyRowMapper.newInstance(Field.class), id);
58        if (l.size() > 0) {
59            return l.get(0);
60        } else {
61            return null; 
62        }
63    }
64
65    @Override
66    public List<Field> getFieldsByDB() {
67        if(layerIntersectDao.getConfig().getLayerIndexUrl() != null) {
68            return layerIntersectDao.getConfig().getFieldsByDB();
69        } else {
70            //return hibernateTemplate.find("from Field where enabled=true and indb=true");
71            logger.info("Getting a list of all enabled fields with indb");
72            String sql = "select * from fields where enabled=TRUE and indb=TRUE";
73            return jdbcTemplate.query(sql, ParameterizedBeanPropertyRowMapper.newInstance(Field.class));
74        }
75
76    }
77}