1 22 package org.jboss.ejb3.test.lob; 23 24 import java.io.ByteArrayOutputStream ; 25 import java.io.IOException ; 26 import java.io.ObjectInputStream ; 27 import java.io.ObjectOutputStream ; 28 import java.util.HashMap ; 29 import javax.ejb.Remote ; 30 import javax.ejb.Stateless ; 31 import javax.persistence.EntityManager; 32 import javax.persistence.PersistenceContext; 33 import javax.persistence.PersistenceContext; 34 import org.hibernate.Hibernate; 35 36 42 @Stateless 43 @Remote (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 map = new HashMap (); 54 map.put("hello", "world"); 55 ByteArrayOutputStream baos = new ByteArrayOutputStream (); 56 try 57 { 58 ObjectOutputStream oos = new ObjectOutputStream (baos); 59 oos.writeObject(map); 60 blob.setBlobby(Hibernate.createBlob(baos.toByteArray())); 61 } 62 catch (IOException e) 63 { 64 throw new RuntimeException (e); 65 } 66 67 68 String 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 findBlob(long id) throws Exception 123 { 124 BlobEntity blob = manager.find(BlobEntity.class, id); 125 ObjectInputStream ois = new ObjectInputStream (blob.getBlobby().getBinaryStream()); 126 return (HashMap ) ois.readObject(); 127 } 128 129 public String findClob(long id) throws Exception 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 map = new HashMap (); 140 map.put("hello", "world"); 141 ByteArrayOutputStream baos = new ByteArrayOutputStream (); 142 try 143 { 144 ObjectOutputStream oos = new ObjectOutputStream (baos); 145 oos.writeObject(map); 146 blob.setBlobby(baos.toByteArray()); 147 } 148 catch (IOException e) 149 { 150 throw new RuntimeException (e); 151 } 152 153 154 String 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 209 { 210 return manager.find(BlobEntity2.class, id); 211 } 212 213 } 214 | Popular Tags |