1 22 package org.jboss.test.cmp2.lob; 23 24 25 import javax.ejb.SessionBean ; 26 import javax.ejb.SessionContext ; 27 import javax.ejb.CreateException ; 28 import javax.ejb.EJBException ; 29 import javax.naming.InitialContext ; 30 import javax.rmi.PortableRemoteObject ; 31 import java.util.Set ; 32 import java.util.Map ; 33 import java.util.List ; 34 35 39 public class FacadeSessionBean 40 implements SessionBean 41 { 42 private LOBHome lobHome; 43 44 46 public void createLOB(Integer id) throws Exception 47 { 48 getLOBHome().create(id); 49 } 50 51 public void removeLOB(Integer id) throws Exception 52 { 53 getLOBHome().remove(id); 54 } 55 56 public void addMapEntry(Integer id, Object key, Object value) throws Exception 57 { 58 getLOBHome().findByPrimaryKey(id).getMapField().put(key, value); 59 } 60 61 public Map getMapField(Integer id) throws Exception 62 { 63 return getLOBHome().findByPrimaryKey(id).getMapField(); 64 } 65 66 public void addSetElement(Integer id, Object value) throws Exception 67 { 68 getLOBHome().findByPrimaryKey(id).getSetField().add(value); 69 } 70 71 public Set getSetField(Integer id) throws Exception 72 { 73 return getLOBHome().findByPrimaryKey(id).getSetField(); 74 } 75 76 public void addListElement(Integer id, Object value) throws Exception 77 { 78 getLOBHome().findByPrimaryKey(id).getListField().add(value); 79 } 80 81 public List getListField(Integer id) throws Exception 82 { 83 return getLOBHome().findByPrimaryKey(id).getListField(); 84 } 85 86 public void setBinaryData(Integer id, byte[] value) throws Exception 87 { 88 getLOBHome().findByPrimaryKey(id).setBinaryData(value); 89 } 90 91 public void setBinaryDataElement(Integer id, int index, byte value) 92 throws Exception 93 { 94 getLOBHome().findByPrimaryKey(id).getBinaryData()[index] = value; 95 } 96 97 public byte getBinaryDataElement(Integer id, int index) 98 throws Exception 99 { 100 return getLOBHome().findByPrimaryKey(id).getBinaryData()[index]; 101 } 102 103 public void setValueHolderValue(Integer id, String value) 104 throws Exception 105 { 106 getLOBHome().findByPrimaryKey(id).getValueHolder().setValue(value); 107 } 108 109 public String getValueHolderValue(Integer id) 110 throws Exception 111 { 112 return getLOBHome().findByPrimaryKey(id).getValueHolder().getValue(); 113 } 114 115 public void setCleanGetValueHolderValue(Integer id, String value) 116 throws Exception 117 { 118 getLOBHome().findByPrimaryKey(id).setCleanGetValueHolder(new ValueHolder(value)); 119 } 120 121 public void modifyCleanGetValueHolderValue(Integer id, String value) 122 throws Exception 123 { 124 getLOBHome().findByPrimaryKey(id).getCleanGetValueHolder().setValue(value); 125 } 126 127 public String getCleanGetValueHolderValue(Integer id) 128 throws Exception 129 { 130 return getLOBHome().findByPrimaryKey(id).getCleanGetValueHolder().getValue(); 131 } 132 133 public String getStateFactoryValueHolderValue(Integer id) 134 throws Exception 135 { 136 return getLOBHome().findByPrimaryKey(id).getStateFactoryValueHolder().getValue(); 137 } 138 139 public void modifyStateFactoryValueHolderValue(Integer id, String value) 140 throws Exception 141 { 142 getLOBHome().findByPrimaryKey(id).getStateFactoryValueHolder().setValue(value); 143 } 144 145 public void setStateFactoryValueHolderValue(Integer id, String value) 146 throws Exception 147 { 148 ValueHolder holder = getLOBHome().findByPrimaryKey(id).getStateFactoryValueHolder(); 149 holder.setValue(value); 150 holder.setDirty(true); 151 } 152 153 155 159 public void ejbCreate() throws CreateException 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 ctx) 176 { 177 } 178 179 181 private LOBHome getLOBHome() 182 { 183 if(lobHome == null) 184 { 185 try 186 { 187 InitialContext initialContext = new InitialContext (); 188 Object home = initialContext.lookup(LOBHome.LOB_HOME_CONTEXT); 189 lobHome = (LOBHome)PortableRemoteObject.narrow(home, LOBHome.class); 190 } 191 catch(Exception e) 192 { 193 throw new EJBException ("Could not lookup " + LOBHome.LOB_HOME_CONTEXT); 194 } 195 } 196 return lobHome; 197 } 198 } 199 | Popular Tags |