Revision 36081
Added by Antonis Lempesis about 9 years ago
OrganizationDAO.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import eu.dnetlib.goldoa.domain.Budget; |
4 | 4 |
import eu.dnetlib.goldoa.domain.Organization; |
5 |
import eu.dnetlib.goldoa.domain.Publication; |
|
5 | 6 |
import eu.dnetlib.goldoa.domain.Vocabulary; |
6 | 7 |
import org.springframework.beans.factory.annotation.Autowired; |
7 | 8 |
import org.springframework.jdbc.core.BatchPreparedStatementSetter; |
... | ... | |
36 | 37 |
"where a.person=?\n" + |
37 | 38 |
"group by o.id, name, shortname"; |
38 | 39 |
|
39 |
private final String INSERT_ORGANIZATION = "insert into organization (id, name, shortname, source) values (?, ?, ?, 'user')"; |
|
40 |
private final String INSERT_ORGANIZATION = "insert into organization (name, shortname, source, id) values (?,?,?,?)"; |
|
41 |
private final String UPDATE_ORGANIZATION = "update organization set name=?, shortname=?, source=? where id=?"; |
|
40 | 42 |
|
41 | 43 |
private final String INSERT_ORGANIZATION_BUDGET = "insert into organization_budget (organization, budget) values (?, ?)"; |
42 | 44 |
|
... | ... | |
70 | 72 |
}); |
71 | 73 |
} |
72 | 74 |
|
75 |
public Organization saveOrganization(Organization organization) { |
|
76 |
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); |
|
77 |
Object[] args = {organization.getName(), organization.getShortName(), organization.getSource(), organization.getId()}; |
|
78 |
int[] types = {Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR}; |
|
79 |
|
|
80 |
if (jdbcTemplate.update(UPDATE_ORGANIZATION, args, types) == 0) |
|
81 |
jdbcTemplate.update(INSERT_ORGANIZATION, args, types); |
|
82 |
|
|
83 |
return organization; |
|
84 |
} |
|
85 |
|
|
73 | 86 |
public void insertOrganization(final Organization organization) { |
74 | 87 |
new JdbcTemplate(dataSource).update(INSERT_ORGANIZATION, new PreparedStatementSetter() { |
75 | 88 |
@Override |
... | ... | |
81 | 94 |
}); |
82 | 95 |
} |
83 | 96 |
|
84 |
public void insertOrganizationBudget(final Organization organization) { |
|
97 |
public void insertOrganizationBudgets(final Organization organization) {
|
|
85 | 98 |
new JdbcTemplate(dataSource).batchUpdate(INSERT_ORGANIZATION_BUDGET, new BatchPreparedStatementSetter() { |
86 | 99 |
@Override |
87 | 100 |
public void setValues(PreparedStatement ps, int i) throws SQLException { |
... | ... | |
116 | 129 |
} |
117 | 130 |
}); |
118 | 131 |
} |
132 |
|
|
133 |
public void deleteOrganizationBudgets(Organization organization) { |
|
134 |
new JdbcTemplate(dataSource).update("delete from organization_budget where organization = ?", new String[] {organization.getId()}, new int[] {Types.VARCHAR}); |
|
135 |
} |
|
119 | 136 |
} |
Also available in: Unified diff
changed organizationDAO save to updateorsave