dcxmldal.cpp
2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "dcxmldal.h"
#include "dcxmlconfig.h"
using namespace osdev::components;
static const char* selectFunctions = "selectFunctions"; // return all functions
static const char* selectFunctionByName = "selectFunction"; // return function by command name
// The only instance of the singleton Dal Config Parser.
std::unique_ptr<DcXmlDal> DcXmlDal::s_instance( nullptr );
DcXmlDal& DcXmlDal::Instance()
{
if( nullptr == s_instance )
{
s_instance = std::unique_ptr<DcXmlDal>( new DcXmlDal( DCXmlConfig::Instance().getDalConfig() ) );
}
return *s_instance;
}
DcXmlDal::DcXmlDal( const QString &fileName )
{
if( !fileName.isEmpty() )
{
if( !loadConfiguration( fileName ) )
{
LogWarning( "[DcXmlDal::DcXmlDal]", QString( "There was an error reading file : %1" ).arg( fileName ) );
}
}
else
{
LogWarning( "[DcXmlDal::DcXmlDal]", QString( "No filename given. No configuration read." ) );
}
constructXPathHash();
}
DcXmlDal::~DcXmlDal()
{
}
bool DcXmlDal::loadConfiguration( const QString &fileName )
{
return loadConfiguration( DCXmlConfig::Instance().getConfigPath(), fileName );
}
bool DcXmlDal::loadConfiguration( const QString &configDir, const QString &fileName )
{
return DcXmlBase::parseFile( configDir + fileName );
}
void DcXmlDal::constructXPathHash()
{
DcXmlBase::addXPath( selectFunctions , "//data_access/functions/function" );
DcXmlBase::addXPath( selectFunctionByName , "//data_access/functions/function[@name='%1']" );
}
QStringList DcXmlDal::getQueries() const
{
QStringList lstResult;
QList<pugi::xpath_node> functionList = DcXmlBase::selectNodes( DcXmlBase::getXPath( selectFunctions ) );
for( const auto& nodeItem : functionList )
{
lstResult.append( nodeItem.node().attribute( "name" ).value() );
}
return lstResult;
}
QString DcXmlDal::getQueryByName( const QString &_queryName ) const
{
QList<QVariant> varList;
varList.append( _queryName );
return QString( DcXmlBase::selectNode( evaluateXPath( selectFunctionByName, varList ) ).node().attribute( "value" ).value() );
}