From e772b3efcd8a4f8638c45820a34d7cf8ab5514fc Mon Sep 17 00:00:00 2001 From: Marco De Marco <demarco@oats.inaf.it> Date: Fri, 6 Mar 2015 11:06:17 +0100 Subject: [PATCH] Select key and value substituted by where condition --- src/Configuration.h | 31 +++++++++++++------------------ src/DBManager.cpp | 8 +++----- src/DataImporter.cpp | 33 +++++++++------------------------ src/DataImporter.h | 6 ++---- src/DataImporter.xmi | 8 ++------ src/DataImporterClass.cpp | 17 ++--------------- 6 files changed, 31 insertions(+), 72 deletions(-) diff --git a/src/Configuration.h b/src/Configuration.h index 8a37bf1..0ba9b20 100644 --- a/src/Configuration.h +++ b/src/Configuration.h @@ -28,13 +28,13 @@ private: std::string auxDatabaseHost, unsigned int auxDatabasePort, std::string auxDatabaseUsername, std::string auxDatabasePassword, std::string auxDatabaseSchema, std::string auxDatabaseTimestampTable, - std::string auxDatabaseFailedTable, std::string selectKey, - std::string selectValue) : m_certificateFile (certificateFile), - m_storagePath(storagePath), m_remoteHost(remoteHost), - m_remotePort(remotePort), m_remoteUsername(remoteUsername), - m_remotePassword(remotePassword), m_databaseHost(databaseHost), - m_databasePort(databasePort), m_databaseUsername(databaseUsername), - m_databasePassword(databasePassword), m_databaseSchema(databaseSchema), + std::string auxDatabaseFailedTable, std::string whereCondition) : + m_certificateFile (certificateFile), m_storagePath(storagePath), + m_remoteHost(remoteHost), m_remotePort(remotePort), + m_remoteUsername(remoteUsername), m_remotePassword(remotePassword), + m_databaseHost(databaseHost), m_databasePort(databasePort), + m_databaseUsername(databaseUsername), + m_databasePassword(databasePassword), m_databaseSchema(databaseSchema), m_databaseTable(databaseTable), m_refreshTime(refreshTime), m_timeout(timeout), m_recoveryTime(recoveryTime), m_auxDatabaseHost(auxDatabaseHost), m_auxDatabasePort(auxDatabasePort), @@ -43,7 +43,7 @@ private: m_auxDatabaseSchema(auxDatabaseSchema), m_auxDatabaseTimestampTable(auxDatabaseTimestampTable), m_auxDatabaseFailedTable(auxDatabaseFailedTable), - m_selectKey(selectKey), m_selectValue(selectValue) { }; + m_whereCondition(whereCondition) { }; virtual ~Configuration() {} @@ -69,8 +69,7 @@ public: std::string auxDatabaseHost, unsigned int auxDatabasePort, std::string auxDatabaseUsername, std::string auxDatabasePassword, std::string auxDatabaseSchema, std::string auxDatabaseTimestampTable, - std::string auxDatabaseFailedTable, std::string selectKey, - std::string selectValue) + std::string auxDatabaseFailedTable, std::string whereCondition) { Configuration::SP c_sp(new Configuration(certificateFile, storagePath, remoteHost, remotePort, remoteUsername, remotePassword, databaseHost, @@ -78,7 +77,7 @@ public: databaseTable, refreshTime, timeout, recoveryTime, auxDatabaseHost, auxDatabasePort, auxDatabaseUsername, auxDatabasePassword, auxDatabaseSchema, auxDatabaseTimestampTable, auxDatabaseFailedTable, - selectKey, selectValue), Configuration::Deleter()); + whereCondition), Configuration::Deleter()); return c_sp; } @@ -108,8 +107,7 @@ public: std::string getAuxDatabaseSchema() const { return m_auxDatabaseSchema; } std::string getAuxDatabaseTimestampTable() const { return m_auxDatabaseTimestampTable; } std::string getAuxDatabaseFailedTable() const { return m_auxDatabaseFailedTable; } - std::string getSelectKey() const { return m_selectKey; } - std::string getSelectValue() const { return m_selectValue; } + std::string getWhereCondition() const { return m_whereCondition; } private: //------------------------------------------------------------------------------ @@ -181,11 +179,8 @@ private: //Auxiliary database failed table const std::string m_auxDatabaseFailedTable; - //Files selection key - const std::string m_selectKey; - - //File selection value - const std::string m_selectValue; + //Files retrieval where condition + const std::string m_whereCondition; }; } //End of namespace diff --git a/src/DBManager.cpp b/src/DBManager.cpp index 44ea6f4..78f08ad 100644 --- a/src/DBManager.cpp +++ b/src/DBManager.cpp @@ -202,12 +202,11 @@ DBManager::FileRowsetSP DBManager::retrieveNewFiles(boost::posix_time::ptime pti if(m_mainSession_sp->get_backend() == NULL) m_mainSession_sp->reconnect(); - std::string selectKey = m_configuration_sp->getSelectKey(); - std::string selectValue = m_configuration_sp->getSelectValue(); + std::string whereCondition = m_configuration_sp->getWhereCondition(); FileRowsetSP newFileRowset_sp; - if(selectKey.empty()) + if(whereCondition.empty()) { newFileRowset_sp.reset(new FileRowset(m_mainSession_sp->prepare << "select storage_path, file_path, file_version, file_name, update_time " @@ -222,8 +221,7 @@ DBManager::FileRowsetSP DBManager::retrieveNewFiles(boost::posix_time::ptime pti << "from " << m_configuration_sp->getDatabaseSchema() << "." << m_configuration_sp->getDatabaseTable() << " where update_time>'" << boost::posix_time::to_iso_string(ptime) << "' and " - << selectKey << " like '%" << selectValue << "%' " - << "order by update_time asc")); + << whereCondition << " order by update_time asc")); } return newFileRowset_sp; diff --git a/src/DataImporter.cpp b/src/DataImporter.cpp index 4e95977..4955f0d 100644 --- a/src/DataImporter.cpp +++ b/src/DataImporter.cpp @@ -238,8 +238,7 @@ void DataImporter::get_device_property() dev_prop.push_back(Tango::DbDatum("AuxDatabaseSchema")); dev_prop.push_back(Tango::DbDatum("AuxDatabaseTimestampTable")); dev_prop.push_back(Tango::DbDatum("AuxDatabaseFailedTable")); - dev_prop.push_back(Tango::DbDatum("SelectKey")); - dev_prop.push_back(Tango::DbDatum("SelectValue")); + dev_prop.push_back(Tango::DbDatum("WhereCondition")); // is there at least one property to be read ? if (dev_prop.size()>0) @@ -518,27 +517,16 @@ void DataImporter::get_device_property() // And try to extract AuxDatabaseFailedTable value from database if (dev_prop[i].is_empty()==false) dev_prop[i] >> auxDatabaseFailedTable; - // Try to initialize SelectKey from class property + // Try to initialize WhereCondition from class property cl_prop = ds_class->get_class_property(dev_prop[++i].name); - if (cl_prop.is_empty()==false) cl_prop >> selectKey; + if (cl_prop.is_empty()==false) cl_prop >> whereCondition; else { - // Try to initialize SelectKey from default device value + // Try to initialize WhereCondition from default device value def_prop = ds_class->get_default_device_property(dev_prop[i].name); - if (def_prop.is_empty()==false) def_prop >> selectKey; + if (def_prop.is_empty()==false) def_prop >> whereCondition; } - // And try to extract SelectKey value from database - if (dev_prop[i].is_empty()==false) dev_prop[i] >> selectKey; - - // Try to initialize SelectValue from class property - cl_prop = ds_class->get_class_property(dev_prop[++i].name); - if (cl_prop.is_empty()==false) cl_prop >> selectValue; - else { - // Try to initialize SelectValue from default device value - def_prop = ds_class->get_default_device_property(dev_prop[i].name); - if (def_prop.is_empty()==false) def_prop >> selectValue; - } - // And try to extract SelectValue value from database - if (dev_prop[i].is_empty()==false) dev_prop[i] >> selectValue; + // And try to extract WhereCondition value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> whereCondition; } @@ -619,16 +607,13 @@ void DataImporter::get_device_property() if(auxDatabaseFailedTable.empty()) throw(invalid_argument("AuxDatabaseFailedTable property is empty or not defined")); - if(!selectKey.empty() && selectValue.empty()) - throw(invalid_argument("SelectValue property is empty or not defined, but SelectKey is defined")); - m_configuration_sp = Configuration::create(certificateFile, storagePath, remoteHost, remotePort, remoteUsername, remotePassword, databaseHost, databasePort, databaseUsername, databasePassword, databaseSchema, databaseTable, refreshTime, timeout, recoveryTime, auxDatabaseHost, auxDatabasePort, auxDatabaseUsername, auxDatabasePassword, auxDatabaseSchema, auxDatabaseTimestampTable, - auxDatabaseFailedTable, selectKey, selectValue); + auxDatabaseFailedTable, whereCondition); } catch(invalid_argument& ex) { @@ -649,7 +634,7 @@ void DataImporter::get_device_property() //-------------------------------------------------------- void DataImporter::always_executed_hook() { - INFO_STREAM << "DataImporter::always_executed_hook() " << device_name << endl; + DEBUG_STREAM << "DataImporter::always_executed_hook() " << device_name << endl; /*----- PROTECTED REGION ID(DataImporter::always_executed_hook) ENABLED START -----*/ if(get_state() != Tango::FAULT) diff --git a/src/DataImporter.h b/src/DataImporter.h index 7c4b391..0e81f61 100644 --- a/src/DataImporter.h +++ b/src/DataImporter.h @@ -143,10 +143,8 @@ public: string auxDatabaseTimestampTable; // AuxDatabaseFailedTable: File transfer auxiliary database failed transfer table string auxDatabaseFailedTable; - // SelectKey: Files delivery selection key - string selectKey; - // SelectValue: Files delivery selection value - string selectValue; + // WhereCondition: Files retrieval sql where condition + string whereCondition; // Attribute data members public: diff --git a/src/DataImporter.xmi b/src/DataImporter.xmi index b627143..8866ef0 100644 --- a/src/DataImporter.xmi +++ b/src/DataImporter.xmi @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="ASCII"?> <pogoDsl:PogoSystem xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:pogoDsl="http://www.esrf.fr/tango/pogo/PogoDsl"> <classes name="DataImporter" pogoRevision="8.1"> - <description description="" title="Data importer" sourcePath="/home/mdm/workspace/nadir/data_importer/src" language="Cpp" filestogenerate="XMI file,Code files" license="GPL" hasMandatoryProperty="false" hasConcreteProperty="true" hasAbstractCommand="false" hasAbstractAttribute="false"> + <description description="" title="Data importer" sourcePath="/home/marco/workspace/nadir/data_importer/src" language="Cpp" filestogenerate="XMI file,Code files" license="GPL" hasMandatoryProperty="false" hasConcreteProperty="true" hasAbstractCommand="false" hasAbstractAttribute="false"> <inheritances classname="Device_Impl" sourcePath=""/> <identification contact="at oats.inaf.it - demarco" author="demarco" emailDomain="oats.inaf.it" classFamily="Communication" siteSpecific="" platform="Unix Like" bus="TCP/UDP" manufacturer="none" reference=""/> </description> @@ -141,11 +141,7 @@ <type xsi:type="pogoDsl:StringType"/> <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> </deviceProperties> - <deviceProperties name="SelectKey" description="Files delivery selection key"> - <type xsi:type="pogoDsl:StringType"/> - <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> - </deviceProperties> - <deviceProperties name="SelectValue" description="Files delivery selection value"> + <deviceProperties name="WhereCondition" description="Files retrieval sql where condition"> <type xsi:type="pogoDsl:StringType"/> <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> </deviceProperties> diff --git a/src/DataImporterClass.cpp b/src/DataImporterClass.cpp index ff07739..c4536aa 100644 --- a/src/DataImporterClass.cpp +++ b/src/DataImporterClass.cpp @@ -859,21 +859,8 @@ void DataImporterClass::set_default_property() } else add_wiz_dev_prop(prop_name, prop_desc); - prop_name = "SelectKey"; - prop_desc = "Files delivery selection key"; - prop_def = ""; - vect_data.clear(); - if (prop_def.length()>0) - { - Tango::DbDatum data(prop_name); - data << vect_data ; - dev_def_prop.push_back(data); - add_wiz_dev_prop(prop_name, prop_desc, prop_def); - } - else - add_wiz_dev_prop(prop_name, prop_desc); - prop_name = "SelectValue"; - prop_desc = "Files delivery selection value"; + prop_name = "WhereCondition"; + prop_desc = "Files retrieval sql where condition"; prop_def = ""; vect_data.clear(); if (prop_def.length()>0) -- GitLab