# ItemsBean_S.ejb Sample

This topic inludes the source code for the ItemsBean_S.ejb Sample.

## Sample Location

This sample is located in the following directory in your WebLogic Workshop installation:

BEA_HOME/weblogic81/samples/workshop/SamplesApp/EJBs/selectMethods/

## Sample Source Code

`001 package selectMethods; 002 003 import java.sql.ResultSet; 004 import java.sql.SQLException; 005 import java.text.DecimalFormat; 006 import java.util.Collection; 007 import javax.ejb.CreateException; 008 import javax.ejb.FinderException; 009 import weblogic.ejb.GenericEntityBean; 010 011 /** 012 * @ejbgen:entity default-transaction="Supports" concurrency-strategy="ReadOnly" 013 * ejb-name="ItemsBean_S" 014 * data-source-name = "cgSampleDataSource" 015 * table-name="EJB_ITEMS" 016 * prim-key-class = "java.lang.Integer" 017 * 018 * @ejbgen:jndi-name 019 * local="ejb.ItemsBean_SHome" 020 * 021 * @ejbgen:file-generation local-class = "true" local-class-name="Items_S" local-home = "true" local-home-name="Items_SHome" remote-class = "false" remote-class-name = "ItemsRemote" remote-home = "false" remote-home-name = "ItemsRemoteHome" value-class = "false" value-class-name = "ItemsValue" pk-class = "true" 022 * @ejbgen:relation role-name="ItemsBean_Ss-have-ManufacturerBean_S" fk-column="MANUFACTURER" cmr-field="manufacturer" target-ejb="ManufacturerBean_S" multiplicity="Many" name="ItemsBean_S-ManufacturerBean_S" 023 */ 024 025 public abstract class ItemsBean_S extends GenericEntityBean 026 { 027 028 /** 029 * @ejbgen:cmp-field column = "ITEMNUMBER" 030 * primkey-field="true" 031 * @ejbgen:local-method 032 */ 033 public abstract Integer getItemnumber(); 034 /** 035 * @ejbgen:local-method 036 */ 037 public abstract void setItemnumber(Integer val); 038 039 /** 040 * @ejbgen:cmp-field column = "ITEMNAME" 041 * @ejbgen:local-method 042 */ 043 public abstract String getItemname(); 044 /** 045 * @ejbgen:local-method 046 */ 047 public abstract void setItemname(String val); 048 049 /** 050 * @ejbgen:cmp-field column = "PRICE" 051 * @ejbgen:local-method 052 */ 053 public abstract double getPrice(); 054 /** 055 * @ejbgen:local-method 056 */ 057 public abstract void setPrice(double val); 058 059 /** 060 * @ejbgen:cmp-field column = "QUANTITYAVAILABLE" 061 * @ejbgen:local-method 062 */ 063 public abstract int getQuantityavailable(); 064 /** 065 * @ejbgen:local-method 066 */ 067 public abstract void setQuantityavailable(int val); 068 069 070 /** 071 * @ejbgen:select ejb-ql="SELECT OBJECT(o) from ItemsBean_S as o" 072 */ 073 public abstract java.util.Collection ejbSelectAll() throws FinderException; 074 075 /** 076 * @ejbgen:select ejb-ql="SELECT o.itemname from ItemsBean_S as o" 077 */ 078 public abstract java.util.Collection ejbSelectItemNames() throws FinderException; 079 080 /** 081 * @ejbgen:select weblogic-ejb-ql="SELECT o.itemname from ItemsBean_S as o ORDERBY o.price DESC, o.quantityavailable ASC" ejb-ql="SELECT o.itemname from ItemsBean_S as o" 082 */ 083 public abstract java.util.Collection ejbSelectItemNamesOrdered() throws FinderException; 084 085 /** 086 * @ejbgen:select ejb-ql="SELECT o.itemname from ItemsBean_S as o WHERE o.price > ?1" 087 */ 088 public abstract java.util.Collection ejbSelectNameByPrice(double price) throws FinderException; 089 090 /** 091 * @ejbgen:select ejb-ql="SELECT i.itemname from ManufacturerBean_S as o, IN(o.items) AS i WHERE o.usManufacturer= 1" 092 */ 093 public abstract java.util.Collection ejbSelectByUSManufacturer() throws FinderException; 094 095 /** 096 * @ejbgen:select ejb-ql="SELECT o.itemname from ItemsBean_S as o WHERE o.itemnumber = ?1" 097 */ 098 public abstract java.lang.String ejbSelectByPrimaryKey(java.lang.Integer itemnumber) throws FinderException; 099 100 /** 101 * @ejbgen:select weblogic-ejb-ql="SELECT o.itemname, o.quantityavailable from ItemsBean_S as o " ejb-ql="" 102 */ 103 public abstract java.sql.ResultSet ejbSelectNameQuantity() throws FinderException; 104 105 /** 106 * @ejbgen:select weblogic-ejb-ql="SELECT o.manufacturer.manufacturername, COUNT(o.itemnumber), AVG(o.price) from ItemsBean_S as o GROUP BY o.manufacturer.manufacturername ORDERBY o.manufacturer.manufacturername" ejb-ql="" 107 */ 108 public abstract java.sql.ResultSet ejbSelectManufacturerPriceN() throws FinderException; 109 110 public java.lang.Integer ejbCreate(java.lang.Integer Itemnumber) 111 { 112 setItemnumber(Itemnumber); 113 114 return null; // FIXME return PK value 115 } 116 117 public void ejbPostCreate(java.lang.Integer Itemnumber) 118 { 119 } 120 121 /** 122 * @ejbgen:local-home-method 123 */ 124 public String ejbHomeSelectAll() 125 { 126 try { 127 Collection Items = ejbSelectAll(); 128 return Items.toString(); 129 } 130 catch(FinderException fe) { 131 return "null"; 132 } 133 } 134 135 /** 136 * @ejbgen:local-home-method 137 */ 138 public String ejbHomeSelectNameByPrice(double price) 139 { 140 try { 141 Collection Items = ejbSelectNameByPrice(price); 142 return Items.toString(); 143 } 144 catch(FinderException fe) { 145 return "null"; 146 } 147 } 148 149 /** 150 * @ejbgen:local-home-method 151 */ 152 public String ejbHomeSelectByPrimaryKey(int itemnumber) 153 { 154 try { 155 return ejbSelectByPrimaryKey(new Integer(itemnumber)); 156 } 157 catch(FinderException fe) { 158 return "null"; 159 } 160 } 161 162 /** 163 * @ejbgen:local-home-method 164 */ 165 public String ejbHomeSelectByUSManufacturer() 166 { 167 try { 168 Collection Items = ejbSelectByUSManufacturer(); 169 return Items.toString(); 170 } 171 catch(FinderException fe) { 172 return "null"; 173 } 174 } 175 176 /** 177 * @ejbgen:local-home-method 178 */ 179 public String ejbHomeSelectItemNames() 180 { 181 try { 182 Collection Items = ejbSelectItemNames(); 183 return Items.toString(); 184 } 185 catch(FinderException fe) { 186 return "null"; 187 } 188 } 189 190 /** 191 * @ejbgen:local-home-method 192 */ 193 public String ejbHomeSelectItemNamesOrdered() 194 { 195 try { 196 Collection Items = ejbSelectItemNamesOrdered(); 197 return Items.toString(); 198 } 199 catch(FinderException fe) { 200 return "null"; 201 } 202 } 203 204 /** 205 * @ejbgen:local-home-method 206 */ 207 public String ejbHomeSelectNameQuantity() 208 { 209 String outcome = ""; 210 try { 211 ResultSet Items = ejbSelectNameQuantity(); 212 while(Items.next()) { 213 outcome += "["+Items.getString("itemname")+","+Items.getString("quantityavailable")+"]"; 214 } 215 return outcome; 216 } 217 catch(FinderException fe) { 218 return "null"; 219 } 220 catch(SQLException se) { 221 return "null"; 222 } 223 } 224 225 /** 226 * @ejbgen:local-home-method 227 */ 228 public String ejbHomeSelectManufacturerPriceN() 229 { 230 // Format average to two digits after decimal 231 String outcome = ""; 232 String price = ""; 233 try { 234 ResultSet Items = ejbSelectManufacturerPriceN(); 235 while(Items.next()) { 236 price = Items.getString(3); 237 outcome += "["+Items.getString(1)+","+Items.getString(2)+","+price.substring(0,(price.indexOf(".")+3))+"] "; 238 } 239 return outcome; 240 } 241 catch(FinderException fe) { 242 return "null"; 243 } 244 catch(SQLException se) { 245 return "null"; 246 } 247 } 248 249 /** 250 * @ejbgen:local-method 251 */ 252 public String toString() 253 { 254 return "["+getItemnumber().toString()+","+getItemname()+","+getPrice()+","+getQuantityavailable()+"]"; 255 } 256 257 258 259 /** 260 * @ejbgen:cmr-field 261 * @ejbgen:local-method 262 */ 263 public abstract ManufacturerBean_SLocal getManufacturer(); 264 265 /** 266 * @ejbgen:local-method 267 */ 268 public abstract void setManufacturer(ManufacturerBean_SLocal arg); 269 }`