Skip to content
Snippets Groups Projects
Commit e772b3ef authored by Marco De Marco's avatar Marco De Marco
Browse files

Select key and value substituted by where condition

parent c78d4ad1
Branches
No related tags found
No related merge requests found
...@@ -28,12 +28,12 @@ private: ...@@ -28,12 +28,12 @@ private:
std::string auxDatabaseHost, unsigned int auxDatabasePort, std::string auxDatabaseHost, unsigned int auxDatabasePort,
std::string auxDatabaseUsername, std::string auxDatabasePassword, std::string auxDatabaseUsername, std::string auxDatabasePassword,
std::string auxDatabaseSchema, std::string auxDatabaseTimestampTable, std::string auxDatabaseSchema, std::string auxDatabaseTimestampTable,
std::string auxDatabaseFailedTable, std::string selectKey, std::string auxDatabaseFailedTable, std::string whereCondition) :
std::string selectValue) : m_certificateFile (certificateFile), m_certificateFile (certificateFile), m_storagePath(storagePath),
m_storagePath(storagePath), m_remoteHost(remoteHost), m_remoteHost(remoteHost), m_remotePort(remotePort),
m_remotePort(remotePort), m_remoteUsername(remoteUsername), m_remoteUsername(remoteUsername), m_remotePassword(remotePassword),
m_remotePassword(remotePassword), m_databaseHost(databaseHost), m_databaseHost(databaseHost), m_databasePort(databasePort),
m_databasePort(databasePort), m_databaseUsername(databaseUsername), m_databaseUsername(databaseUsername),
m_databasePassword(databasePassword), m_databaseSchema(databaseSchema), m_databasePassword(databasePassword), m_databaseSchema(databaseSchema),
m_databaseTable(databaseTable), m_refreshTime(refreshTime), m_databaseTable(databaseTable), m_refreshTime(refreshTime),
m_timeout(timeout), m_recoveryTime(recoveryTime), m_timeout(timeout), m_recoveryTime(recoveryTime),
...@@ -43,7 +43,7 @@ private: ...@@ -43,7 +43,7 @@ private:
m_auxDatabaseSchema(auxDatabaseSchema), m_auxDatabaseSchema(auxDatabaseSchema),
m_auxDatabaseTimestampTable(auxDatabaseTimestampTable), m_auxDatabaseTimestampTable(auxDatabaseTimestampTable),
m_auxDatabaseFailedTable(auxDatabaseFailedTable), m_auxDatabaseFailedTable(auxDatabaseFailedTable),
m_selectKey(selectKey), m_selectValue(selectValue) { }; m_whereCondition(whereCondition) { };
virtual ~Configuration() {} virtual ~Configuration() {}
...@@ -69,8 +69,7 @@ public: ...@@ -69,8 +69,7 @@ public:
std::string auxDatabaseHost, unsigned int auxDatabasePort, std::string auxDatabaseHost, unsigned int auxDatabasePort,
std::string auxDatabaseUsername, std::string auxDatabasePassword, std::string auxDatabaseUsername, std::string auxDatabasePassword,
std::string auxDatabaseSchema, std::string auxDatabaseTimestampTable, std::string auxDatabaseSchema, std::string auxDatabaseTimestampTable,
std::string auxDatabaseFailedTable, std::string selectKey, std::string auxDatabaseFailedTable, std::string whereCondition)
std::string selectValue)
{ {
Configuration::SP c_sp(new Configuration(certificateFile, storagePath, Configuration::SP c_sp(new Configuration(certificateFile, storagePath,
remoteHost, remotePort, remoteUsername, remotePassword, databaseHost, remoteHost, remotePort, remoteUsername, remotePassword, databaseHost,
...@@ -78,7 +77,7 @@ public: ...@@ -78,7 +77,7 @@ public:
databaseTable, refreshTime, timeout, recoveryTime, auxDatabaseHost, databaseTable, refreshTime, timeout, recoveryTime, auxDatabaseHost,
auxDatabasePort, auxDatabaseUsername, auxDatabasePassword, auxDatabasePort, auxDatabaseUsername, auxDatabasePassword,
auxDatabaseSchema, auxDatabaseTimestampTable, auxDatabaseFailedTable, auxDatabaseSchema, auxDatabaseTimestampTable, auxDatabaseFailedTable,
selectKey, selectValue), Configuration::Deleter()); whereCondition), Configuration::Deleter());
return c_sp; return c_sp;
} }
...@@ -108,8 +107,7 @@ public: ...@@ -108,8 +107,7 @@ public:
std::string getAuxDatabaseSchema() const { return m_auxDatabaseSchema; } std::string getAuxDatabaseSchema() const { return m_auxDatabaseSchema; }
std::string getAuxDatabaseTimestampTable() const { return m_auxDatabaseTimestampTable; } std::string getAuxDatabaseTimestampTable() const { return m_auxDatabaseTimestampTable; }
std::string getAuxDatabaseFailedTable() const { return m_auxDatabaseFailedTable; } std::string getAuxDatabaseFailedTable() const { return m_auxDatabaseFailedTable; }
std::string getSelectKey() const { return m_selectKey; } std::string getWhereCondition() const { return m_whereCondition; }
std::string getSelectValue() const { return m_selectValue; }
private: private:
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
...@@ -181,11 +179,8 @@ private: ...@@ -181,11 +179,8 @@ private:
//Auxiliary database failed table //Auxiliary database failed table
const std::string m_auxDatabaseFailedTable; const std::string m_auxDatabaseFailedTable;
//Files selection key //Files retrieval where condition
const std::string m_selectKey; const std::string m_whereCondition;
//File selection value
const std::string m_selectValue;
}; };
} //End of namespace } //End of namespace
......
...@@ -202,12 +202,11 @@ DBManager::FileRowsetSP DBManager::retrieveNewFiles(boost::posix_time::ptime pti ...@@ -202,12 +202,11 @@ DBManager::FileRowsetSP DBManager::retrieveNewFiles(boost::posix_time::ptime pti
if(m_mainSession_sp->get_backend() == NULL) if(m_mainSession_sp->get_backend() == NULL)
m_mainSession_sp->reconnect(); m_mainSession_sp->reconnect();
std::string selectKey = m_configuration_sp->getSelectKey(); std::string whereCondition = m_configuration_sp->getWhereCondition();
std::string selectValue = m_configuration_sp->getSelectValue();
FileRowsetSP newFileRowset_sp; FileRowsetSP newFileRowset_sp;
if(selectKey.empty()) if(whereCondition.empty())
{ {
newFileRowset_sp.reset(new FileRowset(m_mainSession_sp->prepare newFileRowset_sp.reset(new FileRowset(m_mainSession_sp->prepare
<< "select storage_path, file_path, file_version, file_name, update_time " << "select storage_path, file_path, file_version, file_name, update_time "
...@@ -222,8 +221,7 @@ DBManager::FileRowsetSP DBManager::retrieveNewFiles(boost::posix_time::ptime pti ...@@ -222,8 +221,7 @@ DBManager::FileRowsetSP DBManager::retrieveNewFiles(boost::posix_time::ptime pti
<< "from " << m_configuration_sp->getDatabaseSchema() << "." << "from " << m_configuration_sp->getDatabaseSchema() << "."
<< m_configuration_sp->getDatabaseTable() << " where update_time>'" << m_configuration_sp->getDatabaseTable() << " where update_time>'"
<< boost::posix_time::to_iso_string(ptime) << "' and " << boost::posix_time::to_iso_string(ptime) << "' and "
<< selectKey << " like '%" << selectValue << "%' " << whereCondition << " order by update_time asc"));
<< "order by update_time asc"));
} }
return newFileRowset_sp; return newFileRowset_sp;
......
...@@ -238,8 +238,7 @@ void DataImporter::get_device_property() ...@@ -238,8 +238,7 @@ void DataImporter::get_device_property()
dev_prop.push_back(Tango::DbDatum("AuxDatabaseSchema")); dev_prop.push_back(Tango::DbDatum("AuxDatabaseSchema"));
dev_prop.push_back(Tango::DbDatum("AuxDatabaseTimestampTable")); dev_prop.push_back(Tango::DbDatum("AuxDatabaseTimestampTable"));
dev_prop.push_back(Tango::DbDatum("AuxDatabaseFailedTable")); dev_prop.push_back(Tango::DbDatum("AuxDatabaseFailedTable"));
dev_prop.push_back(Tango::DbDatum("SelectKey")); dev_prop.push_back(Tango::DbDatum("WhereCondition"));
dev_prop.push_back(Tango::DbDatum("SelectValue"));
// is there at least one property to be read ? // is there at least one property to be read ?
if (dev_prop.size()>0) if (dev_prop.size()>0)
...@@ -518,27 +517,16 @@ void DataImporter::get_device_property() ...@@ -518,27 +517,16 @@ void DataImporter::get_device_property()
// And try to extract AuxDatabaseFailedTable value from database // And try to extract AuxDatabaseFailedTable value from database
if (dev_prop[i].is_empty()==false) dev_prop[i] >> auxDatabaseFailedTable; 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); 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 { 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); 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 // And try to extract WhereCondition value from database
if (dev_prop[i].is_empty()==false) dev_prop[i] >> selectKey; if (dev_prop[i].is_empty()==false) dev_prop[i] >> whereCondition;
// 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;
} }
...@@ -619,16 +607,13 @@ void DataImporter::get_device_property() ...@@ -619,16 +607,13 @@ void DataImporter::get_device_property()
if(auxDatabaseFailedTable.empty()) if(auxDatabaseFailedTable.empty())
throw(invalid_argument("AuxDatabaseFailedTable property is empty or not defined")); 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, m_configuration_sp = Configuration::create(certificateFile, storagePath,
remoteHost, remotePort, remoteUsername, remotePassword, databaseHost, remoteHost, remotePort, remoteUsername, remotePassword, databaseHost,
databasePort, databaseUsername, databasePassword, databaseSchema, databasePort, databaseUsername, databasePassword, databaseSchema,
databaseTable, refreshTime, timeout, recoveryTime, auxDatabaseHost, databaseTable, refreshTime, timeout, recoveryTime, auxDatabaseHost,
auxDatabasePort, auxDatabaseUsername, auxDatabasePassword, auxDatabasePort, auxDatabaseUsername, auxDatabasePassword,
auxDatabaseSchema, auxDatabaseTimestampTable, auxDatabaseSchema, auxDatabaseTimestampTable,
auxDatabaseFailedTable, selectKey, selectValue); auxDatabaseFailedTable, whereCondition);
} }
catch(invalid_argument& ex) catch(invalid_argument& ex)
{ {
...@@ -649,7 +634,7 @@ void DataImporter::get_device_property() ...@@ -649,7 +634,7 @@ void DataImporter::get_device_property()
//-------------------------------------------------------- //--------------------------------------------------------
void DataImporter::always_executed_hook() 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 -----*/ /*----- PROTECTED REGION ID(DataImporter::always_executed_hook) ENABLED START -----*/
if(get_state() != Tango::FAULT) if(get_state() != Tango::FAULT)
......
...@@ -143,10 +143,8 @@ public: ...@@ -143,10 +143,8 @@ public:
string auxDatabaseTimestampTable; string auxDatabaseTimestampTable;
// AuxDatabaseFailedTable: File transfer auxiliary database failed transfer table // AuxDatabaseFailedTable: File transfer auxiliary database failed transfer table
string auxDatabaseFailedTable; string auxDatabaseFailedTable;
// SelectKey: Files delivery selection key // WhereCondition: Files retrieval sql where condition
string selectKey; string whereCondition;
// SelectValue: Files delivery selection value
string selectValue;
// Attribute data members // Attribute data members
public: public:
......
<?xml version="1.0" encoding="ASCII"?> <?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"> <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"> <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=""/> <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=""/> <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> </description>
...@@ -141,11 +141,7 @@ ...@@ -141,11 +141,7 @@
<type xsi:type="pogoDsl:StringType"/> <type xsi:type="pogoDsl:StringType"/>
<status abstract="false" inherited="false" concrete="true" concreteHere="true"/> <status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
</deviceProperties> </deviceProperties>
<deviceProperties name="SelectKey" description="Files delivery selection key"> <deviceProperties name="WhereCondition" description="Files retrieval sql where condition">
<type xsi:type="pogoDsl:StringType"/>
<status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
</deviceProperties>
<deviceProperties name="SelectValue" description="Files delivery selection value">
<type xsi:type="pogoDsl:StringType"/> <type xsi:type="pogoDsl:StringType"/>
<status abstract="false" inherited="false" concrete="true" concreteHere="true"/> <status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
</deviceProperties> </deviceProperties>
......
...@@ -859,21 +859,8 @@ void DataImporterClass::set_default_property() ...@@ -859,21 +859,8 @@ void DataImporterClass::set_default_property()
} }
else else
add_wiz_dev_prop(prop_name, prop_desc); add_wiz_dev_prop(prop_name, prop_desc);
prop_name = "SelectKey"; prop_name = "WhereCondition";
prop_desc = "Files delivery selection key"; prop_desc = "Files retrieval sql where condition";
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_def = ""; prop_def = "";
vect_data.clear(); vect_data.clear();
if (prop_def.length()>0) if (prop_def.length()>0)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment