1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.kuali.rice.kew.engine.node; |
18 | |
|
19 | |
import java.io.Serializable; |
20 | |
import java.util.ArrayList; |
21 | |
import java.util.Iterator; |
22 | |
import java.util.List; |
23 | |
|
24 | |
import javax.persistence.CascadeType; |
25 | |
import javax.persistence.Column; |
26 | |
import javax.persistence.Entity; |
27 | |
import javax.persistence.FetchType; |
28 | |
import javax.persistence.Id; |
29 | |
import javax.persistence.JoinColumn; |
30 | |
import javax.persistence.OneToMany; |
31 | |
import javax.persistence.OneToOne; |
32 | |
import javax.persistence.PrePersist; |
33 | |
import javax.persistence.Table; |
34 | |
import javax.persistence.Version; |
35 | |
|
36 | |
import org.hibernate.annotations.Cascade; |
37 | |
import org.hibernate.annotations.Fetch; |
38 | |
import org.hibernate.annotations.FetchMode; |
39 | |
import org.kuali.rice.core.jpa.annotations.Sequence; |
40 | |
import org.kuali.rice.core.util.OrmUtils; |
41 | |
import org.kuali.rice.kew.service.KEWServiceLocator; |
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
@Entity |
49 | |
@Sequence(name="KREW_RTE_NODE_S",property="branchId") |
50 | |
@Table(name="KREW_RTE_BRCH_T") |
51 | 0 | public class Branch implements Serializable { |
52 | |
|
53 | |
private static final long serialVersionUID = 7164561979112939112L; |
54 | |
|
55 | |
@Id |
56 | |
@Column(name="RTE_BRCH_ID") |
57 | |
private Long branchId; |
58 | |
@OneToOne(fetch=FetchType.EAGER) |
59 | |
@JoinColumn(name="PARNT_ID") |
60 | |
private Branch parentBranch; |
61 | |
@Column(name="NM") |
62 | |
private String name; |
63 | 0 | @OneToMany(fetch=FetchType.EAGER,cascade={CascadeType.REMOVE,CascadeType.PERSIST,CascadeType.MERGE}, mappedBy="branch") |
64 | |
@Cascade({org.hibernate.annotations.CascadeType.DELETE_ORPHAN}) |
65 | |
@Fetch(value=FetchMode.SUBSELECT) |
66 | |
private List<BranchState> branchState = new ArrayList<BranchState>(); |
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
@OneToOne(cascade={CascadeType.PERSIST}) |
75 | |
@JoinColumn(name="INIT_RTE_NODE_INSTN_ID") |
76 | |
private RouteNodeInstance initialNode; |
77 | |
@OneToOne |
78 | |
@JoinColumn(name="SPLT_RTE_NODE_INSTN_ID") |
79 | |
private RouteNodeInstance splitNode; |
80 | |
@OneToOne(cascade={CascadeType.PERSIST,CascadeType.MERGE}) |
81 | |
@JoinColumn(name="JOIN_RTE_NODE_INSTN_ID") |
82 | |
private RouteNodeInstance joinNode; |
83 | |
|
84 | |
@Version |
85 | |
@Column(name="VER_NBR") |
86 | |
private Integer lockVerNbr; |
87 | |
|
88 | |
public String getName() { |
89 | 0 | return name; |
90 | |
} |
91 | |
|
92 | |
public void setName(String name) { |
93 | 0 | this.name = name; |
94 | 0 | } |
95 | |
|
96 | |
public RouteNodeInstance getSplitNode() { |
97 | 0 | return splitNode; |
98 | |
} |
99 | |
public void setSplitNode(RouteNodeInstance splitNode) { |
100 | 0 | this.splitNode = splitNode; |
101 | 0 | } |
102 | |
public RouteNodeInstance getInitialNode() { |
103 | 0 | return initialNode; |
104 | |
} |
105 | |
public void setInitialNode(RouteNodeInstance activeNode) { |
106 | 0 | this.initialNode = activeNode; |
107 | 0 | } |
108 | |
public Long getBranchId() { |
109 | 0 | return branchId; |
110 | |
} |
111 | |
public void setBranchId(Long branchId) { |
112 | 0 | this.branchId = branchId; |
113 | 0 | } |
114 | |
public RouteNodeInstance getJoinNode() { |
115 | 0 | return joinNode; |
116 | |
} |
117 | |
public void setJoinNode(RouteNodeInstance joinNode) { |
118 | 0 | this.joinNode = joinNode; |
119 | 0 | } |
120 | |
public Branch getParentBranch() { |
121 | 0 | return parentBranch; |
122 | |
} |
123 | |
public void setParentBranch(Branch parentBranch) { |
124 | 0 | this.parentBranch = parentBranch; |
125 | 0 | } |
126 | |
public BranchState getBranchState(String key) { |
127 | 0 | for (Iterator iter = branchState.iterator(); iter.hasNext();) { |
128 | 0 | BranchState branchState = (BranchState) iter.next(); |
129 | 0 | if (branchState.getKey().equals(key)) { |
130 | 0 | return branchState; |
131 | |
} |
132 | 0 | } |
133 | 0 | return null; |
134 | |
} |
135 | |
public void addBranchState(BranchState state) { |
136 | 0 | branchState.add(state); |
137 | 0 | state.setBranch(this); |
138 | 0 | } |
139 | |
public List<BranchState> getBranchState() { |
140 | 0 | return branchState; |
141 | |
} |
142 | |
public void setBranchState(List<BranchState> branchState) { |
143 | 0 | this.branchState.clear(); |
144 | 0 | this.branchState.addAll(branchState); |
145 | |
|
146 | 0 | } |
147 | |
|
148 | |
public BranchState getDocBranchState(int index){ |
149 | 0 | while (branchState.size() <= index) { |
150 | 0 | branchState.add(new BranchState()); |
151 | |
} |
152 | 0 | return (BranchState) branchState.get(index); |
153 | |
|
154 | |
} |
155 | |
|
156 | |
public Integer getLockVerNbr() { |
157 | 0 | return lockVerNbr; |
158 | |
} |
159 | |
public void setLockVerNbr(Integer lockVerNbr) { |
160 | 0 | this.lockVerNbr = lockVerNbr; |
161 | 0 | } |
162 | |
|
163 | |
public String toString() { |
164 | 0 | return "[Branch: branchId=" + branchId + |
165 | |
", parentBranch=" + (parentBranch == null ? "null" : parentBranch.getBranchId()) + |
166 | |
"]"; |
167 | |
} |
168 | |
|
169 | |
@PrePersist |
170 | |
public void beforeInsert(){ |
171 | 0 | OrmUtils.populateAutoIncValue(this, KEWServiceLocator.getEntityManagerFactory().createEntityManager()); |
172 | 0 | } |
173 | |
} |
174 | |
|