LSSTApplications  10.0-2-g4f67435,11.0.rc2+1,11.0.rc2+12,11.0.rc2+3,11.0.rc2+4,11.0.rc2+5,11.0.rc2+6,11.0.rc2+7,11.0.rc2+8
LSSTDataManagementBasePackage
DbStorageLocation.cc
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
2 
3 /*
4  * LSST Data Management System
5  * Copyright 2008, 2009, 2010 LSST Corporation.
6  *
7  * This product includes software developed by the
8  * LSST Project (http://www.lsst.org/).
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the LSST License Statement and
21  * the GNU General Public License along with this program. If not,
22  * see <http://www.lsstcorp.org/LegalNotices/>.
23  */
24 
25 
37 #ifndef __GNUC__
38 # define __attribute__(x) /*NOTHING*/
39 #endif
40 static char const* SVNid __attribute__((unused)) = "$Id$";
41 
43 
44 #include <boost/regex.hpp>
45 
46 #include "lsst/pex/exceptions.h"
48 
49 namespace lsst {
50 namespace daf {
51 namespace persistence {
52 
56  lsst::daf::base::Citizen(typeid(*this)),
57  _dbType(), _hostname(), _port(), _username(), _password(), _dbName() {
58 }
59 
64 DbStorageLocation::DbStorageLocation(std::string const& url) :
65  lsst::daf::base::Citizen(typeid(*this)) {
66  boost::smatch what;
67  boost::regex
68  expression("(\\w+)://(\\S+):(\\d+)/(\\S+)");
69  if (boost::regex_match(url, what, expression)) {
70  _dbType = what[1];
71  _hostname = what[2];
72  _port = what[3];
73  _dbName = what[4];
76  }
77  else {
78  throw LSST_EXCEPT(lsst::pex::exceptions::InvalidParameterError,
79  "Unparseable connection string passed to DbStorageLocation: " +
80  url);
81  }
82 }
83 
87 }
88 
92 std::string DbStorageLocation::toString(void) const {
93  return _dbType + "://" + _username + ":" + _password + "@" +
94  _hostname + ":" + _port + "/" + _dbName;
95 }
96 
101 std::string DbStorageLocation::getConnString(void) const {
102  return _dbType + "://" + _hostname + ":" + _port + "/" + _dbName;
103 }
104 
108 std::string const& DbStorageLocation::getDbType(void) const {
109  return _dbType;
110 }
111 
115 std::string const& DbStorageLocation::getHostname(void) const {
116  return _hostname;
117 }
118 
122 std::string const& DbStorageLocation::getPort(void) const {
123  return _port;
124 }
125 
129 std::string const& DbStorageLocation::getUsername(void) const {
130  return _username;
131 }
132 
136 std::string const& DbStorageLocation::getPassword(void) const {
137  return _password;
138 }
139 
143 std::string const& DbStorageLocation::getDbName(void) const {
144  return _dbName;
145 }
146 
147 }}} // namespace lsst::daf::persistence
Interface for DbAuth class.
virtual std::string toString(void) const
std::string _dbType
Database type (e.g. &quot;mysql&quot;).
#define __attribute__(x)
virtual std::string const & getPort(void) const
virtual std::string const & getDbType(void) const
virtual std::string getConnString(void) const
virtual std::string const & getPassword(void) const
virtual std::string const & getHostname(void) const
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
static std::string username(std::string const &host, std::string const &port)
Definition: DbAuth.cc:158
static std::string password(std::string const &host, std::string const &port)
Definition: DbAuth.cc:169
std::string _dbName
Database (not server) name.
virtual std::string const & getDbName(void) const
virtual std::string const & getUsername(void) const
Include files required for standard LSST Exception handling.
Interface for DbStorageLocation class.