text
stringlengths
0
234
-- ------------------------------
-- Increment the counter identified by <tt>Counter</tt>.
-- ------------------------------
procedure Increment (Plugin : in out Counter_Module;
Counter : in Counter_Index_Type) is
Key : ADO.Objects.Object_Key (ADO.Objects.KEY_INTEGER, null);
begin
if Plugin.Counters.Need_Flush (Plugin.Counter_Limit, Plugin.Age_Limit) then
Plugin.Flush;
end if;
Plugin.Counters.Increment (Counter, Key);
end Increment;
-- ------------------------------
-- Get the current counter value.
-- ------------------------------
procedure Get_Counter (Plugin : in out Counter_Module;
Counter : in AWA.Counters.Counter_Index_Type;
Object : in ADO.Objects.Object_Ref'Class;
Result : out Natural) is
Id : constant ADO.Identifier := ADO.Objects.Get_Value (Object.Get_Key);
DB : ADO.Sessions.Master_Session := Plugin.Get_Master_Session;
Stmt : ADO.Statements.Query_Statement
:= DB.Create_Statement ("SELECT SUM(counter) FROM awa_counter WHERE "
& "object_id = :id AND definition_id = :definition_id");
Def_Id : Natural;
begin
Plugin.Counters.Get_Definition (DB, Counter, Def_Id);
Stmt.Bind_Param ("id", Id);
Stmt.Bind_Param ("definition_id", Def_Id);
Stmt.Execute;
Result := Stmt.Get_Result_Integer;
end Get_Counter;
protected body Counter_Table is
-- ------------------------------
-- Increment the counter identified by <tt>Counter</tt> and associated with the
-- database object <tt>Key</tt>.
-- ------------------------------
procedure Increment (Counter : in Counter_Index_Type;
Key : in ADO.Objects.Object_Key) is
procedure Increment (Key : in ADO.Objects.Object_Key;
Element : in out Positive);
procedure Increment (Key : in ADO.Objects.Object_Key;
Element : in out Positive) is
pragma Unreferenced (Key);
begin
Element := Element + 1;
end Increment;
Pos : Counter_Maps.Cursor;
begin
if Counters = null then
Counters := new Counter_Map_Array (1 .. Counter_Arrays.Get_Last);
Day := Ada.Calendar.Clock;
Day_End := Util.Dates.Get_Day_End (Day);
end if;
Pos := Counters (Counter).Find (Key);
if Counter_Maps.Has_Element (Pos) then
Counters (Counter).Update_Element (Pos, Increment'Access);
else
Counters (Counter).Insert (Key, 1);
Nb_Counters := Nb_Counters + 1;
end if;
end Increment;
-- ------------------------------
-- Get the counters that have been collected with the date and prepare to collect
-- new counters.
-- ------------------------------
procedure Steal_Counters (Result : out Counter_Map_Array_Access;
Date : out Ada.Calendar.Time) is
begin
Result := Counters;
Date := Day;
Counters := null;
Nb_Counters := 0;
end Steal_Counters;
-- ------------------------------
-- Check if we must flush the counters.
-- ------------------------------
function Need_Flush (Limit : in Natural;
Seconds : in Duration) return Boolean is
use type Ada.Calendar.Time;
begin
if Counters = null then
return False;
elsif Nb_Counters > Limit then
return True;
else
declare
Now : constant Ada.Calendar.Time := Ada.Calendar.Clock;
begin
return Now > Day_End or Now - Day >= Seconds;
Function Definition: procedure Free is new