Project

General

Profile

1
/*
2
package eu.dnetlib.goldoa.service;
3

    
4
import eu.dnetlib.goldoa.domain.Funder;
5
import eu.dnetlib.goldoa.domain.Vocabulary;
6
import org.springframework.beans.factory.annotation.Autowired;
7
import org.springframework.dao.EmptyResultDataAccessException;
8
import org.springframework.jdbc.core.JdbcTemplate;
9
import org.springframework.jdbc.core.RowMapper;
10

    
11
import javax.sql.DataSource;
12
import java.sql.ResultSet;
13
import java.sql.SQLException;
14
import java.sql.Types;
15
import java.util.List;
16

    
17
*/
18
/**
19
 * Created by antleb on 5/6/15.
20
 *//*
21

    
22
public class FunderManagerImpl implements FunderManager {
23

    
24
	@Autowired
25
	private DataSource dataSource;
26

    
27
	private final static String SEARCH_FUNDERS = "select id, name from funder where lower(name) like lower(?)";
28
	private final static String GET_FUNDER = "select id, name, url, source from funder where id=?";
29

    
30
	@Override
31
	public List<Vocabulary> search(String term) {
32
		return new JdbcTemplate(dataSource).query(SEARCH_FUNDERS, new String[]{"%" + term + "%"}, new int[]{Types.VARCHAR}, new RowMapper<Vocabulary>() {
33
			@Override
34
			public Vocabulary mapRow(ResultSet rs, int rowNum) throws SQLException {
35
				return new Vocabulary(rs.getString("id"), rs.getString("name"));
36
			}
37
		});
38
	}
39

    
40
	@Override
41
	public Funder getById(String id) {
42
		try {
43
			return new JdbcTemplate(dataSource).queryForObject(GET_FUNDER, new String[]{id}, new int[]{Types.VARCHAR}, new RowMapper<Funder>() {
44
				@Override
45
				public Funder mapRow(ResultSet rs, int rowNum) throws SQLException {
46
					return new Funder(rs.getString("id"), rs.getString("name"), rs.getString("url"), rs.getString("source"));
47
				}
48
			});
49
		} catch (EmptyResultDataAccessException e) {
50
			return null;
51
		}
52
	}
53
}
54
*/
(8-8/29)