|
| 1 | +/* |
| 2 | + * Copyright (C) 2009-2014 Slava Semushin <[email protected]> |
| 3 | + * |
| 4 | + * This program is free software; you can redistribute it and/or modify |
| 5 | + * it under the terms of the GNU General Public License as published by |
| 6 | + * the Free Software Foundation; either version 2 of the License, or |
| 7 | + * (at your option) any later version. |
| 8 | + * |
| 9 | + * This program is distributed in the hope that it will be useful, |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + * GNU General Public License for more details. |
| 13 | + * |
| 14 | + * You should have received a copy of the GNU General Public License |
| 15 | + * along with this program; if not, write to the Free Software |
| 16 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | + */ |
| 18 | +package ru.mystamps.web.dao.impl; |
| 19 | + |
| 20 | +import java.util.Collections; |
| 21 | + |
| 22 | +import javax.sql.DataSource; |
| 23 | + |
| 24 | +import org.springframework.beans.factory.annotation.Value; |
| 25 | +import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; |
| 26 | + |
| 27 | +import ru.mystamps.web.dao.JdbcCategoryDao; |
| 28 | + |
| 29 | +public class JdbcCategoryDaoImpl implements JdbcCategoryDao { |
| 30 | + |
| 31 | + private final NamedParameterJdbcTemplate jdbcTemplate; |
| 32 | + |
| 33 | + @Value("${category.count_categories_of_collection}") |
| 34 | + private String countCategoriesOfCollectionSql; |
| 35 | + |
| 36 | + public JdbcCategoryDaoImpl(DataSource dataSource) { |
| 37 | + jdbcTemplate = new NamedParameterJdbcTemplate(dataSource); |
| 38 | + } |
| 39 | + |
| 40 | + @Override |
| 41 | + public long countCategoriesOfCollection(Integer collectionId) { |
| 42 | + return jdbcTemplate.queryForObject( |
| 43 | + countCategoriesOfCollectionSql, |
| 44 | + Collections.singletonMap("collection_id", collectionId), |
| 45 | + Long.class |
| 46 | + ); |
| 47 | + } |
| 48 | + |
| 49 | +} |
0 commit comments