CatalogueFactory.cpp 2.08 KB
Newer Older
Steven Murray's avatar
Steven Murray committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/*
 * 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/>.
 */

#include "catalogue/CatalogueFactory.hpp"
20
21
#include "catalogue/InMemoryCatalogue.hpp"
#include "catalogue/OracleCatalogue.hpp"
22
#include "catalogue/SqliteCatalogue.hpp"
Steven Murray's avatar
Steven Murray committed
23
#include "common/exception/Exception.hpp"
24
#include "common/make_unique.hpp"
Steven Murray's avatar
Steven Murray committed
25
26
27
28
29
30
31

namespace cta {
namespace catalogue {

//------------------------------------------------------------------------------
// create
//------------------------------------------------------------------------------
32
std::unique_ptr<Catalogue> CatalogueFactory::create(const rdbms::Login &login, const uint64_t nbConns) {
Steven Murray's avatar
Steven Murray committed
33
  try {
34
35
    switch(login.dbType) {
    case rdbms::Login::DBTYPE_IN_MEMORY:
36
      return make_unique<InMemoryCatalogue>(nbConns);
37
    case rdbms::Login::DBTYPE_ORACLE:
38
      return make_unique<OracleCatalogue>(login.username, login.password, login.database, nbConns);
39
    case rdbms::Login::DBTYPE_SQLITE:
40
      return make_unique<SqliteCatalogue>(login.database, nbConns);
41
    case rdbms::Login::DBTYPE_NONE:
Steven Murray's avatar
Steven Murray committed
42
43
44
45
      throw exception::Exception("Cannot create a catalogue without a database type");
    default:
      {
        exception::Exception ex;
46
        ex.getMessage() << "Unknown database type: value=" << login.dbType;
Steven Murray's avatar
Steven Murray committed
47
48
49
50
51
52
53
54
55
56
        throw ex;
      }
    }
  } catch(exception::Exception &ex) {
    throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str());
  }
}

} // namespace catalogue
} // namespace cta