KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > test > lob > LobTesterBean


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.ejb3.test.lob;
23
24 import java.io.ByteArrayOutputStream JavaDoc;
25 import java.io.IOException JavaDoc;
26 import java.io.ObjectInputStream JavaDoc;
27 import java.io.ObjectOutputStream JavaDoc;
28 import java.util.HashMap JavaDoc;
29 import javax.ejb.Remote JavaDoc;
30 import javax.ejb.Stateless JavaDoc;
31 import javax.persistence.EntityManager;
32 import javax.persistence.PersistenceContext;
33 import javax.persistence.PersistenceContext;
34 import org.hibernate.Hibernate;
35
36 /**
37  * Comment
38  *
39  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
40  * @version $Revision: 37459 $
41  */

42 @Stateless JavaDoc
43 @Remote JavaDoc(LobTester.class)
44 public class LobTesterBean implements LobTester
45 {
46
47    @PersistenceContext EntityManager manager;
48
49    public long create()
50    {
51       BlobEntity blob = new BlobEntity();
52
53       HashMap JavaDoc map = new HashMap JavaDoc();
54       map.put("hello", "world");
55       ByteArrayOutputStream JavaDoc baos = new ByteArrayOutputStream JavaDoc();
56       try
57       {
58          ObjectOutputStream JavaDoc oos = new ObjectOutputStream JavaDoc(baos);
59          oos.writeObject(map);
60          blob.setBlobby(Hibernate.createBlob(baos.toByteArray()));
61       }
62       catch (IOException JavaDoc e)
63       {
64          throw new RuntimeException JavaDoc(e);
65       }
66
67
68       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" +
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       "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" +
103       "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" +
104       "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" +
105       "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" +
106       "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" +
107       "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" +
108       "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" +
109       "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" +
110       "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" +
111       "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" +
112       "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" +
113       "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" +
114       "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" +
115       "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" +
116       "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";
117       blob.setClobby(Hibernate.createClob(clobby));
118       manager.persist(blob);
119       return blob.getId();
120    }
121
122    public HashMap JavaDoc findBlob(long id) throws Exception JavaDoc
123    {
124       BlobEntity blob = manager.find(BlobEntity.class, id);
125       ObjectInputStream JavaDoc ois = new ObjectInputStream JavaDoc(blob.getBlobby().getBinaryStream());
126       return (HashMap JavaDoc) ois.readObject();
127    }
128
129    public String JavaDoc findClob(long id) throws Exception JavaDoc
130    {
131       BlobEntity blob = manager.find(BlobEntity.class, id);
132       return blob.getClobby().getSubString(1, 31);
133    }
134
135    public long create2()
136    {
137       BlobEntity2 blob = new BlobEntity2();
138
139       HashMap JavaDoc map = new HashMap JavaDoc();
140       map.put("hello", "world");
141       ByteArrayOutputStream JavaDoc baos = new ByteArrayOutputStream JavaDoc();
142       try
143       {
144          ObjectOutputStream JavaDoc oos = new ObjectOutputStream JavaDoc(baos);
145          oos.writeObject(map);
146          blob.setBlobby(baos.toByteArray());
147       }
148       catch (IOException JavaDoc e)
149       {
150          throw new RuntimeException JavaDoc(e);
151       }
152
153
154       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" +
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       "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" +
189       "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" +
190       "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" +
191       "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" +
192       "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" +
193       "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" +
194       "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" +
195       "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" +
196       "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" +
197       "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" +
198       "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" +
199       "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" +
200       "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" +
201       "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" +
202       "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";
203       blob.setClobby(clobby);
204       manager.persist(blob);
205       return blob.getId();
206    }
207
208    public BlobEntity2 findBlob2(long id) throws Exception JavaDoc
209    {
210       return manager.find(BlobEntity2.class, id);
211    }
212
213 }
214
Popular Tags