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