KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > cmp2 > lob > FacadeSessionBean


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.test.cmp2.lob;
23
24
25 import javax.ejb.SessionBean JavaDoc;
26 import javax.ejb.SessionContext JavaDoc;
27 import javax.ejb.CreateException JavaDoc;
28 import javax.ejb.EJBException JavaDoc;
29 import javax.naming.InitialContext JavaDoc;
30 import javax.rmi.PortableRemoteObject JavaDoc;
31 import java.util.Set JavaDoc;
32 import java.util.Map JavaDoc;
33 import java.util.List JavaDoc;
34
35 /**
36  *
37  * @author <a HREF="mailto:alex@jboss.org">Alexey Loubyansky</a>
38  */

39 public class FacadeSessionBean
40    implements SessionBean JavaDoc
41 {
42    private LOBHome lobHome;
43
44    // Business methods
45

46    public void createLOB(Integer JavaDoc id) throws Exception JavaDoc
47    {
48       getLOBHome().create(id);
49    }
50
51    public void removeLOB(Integer JavaDoc id) throws Exception JavaDoc
52    {
53       getLOBHome().remove(id);
54    }
55
56    public void addMapEntry(Integer JavaDoc id, Object JavaDoc key, Object JavaDoc value) throws Exception JavaDoc
57    {
58       getLOBHome().findByPrimaryKey(id).getMapField().put(key, value);
59    }
60
61    public Map JavaDoc getMapField(Integer JavaDoc id) throws Exception JavaDoc
62    {
63       return getLOBHome().findByPrimaryKey(id).getMapField();
64    }
65
66    public void addSetElement(Integer JavaDoc id, Object JavaDoc value) throws Exception JavaDoc
67    {
68       getLOBHome().findByPrimaryKey(id).getSetField().add(value);
69    }
70
71    public Set JavaDoc getSetField(Integer JavaDoc id) throws Exception JavaDoc
72    {
73       return getLOBHome().findByPrimaryKey(id).getSetField();
74    }
75
76    public void addListElement(Integer JavaDoc id, Object JavaDoc value) throws Exception JavaDoc
77    {
78       getLOBHome().findByPrimaryKey(id).getListField().add(value);
79    }
80
81    public List JavaDoc getListField(Integer JavaDoc id) throws Exception JavaDoc
82    {
83       return getLOBHome().findByPrimaryKey(id).getListField();
84    }
85
86    public void setBinaryData(Integer JavaDoc id, byte[] value) throws Exception JavaDoc
87    {
88       getLOBHome().findByPrimaryKey(id).setBinaryData(value);
89    }
90
91    public void setBinaryDataElement(Integer JavaDoc id, int index, byte value)
92       throws Exception JavaDoc
93    {
94       getLOBHome().findByPrimaryKey(id).getBinaryData()[index] = value;
95    }
96
97    public byte getBinaryDataElement(Integer JavaDoc id, int index)
98       throws Exception JavaDoc
99    {
100       return getLOBHome().findByPrimaryKey(id).getBinaryData()[index];
101    }
102
103    public void setValueHolderValue(Integer JavaDoc id, String JavaDoc value)
104       throws Exception JavaDoc
105    {
106       getLOBHome().findByPrimaryKey(id).getValueHolder().setValue(value);
107    }
108
109    public String JavaDoc getValueHolderValue(Integer JavaDoc id)
110       throws Exception JavaDoc
111    {
112       return getLOBHome().findByPrimaryKey(id).getValueHolder().getValue();
113    }
114
115    public void setCleanGetValueHolderValue(Integer JavaDoc id, String JavaDoc value)
116       throws Exception JavaDoc
117    {
118       getLOBHome().findByPrimaryKey(id).setCleanGetValueHolder(new ValueHolder(value));
119    }
120
121    public void modifyCleanGetValueHolderValue(Integer JavaDoc id, String JavaDoc value)
122       throws Exception JavaDoc
123    {
124       getLOBHome().findByPrimaryKey(id).getCleanGetValueHolder().setValue(value);
125    }
126
127    public String JavaDoc getCleanGetValueHolderValue(Integer JavaDoc id)
128       throws Exception JavaDoc
129    {
130       return getLOBHome().findByPrimaryKey(id).getCleanGetValueHolder().getValue();
131    }
132
133    public String JavaDoc getStateFactoryValueHolderValue(Integer JavaDoc id)
134       throws Exception JavaDoc
135    {
136       return getLOBHome().findByPrimaryKey(id).getStateFactoryValueHolder().getValue();
137    }
138
139    public void modifyStateFactoryValueHolderValue(Integer JavaDoc id, String JavaDoc value)
140       throws Exception JavaDoc
141    {
142       getLOBHome().findByPrimaryKey(id).getStateFactoryValueHolder().setValue(value);
143    }
144
145    public void setStateFactoryValueHolderValue(Integer JavaDoc id, String JavaDoc value)
146       throws Exception JavaDoc
147    {
148       ValueHolder holder = getLOBHome().findByPrimaryKey(id).getStateFactoryValueHolder();
149       holder.setValue(value);
150       holder.setDirty(true);
151    }
152
153    // SessionBean implementation
154

155    /**
156     * @exception CreateException Description of Exception
157     * @ejb.create-method
158     */

159    public void ejbCreate() throws CreateException JavaDoc
160    {
161    }
162
163    public void ejbActivate()
164    {
165    }
166
167    public void ejbPassivate()
168    {
169    }
170
171    public void ejbRemove()
172    {
173    }
174
175    public void setSessionContext(SessionContext JavaDoc ctx)
176    {
177    }
178
179    // Private
180

181    private LOBHome getLOBHome()
182    {
183       if(lobHome == null)
184       {
185          try
186          {
187             InitialContext JavaDoc initialContext = new InitialContext JavaDoc();
188             Object JavaDoc home = initialContext.lookup(LOBHome.LOB_HOME_CONTEXT);
189             lobHome = (LOBHome)PortableRemoteObject.narrow(home, LOBHome.class);
190          }
191          catch(Exception JavaDoc e)
192          {
193             throw new EJBException JavaDoc("Could not lookup " + LOBHome.LOB_HOME_CONTEXT);
194          }
195       }
196       return lobHome;
197    }
198 }
199
Popular Tags