詠南LINUX中間件


詠南LINUX中間件

什么是跨平台?

DELPHI跨平台已經不是停留在理論,而是可以實用了。

同一套中間件既能在WINDOWS服務器上面部署,又可以在LINUX服務器上面部署。

而做到這一切,只需要一套源代碼,這完全得益於DELPHI 10.2全新的跨平台編譯器。

想想,你的同一個中間件同時可以在WINDOWS和LINUX服務器上部署運行,這是一件多么激動人心的事情啊!

筆者不免心情澎湃!同時支持TCP/IP、HTTP通信協議。

LINUX 支持:

  • Ubuntu Server (Ubuntu 16.04 LTS)
  • RedHat Enterprise Linux (版本 7)

CENTOS 7 服務器上運行中間件:

 中間件詳情日志:

 WINDOWS客戶端訪問CENTOS7上的中間件並返回查詢數據:

同一份源代碼只需要編譯成不同的目標平台即可:

WINDOWS服務器上部署運行中間件:

 支持REST調用

測試客戶端代碼:

// cxg 2017-9-16 跨平台中間件的客戶端

unit Unit1;

interface

uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Data.DB, Data.SqlExpr,
Data.DBXDataSnap, Data.DBXCommon, IPPeerClient, Unit2, Vcl.Grids, Vcl.DBGrids,
Vcl.StdCtrls, FireDAC.Stan.Def, FireDAC.Stan.StorageJSON, FireDAC.Stan.StorageBin,
FireDAC.Stan.Intf, FireDAC.Stan.Option, FireDAC.Stan.Param, FireDAC.Stan.Error,
FireDAC.DatS, FireDAC.Phys.Intf, FireDAC.DApt.Intf, FireDAC.Comp.DataSet,
FireDAC.Comp.Client, Vcl.ExtCtrls, Data.DbxHTTPLayer;

type
TForm1 = class(TForm)
SQLConnection1: TSQLConnection;
DBGrid1: TDBGrid;
DataSource1: TDataSource;
FDMemTable1: TFDMemTable;
btnsave: TButton;
btnappend: TButton;
btndel: TButton;
btnquery: TButton;
btnsp: TButton;
procedure FormCreate(Sender: TObject);
procedure btnsaveClick(Sender: TObject);
procedure btnappendClick(Sender: TObject);
procedure btndelClick(Sender: TObject);
procedure btnqueryClick(Sender: TObject);
procedure btnspClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

uses
ujson;

procedure TForm1.btnsaveClick(Sender: TObject);
// 保存數據
var
c: TServerMethods1Client;
sResult: string;
begin
if FDMemTable1.State in [dsInsert, dsEdit] then
FDMemTable1.Post;
if FDMemTable1.ChangeCount = 0 then
Exit;
SQLConnection1.Close;
SQLConnection1.Open;
c := TServerMethods1Client.Create(SQLConnection1.DBXConnection);
try
sResult := c.ExecuteSQL(ujson.deltaToJSON(FDMemTable1, 't1', 'c1', ''));
if Pos('true', sResult) > 0 then
begin
FDMemTable1.MergeChangeLog;
ShowMessage('save ok');
end
else
begin
FDMemTable1.Cancel;
ShowMessage('save fail');
end;
finally
c.Free;
SQLConnection1.Close;
end;

end;

procedure TForm1.btnspClick(Sender: TObject);
// 執行存儲過程
//CREATE PROCEDURE sp2(in a varchar(5))
//BEGIN
//SELECT * FROM t1 where c1=a;
//END;
var
c: TServerMethods1Client;
begin
SQLConnection1.Close;
SQLConnection1.Open;
c := TServerMethods1Client.Create(SQLConnection1.DBXConnection);
try
ujson.jsonToDB(c.SPOpen('sp2', '{"a":"1"}'), FDMemTable1);
finally
c.Free;
SQLConnection1.Close;
end;
end;

procedure TForm1.btnqueryClick(Sender: TObject);
// 查詢數據
var
c: TServerMethods1Client;
begin
SQLConnection1.Close;
SQLConnection1.Open;

c := TServerMethods1Client.Create(SQLConnection1.DBXConnection);
try
ujson.jsonToDB(c.QuerySQL('select * from t1'), FDMemTable1);
FDMemTable1.MergeChangeLog;
finally
c.Free;
SQLConnection1.Close;
end;
end;

procedure TForm1.btnappendClick(Sender: TObject);
// 新增
begin
FDMemTable1.Append;
end;

procedure TForm1.btndelClick(Sender: TObject);
// 刪除數據
var
c: TServerMethods1Client;
sResult: string;
begin
if not FDMemTable1.IsEmpty then
begin
FDMemTable1.Delete; // del
SQLConnection1.Close;
SQLConnection1.Open;
c := TServerMethods1Client.Create(SQLConnection1.DBXConnection);
try
sResult := c.ExecuteSQL(ujson.deltaToJSON(FDMemTable1, 't1', 'c1', ''));
if Pos('true', sResult) > 0 then
begin
FDMemTable1.MergeChangeLog;
ShowMessage('del ok');
end
else
begin
FDMemTable1.Cancel;
ShowMessage('del fail');
end;
finally
c.Free;
SQLConnection1.Close;
end;
end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
FDMemTable1.CachedUpdates := True; // 否則不能保存
end;

end.


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM