]> git.argeo.org Git - gpl/argeo-slc.git/blob - org.argeo.slc.hibernate/src/main/java/org/argeo/slc/hibernate/process/SlcExecutionDaoHibernate.java
Merge error management fixes from trunk -r:1685:1690
[gpl/argeo-slc.git] / org.argeo.slc.hibernate / src / main / java / org / argeo / slc / hibernate / process / SlcExecutionDaoHibernate.java
1 package org.argeo.slc.hibernate.process;
2
3 import java.sql.SQLException;
4 import java.util.List;
5
6 import org.springframework.orm.hibernate3.HibernateCallback;
7 import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
8
9 import org.argeo.slc.core.SlcException;
10 import org.argeo.slc.core.process.SlcExecution;
11 import org.argeo.slc.core.process.SlcExecutionStep;
12 import org.argeo.slc.dao.process.SlcExecutionDao;
13 import org.hibernate.HibernateException;
14 import org.hibernate.Session;
15
16 public class SlcExecutionDaoHibernate extends HibernateDaoSupport implements
17 SlcExecutionDao {
18
19 public void create(SlcExecution slcExecution) {
20 getHibernateTemplate().save(slcExecution);
21 }
22
23 public void update(final SlcExecution slcExecution) {
24 getHibernateTemplate().update(slcExecution);
25 }
26
27 public void merge(final SlcExecution slcExecution) {
28 getHibernateTemplate().merge(slcExecution);
29 }
30
31 public SlcExecution getSlcExecution(String uuid) {
32 return (SlcExecution) getHibernateTemplate().get(SlcExecution.class,
33 uuid);
34 }
35
36 public List<SlcExecution> listSlcExecutions() {
37 return (List<SlcExecution>) getHibernateTemplate().loadAll(
38 SlcExecution.class);
39 }
40
41 public void addSteps(final String slcExecutionId,
42 final List<SlcExecutionStep> additionalSteps) {
43 getHibernateTemplate().execute(new HibernateCallback() {
44
45 public Object doInHibernate(Session session)
46 throws HibernateException, SQLException {
47 SlcExecution slcExecution = (SlcExecution) session.get(
48 SlcExecution.class, slcExecutionId);
49
50 if (slcExecution == null)
51 throw new SlcException("Could not find SLC execution "
52 + slcExecutionId);
53
54 slcExecution.getSteps().addAll(additionalSteps);
55 session.update(slcExecution);
56 return slcExecution;
57 }
58 });
59
60 }
61
62 }