Guest User

Untitled

a guest
Feb 21st, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ada 1.86 KB | None | 0 0
  1. with gnatcoll.sql.Exec;
  2.  
  3.  
  4.  
  5. package body db_connection_pool
  6. is
  7.  
  8.  
  9.    DB_Description : GNATCOLL.SQL.Exec.Database_Description := GNATCOLL.SQL.Postgres.Setup
  10.                                                                 (Database      => "rod",
  11.                                                                  User          => "rod",
  12.                                                                  Host          => "localhost",
  13.                                                                  Password      => "secret",
  14.                                                                  SSL           => gnatColl.SQL.postgres.Prefer);
  15.  
  16.  
  17.    
  18.    protected body
  19.    safe_Connections
  20.    is
  21.       procedure fetch (new_Connection :     out gnatcoll.sql.Exec.Database_Connection)
  22.       is
  23.       begin
  24.          if next_Available > 0 then
  25.             new_Connection := Available (next_Available);   -- tbd: probly have to reset connection here, in case it's a new task ?
  26.             next_Available := next_Available - 1;
  27.          else
  28.             new_Connection := gnatcoll.sql.Exec.build_Connection (DB_Description);
  29.          end if;
  30.       end;
  31.      
  32.  
  33.  
  34.  
  35.       procedure free  (the_Connection : in      gnatcoll.sql.Exec.Database_Connection)
  36.       is
  37.       begin
  38.          next_Available             := next_Available + 1;
  39.          Available (next_Available) := the_Connection;
  40.       end;
  41.      
  42.    end safe_Connections;
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.    function  fetch return gnatcoll.sql.Exec.Database_Connection
  50.    is
  51.       new_Connection : gnatcoll.sql.Exec.Database_Connection;
  52.    begin
  53.       safe_Connections.fetch (new_Connection);
  54.      
  55.       return new_Connection;
  56.    end;
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.    procedure free (the_Connection : in gnatcoll.sql.Exec.Database_Connection)
  65.    is
  66.    begin
  67.       safe_Connections.free (the_Connection);
  68.    end;
  69.  
  70.  
  71.  
  72.  
  73. end db_connection_pool;
Add Comment
Please, Sign In to add comment