Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit Unit2;
- interface
- uses
- Aurelius.Sql.Register,
- Aurelius.Sql.MySQL,
- Aurelius.Schema.MySQL,
- Aurelius.Engine.ObjectManager,
- Aurelius.Engine.DatabaseManager,
- Aurelius.Drivers.Interfaces,
- Aurelius.Drivers.FireDac,
- Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
- Vcl.Controls, Vcl.Forms, Vcl.Dialogs, FireDAC.Stan.Intf, FireDAC.Stan.Option, FireDAC.Stan.Error, FireDAC.UI.Intf, FireDAC.Phys.Intf, FireDAC.Stan.Def, FireDAC.Stan.Pool, FireDAC.Stan.Async, FireDAC.Phys, FireDAC.VCLUI.Wait, Data.DB,
- FireDAC.Comp.Client, FireDAC.Phys.FB, FireDAC.Phys.FBDef, Vcl.StdCtrls, FireDAC.Phys.ODBC, FireDAC.Phys.ODBCDef, FireDAC.Phys.MySQL, FireDAC.Phys.MySQLDef, Vcl.ExtCtrls;
- type
- TForm2 = class(TForm)
- Label1: TLabel;
- Timer1: TTimer;
- procedure FormCreate(Sender: TObject);
- procedure Timer1Timer(Sender: TObject);
- end;
- var
- Form2: TForm2;
- implementation
- uses
- Threading,
- SyncObjs,
- MariaData;
- {$R *.dfm}
- var
- Generator: TMySqlSQLGenerator;
- cnt: integer = 0;
- Sem: TCriticalSection;
- ready: boolean = false;
- procedure Run(ref: integer);
- var
- lConnectionIntf: IDBConnection;
- lDatabaseManager: TDatabaseManager;
- lObjectManager: TObjectManager;
- procedure Prepare;
- var
- lConnection: TFDConnection;
- begin
- lConnection := TFDConnection.Create(nil);
- lConnection.DriverName := 'MySql';
- lConnection.Params.Database := 'Test';
- lConnection.Params.DriverId := 'MySql';
- lConnection.Params.Password := 'lartsek';
- lConnection.Params.UserName := 'root';
- lConnectionIntf := TFireDacConnectionAdapter.Create(lConnection, 'MySql', false);
- end;
- procedure Open;
- begin
- if ref = 1 then // only the 1st one can create/alter the schema
- begin
- lDatabaseManager := TDatabaseManager.Create(lConnectionIntf);
- lDatabaseManager.UpdateDatabase;
- end;
- lObjectManager := TObjectManager.Create(lConnectionIntf);
- ready := true;
- end;
- procedure Close;
- begin
- lObjectManager.Free;
- if ref = 1 then
- lDatabaseManager.Free;
- end;
- begin
- Prepare;
- Open;
- for var i:=1 to 1000 do
- begin
- Sem.Enter;
- inc(cnt); // protect the counter
- Sem.Leave;
- var lTransaction := lConnectionIntf.BeginTransaction;
- var x := TTest.Create;
- x.data := 'Testing ' + i.ToString;
- lObjectManager.Save(x);
- lObjectManager.Flush;
- lTransaction.Commit;
- end;
- Close;
- end;
- procedure TForm2.FormCreate(Sender: TObject);
- begin
- Sem := TCriticalSection.Create;
- Generator := (TSQLGeneratorRegister.GetInstance.GetGenerator('MySql') as TMySqlSQLGenerator);
- TTask.Run(procedure begin Run(1); end);
- while not ready do
- sleep(10);
- for var j := 2 to 10 do
- TTask.Run(procedure begin Run(j); end);
- end;
- procedure TForm2.Timer1Timer(Sender: TObject);
- begin
- sem.Enter;
- Label1.Caption := cnt.ToString;
- sem.Leave;
- end;
- end.
Add Comment
Please, Sign In to add comment