`

集成层模式:Data Access Object—数据访问对象模式

阅读更多

Context
Access to data varies depending on the source of the data. Access to persistent storage,
such as to a database, varies greatly depending on the type of storage (relational databases,
object-oriented databases, flat files, and so forth) and the vendor implementation.
Problem
Many real-world Java 2 Platform, Enterprise Edition (J2EE) applications need to use
persistent data at some point. For many applications, persistent storage is implemented with
different mechanisms, and there are marked differences in the APIs used to access these
different persistent storage mechanisms. Other applications may need to access data that
resides on separate systems. For example, the data may reside in mainframe systems,
Lightweight Directory Access Protocol (LDAP) repositories, and so forth. Another example
is where data is provided by services through external systems such as business-to-business
(B2B) integration systems, credit card bureau service, and so forth.
Typically, applications use shared distributed components such as entity beans to
represent persistent data. An application is considered to employ bean-managed persistence
(BMP) for its entity beans when these entity beans explicitly access the persistent
storage-the entity bean includes code to directly access the persistent storage. An
application with simpler requirements may forego using entity beans and instead use
session beans or servlets to directly access the persistent storage to retrieve and modify the
data. Or, the application could use entity beans with container-managed persistence, and
thus let the container handle the transaction and persistent details.
Applications can use the JDBC API to access data residing in a relational database
management system (RDBMS). The JDBC API enables standard access and manipulation
of data in persistent storage, such as a relational database. The JDBC API enables J2EE
applications to use SQL statements, which are the standard means for accessing RDBMS
tables. However, even within an RDBMS environment, the actual syntax and format of the
SQL statements may vary depending on the particular database product.
There is even greater variation with different types of persistent storage. Access
mechanisms, supported APIs, and features vary between different types of persistent stores
such as RDBMS, object-oriented databases, flat files, and so forth. Applications that need to
access data from a legacy or disparate system (such as a mainframe, or B2B service) are
often required to use APIs that may be proprietary. Such disparate data sources offer
challenges to the application and can potentially create a direct dependency between
application code and data access code. When business components-entity beans, session
beans, and even presentation components like servlets and helper objects for JavaServer
Pages (JSP) pages --need to access a data source, they can use the appropriate API to
achieve connectivity and manipulate the data source. But including the connectivity and
data access code within these components introduces a tight coupling between the
components and the data source implementation. Such code dependencies in components
make it difficult and tedious to migrate the application from one type of data source to
another. When the data source changes, the components need to be changed to handle the
new type of data source.
Forces
Components such as bean-managed entity beans, session beans, servlets, and other
objects like helpers for JSP pages need to retrieve and store information from persistent
stores and other data sources like legacy systems, B2B, LDAP, and so forth.
Persistent storage APIs vary depending on the product vendor. Other data sources
may have APIs that are nonstandard and/or proprietary. These APIs and their capabilities
also vary depending on the type of storage-RDBMS, object-oriented database management
system (OODBMS), XML documents, flat files, and so forth. There is a lack of uniform
APIs to address the requirements to access such disparate systems.
Components typically use proprietary APIs to access external and/or legacy systems
to retrieve and store data.
Portability of the components is directly affected when specific access mechanisms
and APIs are included in the components.
Components need to be transparent to the actual persistent store or data source
implementation to provide easy migration to different vendor products, different storage
types, and different data source types.
Solution
Use a Data Access Object (DAO) to abstract and encapsulate all access to the data
source. The DAO manages the connection with the data source to obtain and store data.
The DAO implements the access mechanism required to work with the data source.
The data source could be a persistent store like an RDBMS, an external service like a B2B
exchange, a repository like an LDAP database, or a business service accessed via CORBA
Internet Inter-ORB Protocol (IIOP) or low-level sockets. The business component that relies
on the DAO uses the simpler interface exposed by the DAO for its clients. The DAO
completely hides the data source implementation details from its clients. Because the
interface exposed by the DAO to clients does not change when the underlying data source
implementation changes, this pattern allows the DAO to adapt to different storage schemes
without affecting its clients or business components. Essentially, the DAO acts as an adapter
between the component and the data source.

分享到:
评论

相关推荐

    ActiveRDF:将语义Web数据嵌入到面向对象的语言中-研究论文

    我们分析了语义Web和Web之间的关系,并调查了语义Web应用程序中的典型数据访问模式。 我们讨论了面向对象的编程语言与语义Web数据之间的不匹配,例如,在类成员资格,继承关系以及对象与模式的一致性方面。 我们...

    ASP3《高级编程》(第一部分)

    第8~12章介绍了通用数据的访问和连接问题,包括ADO、UDA和XML。第13~18章介绍了使用ASP建立组件的问题,以及COM和COM+如何改变组件的环境。第19~23章是关于ASP与BackOffice类应用软件的结合问题,如Microsoft ...

    ASP3《高级编程》(第二部分)

    第8~12章介绍了通用数据的访问和连接问题,包括ADO、UDA和XML。第13~18章介绍了使用ASP建立组件的问题,以及COM和COM+如何改变组件的环境。第19~23章是关于ASP与BackOffice类应用软件的结合问题,如Microsoft ...

    asp.net知识库

    有了System.Data.IDataReader,一切皆成数据 理解DataSet的数据缓存机制 存储过程 可按任意字段排序的分页存储过程(不用临时表的方法,不看全文会后悔) 常用sql存储过程集锦 存储过程中实现类似split功能(charindex) ...

    AppFramework数据库访问组件_代码生成插件_V1.1.rar

    除了实现数据的增删改查,数据访问层还要提供一些与业务无关功能,例如面向对象的持久化与访问机制、本地事务与分布式事务支持、多数据库支持,这些机制或功能形成相对独立的逻辑领域,其主要目的有: <br>1、 ...

    Delphi5开发人员指南

    2.18.6 TObject:所有对象的祖先 63 2.18.7 接口 63 2.19 结构化异常处理 66 2.19.1 异常类 68 2.19.2 执行的流程 70 2.19.3 重新触发异常 71 2.20 运行期类型信息 72 2.21 总结 72 第3章 Win32 API 73 3.1 对象:...

    spring.net中文手册在线版

    中间层数据访问 第十四章. 事务管理 14.1.简介 14.2.动机 14.3.核心接口 14.4.用事务进行资源同步 14.4.1.高层次方法 14.4.2.低层次方法 14.5.声明式事务管理 14.5.1.理解Spring.NET声明式事务管理的实现 14.5.2.第...

    asp.net面试题

    答:SOAP(Simple Object Access Protocol )简单对象访问协议是在分散或分布式的环境中交换信息并执行远程过程调用的协议,是一个基于XML的协议。使用SOAP,不用考虑任何特定的传输协议(最常用的还是HTTP协议),...

    AppFramework_V1.0_New

    除了实现数据的增删改查,数据访问层还要提供一些与业务无关功能,例如面向对象的持久化与访问机制、本地事务与分布式事务支持、多数据库支持,这些机制或功能形成相对独立的逻辑领域,其主要目的有: <br>1、 ...

    easydao:简单易用的DAO框架,非侵入式的api,可以与Hibernate、SpringJdbc等框架很好的集成

    easydaoEasydao是简单易用的轻量级DAO(Data Access Object)框架,它集成了Hibernate实体维护和Mybaits SQL分离的两大优势,提供了非入侵式API,可以与Hibernate、SpringJdbc等数据库框架很好的集成。### Author:...

    Spring Framework 5.3.6

    并且面向JDBC的异常与Spring通用数据访问对象(Data Access Object)异常等级相一致. • 以资源容器,DAO实现和事务策略等形式与Hibernate,JDO和iBATIS SQL Maps集成。利用众多的翻转控制方便特性来全面支持, 解决...

    JAVA上百实例源码以及开源项目源代码

     关于数字签名:产生RSA密钥对(myKeyPair),得到RSA密钥对,产生Signature对象,对用私钥对信息(info)签名,用指定算法产生签名对象,用私钥初始化签名对象,将待签名的数据传送给签名对象(须在初始化之后),用公钥...

    AppFramework_V1.0

    除了实现数据的增删改查,数据访问层还要提供一些与业务无关功能,例如面向对象的持久化与访问机制、本地事务与分布式事务支持、多数据库支持,这些机制或功能形成相对独立的逻辑领域,其主要目的有: <br>1、 ...

    目 录关键词本文是一篇讨论基于Web的数据库管理的本科毕业论文,它详细地讲述了开发一个基于Web的通用BBS(Bullitin Board Syste统所用到的技术和方法。其中运用了ASP技术(Avtive Server Page)、ADO技术(ActiveX Data Object)、MS Access数据库技术、RegExp技术(Regular Expression 正则表达式)、VBScript及JavaScript脚本语言技术等等,并从几个不同的方面来对上述技术的实现方法进行了讨论。

    进入二十一世纪,计算机技术迅速向着网络化、集成化方向发展。传统的单机版应用软件正在逐渐退出舞台,取而代之的是支持网络、支持多种数据信息(多媒体)的新一代网络版应用软件,而目前网络版软件中似乎存在着两种...

    Spring中文帮助文档

    中间层数据访问 9. 事务管理 9.1. 简介 9.2. 动机 9.3. 关键抽象 9.4. 使用资源同步的事务 9.4.1. 高层次方案 9.4.2. 低层次方案 9.4.3. TransactionAwareDataSourceProxy 9.5. 声明式事务管理 9.5.1. ...

    Spring API

    中间层数据访问 9. 事务管理 9.1. 简介 9.2. 动机 9.3. 关键抽象 9.4. 使用资源同步的事务 9.4.1. 高层次方案 9.4.2. 低层次方案 9.4.3. TransactionAwareDataSourceProxy 9.5. 声明式事务管理 9.5.1. ...

    rom:Ruby数据映射和持久性工具包

    Ruby Object Mapper(rom-rb)是Ruby的数据映射和持久性工具包,旨在提供强大的对象映射功能而又不限制数据库的全部功能。 主要rom gem提供以下组件: -核心和适配器API 与rom-core集成的Changeset对象 -与rom-...

    JAVA上百实例源码以及开源项目

     关于数字签名:产生RSA密钥对(myKeyPair),得到RSA密钥对,产生Signature对象,对用私钥对信息(info)签名,用指定算法产生签名对象,用私钥初始化签名对象,将待签名的数据传送给签名对象(须在初始化之后),用公钥...

    操作系统(内存管理)

    其次,它不仅可以将虚拟地址映射到物理的 RAM 或者 swap,它还可以将它们映射到文件和文件位置,这样,读写内存将对文件中的数据进行读写。不过,在这里,我们只关心 mmap 向进程添加被映射的内存的能力。 munmap() ...

Global site tag (gtag.js) - Google Analytics