introduction
With the development of traditional client / server mode, the disadvantages of its existence have also promoted, and the generation of enterprise application architecture - the emergence of distributed three-layer structure provides greater flexibility and can Scalability.
The advantages are as follows:
. Package complex business logic
Make the traditional object-oriented object to a new level, implementing a service in one component makes the service change when the business needs changes.
. Independent programming language
The technology based on the COM component is a set of binary standards, regardless of specific language.
. Reduce project risks
Components developed based on service-based concepts, separating public business logic as enterprise objects from user interfaces and data layers, enhances the reusability of components.
Basic mode is divided into: performance layer - business layer - data layer
The performance layer is the human-machine interaction interface, and the root traditional application has no difference (except for business logic).
The business layer is also called a transaction logic layer or an intermediate layer. This layer is mainly used in large-volume transaction, transaction support, large configuration, information transfer, and network communication. At this layer, the complex business relationship is subdivided into a single service, and each service performs a special task that can be implemented with relatively independent service components. By distributing these components, data processing load, coordination logical relationship, adjust business scale, and business rules can be balanced. This layer can be deployed anywhere in the network, usually called the application server.
The data layer is popular, that is, our traditional data server. Such as Oracle et al.
Under such an architecture, traditional performance layers and data layers will focus on business layer management. This increases the versatility, independence of the client application, and also avoids the bloated stored procedures and triggers. In addition, it also reduces the difficulties of software configuration and version updates. It is enough to configure and update the business layer.
Operating mechanism
1. The client first launches the client program, and the client will try to connect the application server if the application server has not yet run, and the client program will activate the application server and get an iProvider interface.
2. The client program is applied to the server request data. If the TClentDataSet's Fetchondemand property is set to True, the client will automatically retrieve additional packets as needed, such as the Blob field. Otherwise, you want to display the getNextPacket;
3. After the application server receives the request from the client, the data is retrieved from the remote database server and packages the client program.
4. After the client program receives the packet, open the package and display the activity.
5. Users edit the data and apply to the application server to update the data.
6. After the application server receives the application of the client, it is like the remote data server application update data. Error returns information.
Technical realization
Delphi6 is re-expanded and packaged MIDASNAP provides a comprehensive solution.
See example in DEMOS / MIDAS in Delphi6 installation directory
The database server is the same as the traditional mode. Install a database software, such as Oracle
1. Create a business layer (application server)
. Create a new application, add a Remote Data Module from Multitier, (remote data module) (Delphi provides five different connection methods, including DCOM, TCP / IP, HTTP, Olenterprise, CORBA.
The five middle methods have their own advantages and disadvantages. In addition to DCOM (Win95 needs to install DCOM95), it requires running period software support, TCP / IP requires SCKTSRVER.EXE or SCKTSRVC.EXE (NT), HTTP requires IIS4.0 or Netscape Server 3.6 or more Web servers, and installed with Borland HTTPSRVR.DLL program, the client must have Wininet.dll, which can be provided by the browser above IE3.0 or more. The CORBA server and the client need to install ORB software, you can use the Visibroker with Delphi. The client connection component has an exception before reference to the iProvider interface, and the TCP / IP connection will not be detected, and the application server cannot be notified, which may cause the application server resources to be occupied. The consequences of the release. The DCOM connection is slower than TCP / IP when the application server is activated for the first time. ) Place TQuery, TTable, TSTOREDPROC, TDATABASE, etc. on the remote data module (you need to set the handleshared property to true to avoid "Name Not Unique In Context" errors ;. Place a TDataSetProvider component and make the DataSet property set to TQuery or TTABLE, connect the data source you want to connect.
. Write code to realize business rules.
You can use the add to interface on the EDIT menu to increase the interface, you can also use the Type library in the View menu to open the Type Editor, add interface, methods, and properties to implement your business logic.
3. Create a client application
. Create a new application, add a Data Module, place the DataSnap component you need on the data module, such as TDCOMCONNECTION
. Specify the relevant property settings of the TDCOMCONNECTION component to the application server you created, if the specified server is registered, you need to run the server program to register. Then set the connection attribute to TRUE.
. On placing the TclientDataSet component to the data module, set its RemoteServer property to specify the TDCOMConnection you placed, set its provindername to the TDataSetProvider on the application server. This client program can communicate with the application server via the iProvider interface. Then place TDataSource and your data perceived control, TDataSource's DataSet specifies the TclientDataSet you placed, then you can display and edit data. When modified the local copy of the data in the TclientDataSet, the client calls the TclyTaSet Applyupdates to submit the change back to the database. Non-ADO connections, multi-table query needs to be used to use the TupdatesQL control.
Automatic fault tolerance and load balancing
In the three-layer structure, there can be multiple applications that perform the same service simultaneously and can automatically switch the clients in the customer service in the current service to another. Applicable application server after a server fails. (Fault tolerance), you can assign a large number of customer requests to a plurality of applications (balanced loads) that perform the same service. The TSIMpleObjectBroker component will implement the above features (Olenterprise or CORBA way has its own special intermediary service, no need for this component).
The client TDCOMConnection control does not need to set the computername property, set the ObjectBroker to the TSIMpleObjectBroker component you create, specify the application server you deploy in the Servers property of the TSIMpleObjectBroker component, and the loadbalanced property is set to TRUE to take advantage of this control load balance capability. Once the current connection server has failed, in order not to affect the job, for this, the client application must turn off and the original application server connection, then call the TSIMpleObjectBroker's setConnectStatus to inform TsIMpleObjectBroker's original application server can't continue to use, then call GetComputeProgid Re-establish the connection. Follow-up
The most important thing is how to make the program highly plenty of plenty of coupling, how to make the service (business) components, and atomicization.
Reference: "Enterprise Solutions and Application Analysis" Liu Yi