Books
in black and white
Main menu
Share a book About us Home
Books
Biology Business Chemistry Computers Culture Economics Fiction Games Guide History Management Mathematical Medicine Mental Fitnes Physics Psychology Scince Sport Technics
Ads

More Java Pitfalls Share Reactor - Daconta M,C.

Daconta M,C. More Java Pitfalls Share Reactor - Wiley publishing, 2003. - 476 p.
ISBN: 0-471-23751-5
Download (direct link): morejavapitfallssharereactor2003.pdf
Previous << 1 .. 137 138 139 140 141 142 < 143 > 144 145 146 147 148 149 .. 166 >> Next

154 </td>
155 </tr>
156
157 </table>
158
159 </center>
160
161 <table border="0" cellpadding="4" cellspacing="4" width="100%">
162 <tr bgcolor="#eeeeee"><td>Product ID</td><td>Price ($)</td><td>
163 # in Stock</td><td>Delete item?</td></tr>
164 <%
Listing 46.2 (continued)
The following code performs the rendering of the inventory data to the user display. A query is performed using the product table mapping. If data items are found in the product table, a collection handle is obtained and iterated through in the JSP display. A screenshot is provided in Listing 46.1 for this application.
396 Item 46
165 // List all items
166 Query query = pm.getManagerInstance().newQuery(Product.class);
167 try
168 {
169 // ask the broker to retrieve the Extent collection
170
171 Collection allProducts = (Collection)query.execute();
172 // now iterate over the result to print each product
173 java.util.Iterator iter = allProducts.iterator();
174 while (iter.hasNext())
175 {
176 Product a = (Product) iter.next();
177 %>
178 <tr>
179 <td><%= a.getId() %></td>
180 <td>$<%= a.getPrice() %></td>
181 <td><%= a.getStock() %></td>
182 <td><input type="checkbox" name="deleteItems" value="<%=
183 a.getId() %>">Delete?</td>
184 </tr>
185 <%
186 }
187 }
188 catch (Throwable t)
189 {
190 t.printStackTrace();
191 }
192 %>
193 <tr bgcolor="" >
194 <td align="center" colspan="4">
195 <input type="Submit" name="Delete" value="Delete">
196 </td>
197 </tr>
198
199 </table>
200
201 </form>
202
203 </body>
204 </html>
205
Listing 46.3 Inventory results
The jdoPersistenceMgr application which follows uses the JDO PersistenceMan-ager class on line 22 as its primary interface between the Web application jdoForm.jsp and the back-end MySQL database. The PersistenceManager provides both query and transaction management. It uses the resource adapter to access the data store, specifically the OJB libraries.
JDO and Data Persistence 397
01 package org.javapitfalls.item46;
02
03 import 4. l a i r o t u t b. j o e. h c a p a g. r o
04
05 import org.apache.ojb.jdo.PersistenceManagerlmpl;
06 import org.apache.ojb.jdo.PersistenceManagerFactorylmpl;
07 import javax.jdo.PersistenceManager;
08 import javax.jdo.Transaction;
09
10 import javax.jdo.Query;
11 import java.util.Collection;
12
13 import javax.jdo.PersistenceManager;
14 import javax.jdo.PersistenceManagerFactory;
15 import java.io.BufferedReader;
16 import java.io.InputStreamReader;
17 import java.util.Vector;
18
19 public class jdoPersistenceMgr implements java.io.Serializable {
20
21 PersistenceManagerFactory factory;
22 PersistenceManager manager;
23
24 public jdoPersistenceMgr()
25 {
26 manager = null;
27 try
28 {
29 factory = PersistenceManagerFactoryImpl.getInstance();
30 manager = factory.getPersistenceManager();
31
32 }
33 catch (Throwable t)
34 {
35 System.out.println("ERROR: " + t.getMessage());
36 t.printStackTrace();
37 }
38 }
39
40 public PersistenceManager getManagerInstance()
41 {
42 return manager;
43 }
44
45 }
Listing 46.4 do.PersistenceManager.java
There are many discussions in the development community about JDO and the perception that it suffers from its association with Object Data Modeling Group (ODMG), which has not garnered widespread community support because of proprietary language extensions and nonstandard meta data support.
398 Item 47
Personally, I feel that this misperception is badly placed and will be displaced once the development community implements new reference implementations by Sun and the ASF. JDO is still a young standard, but as products like OJB mature, developers will gain a better appreciation of JDO's ability to propagate consistent persistence behavior across implementations, its use of XML meta data representation for mapping data, and its ability to use mature Java Collection class libraries to manipulate data. These capabilities could make your persistence questions easier to tackle on your system's data layer.
JDO is relevant because it minimizes database transaction implementations by developers and it supports reuse, particularly with Java components. OJB JDO facilitates cache and object management through object models and avoids relational modeling and EJB/CMP intricacies that can be specific to an application.
Item 47: Where's the WSDL? Pitfalls of Using JAXR with UDDI
The Java API for XML Registries (JAXR) provides a Java API for accessing different kinds of registries. Built on the OASIS ebXML Registry Information Model (RIM), mappings between ebXML interfaces and JAXR interfaces are direct and seem intuitive. When JAXR is used with UDDI (Universal Description and Discovery Integration) registries, however, there is sometimes a bit of confusion. In our experience, Java developers that are new to JAXR face a learning curve and a few pitfalls that revolve around misunderstanding the relationships between JAXR objects and the UDDI data structures. This item shows examples of these pitfalls and provides guidance on how to avoid them.
Previous << 1 .. 137 138 139 140 141 142 < 143 > 144 145 146 147 148 149 .. 166 >> Next