View Javadoc

1   /*
2    * Copyright 2011 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl1.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.krad.test.document.bo;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  
21  import javax.persistence.CascadeType;
22  import javax.persistence.Column;
23  import javax.persistence.Entity;
24  import javax.persistence.FetchType;
25  import javax.persistence.GeneratedValue;
26  import javax.persistence.Id;
27  import javax.persistence.JoinColumn;
28  import javax.persistence.OneToMany;
29  import javax.persistence.Table;
30  
31  import org.kuali.rice.krad.data.jpa.eclipselink.PortableSequenceGenerator;
32  
33  @Entity
34  @Table(name="KRTST_PARENT_GEN_KEY_T")
35  public class ParentObjectWithGeneratedKey {
36  
37      @Id
38      @Column(name="GENERATED_PK_COL",length=8,precision=0)
39      @GeneratedValue(generator="KRTST_GENERATED_PK_S")
40      @PortableSequenceGenerator(name="KRTST_GENERATED_PK_S")
41      Long generatedKey;
42  
43      @OneToMany(fetch=FetchType.LAZY,cascade= {CascadeType.ALL}, orphanRemoval=true)
44      @JoinColumn(name="GENERATED_PK_COL",referencedColumnName="GENERATED_PK_COL",updatable=false,insertable=false)
45      List<ChildOfParentObjectWithGeneratedKey> children = new ArrayList<ChildOfParentObjectWithGeneratedKey>();
46  
47      public Long getGeneratedKey() {
48          return this.generatedKey;
49      }
50  
51      public void setGeneratedKey(Long generatedKey) {
52          this.generatedKey = generatedKey;
53      }
54  
55      public List<ChildOfParentObjectWithGeneratedKey> getChildren() {
56          return this.children;
57      }
58  
59      public void setChildren(List<ChildOfParentObjectWithGeneratedKey> children) {
60          this.children = children;
61      }
62  
63      public ChildOfParentObjectWithGeneratedKey getChildByKey( Long childKey ) {
64          for ( ChildOfParentObjectWithGeneratedKey child : children ) {
65              if ( child.childKey.equals(childKey) ) {
66                  return child;
67              }
68          }
69          return null;
70      }
71  
72      @Override
73      public String toString() {
74          StringBuilder builder = new StringBuilder();
75          builder.append("ParentObjectWithGeneratedKey [");
76          if (this.generatedKey != null) {
77              builder.append("generatedKey=").append(this.generatedKey).append(", ");
78          }
79          if (this.children != null) {
80              builder.append("children=").append(this.children);
81          }
82          builder.append("]");
83          return builder.toString();
84      }
85  
86  
87  }