Update wrt-plugins-common_0.3.53
[framework/web/wrt-plugins-common.git] / src / modules / tizen / WidgetInterfaceDAO / WidgetInterfaceDAO.cpp
index a6fe123..246c99f 100644 (file)
@@ -38,6 +38,8 @@
 namespace {
 DPL::DB::SqlConnection::Flag::Type DATABASE_FLAGS =
     DPL::DB::SqlConnection::Flag::UseLucene;
+DPL::DB::SqlConnection::Flag::Option DATABASE_OPTIONS =
+    DPL::DB::SqlConnection::Flag::RW;
 const char *KEY_WIDGET_ARG = "widget_arg";
 }
 
@@ -50,7 +52,7 @@ WidgetInterfaceDAO::WidgetInterfaceDAO(int widgetHandle) :
     if (!checkDatabase()) {
         LogError("There is a problem with database");
     }
-    m_databaseInterface.AttachToThread();
+    m_databaseInterface.AttachToThread(DPL::DB::SqlConnection::Flag::RW);
 }
 
 WidgetInterfaceDAO::~WidgetInterfaceDAO()
@@ -83,7 +85,8 @@ bool WidgetInterfaceDAO::checkDatabase()
 
         Try
         {
-            DPL::DB::SqlConnection con(databaseFile);
+            DPL::DB::SqlConnection con(databaseFile,
+                DATABASE_FLAGS, DATABASE_OPTIONS);
             con.ExecCommand(buffer.str().c_str());
         }
         Catch(DPL::DB::SqlConnection::Exception::Base)
@@ -102,8 +105,8 @@ bool WidgetInterfaceDAO::copyPropertiesFromWrtDatabase()
     using namespace DPL::DB::ORM::widget_interface;
 
     bool result = true;
-    WrtDB::WrtDatabase::attachToThread();
-    m_databaseInterface.AttachToThread();
+    WrtDB::WrtDatabase::attachToThreadRO();
+    m_databaseInterface.AttachToThread(DPL::DB::SqlConnection::Flag::RW);
 
     Try
     {
@@ -163,14 +166,14 @@ void WidgetInterfaceDAO::setItem(const std::string& key,
         //check if key exists
         Properties::Select select(&m_databaseInterface);
         select.Where(
-            Equals<Properties::key>(DPL::FromASCIIString(key)));
+            Equals<Properties::key>(DPL::FromUTF8String(key)));
         std::list<Properties::Row> rows = select.GetRowList();
 
         if (rows.size() == 0) {
             Properties::Insert insert(&m_databaseInterface);
             Properties::Row row;
-            row.Set_key(DPL::FromASCIIString(key));
-            row.Set_value(DPL::FromASCIIString(value));
+            row.Set_key(DPL::FromUTF8String(key));
+            row.Set_value(DPL::FromUTF8String(value));
             row.Set_readonly(readOnly ? 1 : 0);
             row.Set_configxml(fromConfigXml ? 1 : 0);
             insert.Values(row);
@@ -182,10 +185,10 @@ void WidgetInterfaceDAO::setItem(const std::string& key,
             if (row.Get_readonly() != 0) {
                 Throw(Commons::LocalStorageValueNoModifableException);
             }
-            row.Set_value(DPL::FromASCIIString(value));
+            row.Set_value(DPL::FromUTF8String(value));
             row.Set_readonly(readOnly ? 1 : 0);
             Properties::Update update(&m_databaseInterface);
-            update.Where(Equals<Properties::key>(DPL::FromASCIIString(key)));
+            update.Where(Equals<Properties::key>(DPL::FromUTF8String(key)));
             update.Values(row);
             update.Execute();
         }
@@ -207,14 +210,14 @@ void WidgetInterfaceDAO::removeItem(const std::string& key)
     Try
     {
         Properties::Select select(&m_databaseInterface);
-        select.Where(Equals<Properties::key>(DPL::FromASCIIString(key)));
+        select.Where(Equals<Properties::key>(DPL::FromUTF8String(key)));
         bool readonly = select.GetSingleValue<Properties::readonly>();
         if (readonly) {
             ThrowMsg(Commons::LocalStorageValueNoModifableException,
                 "Cannot delete item. Item is readonly");
         }
         Properties::Delete deleteItem(&m_databaseInterface);
-        deleteItem.Where(Equals<Properties::key>(DPL::FromASCIIString(key)));
+        deleteItem.Where(Equals<Properties::key>(DPL::FromUTF8String(key)));
         deleteItem.Execute();
     }
     Catch(DPL::DB::SqlConnection::Exception::Base)
@@ -233,7 +236,7 @@ DPL::Optional<std::string> WidgetInterfaceDAO::getValue(
     Try
     {
         Properties::Select select(&m_databaseInterface);
-        select.Where(Equals<Properties::key>(DPL::FromASCIIString(key)));
+        select.Where(Equals<Properties::key>(DPL::FromUTF8String(key)));
         std::list<DPL::String> value = select.GetValueList<Properties::value>();
         if (value.size() == 0) {
             return DPL::Optional<std::string>();
@@ -287,7 +290,7 @@ size_t WidgetInterfaceDAO::getStorageSize() const
     return 0;
 }
 
-std::string WidgetInterfaceDAO::getValueByIndex(size_t index) const
+std::string WidgetInterfaceDAO::getKeyByIndex(size_t index) const
 {
     using namespace DPL::DB::ORM;
     using namespace DPL::DB::ORM::widget_interface;
@@ -297,7 +300,7 @@ std::string WidgetInterfaceDAO::getValueByIndex(size_t index) const
         Properties::Select select(&m_databaseInterface);
         select.OrderBy("key");
         std::list<DPL::String> list =
-            select.GetValueList<Properties::value>();
+            select.GetValueList<Properties::key>();
         if (index >= list.size()) {
             Throw(Commons::InvalidArgumentException);
         }
@@ -320,7 +323,7 @@ std::string WidgetInterfaceDAO::databaseFileName(int widgetHandle)
     using namespace WrtDB::WidgetConfig;
     using namespace WrtDB::GlobalConfig;
 
-    WrtDB::WrtDatabase::attachToThread();
+    WrtDB::WrtDatabase::attachToThreadRO();
 
     std::stringstream filename;
     Try