View Javadoc

1   /*
2    * Copyright 2005-2007 The Kuali Foundation
3    * 
4    * 
5    * Licensed under the Educational Community License, Version 2.0 (the "License");
6    * you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    * 
9    * http://www.opensource.org/licenses/ecl2.php
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
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   * Represents a branch in the routing path of the document.
45   * 
46   * @author Kuali Rice Team (rice.collab@kuali.org)
47   */
48  @Entity
49  @Sequence(name="KREW_RTE_NODE_S",property="branchId")
50  @Table(name="KREW_RTE_BRCH_T")
51  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      @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  //	  apache lazy list commented out due to not being serializable
68  //    private List branchState = ListUtils.lazyList(new ArrayList(),
69  //            new Factory() {
70  //				public Object create() {
71  //					return new BranchState();
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  		return name;
90  	}
91  	
92  	public void setName(String name) {
93  		this.name = name;	
94  	}
95  	
96      public RouteNodeInstance getSplitNode() {
97          return splitNode;
98      }
99      public void setSplitNode(RouteNodeInstance splitNode) {
100         this.splitNode = splitNode;
101     }
102     public RouteNodeInstance getInitialNode() {
103 		return initialNode;
104 	}
105 	public void setInitialNode(RouteNodeInstance activeNode) {
106 		this.initialNode = activeNode;
107 	}
108 	public Long getBranchId() {
109 		return branchId;
110 	}
111 	public void setBranchId(Long branchId) {
112 		this.branchId = branchId;
113 	}
114 	public RouteNodeInstance getJoinNode() {
115 		return joinNode;
116 	}
117 	public void setJoinNode(RouteNodeInstance joinNode) {
118 		this.joinNode = joinNode;
119 	}
120 	public Branch getParentBranch() {
121 		return parentBranch;
122 	}
123 	public void setParentBranch(Branch parentBranch) {
124 		this.parentBranch = parentBranch;
125 	}
126     public BranchState getBranchState(String key) {
127         for (Iterator iter = branchState.iterator(); iter.hasNext();) {
128             BranchState branchState = (BranchState) iter.next();
129             if (branchState.getKey().equals(key)) {
130                 return branchState;
131             }
132         }
133         return null;
134     }
135     public void addBranchState(BranchState state) {
136         branchState.add(state);
137         state.setBranch(this);
138     }
139     public List<BranchState> getBranchState() {
140         return branchState;
141     }
142     public void setBranchState(List<BranchState> branchState) {
143         this.branchState.clear();
144         this.branchState.addAll(branchState);
145     	//this.branchState = branchState;
146     }
147     
148     public BranchState getDocBranchState(int index){
149     	while (branchState.size() <= index) {
150             branchState.add(new BranchState());
151         }
152         return (BranchState) branchState.get(index);
153    
154     }
155     
156 	public Integer getLockVerNbr() {
157         return lockVerNbr;
158     }
159     public void setLockVerNbr(Integer lockVerNbr) {
160         this.lockVerNbr = lockVerNbr;
161     }
162 
163     public String toString() {
164         return "[Branch: branchId=" + branchId +
165                       ", parentBranch=" + (parentBranch == null ? "null" : parentBranch.getBranchId()) +
166                       "]";
167     }
168     
169     @PrePersist
170     public void beforeInsert(){
171     	OrmUtils.populateAutoIncValue(this, KEWServiceLocator.getEntityManagerFactory().createEntityManager());
172     }    
173 }
174