Now using JPA with a container managed entity manager.
[utils] / mythtv / monitor / src / main / java / org / wamblee / mythtv / Recording.java
1 /*
2  * Copyright 2006 the original author or authors.
3  * 
4  * Licensed under the Apache 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.apache.org/licenses/LICENSE-2.0
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
17 package org.wamblee.mythtv;
18
19 import java.io.Serializable;
20 import java.util.Date;
21
22 import javax.persistence.Column;
23 import javax.persistence.EmbeddedId;
24 import javax.persistence.Entity;
25 import javax.persistence.Id;
26 import javax.persistence.IdClass;
27 import javax.persistence.JoinColumn;
28 import javax.persistence.JoinColumns;
29 import javax.persistence.ManyToOne;
30 import javax.persistence.Table;
31 import javax.persistence.Temporal;
32 import javax.persistence.TemporalType;
33 import javax.persistence.Transient;
34
35 /**
36  * 
37  */
38 @Entity
39 @Table(name="recorded")
40 public class Recording implements Serializable {
41     
42     private RecordingPk _id;
43
44     private String _basename;
45
46     private Date _progstart;
47
48     private String _title;
49     
50     private String _subtitle;
51     
52     private long _filesize;
53
54     protected Recording() {
55         // Empty
56     }
57
58     /**
59      * @return the channel
60      */
61     //@Id
62     //@ManyToOne(targetEntity=Channel.class)
63     //@JoinColumn(name="chanid")
64     
65     /**
66      * @return the id
67      */
68     @EmbeddedId
69     public RecordingPk getId() {
70         return _id;
71     }
72     
73     /**
74      * @param aId the id to set
75      */
76     public void setId(RecordingPk aId) {
77         _id = aId;
78     }
79    
80     /**
81      * @return the basename
82      */
83     @Column(name="basename")
84     public String getBasename() {
85         return _basename;
86     }
87     
88     /**
89      * @param aBasename the basename to set
90      */
91     public void setBasename(String aBasename) {
92         _basename = aBasename;
93     }
94
95     /**
96      * @return the progstart
97      */
98     @Column(name="progstart")
99     @Temporal(TemporalType.TIMESTAMP)
100     public Date getProgstart() {
101         return _progstart;
102     }
103     
104     /**
105      * @param aProgstart the progstart to set
106      */
107     public void setProgstart(Date aProgstart) {
108         _progstart = aProgstart;
109     }
110     
111     @Transient
112     public Channel getChannel() { 
113         return _id.getChannel();
114     }
115     
116     @Transient
117     public Date getStarttime() { 
118         return _id.getStartTime();
119     }
120     
121     /**
122      * @return the title
123      */
124     @Column(name="title")
125     public String getTitle() {
126         return _title;
127     }
128     
129     /**
130      * @param aTitle the title to set
131      */
132     public void setTitle(String aTitle) {
133         _title = aTitle;
134     }
135
136     /**
137      * @return the subtitle
138      */
139     @Column(name="subtitle")
140     public String getSubtitle() {
141         return _subtitle;
142     }
143     
144     /**
145      * @param aSubtitle the subtitle to set
146      */
147     public void setSubtitle(String aSubtitle) {
148         _subtitle = aSubtitle;
149     }
150     
151     /**
152      * @return the filesize
153      */
154     @Column(name="filesize")
155     public long getFilesize() {
156         return _filesize;
157     }
158     
159     public void setFilesize(long aFilesize) { 
160         _filesize = aFilesize; 
161     }
162     
163     /* (non-Javadoc)
164      * @see java.lang.Object#toString()
165      */
166     @Override
167     public String toString() {
168         return "Recording(" + _id + "," + _basename + "," + _progstart + "," + _title + "," + _subtitle + ")";
169     }
170     
171     /* (non-Javadoc)
172      * @see java.lang.Object#equals(java.lang.Object)
173      */
174     @Override
175     public boolean equals(Object aObj) {
176         if ( !(aObj instanceof Recording)) { 
177             return false;
178         }
179         Recording recording = (Recording)aObj; 
180         return _id.equals(recording._id); 
181     }
182     
183     /* (non-Javadoc)
184      * @see java.lang.Object#hashCode()
185      */
186     @Override
187     public int hashCode() {
188         return _id.hashCode(); 
189     }
190
191 }