DropSchemaCmd.hpp 3.41 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/*
 * The CERN Tape Archive (CTA) project
 * Copyright (C) 2015  CERN
 *
 * 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.
 *
 * 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.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#pragma once

#include "catalogue/Catalogue.hpp"
#include "catalogue/CmdLineTool.hpp"
#include "rdbms/Conn.hpp"
#include "rdbms/Login.hpp"
25
#include "rdbms/OcciConn.hpp"
26
27
28
29
30

namespace cta {
namespace catalogue {

/**
31
 * Command-line tool that drops the schema of the catalogue database.
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
 */
class DropSchemaCmd: public CmdLineTool {
public:

  /**
   * Constructor.
   *
   * @param inStream Standard input stream.
   * @param outStream Standard output stream.
   * @param errStream Standard error stream.
   */
  DropSchemaCmd(std::istream &inStream, std::ostream &outStream, std::ostream &errStream);

  /**
   * Destructor.
   */
  ~DropSchemaCmd() noexcept;

50
51
private:

52
53
54
55
56
57
58
  /**
   * An exception throwing version of main().
   *
   * @param argc The number of command-line arguments including the program name.
   * @param argv The command-line arguments.
   * @return The exit value of the program.
   */
59
  int exceptionThrowingMain(const int argc, char *const *const argv) override;
60

61
62
63
64
65
66
  /**
   * Prints the usage message of the command-line tool.
   *
   * @param os The output stream to which the usage message is to be printed.
   */
  void printUsage(std::ostream &os) override;
67

68
69
70
71
72
73
74
75
76
  /**
   * Asks the user to confirm that they want to drop the schema of the catalogue
   * database.
   *
   * @param dbLogin The database login.
   * @return True if the user confirmed.
   */
  bool userConfirmsDropOfSchema(const rdbms::Login &dbLogin);

77
78
  /**
   * Unconditionally drops the schema of the catalogue database associated with
79
   * the specified database connection.
80
   *
81
82
83
84
85
86
87
88
89
90
91
92
93
   * @param dbType The database type.
   * @param conn The database connection.
   */
  void dropCatalogueSchema(const rdbms::Login::DbType &dbType, rdbms::Conn &conn);

  /**
   * Unconditionally drops the schema of the catalogue database associated with
   * the specified database connection.
   *
   * @param conn The database connection.
   */
  void dropSqliteCatalogueSchema(rdbms::Conn &conn);

94
95
96
97
98
99
100
  /**
   * Drops the database tables with the specified names.
   *
   * @param tablesToDrop The names of the database tables to be dropped.
   */
  void dropDatabaseTables(rdbms::Conn &conn, const std::list<std::string> &tablesToDrop);

101
102
103
104
105
  /**
   * Unconditionally drops the schema of the catalogue database associated with
   * the specified database connection.
   *
   * @param conn The database connection.
106
   */
107
  void dropOracleCatalogueSchema(rdbms::Conn &conn);
108

109
110
111
112
113
114
115
  /**
   * Drops the database sequences with the specified names.
   *
   * @param seqeuncesToDrop The names of the database sequences to be dropped.
   */
  void dropDatabaseSequences(rdbms::OcciConn &conn, const std::list<std::string> &sequencesToDrop);

116
117
118
119
}; // class DropSchemaCmd

} // namespace catalogue
} // namespace cta