KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > tutorial > blob > bean > LobTesterBean


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

7 package org.jboss.tutorial.blob.bean;
8
9 import java.io.ByteArrayOutputStream JavaDoc;
10 import java.io.IOException JavaDoc;
11 import java.io.ObjectInputStream JavaDoc;
12 import java.io.ObjectOutputStream JavaDoc;
13 import java.util.HashMap JavaDoc;
14 import javax.ejb.Remote JavaDoc;
15 import javax.ejb.Stateless JavaDoc;
16 import javax.persistence.EntityManager;
17 import javax.persistence.PersistenceContext;
18 import javax.persistence.PersistenceContext;
19 import org.hibernate.Hibernate;
20
21 /**
22  * Comment
23  *
24  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
25  * @version $Revision: 1.8.2.3 $
26  */

27 @Stateless JavaDoc
28 @Remote JavaDoc(LobTester.class)
29 public class LobTesterBean implements LobTester
30 {
31
32    @PersistenceContext EntityManager manager;
33
34    public long create()
35    {
36       BlobEntity blob = new BlobEntity();
37
38       HashMap JavaDoc map = new HashMap JavaDoc();
39       map.put("hello", "world");
40       ByteArrayOutputStream JavaDoc baos = new ByteArrayOutputStream JavaDoc();
41       try
42       {
43          ObjectOutputStream JavaDoc oos = new ObjectOutputStream JavaDoc(baos);
44          oos.writeObject(map);
45          blob.setBlobby(Hibernate.createBlob(baos.toByteArray()));
46       }
47       catch (IOException JavaDoc e)
48       {
49          throw new RuntimeException JavaDoc(e);
50       }
51
52
53       String JavaDoc clobby = "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
54       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
55       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
56       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
57       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
58       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
59       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
60       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
61       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
62       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
63       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
64       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
65       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
66       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
67       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
68       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
69       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
70       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
71       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
72       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
73       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
74       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
75       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
76       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
77       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
78       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
79       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
80       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
81       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
82       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
83       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
84       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
85       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
86       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
87       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
88       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
89       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
90       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
91       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
92       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
93       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
94       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
95       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
96       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
97       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
98       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
99       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
100       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
101       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work";
102       blob.setClobby(Hibernate.createClob(clobby));
103       manager.persist(blob);
104       return blob.getId();
105    }
106
107    public HashMap JavaDoc findBlob(long id) throws Exception JavaDoc
108    {
109       BlobEntity blob = manager.find(BlobEntity.class, id);
110       ObjectInputStream JavaDoc ois = new ObjectInputStream JavaDoc(blob.getBlobby().getBinaryStream());
111       return (HashMap JavaDoc) ois.readObject();
112    }
113
114    public String JavaDoc findClob(long id) throws Exception JavaDoc
115    {
116       BlobEntity blob = manager.find(BlobEntity.class, id);
117       return blob.getClobby().getSubString(1, 31);
118    }
119
120    public long create2()
121    {
122       BlobEntity2 blob = new BlobEntity2();
123
124       HashMap JavaDoc map = new HashMap JavaDoc();
125       map.put("hello", "world");
126       ByteArrayOutputStream JavaDoc baos = new ByteArrayOutputStream JavaDoc();
127       try
128       {
129          ObjectOutputStream JavaDoc oos = new ObjectOutputStream JavaDoc(baos);
130          oos.writeObject(map);
131          blob.setBlobby(baos.toByteArray());
132       }
133       catch (IOException JavaDoc e)
134       {
135          throw new RuntimeException JavaDoc(e);
136       }
137
138
139       String JavaDoc clobby = "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
140       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
141       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
142       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
143       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
144       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
145       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
146       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
147       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
148       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
149       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
150       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
151       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
152       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
153       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
154       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
155       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
156       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
157       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
158       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
159       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
160       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
161       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
162       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
163       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
164       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
165       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
166       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
167       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
168       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
169       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
170       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
171       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
172       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
173       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
174       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
175       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
176       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
177       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
178       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
179       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
180       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
181       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
182       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
183       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
184       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
185       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
186       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work" +
187       "This is a very long string that will be stored in a java.sql.Clob hopefully. We'll see how this works and if it will work";
188       blob.setClobby(clobby);
189       manager.persist(blob);
190       return blob.getId();
191    }
192
193    public BlobEntity2 findBlob2(long id) throws Exception JavaDoc
194    {
195       return manager.find(BlobEntity2.class, id);
196    }
197
198 }
199
Popular Tags