NHibernate in Action 2.2 Understanding the architecture

本文深入解析了NHibernate中NHAPIinalayeredarchitecture的组成部分,包括被Application调用执行CRUD的接口、配置NH的结构、对Entity中的Field或者Property变化的响应、扩展NH的Mapping功能以及与ADO.net的集成。详细阐述了每个部分的作用,如ISession作为持久化管理器,提供CRUD操作;ISessionFactory作为轻量级组件,管理会话缓存和映射元数据;IQuery和ICriteria用于执行查询;IInterceptor用于处理回调事件。文章还强调了NHibernate如何利用现有.net API,包括ADO.net,实现跨数据库的支持。

NH API in a layered architecture

image

包含那么几个部分:

  • 被Application调用执行CRUD的接口。包含 ISession, ITransaction, IQuery, ICriteria.
  • 配置NH的结构。 包含Configuration
  • 允许Application回调响应NHibernate内部事件的部分,比如IInterceptor, ILifecycle, iValidateble.  这一部分是对Entity中的Field或者Property的一些变化进行的响应,猜应该有 NewObject, DeleteObject, UpdateObject , Update Field等事件的响应,是实现业务规则的重要地方。
  • 允许扩展NH的Mapping功能的部分。比如IUserType,  ICompositeUserType, IIdentifierGenerator。

另外NH的基础还是ADO.net, 作者也提到:

    NHibernate makes use of existing .net apis, including ADO.net and its ITransaction API. ADO.net provides a rudimentary level of abstraction of functionality common to relational databases, letting NHibernate support almost any database with ADO.net driver.

The core interfaces

ISession interface

  • 负责CRUD操作, exposes NH’methods for finding, saving , updating,  and deleting objects.
  • lightweight and inexpensive. 可以任意的Create 和 destroy的。
  • not thread safe.
  • the nh notion of a session is something between connection and transaction.  it may be easier to think of a session as a cache or collection of loaded objects relating to a single unit of work. we sometimes call the ISession a  persistence manager. ISession的作用应该就是一个Persistence manager,  应该说有点类似于DataSet,可以连接到数据库进行操作,也可以进行事务管理。

ISessionfactory interface

  • isn’t lightweight!
  • one sessionfactory for one database.
  • caches generated SQL statements and other mapping metadata that NHibernate uses at runtime.
  • secod-level cache.  it can also hold cached data that has been read in one unit of work and which may be reused in a futrue unit of work or session . this is possible if you configure class and collection mappings to use the scond-level cache.

Configuration interface

  • specify the location of mapping documents
  • set NHibernate-specifc properties before creating the ISesionfactory

ITransaction interface

  • optional API.
  • 其他的都没有说。

IQuery and ICriteria interface

  • IQuery uses queries written in HQL.
  • ICriteria lets you create and execute object-oriented criteria queries.

Callback interface

  • callback interface allow the application to receive a notification when somthing interesting happens to an object- for example, when an object is loaded, saved, or deleted.
  • the Ilifecycle and ivalidateble interface let a persistent object react to events relating to its own persistence lifecyle. the persistence lifecycle is encompassed by an object’s curd operation.
  • the iinterceptor interface was introduced to let the application process callbacks without forcing the persistent classes to implement nhibernate-specific APIs.

Types

  • 一句话,进行NH和Database 之间的映射。

Extension inteface

  • 主要是Cache,Tranaction等功能

转载于:https://www.cnblogs.com/sunshinefly128/archive/2011/07/30/2122033.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值