KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > bsf > smartValueObject > demo > CompanyVO


1 package org.bsf.smartValueObject.demo;
2
3 import java.io.Serializable JavaDoc;
4 import java.text.SimpleDateFormat JavaDoc;
5 import java.util.ArrayList JavaDoc;
6 import java.util.Collection JavaDoc;
7 import java.util.Date JavaDoc;
8 import java.util.Iterator JavaDoc;
9
10 /**
11  * Company.
12  *
13  * @hibernate.class table="company"
14  */

15 public class CompanyVO implements Serializable JavaDoc {
16     private Long JavaDoc id;
17     private String JavaDoc name;
18     private Date JavaDoc creationDate;
19     private Collection JavaDoc subsidiaries = new ArrayList JavaDoc();
20
21     private final SimpleDateFormat JavaDoc _dateFormat = new SimpleDateFormat JavaDoc( "dd/MM/yy" );
22
23     /** @hibernate.id generator-class="native" column="id" unsaved-value="0" */
24     public Long JavaDoc getId() {
25         return id;
26     }
27
28     public void setId( Long JavaDoc id ) {
29         this.id = id;
30     }
31
32     /** @hibernate.property column="name" */
33     public String JavaDoc getName() {
34         return name;
35     }
36
37     public void setName( String JavaDoc name ) {
38         this.name = name;
39     }
40
41     /** @hibernate.property column="creationdate" */
42     public Date JavaDoc getCreationDate() {
43         return creationDate;
44     }
45
46     public void setCreationDate( Date JavaDoc creationDate ) {
47         this.creationDate = creationDate;
48     }
49
50     public void addSubsidiary( SubsidiaryVO s ) {
51         s.setCompanyVO(this);
52         subsidiaries.add( s );
53     }
54
55     public void removeSubsidiary( SubsidiaryVO s ) {
56         subsidiaries.remove( s );
57     }
58
59     /**
60      * @hibernate.bag inverse="true" cascade="all"
61      * @hibernate.collection-one-to-many class="org.bsf.smartValueObject.demo.SubsidiaryVO"
62      * @hibernate.collection-key column="companyId"
63      */

64     public Collection JavaDoc getSubsidiaries() {
65         return subsidiaries;
66     }
67
68     // hibernate requirement
69
private void setSubsidiaries(Collection JavaDoc s) {
70         this.subsidiaries = s;
71     }
72
73     public Iterator JavaDoc subsidiaries() {
74         return subsidiaries.iterator();
75     }
76
77     public String JavaDoc toString() {
78         String JavaDoc dateAsString = "";
79
80         if ( creationDate != null ) {
81             // We don't want to return the time...
82
dateAsString = _dateFormat.format( creationDate );
83         }
84
85         return "CompanyVO: id=" + id + " name=" + name + " creationdate=" + dateAsString;
86     }
87 }
88
Popular Tags