Auto initialization for all DB back-ends and some tidy-up for network
windows auto initialization
This commit is contained in:
aleks-f 2013-02-10 09:06:54 -06:00
Родитель c7cb7e4498
Коммит 4bcddad43e
7 изменённых файлов: 149 добавлений и 28 удалений

Просмотреть файл

@ -44,6 +44,12 @@
#include "Poco/Data/Connector.h"
// Note: to avoid static (de)initialization problems,
// during connector automatic (un)registration, it is
// best to have this as a macro.
#define POCO_DATA_MYSQL_CONNECTOR_NAME "mysql"
namespace Poco {
namespace Data {
namespace MySQL {
@ -80,4 +86,55 @@ public:
} } } // namespace Poco::Data::MySQL
//
// Automatic Connector registration
//
struct MySQL_API MySQLConnectorRegistrator
/// Connector registering class.
/// A global instance of this class is instantiated
/// with sole purpose to automatically register the
/// MySQL connector with central Poco Data registry.
{
MySQLConnectorRegistrator()
/// Calls Poco::Data::MySQL::registerConnector();
{
Poco::Data::MySQL::Connector::registerConnector();
}
~MySQLConnectorRegistrator()
/// Calls Poco::Data::MySQL::unregisterConnector();
{
Poco::Data::MySQL::Connector::unregisterConnector();
}
};
#if !defined(POCO_NO_AUTOMATIC_LIB_INIT)
#if defined(POCO_OS_FAMILY_WINDOWS)
extern "C" const struct MySQL_API MySQLConnectorRegistrator pocoMySQLConnectorRegistrator;
#if defined(MySQL_EXPORTS)
#if defined(_WIN64)
#define POCO_DATA_MYSQL_FORCE_SYMBOL(s) __pragma(comment (linker, "/export:"#s))
#elif defined(_WIN32)
#define POCO_DATA_MYSQL_FORCE_SYMBOL(s) __pragma(comment (linker, "/export:_"#s))
#endif
#else // !MySQL_EXPORTS
#if defined(_WIN64)
#define POCO_DATA_MYSQL_FORCE_SYMBOL(s) __pragma(comment (linker, "/include:"#s))
#elif defined(_WIN32)
#define POCO_DATA_MYSQL_FORCE_SYMBOL(s) __pragma(comment (linker, "/include:_"#s))
#endif
#endif // MySQL_EXPORTS
#else // !POCO_OS_FAMILY_WINDOWS
#define POCO_DATA_MYSQL_FORCE_SYMBOL(s) extern "C" const struct MySQLConnectorRegistrator s;
#endif // POCO_OS_FAMILY_WINDOWS
POCO_DATA_MYSQL_FORCE_SYMBOL(pocoMySQLConnectorRegistrator)
#endif // POCO_NO_AUTOMATIC_LIB_INIT
//
// End automatic Connector registration
//
#endif // Data_MySQL_Connector_INCLUDED

Просмотреть файл

@ -38,16 +38,18 @@
#include "Poco/Data/MySQL/SessionImpl.h"
#include "Poco/Data/SessionFactory.h"
#include "Poco/Exception.h"
#include <mysql.h>
const MySQLConnectorRegistrator pocoMySQLConnectorRegistrator;
namespace Poco {
namespace Data {
namespace MySQL {
std::string Connector::KEY("mysql");
std::string Connector::KEY(POCO_DATA_MYSQL_CONNECTOR_NAME);
Connector::Connector()
@ -61,7 +63,8 @@ Connector::~Connector()
const std::string& Connector::name() const
{
return KEY;
static const std::string n(POCO_DATA_MYSQL_CONNECTOR_NAME);
return n;
}
Poco::AutoPtr<Poco::Data::SessionImpl> Connector::createSession(const std::string& connectionString,
@ -84,7 +87,7 @@ void Connector::registerConnector()
void Connector::unregisterConnector()
{
Poco::Data::SessionFactory::instance().remove(KEY);
Poco::Data::SessionFactory::instance().remove(POCO_DATA_MYSQL_CONNECTOR_NAME);
mysql_library_end();
}

Просмотреть файл

@ -44,6 +44,12 @@
#include "Poco/Data/Connector.h"
// Note: to avoid static (de)initialization problems,
// during connector automatic (un)registration, it is
// best to have this as a macro.
#define POCO_DATA_ODBC_CONNECTOR_NAME "odbc"
namespace Poco {
namespace Data {
namespace ODBC {
@ -83,11 +89,63 @@ public:
inline const std::string& Connector::name() const
{
return KEY;
static const std::string n(POCO_DATA_ODBC_CONNECTOR_NAME);
return n;
}
} } } // namespace Poco::Data::ODBC
//
// Automatic Connector registration
//
struct ODBC_API ODBCConnectorRegistrator
/// Connector registering class.
/// A global instance of this class is instantiated
/// with sole purpose to automatically register the
/// ODBC connector with central Poco Data registry.
{
ODBCConnectorRegistrator()
/// Calls Poco::Data::ODBC::registerConnector();
{
Poco::Data::ODBC::Connector::registerConnector();
}
~ODBCConnectorRegistrator()
/// Calls Poco::Data::ODBC::unregisterConnector();
{
Poco::Data::ODBC::Connector::unregisterConnector();
}
};
#if !defined(POCO_NO_AUTOMATIC_LIB_INIT)
#if defined(POCO_OS_FAMILY_WINDOWS)
extern "C" const struct ODBC_API ODBCConnectorRegistrator pocoODBCConnectorRegistrator;
#if defined(ODBC_EXPORTS)
#if defined(_WIN64)
#define POCO_DATA_ODBC_FORCE_SYMBOL(s) __pragma(comment (linker, "/export:"#s))
#elif defined(_WIN32)
#define POCO_DATA_ODBC_FORCE_SYMBOL(s) __pragma(comment (linker, "/export:_"#s))
#endif
#else // !ODBC_EXPORTS
#if defined(_WIN64)
#define POCO_DATA_ODBC_FORCE_SYMBOL(s) __pragma(comment (linker, "/include:"#s))
#elif defined(_WIN32)
#define POCO_DATA_ODBC_FORCE_SYMBOL(s) __pragma(comment (linker, "/include:_"#s))
#endif
#endif // ODBC_EXPORTS
#else // !POCO_OS_FAMILY_WINDOWS
#define POCO_DATA_ODBC_FORCE_SYMBOL(s) extern "C" const struct ODBCConnectorRegistrator s;
#endif // POCO_OS_FAMILY_WINDOWS
POCO_DATA_ODBC_FORCE_SYMBOL(pocoODBCConnectorRegistrator)
#endif // POCO_NO_AUTOMATIC_LIB_INIT
//
// End automatic Connector registration
//
#endif // Data_ODBC_Connector_INCLUDED

Просмотреть файл

@ -39,12 +39,15 @@
#include "Poco/Data/SessionFactory.h"
const ODBCConnectorRegistrator pocoODBCConnectorRegistrator;
namespace Poco {
namespace Data {
namespace ODBC {
const std::string Connector::KEY("odbc");
const std::string Connector::KEY(POCO_DATA_ODBC_CONNECTOR_NAME);
Connector::Connector()
@ -72,7 +75,7 @@ void Connector::registerConnector()
void Connector::unregisterConnector()
{
Poco::Data::SessionFactory::instance().remove(KEY);
Poco::Data::SessionFactory::instance().remove(POCO_DATA_ODBC_CONNECTOR_NAME);
}

Просмотреть файл

@ -1313,7 +1313,6 @@ ODBCTest::SessionPtr ODBCTest::init(const std::string& driver,
Utility::drivers(_drivers);
if (!canConnect(driver, dsn, uid, pwd, dbConnString, db)) return 0;
Poco::Data::ODBC::Connector::registerConnector();
try
{
std::cout << "Conecting to [" << dbConnString << ']' << std::endl;

Просмотреть файл

@ -97,8 +97,8 @@ public:
///
inline const std::string& Connector::name() const
{
static const std::string name(POCO_DATA_SQLITE_CONNECTOR_NAME);
return name;
static const std::string n(POCO_DATA_SQLITE_CONNECTOR_NAME);
return n;
}
@ -138,14 +138,14 @@ struct SQLite_API SQLiteConnectorRegistrator
#elif defined(_WIN32)
#define POCO_DATA_SQLITE_FORCE_SYMBOL(s) __pragma(comment (linker, "/export:_"#s))
#endif
#else // SQLite_EXPORTS
#else // !SQLite_EXPORTS
#if defined(_WIN64)
#define POCO_DATA_SQLITE_FORCE_SYMBOL(s) __pragma(comment (linker, "/include:"#s))
#elif defined(_WIN32)
#define POCO_DATA_SQLITE_FORCE_SYMBOL(s) __pragma(comment (linker, "/include:_"#s))
#endif
#endif // SQLite_EXPORTS
#else // !POCO_OS_FAMILY_WINDOWS
#else // !POCO_OS_FAMILY_WINDOWS
#define POCO_DATA_SQLITE_FORCE_SYMBOL(s) extern "C" const struct SQLiteConnectorRegistrator s;
#endif // POCO_OS_FAMILY_WINDOWS
POCO_DATA_SQLITE_FORCE_SYMBOL(pocoSQLiteConnectorRegistrator)

Просмотреть файл

@ -67,24 +67,25 @@ void Net_API uninitializeNetwork()
} } // namespace Poco::Net
struct NetworkInitializer
/// Network initializer for windows statically
/// linked library.
{
NetworkInitializer()
/// Calls Poco::Net::initializeNetwork();
#if defined(POCO_OS_FAMILY_WINDOWS) && !defined(POCO_NO_AUTOMATIC_LIB_INIT)
struct NetworkInitializer
/// Network initializer for windows statically
/// linked library.
{
Poco::Net::initializeNetwork();
}
NetworkInitializer()
/// Calls Poco::Net::initializeNetwork();
{
Poco::Net::initializeNetwork();
}
~NetworkInitializer()
/// Calls Poco::Net::uninitializeNetwork();
{
Poco::Net::uninitializeNetwork();
}
};
~NetworkInitializer()
/// Calls Poco::Net::uninitializeNetwork();
{
Poco::Net::uninitializeNetwork();
}
};
#ifndef POCO_NO_AUTOMATIC_LIB_INIT
const NetworkInitializer pocoNetworkInitializer;
#endif