KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > media > entity > MediaEntityBean


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7
8 package org.jboss.media.entity;
9
10 import java.util.Collection JavaDoc;
11 import java.util.Vector JavaDoc;
12
13 import javax.ejb.CreateException JavaDoc;
14 import javax.ejb.EntityBean JavaDoc;
15 import javax.ejb.EntityContext JavaDoc;
16 import javax.ejb.RemoveException JavaDoc;
17 import javax.emb.MediaEntityLocal;
18 import javax.naming.InitialContext JavaDoc;
19 import javax.naming.NamingException JavaDoc;
20
21 import org.jboss.ejb.plugins.keygenerator.KeyGenerator;
22 import org.jboss.ejb.plugins.keygenerator.KeyGeneratorFactory;
23 import org.jboss.logging.Logger;
24
25 /**
26  * Media Entity Bean implementation based on Entity Beans.
27  *
28  * <p>It extends the abstract <code>MediaEntity</code> class, and only
29  * declares CMP/CMR methods and implements <code>ejbCreate()</code>.
30  *
31  * @version <tt>$Revision: 1.7 $</tt>
32  * @author <a HREF="mailto:ricardoarguello@users.sourceforge.net">Ricardo Argüello</a>
33  *
34  * @ejb.bean name="MediaEntity"
35  * local-jndi-name="ejb/media/MediaEntity"
36  * view-type="local"
37  * reentrant="true"
38  * type="CMP"
39  * cmp-version="2.x"
40  * primkey-field="managedIdentity"
41  *
42  * @ejb.interface generate="false" local-class="javax.emb.MediaEntityLocal" *
43  * @ejb.home generate="false" local-class="javax.emb.MediaEntityLocalHome"
44  * @ejb.transaction type="Required"
45  * @ejb.util generate="false"
46  *
47  * @ejb.finder signature="java.util.Collection findByPartialDescription(java.lang.String partialDescription)"
48  * query="SELECT DISTINCT OBJECT(mediaEntity) FROM MediaEntity AS mediaEntity WHERE LOCATE(?1, mediaEntity.managedDescription) > -1"
49  *
50  * @ejb.finder signature="java.util.Collection findByPartialLocation(java.lang.String partialLocation)"
51  * query="SELECT DISTINCT OBJECT(mediaEntity) FROM MediaEntity AS mediaEntity WHERE LOCATE(?1, mediaEntity.managedLocation) > -1"
52  *
53  * @ejb.persistence table-name="JBOSS_MEDIA_ENTITY_BEANS"
54  *
55  * @jboss.create-table "true"
56  * @jboss.remove-table "false"
57  */

58 public abstract class MediaEntityBean extends MediaEntity implements EntityBean JavaDoc
59 {
60    public static final String JavaDoc MEDIA_ENTITY_JNDI = "ejb/media/MediaEntity";
61
62    private EntityContext JavaDoc entityContext;
63
64    /** Logger. */
65    private Logger log = Logger.getLogger(MediaEntityBean.class);
66
67    /** KeyGenerator Factory JNDI. */
68    private static final String JavaDoc KEY_GENERATOR_JNDI = "UUIDKeyGeneratorFactory";
69
70    // Container Managed Persistance (CMP): ------------------------------------
71

72    /**
73     * @ejb.pk-field
74     * @ejb.persistence column-name="IDENTITY"
75     */

76    public abstract String JavaDoc getManagedIdentity();
77    public abstract void setManagedIdentity(String JavaDoc identity);
78
79    /**
80     * @ejb.persistence column-name="CONTENT"
81     */

82    public abstract byte[] getManagedContent();
83    public abstract void setManagedContent(byte[] content);
84
85    /**
86     * @ejb.persistence column-name="LOCATION"
87     */

88    public abstract String JavaDoc getManagedLocation();
89    public abstract void setManagedLocation(String JavaDoc location);
90
91    /**
92     * @ejb.persistence column-name="DESCRIPTION"
93     */

94    public abstract String JavaDoc getManagedDescription();
95    public abstract void setManagedDescription(String JavaDoc description);
96
97    /**
98     * @ejb.persistence column-name="NAME"
99     */

100    public abstract String JavaDoc getManagedName();
101    public abstract void setManagedName(String JavaDoc name);
102
103    /**
104     * @ejb.persistence column-name="MIME_TYPE"
105     */

106    public abstract String JavaDoc getManagedMimeType();
107    public abstract void setManagedMimeType(String JavaDoc mimeType);
108
109    /**
110     * @ejb.persistence column-name="LAST_MODIFIED"
111     */

112    public abstract long getManagedLastModified();
113    public abstract void setManagedLastModified(long lastModified);
114
115    /**
116     * @ejb.persistence column-name="LISTENERS"
117     */

118    public abstract Vector JavaDoc getManagedListeners();
119    public abstract void setManagedListeners(Vector JavaDoc listeners);
120
121    // Container Managed Relationships (CMR): ----------------------------------
122

123    /**
124     * @ejb.relation name="Media-ProxyMedia"
125     * role-name="media-has-proxy-media"
126     * target-ejb="MediaEntity"
127     * target-multiple="no"
128     * target-role-name="proxy-media-has-media"
129     *
130     * @jboss.relation related-pk-field="managedIdentity"
131     * fk-column="proxy_identity_fk"
132     */

133    public abstract MediaEntityLocal getManagedProxy();
134    public abstract void setManagedProxy(MediaEntityLocal proxy);
135
136    /**
137     * @ejb.relation name="PreviousMediaVersion-NextMediaVersion"
138     * role-name="previous-media-version-has-next-media-version"
139     *
140     * @jboss.relation related-pk-field="managedIdentity"
141     * fk-column="previous_identity_fk"
142     */

143    public abstract MediaEntityLocal getManagedPreviousVersion();
144    public abstract void setManagedPreviousVersion(MediaEntityLocal previousVersion);
145
146    /**
147     * @ejb.relation name="PreviousMediaVersion-NextMediaVersion"
148     * role-name="next-media-version-has-previous-media-version"
149     *
150     * @jboss.relation related-pk-field="managedIdentity"
151     * fk-column="child_identity_fk"
152     */

153    public abstract MediaEntityLocal getManagedNextVersion();
154    public abstract void setManagedNextVersion(MediaEntityLocal nextVersion);
155
156    /**
157     * @ejb.relation name="MediaParent-MediaChild"
158     * role-name="media-parent-has-media-child"
159     *
160     * @jboss.relation related-pk-field="managedIdentity"
161     * fk-column="parent_identity_fk"
162     */

163    public abstract Collection JavaDoc getManagedParents();
164    public abstract void setManagedParents(Collection JavaDoc parents);
165
166    /**
167     * @ejb.relation name="MediaParent-MediaChild"
168     * role-name="media-child-has-media-parent"
169     *
170     * @jboss.relation related-pk-field="managedIdentity"
171     * fk-column="child_identity_fk"
172     */

173    public abstract Collection JavaDoc getManagedChildren();
174    public abstract void setManagedChildren(Collection JavaDoc children);
175
176    /**
177     * @ejb.relation name="Media-MetaData"
178     * role-name="media-has-metadatas"
179     *
180     * @jboss.relation related-pk-field="managedIdentity"
181     * fk-column="metadata_identity_fk"
182     */

183    public abstract Collection JavaDoc getManagedMetaDatas();
184    public abstract void setManagedMetaDatas(Collection JavaDoc metadatas);
185
186    // javax.emb.MediaEntityLocalHome interface: -------------------------------
187

188    /**
189     * @see javax.emb.MediaEntityLocalHome#create()
190     */

191    public String JavaDoc ejbCreate() throws CreateException JavaDoc
192    {
193       String JavaDoc identity = generateIdentity();
194
195       setManagedIdentity(identity);
196       updateLastModified();
197
198       return null;
199    }
200
201    /**
202     * @see javax.emb.MediaEntityLocalHome#create()
203     */

204    public void ejbPostCreate() throws CreateException JavaDoc
205    {
206    }
207
208    // javax.ejb.EntityBean interface: -----------------------------------------
209

210    public void ejbActivate()
211    {
212    }
213
214    public void ejbPassivate()
215    {
216    }
217
218    public void ejbRemove() throws RemoveException JavaDoc
219    {
220    }
221
222    public void ejbLoad()
223    {
224    }
225
226    public void ejbStore()
227    {
228    }
229
230    public void setEntityContext(EntityContext JavaDoc entityContext)
231    {
232       this.entityContext = entityContext;
233    }
234
235    public void unsetEntityContext()
236    {
237       entityContext = null;
238    }
239
240    // Private: ----------------------------------------------------------------
241

242    /**
243     * Create the identity (primary key) of this bean using a UUID key
244     * generator.
245     *
246     * @return a String containing the primary key.
247     * @throws CreateException if an error accours when generating the primary
248     * key.
249     */

250    private String JavaDoc generateIdentity() throws CreateException JavaDoc
251    {
252       KeyGenerator keyGenerator = null;
253
254       try
255       {
256          KeyGeneratorFactory keyGeneratorFactory =
257             (KeyGeneratorFactory) new InitialContext JavaDoc().lookup(
258                KEY_GENERATOR_JNDI);
259
260          keyGenerator = keyGeneratorFactory.getKeyGenerator();
261
262          String JavaDoc key = (String JavaDoc) keyGenerator.generateKey();
263
264          if (log.isDebugEnabled())
265          {
266             log.debug("Generated identity: " + key);
267          }
268
269          return key;
270       }
271       catch (NamingException JavaDoc e)
272       {
273          throw new CreateException JavaDoc(
274             "Error: can't find key generator factory: "
275                + KEY_GENERATOR_JNDI
276                + "; "
277                + e.getMessage());
278       }
279       catch (Exception JavaDoc e)
280       {
281          throw new CreateException JavaDoc(
282             "Error: can't create key generator instance; key generator factory: "
283                + KEY_GENERATOR_JNDI
284                + "; "
285                + e.getMessage());
286       }
287    }
288 }
Popular Tags