With transaction pattern (langage)

De Wiki1000
(Différences entre les versions)
Ligne 1 : Ligne 1 :
 
Le pattern transaction permet d'encapsuler une transaction.
 
Le pattern transaction permet d'encapsuler une transaction.
  
===with transaction do===
+
===withP transaction do===
 
Ce pattern gère une transaction.
 
Ce pattern gère une transaction.
  
Ligne 33 : Ligne 33 :
 
begin
 
begin
 
   // Create an instance
 
   // Create an instance
   with transaction do  
+
   withP transaction do  
 
   begin
 
   begin
 
     inst := MyClass.Create;
 
     inst := MyClass.Create;
Ligne 41 : Ligne 41 :
 
</source>
 
</source>
  
===with private transaction do===
+
===withP private transaction do===
 
Ce pattern gère une transaction privée.  
 
Ce pattern gère une transaction privée.  
  
Ligne 48 : Ligne 48 :
 
<source lang="delphi">
 
<source lang="delphi">
 
begin
 
begin
   // with private transaction do
+
   // withP private transaction do
 
   //
 
   //
 
   old := ClassManager.NewTransContext;
 
   old := ClassManager.NewTransContext;
Ligne 77 : Ligne 77 :
 
var inst:WFClasseB;
 
var inst:WFClasseB;
 
begin
 
begin
   with private Transaction do
+
   withP private Transaction do
 
   for var idx:=1 to 100 do
 
   for var idx:=1 to 100 do
 
     begin
 
     begin
Ligne 87 : Ligne 87 :
 
</source>
 
</source>
  
===with long transaction do===
+
===withP long transaction do===
 
Ce pattern gère une transaction longue.
 
Ce pattern gère une transaction longue.
  
Ligne 129 : Ligne 129 :
 
</source>
 
</source>
  
===with private long transaction do===
+
===withP private long transaction do===
 
Ce pattern gère une transaction longue privé.
 
Ce pattern gère une transaction longue privé.
  
Ligne 136 : Ligne 136 :
 
<source lang="delphi">
 
<source lang="delphi">
 
begin
 
begin
   // with private long(batchSize) transaction do
+
   // with privateP long(batchSize) transaction do
 
   //
 
   //
 
   old := ClassManager.NewTransContext;
 
   old := ClassManager.NewTransContext;

Version du 15 septembre 2011 à 15:51

Le pattern transaction permet d'encapsuler une transaction.

Sommaire

withP transaction do

Ce pattern gère une transaction.

Le code généré par ce pattern est le suivant :

begin
  // with transaction do
  //
  ClassManager.BeginTran;
  try
    //
    glbWorkerPool.BeginParallel;
    try
      h.RunAnonymous(f.sAEntry);
    finally
    glbWorkerPool.EndParallel;
    end;
    //
    ClassManager.Commit([]);
  except
  ClassManager.RollBack;
  raise;
  end;
end;

Exemple d'utilisation :

begin
  // Create an instance
  withP transaction do 
   begin
     inst := MyClass.Create;
     inst.Caption := 'A new instance';
   end;
end;

withP private transaction do

Ce pattern gère une transaction privée.

Le code généré par le pattern est le suivant :

begin
  // withP private transaction do
  //
  old := ClassManager.NewTransContext;
  try
    ClassManager.BeginTran;
    try
      glbWorkerPool.BeginParallel;
      try
        h.RunAnonymous(f.sAEntry);
      finally
      glbWorkerPool.EndParallel;
      end;
      //
      ClassManager.Commit([]);
    except
    ClassManager.RollBack;
    raise;
    end;
  finally
  ClassManager.ActivateContext(old);
  end;
end;

Exemple d'utilisation :

var inst:WFClasseB;
begin
  withP private Transaction do
   for var idx:=1 to 100 do
    begin
     inst := WFClasseB.Create;
     inst.unCode := 'B'+inttostr(index);
     inst.Caption := 'Objet B'+inttostr(index);
    end;
end;

withP long transaction do

Ce pattern gère une transaction longue.

Le code généré par ce pattern est le suivant :

begin
  // with long(batchSize) transaction do
  //
  ClassManager.BeginLongTran(batchSize);
  if batchSize>0 then
   begin
     ClassManager.CurrentTran.AutoBatch := True;
     ClassManager.CurrentTran.AutoBatchOptions := [coDontShowEngineError];
   end;
  try
    {$IFDEF PARALLEL}
    glbWorkerPool.BeginParallel;
    try
    {$ENDIF}
      h.RunAnonymous(f.sAEntry);
    {$IFDEF PARALLEL}
    finally
    if not glbWorkerPool.EndParallel(E) then raise E;
    end;
    {$ENDIF}
 
    ClassManager.CommitLongTran([coDontShowEngineError,coNoConfirmDialog]);
  except
  ClassManager.RollBackLongTran;
  raise;
  end;
end;

Exemple d'utilisation :

begin
end;

withP private long transaction do

Ce pattern gère une transaction longue privé.

Le code généré par ce pattern est le suivant :

begin
  // with privateP long(batchSize) transaction do
  //
  old := ClassManager.NewTransContext;
  try
    ClassManager.BeginLongTran(batchSize);
    if batchSize>0 then
     begin
       ClassManager.CurrentTran.AutoBatch := True;
       ClassManager.CurrentTran.AutoBatchOptions := [coDontShowEngineError];
     end;
    try
      {$IFDEF PARALLEL}
      glbWorkerPool.BeginParallel;
      try
      {$ENDIF}
        h.RunAnonymous(f.sAEntry);
      {$IFDEF PARALLEL}
      finally
      if not glbWorkerPool.EndParallel(E) then raise E;
      end;
      {$ENDIF}
      //
      ClassManager.CommitLongTran([coDontShowEngineError,coNoConfirmDialog]);
    except
    ClassManager.RollBackLongTran;
    raise;
    end;
  finally
  ClassManager.ActivateContext(old);
  end;
end;

Exemple d'utilisation :

begin
end;




Whos here now:   Members 0   Guests 0   Bots & Crawlers 2
 
Outils personnels