Program data layer (3) APIs in nhib.pdf

Source: Internet
Author: User

This articleArticleThis section describes the APIs of nhib.pdf and their functions.

Describes the role of APIs of nhib.pdf in a layered architecture.

APIS of nhib.pdf are roughly divided into four types:
1. AppliedProgramCall the interface for basic data operations (add, delete, modify, and query.These interfaces are the main interaction points between the business logic layer and the control layer of the application and nhib.pdf. Isession, itransaction, IQUERY, and icriteria belong to this category.
2. APIs used by applications to configure Nhibernate.Configuration belongs to this type.
3. Callback interface.The application uses a callback interface to respond to events triggered in nhib.pdf. These interfaces include interceptor, ilifecycle, and ivalidatable.
4. interfaces used to extend the powerful nhing function of Nhibernate.These interfaces are usually implemented by the application infrastructure. Iusertype, icompositeusertype, and iidentifiergenerator belong to this class.

Make full use of nhib.pdf.. Net APIs, including ADO. net and the corresponding itransaction API, due to ADO. NET provides Abstract Functions for different databases, which enables nhib.pdf to support almost all databases.

The core interfaces in nhib.pdf are described as follows:

I. Core interfaces:

1. isession.

Isession is the main interface of the nhib.pdf application. It provides methods for querying, updating, storing, and deleting objects. Isession is a lightweight object that is easy to create and destroy. This is important because sessions may be created at any time in the Nhibernate application, and may be required for every page request. It should be noted that the nhib1_session is NOT thread-safe, so it can only be used by one thread at the same time during design.
The meaning of session in Nhibernate is between the traditional connection and transaction. It can be regarded as the cache or set of objects related to a work unit. Nhibernate can detect the changes of objects in this work unit. Sometimes, isession is also called a permanent manager because it is also an interface for permanent operations, such as accessing objects. It should be noted that the session in nhib.pdf has nothing to do with the session in ASP. NET.

2. isessionfactory.
The application obtains isession from isessionfactory. isessionfactory is not a lightweight object and is used for sharing among multiple application threads. Generally, there is only one isessionfactory instance in the application. For example, you can create an isessionfactory instance during application initialization. However, if your application needs to access multiple databases using nhib.pdf, you need to create an isessionfactory instance for each database.
Isessionfactory caches the ing data between the SQL statements created during the running of nhib.pdf and other ing data. It can also store the data that can be read in a single work unit and that may be used in the next work unit or session. Isessionfactory can also be used to configure the ing between classes and collections to use the second-level cache.

3. configuration interface.
The configuration class is used to configure Nhibernate. The application uses the configuration instance to configure the location of the ing file before isessionfactory is created and set the specific attributes of nhib.pdf.
Although the configuration class only occupies a small part of the whole Nhibernate application, it is the first object we use when we start to use Nhibernate.

4. itransaction interface.
This is an optional interface. The nhib.pdf application does not use this interface.CodeTo manage transactions. Nhib1_transaction from the underlying transaction (such as ADO. net transaction or other transactions) to abstract the application code, so that the application code can control the transaction boundary through a series of consistent client APIs, this allows the nhib.pdf application to be portable in different execution environments and sizes.

5. IQUERY and icriteria interfaces.
The IQUERY interface provides powerful database query capabilities and controls how queries are executed. It is the basic interface for nhib.pdf to obtain data. The query is written as hql or the original SQL statement of the database. IQUERY is lightweight and can only be used in the isession where it is created. It binds parameters, limits the number of results returned by the query, and then executes the query.
The icriteria interface is similar to the IQUERY interface. It can be used to create and execute object-oriented conditional queries.

Ii. Callback interface.

When an event occurs to an object (such as the object being loaded, stored, or deleted), the callback interface can send a notification to the application. The Nhibernate application does not need to implement these events, but they are useful when executing some common tasks, such as creating audit records.

The ilifecycle and ivalidatable interfaces allow a permanent object to respondPermanent Life CycleRelated events. The permanent life cycle is included in the CRUD operation of an object, that is, when the object is created, extracted, updated, and deleted.
(Note: The Nhibernate development team was originally influenced by the ORM solutions with these interfaces. Later they realized that enabling the permanent class to implement these Nhibernate specific interfaces would affect portability, so these two interfaces have expired .)

The iinterceptor interface allows applications to process events without implementing specific interfaces of nhib.pdf. The implementation of the iinterceptor interface is passed to the permanent instance in the form of parameters.

Iii. type.

The concept of the nhibana type is a basic and powerful element in the architecture .. Net Type object maps the type in. net to the column type in the database (one type may be extended to multiple data table columns ). All the permanent attributes of the permanent class, including the Association, have the corresponding Nhibernate type. This design gives Nhibernate great flexibility and scalability, because each type of relational database has a set of Nhibernate types.
Nhibernate contains a wide range of types, including. Net basic classes and many CLR classes, including datetime, system. Enum, byte [], and serializable classes.
Nhib.pdf also supports user-defined types. Iusertype, icompositeusertype, and iparameterizedtype interfaces are used to create our own types. We can also use iusercollectiontype to create our own collection classes. This feature makes it easy and concise to process classes used in applications, such as address, name, and moneyaccount. The custom type is a core attribute of nhib.pdf. The nhib.pdf Team encourages us to use it as much as possible and creatively.

Iv. Extended Interfaces

Most of the functions provided by nhib.pdf are configurable, which allows us to choose between some built-in policies. When the built-in policies meet our needs, nhib.pdf also allows us to insert our own functions through some interfaces. Insert points include:
1. Generation of primary keys (iidentifiergenerator Interface)
2. SQL language support (dialect abstract class)
3. Cache Policy (icache and icacheprovider interfaces ).
4. Ado. net connection management (iconnectionprovider interface ).
5. Transaction Management (itransactionfactory and itransaction interfaces ).
6. Orm Policy (iclasspersister interface level)
7. Attribute Access Policy (ipropertyaccessor interface ).
8. Create a proxy (iproxyfactory interface ).
For the above interfaces, nhib.pdf already has at least one implementation. Therefore, if we want to extend these built-in functions, we do not need to start from scratch.

 

Copyright Disclaimer: This article was originally published in the blog Park, and the author said it was too cold tonight.
The copyright of this article is shared by the author and the blog Park. You are welcome to repost this article. However, you must keep this statement without the author's consent and provide the original article connection clearly on the article page. Otherwise, it is deemed as infringement.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.