A simple layer-2 architecture becomes a layer-3 Architecture

Source: Internet
Author: User

Recently, the company requested that the architecture of a product be changed from two layers to three layers (the reason is: For security review, a three-layer architecture is required because the database port is only open to the server ), when I heard it, I fainted.

The initial architecture of the product was three layers. Later, due to various requirements during the customer's trial, the product was switched back to the two-layer architecture. Now you need to change it back, alas...

Later I thought of a super simple method. Fortunately, the original 2-layer architecture operation database is written in a grass-roots class. You only need to split the base class into 2-layer databases, and you are too lazy to expose the business logic interface. Directly transfer the SQL statement through WebService. Simplicity is simple and brings about a big problem. You can directly operate the database. We should handle the security review first. Hoho.

The problems encountered during the development process are recorded as follows:

1. When Delphi calls WebService, the string parameter passed to webservcie is always null.

Solution: Add invregistry. registerinvokeoptions (typeinfo (dataaccessservicesoap), iodocument) to the unit generated by importing the WSDL in Delphi );

2. garbled characters when Delphi webservcie transfers Chinese Characters

Solution: both users use utf8 for communication. The header declaration in thttprio uses utf8. As follows:

Fhtprdataaccess. httpwebnode. useutf8inheader: = true;

3. Because several query functions in the basic class of the 2-layer architecture use adoquery as the parameter, you have to think of other methods to avoid changing the function call.

Original Function

 

Code

 procedure TDBOperate.SelectByADOQuery(sql : string; adoQuerySelect: TADOQuery);

begin

adoQuerySelect.SQL.Clear;

adoQuerySelect.SQL.Add(sSelectSQL);
adoQuerySelect.Open;

end;

After being changed to three layers, query through WebService. The value returned by WebService is in XML format.

The method to think of is to parse XML and then survive TADODataSet.

 

 

Code

 Function tbasedatabase. xmltodataset (XML: widestring): TADODataSet;
VaR
Xdoc: ixmldomdocument;
Xdn: ixmldomnode;
Xdns: ixmldomnodelist;
I, J: integer;
Tempdataset: TADODataSet;
Begin
Xdoc: = createdomdocument ();
Xdoc. loadxml (XML );

Xdn: = xdoc.doc umentelement;

Xdns: = xdoc. selectnodes ('// table ');
Try
Tempdataset: = TADODataSet. Create (NiL );
If (xdns. length> 0) then
Begin
For I: = 0 to xdns. item [0]. childnodes. Length-1 do
Begin
Tempdataset. fielddefs. Add (xdns. item [0]. childnodes [I]. nodename, ftstring, 8000 );
End;
Tempdataset. createdataset; // create
Tempdataset. Active;

If (xdn. attributes [0]. Text = 'true') then
Begin

For I: = 0 to xdns. Length-1 do
Begin

Tempdataset. append;
For J: = 0 to xdns. item [I]. childnodes. Length-1 do
Begin
Tempdataset. fieldvalues [xdns. item [I]. childnodes [J]. nodename]: = xdns. item [I]. childnodes [J]. text;
End;
Tempdataset. post;
End;
End;
End;
Result: = tempdataset;
Except
Raise;
End;
End;

 

 

 

After the XML result is parsed into TADODataSet, specify adoquery. recordset: = TADODataSet. recordset.

In this way, the original interface remains unchanged.

Summary:

This method is simple, but there are a lot of problems (at least the security is not high ...) Wait for a while and then change it slowly...

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.