Revision 34408
Added by Michele Artini over 9 years ago
DatabaseUtils.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import java.io.IOException; |
4 | 4 |
import java.util.List; |
5 |
import java.util.Map; |
|
5 | 6 |
|
7 |
import javax.sql.DataSource; |
|
8 |
|
|
6 | 9 |
import org.antlr.stringtemplate.StringTemplate; |
7 | 10 |
import org.apache.commons.logging.Log; |
8 | 11 |
import org.apache.commons.logging.LogFactory; |
... | ... | |
19 | 22 |
|
20 | 23 |
private static final Log log = LogFactory.getLog(DatabaseUtils.class); |
21 | 24 |
|
22 |
public List<String> search(final String sql) { |
|
25 |
public List<String> searchJson(final String sql) {
|
|
23 | 26 |
log.debug(sql); |
24 | 27 |
return jdbcTemplate.query(sql, new JsonRowMapper()); |
25 | 28 |
} |
26 | 29 |
|
30 |
public List<Map<String, Object>> searchSimple(final String sql) { |
|
31 |
log.debug(sql); |
|
32 |
return jdbcTemplate.queryForList(sql); |
|
33 |
} |
|
34 |
|
|
27 | 35 |
public int update(final String sql) { |
28 | 36 |
log.debug(sql); |
29 | 37 |
return jdbcTemplate.update(sql); |
... | ... | |
35 | 43 |
|
36 | 44 |
switch (operation) { |
37 | 45 |
case INSERT: |
38 |
st.setTemplate(IOUtils.toString(getClass().getResourceAsStream("/eu/dnetlib/enabling/is/templates/register_insert_trigger.st")));
|
|
46 |
st.setTemplate(IOUtils.toString(getClass().getResourceAsStream("/eu/dnetlib/enabling/is/templates/trigger_insert.sql.st")));
|
|
39 | 47 |
break; |
40 | 48 |
case DELETE: |
41 |
st.setTemplate(IOUtils.toString(getClass().getResourceAsStream("/eu/dnetlib/enabling/is/templates/register_delete_trigger.st")));
|
|
49 |
st.setTemplate(IOUtils.toString(getClass().getResourceAsStream("/eu/dnetlib/enabling/is/templates/trigger_delete.sql.st")));
|
|
42 | 50 |
break; |
43 | 51 |
case UPDATE: |
44 |
st.setTemplate(IOUtils.toString(getClass().getResourceAsStream("/eu/dnetlib/enabling/is/templates/register_update_trigger.st")));
|
|
52 |
st.setTemplate(IOUtils.toString(getClass().getResourceAsStream("/eu/dnetlib/enabling/is/templates/trigger_update.sql.st")));
|
|
45 | 53 |
break; |
46 | 54 |
default: |
47 | 55 |
throw new InformationServiceException("Unknown operation: " + operation); |
... | ... | |
55 | 63 |
} |
56 | 64 |
} |
57 | 65 |
|
66 |
public DataSource getDataSource() { |
|
67 |
return jdbcTemplate.getDataSource(); |
|
68 |
} |
|
69 |
|
|
58 | 70 |
public JdbcTemplate getJdbcTemplate() { |
59 | 71 |
return jdbcTemplate; |
60 | 72 |
} |
Also available in: Unified diff
notification listener