1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
package org.apache.camel.bam.model; |
18 |
|
|
19 |
|
import java.util.List; |
20 |
|
|
21 |
|
import javax.persistence.Entity; |
22 |
|
import javax.persistence.GeneratedValue; |
23 |
|
import javax.persistence.Id; |
24 |
|
import javax.persistence.UniqueConstraint; |
25 |
|
|
26 |
|
import org.apache.camel.util.ObjectHelper; |
27 |
|
import org.apache.commons.logging.Log; |
28 |
|
import org.apache.commons.logging.LogFactory; |
29 |
|
|
30 |
|
import org.springframework.orm.jpa.JpaTemplate; |
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
@Entity |
36 |
|
@UniqueConstraint(columnNames = {"name" }) |
37 |
12 |
public class ProcessDefinition extends EntitySupport { |
38 |
2 |
private static final transient Log LOG = LogFactory.getLog(ProcessDefinition.class); |
39 |
|
private String name; |
40 |
|
|
41 |
|
|
42 |
|
@Override |
43 |
|
@Id |
44 |
|
@GeneratedValue |
45 |
|
public Long getId() { |
46 |
82 |
return super.getId(); |
47 |
|
} |
48 |
|
|
49 |
|
public String getName() { |
50 |
86 |
return name; |
51 |
|
} |
52 |
|
|
53 |
|
public void setName(String name) { |
54 |
6 |
this.name = name; |
55 |
6 |
} |
56 |
|
|
57 |
|
public static ProcessDefinition getRefreshedProcessDefinition(JpaTemplate template, ProcessDefinition definition) { |
58 |
|
|
59 |
|
|
60 |
|
|
61 |
8 |
ObjectHelper.notNull(definition, "definition"); |
62 |
8 |
Long id = definition.getId(); |
63 |
8 |
if (id == null) { |
64 |
0 |
LOG.warn("No primary key is available!"); |
65 |
0 |
return findOrCreateProcessDefinition(template, definition.getName()); |
66 |
|
} |
67 |
8 |
definition = template.find(ProcessDefinition.class, id); |
68 |
8 |
return definition; |
69 |
|
} |
70 |
|
|
71 |
|
public static ProcessDefinition findOrCreateProcessDefinition(JpaTemplate template, String processName) { |
72 |
0 |
List<ProcessDefinition> list = template.find("select x from " + ProcessDefinition.class.getName() + " x where x.name = ?1", processName); |
73 |
0 |
if (!list.isEmpty()) { |
74 |
0 |
return list.get(0); |
75 |
|
} else { |
76 |
0 |
ProcessDefinition answer = new ProcessDefinition(); |
77 |
0 |
answer.setName(processName); |
78 |
0 |
template.persist(answer); |
79 |
0 |
return answer; |
80 |
|
} |
81 |
|
} |
82 |
|
} |