Brief analysis of Java EE application database class design pattern

Source: Internet
Author: User

This paper mainly introduces a design pattern of database-related classes. It also introduces the concrete implementation in the Java EE Framework and some considerations in the transaction processing.

Introduction of Design pattern

When developing a Java EE application, it is often necessary to find the various information involved in the application, such as a company's product catalog, or a website's user information, which we will put in the database.

In the usual design, we want to analyze the properties and relationships of these data, then the logical design of the database, the various information used in different tables to store. For example, to develop a library information query system. You can create the following two tables to represent books and publishers, respectively.

Table book (IDs, Name, ISBN, Author, PublisherID, Price, Volume)

Table Publisher (ID, Name, telephone, address, postcode)

The book contains ID, title, ISBN, author, publisher ID, price, number of pages. Table Publisher contains ID, social name, phone number, address, zip code. The two tables are related through the Publisher ID.

Let's introduce a pattern of the design of database-related classes.

Database-related classes can be divided into entity classes (Entity Class) and Session classes (sessions Class).

An entity class corresponds to the encapsulation of a table's records, that is, one instance of the class corresponds to a record in the table. Also, the properties in the class and the fields in the record correspond to one by one.

The session class corresponds to the operation of all records in a table. For example, add a record, delete a record, find a record, and update a record.

By using this design pattern, the program is more modular and easy to develop and maintain. Of course, you can also use other design patterns.

Second, the realization of the program

In the implementation of the above model, it is often based on specific applications to choose different technologies to achieve. After seeing the above description pattern, it is easy to find that EJB can be implemented (EJB is divided into two kinds, entity EJB and Session EJB).

We know that the purpose of EJB is to provide the development of a distributed component system. If our application is a distributed application system, then there is no doubt that using EJBS can greatly reduce the workload of programming. At the same time, by using some of the advanced features of the EJB container, you can make your application more reliable, and scalability greatly enhanced. As a result, developers do not have to care about the underlying technologies, such as transaction processing, security, and so on, but instead focus on how to implement business logic. However, we should note that if the development of the application is not distributed, then the use of EJB may greatly reduce the performance of the system. Because EJB calls are expensive.

Related Article

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.