⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lib0081.html

📁 j2ee架构师手册
💻 HTML
字号:
<html>
<META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<head>
<title>Chapter 12: Building Database Access Objects</title>
<link rel="STYLESHEET" type="text/css" href="images/xpolecat.css">
<link rel="STYLESHEET" type="text/css" href="images/ie.content.css">
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr><td><div STYLE="MARGIN-LEFT: 0.15in;"><a href="toc.html"><img src="images/teamlib.gif" width="62" height="15" border="0" align="absmiddle"  alt="Team LiB"></a></div></td>
<td align="right"><div STYLE="MARGIN-LEFT: 0.15in;">
<a href="LiB0080.html"><img src="images/previous.gif" width="62" height="15" border="0" align="absmiddle" alt="Previous Section"></a>
<a href="LiB0082.html"><img src="images/next.gif" width="41" height="15" border="0" align="absmiddle" alt="Next Section"></a>
</div></td></tr></table>
<br>
<div class="chapter">
<a name="ch12"></a>
<h1 class="chapter-title"><span class="chapter-titlelabel">Chapter 12: </span>Building Database Access Objects</h1><div class="section">
<h2 class="sect2-title">
<a name="374"></a>Overview</h2>
<a name="375"></a><a name="IDX-153"></a>
<p class="para">Data access objects read and write data in databases and convert that format to value objects usable by other layers in the application. For example, <span class="fixed">PurchaseOrderDAO</span>, a DAO in a purchasing application, reads purchase order information from a database and converts it to value objects (e.g., <span class="fixed">PurchaseOrderVO</span>) that the rest of the application can use. <span class="fixed">PurchaseOrderDAO</span> also uses information in <span class="fixed">PurchaseOrderVO</span> to update or insert data in the database. The following are some methods <span class="fixed">PurchaseOrderDAO</span> might have:</p>
<div class="informalexample">
<pre class="literallayout">
public PurchaseOrderVO getPurchaseOrder(int orderNbr);
public void savePurchaseOrder(PurchaseOrderVO order);

public PurchaseOrderVO[] getCustomerPOs(String customerId);
public PurchaseOrderVO[] getUnshippedPOs();
public PurchaseOrderVO[] getBackOrderedPOs();
</pre>
</div>
<p class="para">
<a class="internaljump" href="#ch12fig01">Figure 12.1</a> illustrates the role of DAOs in the software layer hierarchy.</p>
<div class="figure">
<a name="376"></a><a name="ch12fig01"></a><span class="figuremediaobject"><a href="images/fig170%5F01%5F0%2Ejpg" NAME="IMG_32" target="_parent"><img src="images/fig170_01.jpg" height="250" width="350" alt="Click To expand" border="0"></a></span>
<br style="line-height: 1">
<span class="figure-title"><span class="figure-titlelabel">Figure 12.1: </span>Using Data Access Objects Within a Layered Architecture</span>
</div>
<p class="para">All logic that interprets and processes that data is in the business logic layer, not in the data access object layer. The reason for segregating data access is to limit and consolidate your exposure to changes in the data source. For example, one of my clients migrated from using Sybase to Oracle. The migration was relatively easy in applications with segregated data access. Further, from a maintenance standpoint, it was easy to locate, modify, and <a name="377"></a><a name="IDX-154"></a>enhance the data access object layer to handle minor changes, such as column additions.</p>
<p class="last-para">As discussed in <a href="LiB0030.html#129" target="_parent" class="chapterjump">chapter 5</a>, most developers use native JDBC as a persistence mechanism. The current chapter provides some guidelines for using JDBC effectively and constructing JDBC data access objects that you can easily use in a layered architecture. For readers using entity beans or object-relational mapping tools, I illustrate how these technologies work in a layered architecture.</p>
</div>
</div><br>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr><td><div STYLE="MARGIN-LEFT: 0.15in;"><a href="toc.html"><img src="images/teamlib.gif" width="62" height="15" border="0" align="absmiddle"  alt="Team LiB"></a></div></td>
<td align="right"><div STYLE="MARGIN-LEFT: 0.15in;">
<a href="LiB0080.html"><img src="images/previous.gif" width="62" height="15" border="0" align="absmiddle" alt="Previous Section"></a>
<a href="LiB0082.html"><img src="images/next.gif" width="41" height="15" border="0" align="absmiddle" alt="Next Section"></a>
</div></td></tr></table>
</body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -