1
|
package eu.dnetlib.msro.openaireplus.workflows.nodes.claims;
|
2
|
|
3
|
import java.util.List;
|
4
|
|
5
|
import eu.dnetlib.enabling.database.DataSourceFactory;
|
6
|
import eu.dnetlib.enabling.database.utils.JdbcTemplateFactory;
|
7
|
import org.springframework.beans.factory.annotation.Autowired;
|
8
|
import org.springframework.beans.factory.annotation.Value;
|
9
|
import org.springframework.stereotype.Component;
|
10
|
|
11
|
/**
|
12
|
* Created by Alessia Bardi on 23/06/2017.
|
13
|
*
|
14
|
* @author Alessia Bardi
|
15
|
*/
|
16
|
@Component
|
17
|
public class ClaimDatabaseUtils {
|
18
|
|
19
|
@Autowired
|
20
|
private JdbcTemplateFactory claimsJdbcTemplateFactory;
|
21
|
@Autowired
|
22
|
private DataSourceFactory claimsDataSourceFactory;
|
23
|
|
24
|
@Value("${dnet.openaire.claims.db.name}")
|
25
|
private String dbName;
|
26
|
|
27
|
public List<Claim> query(final String sqlQuery) {
|
28
|
this.claimsJdbcTemplateFactory.setDataSourceFactory(claimsDataSourceFactory);
|
29
|
return this.claimsJdbcTemplateFactory.createJdbcTemplate(dbName).query(sqlQuery,
|
30
|
(rs, rowNum) -> new Claim().setSemantics(rs.getString("semantics"))
|
31
|
.setSource(rs.getString("source_id")).setSourceType(rs.getString("source_type"))
|
32
|
.setTarget(rs.getString("target_id")).setTargetType(rs.getString("target_type")));
|
33
|
}
|
34
|
|
35
|
public int count(final String sqlCountQuery) {
|
36
|
this.claimsJdbcTemplateFactory.setDataSourceFactory(claimsDataSourceFactory);
|
37
|
return this.claimsJdbcTemplateFactory.createJdbcTemplate(dbName).queryForObject(sqlCountQuery, Integer.class);
|
38
|
}
|
39
|
|
40
|
}
|