Use Hibernate to implement DAO mode in SMS bank

xiaoxiao2021-03-06  41

SMS Bank Development Group Liu Bang Tao

1. Introduction to SMS Bank

The Oriental SMS bank platform is a financial service product for banks, which is based on the J2EE architecture. SMS bank platforms as a product, including the following parts:

TongSMS Communication Platform: Responsible for interacting with Unicom, mobile and other SMS gateways. Responsible for sending and receiving SMS. You can also hill one or more GSMMODEMs if needed.

TongSMS Business System: This is the core part of SMS banks. It is responsible for handling user input, and generates corresponding SMS based on user input with the front machine or database. The notification and timing reminder service required by the user is also completed here.

TongSMS Management Center: Responsible for user signing management, system monitoring. Communication platform management, etc. In addition, some additional functions are provided.

TongSMS Demo System: Sims to the banking business. Implement Simulation Demo of SMS Platform.

These parts are combined with each other to form a completed SMS bank platform product.

2. SMS bank view

2.1. Deployment view

The picture below is a deployment view of the SMS system, which can be seen from the figure that interactions between individual systems are done through a database. Therefore, it is possible to flexibly access the database, it is a critical requirement for the system.

2.2.Hibernate location in the system

For SMS banking systems, there are three input and output methods:

Browser: Mainly managed by management center, input via HTTP mode

Socket: Provides it to the external user extension. Currently TLINKQ.

Mobile phone users: via SGIP or CMPP.

For three types of input and output, for each, we basically use the MVC design mode, but for the latter two, the form is slightly changed.

The process is as follows:

1 User Enter commands (may be a browser user clicking on the page, or the mobile phone user enters a command)

2 Controller (C) Analyze the arrival command, call the corresponding model to handle the command

3 Model makes some simple analysis processing, calling the backend business process to deal with this command

4 Simple operation, business process call DAO is completed, responsible, need to use some universal components to make further processing, then call DAO to complete

5 DAO is responsible for accessing the database. DAO is mainly completed by Hibernate.

3.Hibernate Introduction

Hibernate is an easy-to-use, powerful object / relational mapping (O / R mapping) skeleton (Framework), which is mainly able to help completion of the third layer is the persistence layer. Function.

The following figure is a Hibernate architecture diagram, where Persistent Object is a simple business entity object (to be persisted object). The transparent persistence through Hibernate into the database. Thereby, it reduces the operation of cumbersome and easily erroneous JDBC.

4. Configuring Hibernate

In order to be able to run Hibernate in the J2EE environment, you need to make the following configuration:

1 Write hibernate.cfg.xml. For SMS banks, this file is approximately as follows.

"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">

True

True

Java: Comp / Usertransaction /

JDBC / Informixd

Net.sf.hibernate.Dialev.informixdiaLect

Put this file in a web-inf / classpath directory

2 Related files of the lib directory under the Hibernate directory (Note: Not all) to copy to the Web-INF / LIB directory 3 correctly configure TongWeb data source, here is JDBC / Informixd

The configuration is complete. The configuration is very simple.

5. A simple example

In SMS banks, users can customize a lot of services, such as timing reminders, balance change notifications, payment services, and more. We have a table that defines all the types of service, called the service table. The steps of the service table have been described below with reference to the steps of the service table.

1 Define the mapping file, the name is Service.hbm.xml.

2 Use the tools provided by Hibernate to generate the corresponding JavaBean class service.java and the SQL statement of the table, note that the SQL statement of the table may need to modify according to the actual situation, and generate can be used as a foundation.

3 Use SQL to build a table in the database

4 configuration hibernate

Configuration DS = New Configuration (). Configure ();

5 get sessionFactory

SessionFactory sessionFactory = DS.BUILDSessionFactory ();

6 Establish session using sessionFactory

Session session = sessionFactory.openSession ();

7 use session storage

Service service = new service ();

Service.set (...);

Transaction TX = NULL;

Try {

TX = SES.BEGINTRANSACTION ();

SES.SAVEORUPDATE (OBJ);

SES.FLUSH ();

TX.comMit ();

} catch (exception e) {

Try {

IF (tx! = null) tx.rollback ();

} catch (exception ex) {

// ignore

}

}

It is very convenient to reduce a lot of cumbersome work.

6. Summary

The object relationship mapping tool has a lot of tools, and the more famous open source tools are Hibernate and OJB, OJB is a product of Apache.

Another optional solution is to use JDO. In theory, for the application of SMS banks, this should be the best choice, but a problem has caused such a choice to actually not feasible: At present, there is no "free", mature, practice The product is tested. For us such a product, you can't take risks.

There is also a method that uses Entity Bean. We have not used it because the entity bean is too complicated. Moreover, the original intention of SMS bank design is to run on a variety of platforms such as TongWeb, WebSphere, WebLogic. If you use the Entity Bean. It will increase the difficulty of cross-platform. Of course, it is also possible. A preferred method may be to use the xdoclet from moving a deployment descriptor. This requires further research.

For J2EE technology, there are many ways to use, and there is a need for flexible selection according to the size, time, etc. of the project. By using hibernate, our biggest feelings are that the modification of the table structure is very small. And very flexible. For projects such as SMS bank platform, Hibernate fully meets our requirements. It has achieved better results.

转载请注明原文地址:https://www.9cbs.com/read-68782.html

New Post(0)