21 #include "../common/Translator.h"
29 #include <terralib/kernel/TeDatabase.h>
30 #include <terralib/kernel/TeDatabaseFactory.h>
31 #include <terralib/kernel/TeDatabaseFactoryParams.h>
32 #include <terralib/kernel/TeDBConnectionsPool.h>
33 #include <terralib/kernel/TeDefines.h>
34 #include <terralib/utils/TeUpdateDBVersion.h>
66 std::auto_ptr<te::da::DataSourceTransactor> t(
new Transactor(
this, m_db));
74 std::string dbInfo = m_dbInfo.at(
"T4_DRIVER");
75 std::string auxDbName = m_dbInfo.at(
"T4_DB_NAME");
76 std::string hostName =
"";
77 std::string userName =
"";
78 std::string password =
"";
82 m_db = TeDBConnectionsPool::instance().getDatabase(dbInfo, auxDbName, hostName, userName,
83 password, portNumber);
85 if(!m_db->isConnected())
87 if(!m_db->connect(hostName, userName, password, auxDbName, portNumber))
88 throw te::da::Exception(
TR_TERRALIB4(
"Could not connect to informed database!"));
92 if(needUpdateDB(m_db, DBver))
94 std::string dbVersion = TeDBVERSION;
96 if(isLowerVersion(dbVersion, DBver))
100 throw te::da::Exception(
TR_TERRALIB4(
"Cannot connect to database because the version of Terraview is lower than the version of the database!"));
105 throw te::da::Exception(
TR_TERRALIB4(
"The database must be converted to the model ") + dbVersion +
"! \n");
128 return sm_capabilities;
138 throw Exception(
TR_TERRALIB4(
"This driver is read-only!"));
143 throw Exception(
TR_TERRALIB4(
"This driver is read-only!"));
148 std::vector<string> dbnames = getDataSourceNames(dsInfo);
150 return std::find(dbnames.begin(), dbnames.end(), dsInfo.at(
"T4_DB_NAME")) != dbnames.end();
157 std::auto_ptr<TeDatabase> db(TeDatabaseFactory::make(*params.get()));
159 std::vector<std::string> dbnames;
161 db->showDatabases(params->host_, params->user_, params->password_, dbnames, params->port_);
170 std::auto_ptr<TeDatabase> db(TeDatabaseFactory::make(*params.get()));
172 std::vector<std::string> encodings;
174 db->getEncodingList(encodings);
std::auto_ptr< te::da::DataSourceTransactor > getTransactor()
It returns an object that can execute transactions in the context of a data source.
bool isValid() const
It checks if the data source is valid (available for using).
DataSourceTransactor implementation for TerraLib 4.x API.
void create(const std::map< std::string, std::string > &dsInfo)
It creates a new data source.
#define TR_TERRALIB4(message)
It marks a string in order to get translated. This is a special mark used in the DataAccess module of...
~DataSource()
Virtual destructor.
const te::da::SQLDialect * getDialect() const
It returns the data source SQL dialect, if there is one.
std::string getType() const
It returns the data source type name (in UPPER CASE). Ex: POSTGIS, SQLITE, WFS, WMS, or MYSQL.
const std::map< std::string, std::string > & getConnectionInfo() const
It returns the set of parameters used to set up the access channel to the underlying repository...
TeDatabase * getTerralib4Db()
static te::da::SQLDialect * sm_dialect
std::auto_ptr< TeDatabaseFactoryParams > Convert2T4DatabaseParams(const std::map< std::string, std::string > &dsInfo)
It converts a data source information to a TerraLib 4.x database params.
A class that represents the known capabilities of a specific data source, i.e. this class informs all...
bool exists(const std::map< std::string, std::string > &dsInfo)
Check the existence of a data source in a driver.
void drop(const std::map< std::string, std::string > &dsInfo)
It removes the data source with the connection information from a driver.
std::vector< std::string > getEncodings(const std::map< std::string, std::string > &dsInfo)
It gets the encodings for the data source.
void setConnectionInfo(const std::map< std::string, std::string > &connInfo)
It sets the connection information to be used when connecting to the data source. ...
It represents the SQL query dialect accepted by a given data source.
static te::da::DataSourceCapabilities sm_capabilities
bool isOpened() const
It returns true if the data source is opened, otherwise it returns false.
Utilitary functions for dealing with TerraLib 5 and 4.x conversion.
void open()
It opens the data source and makes it ready for using.
Implements the DataSource class for the TerraLib 4.x Data Access Driver.
#define TERRALIB4_DRIVER_IDENTIFIER
The Terralib 4 driver identifier string.
Configuration flags for the TerraLib 4 driver.
std::vector< std::string > getDataSourceNames(const std::map< std::string, std::string > &dsInfo)
It gets the data source names available in a driver.
const te::da::DataSourceCapabilities & getCapabilities() const
It returns the known capabilities of the data source.
void close()
It closes the data source and clears all the resources used by its internal communication channel...