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