21 #include "../core/translator/Translator.h" 22 #include "../core/uri/URI.h" 23 #include "../core/uri/Utils.h" 32 #include <terralib4/kernel/TeDatabase.h> 33 #include <terralib4/kernel/TeDatabaseFactory.h> 34 #include <terralib4/kernel/TeDatabaseFactoryParams.h> 35 #include <terralib4/kernel/TeDBConnectionsPool.h> 36 #include <terralib4/kernel/TeDefines.h> 37 #include <terralib4/kernel/TeTheme.h> 38 #include <terralib4/utils/TeUpdateDBVersion.h> 41 #include <boost/algorithm/string/replace.hpp> 70 std::unique_ptr<te::da::DataSourceTransactor> t(
new Transactor(
this,
m_db));
79 throw te::da::Exception(
TE_TR(
"There is no valid information about the data source"));
82 std::map<std::string, std::string>::const_iterator it = kvp.begin();
83 std::map<std::string, std::string>::const_iterator itend = kvp.end();
84 std::string dbInfo, auxDbName;
86 it = kvp.find(
"T4_DRIVER");
87 if (it != itend && !it->second.empty())
90 throw te::da::Exception(
TE_TR(
"The connection information is invalid. Missing T4_DRIVER parameter!"));
95 boost::replace_all(auxDbName,
"file://",
"");
100 if (auxDbName.empty())
101 throw te::da::Exception(
TE_TR(
"The connection information is invalid. Missing the database name!"));
103 std::string hostName =
"";
104 std::string userName =
"";
105 std::string password =
"";
109 m_db = TeDBConnectionsPool::instance().getDatabase(dbInfo, auxDbName, hostName, userName,
110 password, portNumber);
112 if(!
m_db->isConnected())
114 if(!
m_db->connect(hostName, userName, password, auxDbName, portNumber))
115 throw te::da::Exception(
TE_TR(
"Could not connect to informed database!"));
119 if(needUpdateDB(
m_db, DBver))
121 std::string dbVersion = TeDBVERSION;
123 if(isLowerVersion(dbVersion, DBver))
127 throw te::da::Exception(
TE_TR(
"Cannot connect to database because the version of Terraview is lower than the version of the database!"));
132 throw te::da::Exception(
TE_TR(
"The database must be converted to the model ") + dbVersion +
"! \n");
135 m_db->loadLayerSet();
167 throw Exception(
TE_TR(
"This driver is read-only!"));
172 throw Exception(
TE_TR(
"This driver is read-only!"));
180 return std::find(dbnames.begin(), dbnames.end(), kvp[
"T4_DB_NAME"]) != dbnames.end();
187 std::unique_ptr<TeDatabase> db(TeDatabaseFactory::make(*params.get()));
189 std::vector<std::string> dbnames;
191 db->showDatabases(params->host_, params->user_, params->password_, dbnames, params->port_);
203 std::vector<std::string> layers;
205 std::unique_ptr<te::da::DataSourceTransactor> t =
getTransactor();
215 std::vector<std::string> tables;
217 std::unique_ptr<te::da::DataSourceTransactor> t =
getTransactor();
227 std::vector<std::string>
rasters;
229 std::unique_ptr<te::da::DataSourceTransactor> t =
getTransactor();
239 std::vector<std::pair<std::string, std::string> >
rasters;
241 std::unique_ptr<te::da::DataSourceTransactor> t =
getTransactor();
251 std::vector<::terralib4::ThemeInfo> themes;
253 std::unique_ptr<te::da::DataSourceTransactor> t =
getTransactor();
263 TeTheme* tl4Theme = 0;
265 std::unique_ptr<te::da::DataSourceTransactor> t =
getTransactor();
275 std::unique_ptr<te::da::DataSourceTransactor> t =
getTransactor();
std::unique_ptr< TeDatabaseFactoryParams > Convert2T4DatabaseParams(const std::string &dsInfo)
It converts a data source information to a TerraLib 4.x database params.
std::vector< std::string > getTL4Rasters()
void create(const std::string &dsInfo)
It creates a new data source.
std::string path() const
Retrieving the path.
#define TERRALIB4_DRIVER_IDENTIFIER
The Terralib 4 driver identifier string.
void open()
It opens the data source and makes it ready for using.
std::vector< std::pair< std::string, std::string > > getTL4RasterFiles()
std::vector< std::string > getDataSourceNames(const std::string &dsInfo)
It gets the data source names available in a driver.
std::string getType() const
It returns the data source type name (in UPPER CASE). Ex: POSTGIS, SQLITE, WFS, WMS, or MYSQL.
std::vector< std::string > getTL4Rasters()
It represents the SQL query dialect accepted by a given data source.
static te::da::DataSourceCapabilities sm_capabilities
A class that represents the known capabilities of a specific data source, i.e. this class informs all...
bool isValid() const
Return if the given URI is valid or not.
#define TE_TR(message)
It marks a string in order to get translated.
std::vector< std::string > getTL4Tables()
bool isValid() const
It checks if the data source is valid (available for using).
std::string query() const
Retrieving the query.
The basic information about a Terralib 4.x Theme.
bool isOpened() const
It returns true if the data source is opened, otherwise it returns false.
const te::da::SQLDialect * getDialect() const
It returns the data source SQL dialect, if there is one.
Implements the DataSource class for the TerraLib 4.x Data Access Driver.
TeTheme * getTL4Theme(const ::terralib4::ThemeInfo &theme)
TeDatabase * getTerralib4Db()
DataSource(const std::string &connInfo)
std::vector< std::pair< std::string, std::string > > getTL4RasterFiles()
std::vector< std::string > getTL4Tables()
const std::string & uri() const
Retrieving the full URI.
void drop(const std::string &dsInfo)
It removes the data source with the connection information from a driver.
TETERRALIB4EXPORT std::string Convert2Latin1(const std::string &str)
bool exists(const std::string &dsInfo)
Check the existence of a data source in a driver.
A class for representing an Uniform Resource Identifier (URI).
std::vector<::terralib4::ThemeInfo > getTL4Themes()
static te::da::SQLDialect * sm_dialect
int getLayerSRID(const std::string &layerName)
This file contains utility functions used to manipulate data from a URI.
DataSourceTransactor implementation for TerraLib 4.x API.
te::core::URI m_uri
The URI used to describe the datasource connection;.
TECOREEXPORT std::map< std::string, std::string > Expand(const std::string &query_str)
Split a query string into its components.
const te::da::DataSourceCapabilities & getCapabilities() const
It returns the known capabilities of the data source.
int getLayerSRID(const std::string &layerName)
TeTheme * getTL4Theme(const ::terralib4::ThemeInfo &theme)
void close()
It closes the data source and clears all the resources used by its internal communication channel...
TECOREEXPORT std::string URIDecode(const std::string &srcUri)
Decodes an encoded URI. The algorithm implementation is based on http://www.codeguru.com/cpp/cpp/algorithms/strings/article.php/c12759/URI-Encoding-and-Decoding.htm.
std::vector< std::string > getTL4Layers()
~DataSource()
Virtual destructor.
std::unique_ptr< te::da::DataSourceTransactor > getTransactor()
It returns the set of parameters used to set up the access channel to the underlying repository...
std::vector<::terralib4::ThemeInfo > getTL4Themes()
std::vector< std::string > getTL4Layers()
Configuration flags for the TerraLib 4 driver.