DatabaseStatisticsService.hpp 2.97 KB
Newer Older
1
/*
2
 * @project        The CERN Tape Archive (CTA)
3
 * @copyright      Copyright(C) 2015-2021 CERN
4
5
6
7
 * @license        This program is free software: you can redistribute it and/or modify
 *                 it under the terms of the GNU General Public License as published by
 *                 the Free Software Foundation, either version 3 of the License, or
 *                 (at your option) any later version.
8
 *
9
10
11
12
 *                 This program is distributed in the hope that it will be useful,
 *                 but WITHOUT ANY WARRANTY; without even the implied warranty of
 *                 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *                 GNU General Public License for more details.
13
 *
14
15
 *                 You should have received a copy of the GNU General Public License
 *                 along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
 */
17

18
19
20
21
#pragma once

#include "rdbms/Conn.hpp"
#include "rdbms/Login.hpp"
22
#include "Statistics.hpp"
23
#include "StatisticsService.hpp"
24

25
26
namespace cta { namespace statistics {
  
Cedric Caffy's avatar
Cedric Caffy committed
27
28
29
30
31
32
/**
 * Database statistics service that perform statistics operations
 * with a database backend
 * This class can be extended in order to execute database-specific SQL queries if needed
 * @param databaseConnection the database connection used by the service to perform statistics operations
 */
33
class DatabaseStatisticsService: public StatisticsService {
34
public:
Cedric Caffy's avatar
Cedric Caffy committed
35
36
37
38
  /**
   * Constructor
   * @param databaseConnection the database connection that will be used by this service
   */
39
40
41
42
43
  DatabaseStatisticsService(cta::rdbms::Conn &databaseConnection);
  DatabaseStatisticsService(const DatabaseStatisticsService& orig) = delete;
  DatabaseStatisticsService & operator=(const DatabaseStatisticsService &) = delete;
  virtual ~DatabaseStatisticsService();
  
Cedric Caffy's avatar
Cedric Caffy committed
44
45
46
47
48
49
50
51
52
  /**
   * Update the per-Tape statistics in the database used by this service
   */
  virtual void updateStatisticsPerTape() override;
  
  /**
   * Saves the statistics in the service database
   * @param statistics the statistics to save in the database used by this service
   */
53
  virtual void saveStatistics(const cta::statistics::Statistics &statistics) override;
Cedric Caffy's avatar
Cedric Caffy committed
54
55
56
57
58
  
  /**
   * Returns the statistics from the service database
   * @return the Statistics object that will contain the statistics retrieved from the database used by this service
   */
59
  virtual std::unique_ptr<cta::statistics::Statistics> getStatistics() override;
Cedric Caffy's avatar
Cedric Caffy committed
60
  
61
protected:
Cedric Caffy's avatar
Cedric Caffy committed
62
63
64
  /**
   * The database connection of the database that will be used by the service 
   */
65
  cta::rdbms::Conn & m_conn;
Cedric Caffy's avatar
Cedric Caffy committed
66
67
68
69
70
  
  /**
   * Saves the total file statistics in the database used by this service 
   * @param statistics the statistics to save
   */
71
  virtual void saveFileStatistics(const cta::statistics::Statistics & statistics);
Cedric Caffy's avatar
Cedric Caffy committed
72
73
74
75
76
  
  /**
   * Saves the per-VO statistics in the database used by this service
   * @param statistics the statistics to save
   */
77
  virtual void saveStatisticsPerVo(const cta::statistics::Statistics & statistics);
78
79
};

80
}}
81