Implement widget interface DAO library
authorJihoon Chung <jihoon.chung@samsaung.com>
Fri, 9 Aug 2013 05:33:55 +0000 (14:33 +0900)
committerGerrit Code Review <gerrit@gerrit.vlan144.tizendev.org>
Wed, 14 Aug 2013 01:33:19 +0000 (01:33 +0000)
[Issue#] N/A
[Problem] N/A
[Cause] N/A
[Solution] As requirment of customer, DAO should create in install time
To support this, widget interface DAO library should move from
wrt-plugins-common to wrt-commons
[SCMRequest] N/A

Change-Id: I744614dd4ba242f2703d66d1dabd5f643628516e

13 files changed:
CMakeLists.txt
build/CMakeLists.txt
build/widget_interface_dao/CMakeLists.txt [new file with mode: 0644]
build/widget_interface_dao/wrt-commons-widget-interface-dao.pc.in [new file with mode: 0644]
modules/CMakeLists.txt
modules/widget_dao/include/dpl/wrt-dao-ro/global_config.h
modules/widget_interface_dao/CMakeLists.txt [new file with mode: 0644]
modules/widget_interface_dao/dao/widget_interface_dao.cpp [new file with mode: 0644]
modules/widget_interface_dao/include/wrt-commons/widget-interface-dao/widget_interface_dao.h [new file with mode: 0644]
modules/widget_interface_dao/orm/orm_generator_widget_interface.h [new file with mode: 0644]
modules/widget_interface_dao/orm/widget_interface_db [new file with mode: 0644]
modules/widget_interface_dao/orm/widget_interface_db_definitions [new file with mode: 0644]
modules/widget_interface_dao/orm/widget_interface_db_sql_generator.h [new file with mode: 0644]

index 92f1d49..6b92bd0 100644 (file)
@@ -192,6 +192,7 @@ SET(TARGET_SECURITY_ORIGIN_DAO_LIB "wrt-commons-security-origin-dao")
 SET(TARGET_CERTIFICATE_DAO_LIB "wrt-commons-certificate-dao")
 SET(TARGET_DPL_UTILS_EFL "lib${PROJECT_NAME}-utils-efl")
 SET(TARGET_I18N_DAO_RO_LIB "wrt-commons-i18n-dao-ro")
+SET(TARGET_WIDGET_INTERFACE_DAO_LIB "wrt-commons-widget-interface-dao")
 
 macro(configure_and_install_pkg PKG_FILE)
     CONFIGURE_FILE(${PKG_FILE}.in ${PKG_FILE} @ONLY)
index b9598d6..b94d51f 100644 (file)
@@ -33,3 +33,4 @@ ADD_SUBDIRECTORY(utils)
 ADD_SUBDIRECTORY(support)
 ADD_SUBDIRECTORY(certificate_dao)
 ADD_SUBDIRECTORY(i18n)
+ADD_SUBDIRECTORY(widget_interface_dao)
diff --git a/build/widget_interface_dao/CMakeLists.txt b/build/widget_interface_dao/CMakeLists.txt
new file mode 100644 (file)
index 0000000..e726271
--- /dev/null
@@ -0,0 +1,21 @@
+# Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+#
+#    Licensed under the Apache License, Version 2.0 (the "License");
+#    you may not use this file except in compliance with the License.
+#    You may obtain a copy of the License at
+#
+#        http://www.apache.org/licenses/LICENSE-2.0
+#
+#    Unless required by applicable law or agreed to in writing, software
+#    distributed under the License is distributed on an "AS IS" BASIS,
+#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#    See the License for the specific language governing permissions and
+#    limitations under the License.
+#
+# @file        CMakeLists.txt
+# @author      Jihoon Chung (jihoon.chung@samsung.com)
+# @brief
+#
+
+configure_and_install_pkg(wrt-commons-widget-interface-dao.pc)
+
diff --git a/build/widget_interface_dao/wrt-commons-widget-interface-dao.pc.in b/build/widget_interface_dao/wrt-commons-widget-interface-dao.pc.in
new file mode 100644 (file)
index 0000000..348b178
--- /dev/null
@@ -0,0 +1,12 @@
+prefix=/usr
+exec_prefix=${prefix}
+
+libdir=${prefix}/lib
+includedir=${prefix}/include
+Name: wrt-commons-widget-interface-dao
+Description: wrt-commons-widget-interface-dao
+
+Version: @VERSION@
+Requires: dpl-efl
+Libs: -lwrt-commons-widget-interface-dao -L${libdir}
+Cflags: -I${includedir}/dpl-efl
index a80bb78..07c4c05 100644 (file)
@@ -28,6 +28,7 @@ include(rpc/config.cmake)
 include(test/config.cmake)
 include(log/config.cmake)
 ADD_SUBDIRECTORY(widget_dao)
+ADD_SUBDIRECTORY(widget_interface_dao)
 ADD_SUBDIRECTORY(security_origin_dao)
 ADD_SUBDIRECTORY(custom_handler_dao)
 ADD_SUBDIRECTORY(certificate_dao)
index 6d193e4..0eba4e4 100644 (file)
@@ -37,14 +37,6 @@ inline const char* GetWrtDatabaseFilePath()
 }
 
 /**
- * WRT origin widget interface database path
- */
-inline const char* GetWrtWidgetInterfaceDatabaseFilePath()
-{
-    return "/usr/share/wrt-plugins-common/widget_interface_db.sql";
-}
-
-/**
  * WRT device plugin path
  */
 inline const char* GetDevicePluginPath()
@@ -247,14 +239,6 @@ inline const char* GetCookieDatabaseFile()
     return ".cookie.db";
 }
 
-/**
- * widget interface database file name
- */
-inline const char* GetWidgetInterfaceDatabaseFile()
-{
-    return ".widget_interface.db";
-}
-
 inline const char* GetTmpDirPath()
 {
     return "/tmp";
@@ -303,6 +287,11 @@ inline const char* GetNPRuntimePluginsPath()
     return "plugins/x86";
 #endif
 }
+
+inline const char* GetBackupDatabaseSuffix()
+{
+    return ".backup";
+}
 } // namespace GlobalConfig
 } // namespace WrtDB
 
diff --git a/modules/widget_interface_dao/CMakeLists.txt b/modules/widget_interface_dao/CMakeLists.txt
new file mode 100644 (file)
index 0000000..8acad9b
--- /dev/null
@@ -0,0 +1,45 @@
+SET(TARGET_WIDGET_INTERFACE_DAO_DB "Sqlite3DbWidgetInterface")
+
+ADD_CUSTOM_COMMAND( OUTPUT .widget_interface.db
+   COMMAND rm -f ${CMAKE_CURRENT_BINARY_DIR}/.widget_interface.db
+   COMMAND gcc -Wall -I${PROJECT_SOURCE_DIR}/modules/db/include -I${PROJECT_SOURCE_DIR}/modules/widget_interface_dao/orm -E ${PROJECT_SOURCE_DIR}/modules/widget_interface_dao/orm/widget_interface_db_sql_generator.h | grep --invert-match "^#" > ${CMAKE_CURRENT_BINARY_DIR}/widget_interface_db.sql
+   COMMAND sqlite3 ${CMAKE_CURRENT_BINARY_DIR}/.widget_interface.db ".read ${CMAKE_CURRENT_BINARY_DIR}/widget_interface_db.sql" || rm -f ${CMAKE_CURRENT_BINARY_DIR}/.widget_interface.db
+   DEPENDS ${PROJECT_SOURCE_DIR}/modules/widget_interface_dao/orm/widget_interface_db_sql_generator.h ${PROJECT_SOURCE_DIR}/modules/widget_interface_dao/orm/widget_interface_db
+   )
+
+ADD_CUSTOM_TARGET(${TARGET_WIDGET_INTERFACE_DAO_DB} ALL DEPENDS .widget_interface.db)
+INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/widget_interface_db.sql DESTINATION share/wrt-engine/)
+
+INCLUDE(FindPkgConfig)
+
+PKG_CHECK_MODULES(WIDGET_INTERFACE_DAO_DEPS
+    glib-2.0
+    REQUIRED)
+
+SET(WIDGET_INTERFACE_DAO_INCLUDE_DIRS
+    ${PROJECT_SOURCE_DIR}/modules/widget_interface_dao/include
+    ${PROJECT_SOURCE_DIR}/modules/widget_interface_dao/orm
+    ${PROJECT_SOURCE_DIR}/modules/core/include
+    ${PROJECT_SOURCE_DIR}/modules/db/include
+    ${PROJECT_SOURCE_DIR}/modules/log/include
+    ${PROJECT_SOURCE_DIR}/modules/widget_dao/include
+)
+
+SET(WIDGET_INTERFACE_DAO_SOURCES
+    dao/widget_interface_dao.cpp
+)
+
+INCLUDE_DIRECTORIES(SYSTEM ${WIDGET_INTERFACE_DAO_DEPS_INCLUDE_DIRS} )
+INCLUDE_DIRECTORIES(${WIDGET_INTERFACE_DAO_INCLUDE_DIRS})
+
+ADD_LIBRARY(${TARGET_WIDGET_INTERFACE_DAO_LIB} SHARED ${WIDGET_INTERFACE_DAO_SOURCES})
+SET_TARGET_PROPERTIES(${TARGET_WIDGET_INTERFACE_DAO_LIB} PROPERTIES SOVERSION ${API_VERSION} VERSION ${VERSION})
+TARGET_LINK_LIBRARIES(${TARGET_WIDGET_INTERFACE_DAO_LIB} ${TARGET_DPL_EFL} ${TARGET_DPL_DB_EFL} ${TARGET_WRT_DAO_RO_LIB} ${WIDGET_INTERFACE_DAO_DEPS_LIBRARIES})
+ADD_DEPENDENCIES(${TARGET_WIDGET_INTERFACE_DAO_LIB} ${TARGET_WIDGET_INTERFACE_DAO_DB})
+
+INSTALL(TARGETS ${TARGET_WIDGET_INTERFACE_DAO_LIB} DESTINATION lib)
+
+INSTALL(FILES
+    include/wrt-commons/widget-interface-dao/widget_interface_dao.h
+    DESTINATION include/dpl-efl/wrt-commons/widget-interface-dao
+)
diff --git a/modules/widget_interface_dao/dao/widget_interface_dao.cpp b/modules/widget_interface_dao/dao/widget_interface_dao.cpp
new file mode 100644 (file)
index 0000000..88e13ac
--- /dev/null
@@ -0,0 +1,296 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+/*
+ * @author      Lukasz Marek (l.marek@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#include <wrt-commons/widget-interface-dao/widget_interface_dao.h>
+#include <string>
+#include <sstream>
+#include <fstream>
+#include <sys/stat.h>
+#include <dpl/db/sql_connection.h>
+#include <dpl/log/log.h>
+#include <dpl/foreach.h>
+#include <dpl/string.h>
+#include <dpl/wrt-dao-ro/property_dao_read_only.h>
+#include <dpl/wrt-dao-ro/widget_dao_read_only.h>
+#include <dpl/wrt-dao-ro/WrtDatabase.h>
+#include <dpl/wrt-dao-ro/widget_config.h>
+#include "orm_generator_widget_interface.h"
+
+namespace WidgetInterfaceDB {
+using namespace DPL::DB::ORM;
+using namespace DPL::DB::ORM::widget_interface;
+
+#define SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN          Try
+#define SQL_CONNECTION_EXCEPTION_HANDLER_END(message)            \
+    Catch(DPL::DB::SqlConnection::Exception::Base) {             \
+        LogError(message);                                       \
+        ReThrowMsg(WidgetInterfaceDAO::Exception::DatabaseError, \
+                   message);                                     \
+    }
+
+namespace {
+DPL::DB::SqlConnection::Flag::Type DATABASE_FLAG =
+    DPL::DB::SqlConnection::Flag::UseLucene;
+DPL::DB::SqlConnection::Flag::Option DATABASE_OPTION =
+    DPL::DB::SqlConnection::Flag::RW;
+const char *KEY_WIDGET_ARG = "widget_arg";
+
+const char* const DATABASE_NAME = ".widget_interface.db";
+const char* const DATABASE_FILE_PATH =
+    "/usr/share/wrt-engine/widget_interface_db.sql";
+const char* const DATABASE_JOURNAL_FILENAME = "-journal";
+
+const int APP_UID = 5000;
+const int APP_GUID = 5000;
+} // anonymous namespace
+
+WidgetInterfaceDAO::WidgetInterfaceDAO(int widgetHandle) :
+    m_widgetHandle(widgetHandle),
+    m_databaseInterface(databaseFileName(widgetHandle), DATABASE_FLAG)
+{
+    checkDatabase();
+    m_databaseInterface.AttachToThread(DATABASE_OPTION);
+}
+
+WidgetInterfaceDAO::~WidgetInterfaceDAO()
+{
+    m_databaseInterface.DetachFromThread();
+}
+
+void WidgetInterfaceDAO::checkDatabase()
+{
+    std::string databaseFile = databaseFileName(m_widgetHandle);
+    struct stat buffer;
+    if (stat(databaseFile.c_str(), &buffer) != 0) {
+        //Create fresh database
+        LogDebug("Creating database " << databaseFile);
+
+        std::fstream file;
+        file.open(DATABASE_FILE_PATH, std::ios_base::in);
+        if (!file) {
+            ThrowMsg(WidgetInterfaceDAO::Exception::DatabaseError,
+                     "Cannot create database. SQL file is missing.");
+        }
+
+        std::stringstream stream;
+        stream << file.rdbuf();
+
+        file.close();
+
+        SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
+        {
+            DPL::DB::SqlConnection con(databaseFile,
+                                       DATABASE_FLAG,
+                                       DATABASE_OPTION);
+            con.ExecCommand(stream.str().c_str());
+            copyPropertiesFromWrtDatabase();
+        }
+        SQL_CONNECTION_EXCEPTION_HANDLER_END("Cannot create database")
+
+        if(chown(databaseFile.c_str(), APP_UID, APP_GUID) != 0) {
+            ThrowMsg(WidgetInterfaceDAO::Exception::DatabaseError,
+                     "Fail to change uid/guid");
+        }
+        std::string databaseJournal =
+            databaseFile + DATABASE_JOURNAL_FILENAME;
+        if(chown(databaseJournal.c_str(), APP_UID, APP_GUID) != 0) {
+            ThrowMsg(WidgetInterfaceDAO::Exception::DatabaseError,
+                     "Fail to change uid/guid");
+        }
+    }
+}
+
+void WidgetInterfaceDAO::copyPropertiesFromWrtDatabase()
+{
+    WrtDB::WrtDatabase::attachToThreadRO();
+    m_databaseInterface.AttachToThread(DPL::DB::SqlConnection::Flag::RW);
+
+    SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
+    {
+        WrtDB::PropertyDAOReadOnly::WidgetPreferenceList existing =
+            WrtDB::PropertyDAOReadOnly::GetPropertyList(m_widgetHandle);
+
+        //save all properties read from config.xml
+        FOREACH(prop, existing) {
+            std::string key = DPL::ToUTF8String(prop->key_name);
+            if (key != KEY_WIDGET_ARG) {
+                std::string value;
+                if (!prop->key_value.IsNull()) {
+                    value = DPL::ToUTF8String(*(prop->key_value));
+                }
+                bool readonly = !prop->readonly.IsNull() && (*prop->readonly);
+                setItem(key, value, readonly, true);
+            }
+        }
+    }
+    SQL_CONNECTION_EXCEPTION_HANDLER_END(
+        "Cannot copy properties read from config.xml");
+
+    WrtDB::WrtDatabase::detachFromThread();
+    m_databaseInterface.DetachFromThread();
+}
+
+void WidgetInterfaceDAO::setItem(const std::string& key,
+                                 const std::string& value,
+                                 bool readOnly)
+{
+    setItem(key, value, readOnly, false);
+}
+
+void WidgetInterfaceDAO::setItem(const std::string& key,
+                                 const std::string& value,
+                                 bool readOnly,
+                                 bool fromConfigXml)
+{
+    SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
+    {
+        ScopedTransaction tran(&m_databaseInterface);
+        //check if key exists
+        Properties::Select select(&m_databaseInterface);
+        select.Where(Equals<Properties::key>(DPL::FromUTF8String(key)));
+        std::list<Properties::Row> rows = select.GetRowList();
+
+        if (rows.empty()) {
+            Properties::Insert insert(&m_databaseInterface);
+            Properties::Row row;
+            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);
+            insert.Execute();
+        } else {
+            Assert(rows.size() == 1);
+            Properties::Row row = rows.front();
+            if (row.Get_readonly() != 0) {
+                Throw(Exception::LocalStorageValueNoModifableException);
+            }
+            row.Set_value(DPL::FromUTF8String(value));
+            row.Set_readonly(readOnly ? 1 : 0);
+            Properties::Update update(&m_databaseInterface);
+            update.Where(Equals<Properties::key>(DPL::FromUTF8String(key)));
+            update.Values(row);
+            update.Execute();
+        }
+        tran.Commit();
+    }
+    SQL_CONNECTION_EXCEPTION_HANDLER_END("Cannot set item");
+}
+
+void WidgetInterfaceDAO::removeItem(const std::string& key)
+{
+    SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
+    {
+        Properties::Select select(&m_databaseInterface);
+        select.Where(Equals<Properties::key>(DPL::FromUTF8String(key)));
+        bool readonly = select.GetSingleValue<Properties::readonly>();
+        if (readonly) {
+            ThrowMsg(Exception::LocalStorageValueNoModifableException,
+                     "Cannot delete item. Item is readonly");
+        }
+        Properties::Delete deleteItem(&m_databaseInterface);
+        deleteItem.Where(Equals<Properties::key>(DPL::FromUTF8String(key)));
+        deleteItem.Execute();
+    }
+    SQL_CONNECTION_EXCEPTION_HANDLER_END("Cannot delete item");
+}
+
+DPL::Optional<std::string> WidgetInterfaceDAO::getValue(
+    const std::string& key) const
+{
+    SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
+    {
+        Properties::Select select(&m_databaseInterface);
+        select.Where(Equals<Properties::key>(DPL::FromUTF8String(key)));
+        std::list<DPL::String> value =
+            select.GetValueList<Properties::value>();
+        if (value.empty()) {
+            return DPL::Optional<std::string>();
+        }
+        return DPL::Optional<std::string>(DPL::ToUTF8String(value.front()));
+    }
+    SQL_CONNECTION_EXCEPTION_HANDLER_END("Not found item");
+}
+
+void WidgetInterfaceDAO::clear(bool removeReadOnly)
+{
+    SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
+    {
+        Properties::Delete deleteItem(&m_databaseInterface);
+        if (!removeReadOnly) {
+            deleteItem.Where(Equals<Properties::readonly>(0));
+        }
+        deleteItem.Execute();
+    }
+    SQL_CONNECTION_EXCEPTION_HANDLER_END("Cannot delete all items");
+}
+
+size_t WidgetInterfaceDAO::getStorageSize() const
+{
+    SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
+    {
+        Properties::Select select(&m_databaseInterface);
+        std::list<DPL::String> list =
+            select.GetValueList<Properties::key>();
+        return list.size();
+    }
+    SQL_CONNECTION_EXCEPTION_HANDLER_END("Cannot get item count");
+}
+
+std::string WidgetInterfaceDAO::getKeyByIndex(size_t index) const
+{
+    SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
+    {
+        Properties::Select select(&m_databaseInterface);
+        select.OrderBy("key");
+        std::list<DPL::String> list = select.GetValueList<Properties::key>();
+        if (index >= list.size()) {
+            Throw(Exception::InvalidArgumentException);
+        }
+        for (size_t i = 0; i < index; ++i) {
+            list.pop_front();
+        }
+        return DPL::ToUTF8String(list.front());
+    }
+    SQL_CONNECTION_EXCEPTION_HANDLER_END("Cannot get item count");
+}
+
+std::string WidgetInterfaceDAO::databaseFileName(int widgetHandle)
+{
+    using namespace DPL::DB::ORM;
+    using namespace WrtDB::WidgetConfig;
+
+    WrtDB::WrtDatabase::attachToThreadRO();
+    std::stringstream filename;
+    SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
+    {
+        WrtDB::WidgetDAOReadOnly widgetDAO(widgetHandle);
+        WrtDB::TizenPkgId pkgid = widgetDAO.getTizenPkgId();
+
+        filename << GetWidgetPersistentStoragePath(pkgid)
+                 << "/"
+                 << DATABASE_NAME;
+    }
+    SQL_CONNECTION_EXCEPTION_HANDLER_END("Cannot get item count");
+    WrtDB::WrtDatabase::detachFromThread();
+    return filename.str();
+}
+} // namespace WidgetInterfaceDB
diff --git a/modules/widget_interface_dao/include/wrt-commons/widget-interface-dao/widget_interface_dao.h b/modules/widget_interface_dao/include/wrt-commons/widget-interface-dao/widget_interface_dao.h
new file mode 100644 (file)
index 0000000..8b35344
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+/*
+ * @author      Lukasz Marek (l.marek@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _WIDGET_INTERFACE_DAO_H_
+#define _WIDGET_INTERFACE_DAO_H_
+
+#include <string>
+#include <dpl/db/thread_database_support.h>
+#include <dpl/db/orm_interface.h>
+
+namespace WidgetInterfaceDB {
+class WidgetInterfaceDAO
+{
+  public:
+
+    /**
+     * WidgetInterfaceDAO Exception classes
+     */
+    class Exception
+    {
+      public:
+        DECLARE_EXCEPTION_TYPE(DPL::Exception, Base)
+        DECLARE_EXCEPTION_TYPE(Base, DatabaseError)
+        DECLARE_EXCEPTION_TYPE(Base, LocalStorageValueNoModifableException)
+        DECLARE_EXCEPTION_TYPE(Base, InvalidArgumentException)
+    };
+    WidgetInterfaceDAO(int widgetHandle);
+    virtual ~WidgetInterfaceDAO();
+
+    static std::string databaseFileName(int widgetHandle);
+    void setItem(const std::string& key,
+                 const std::string& value,
+                 bool readOnly,
+                 bool fromConfigXml);
+    void setItem(const std::string& key,
+                 const std::string& value,
+                 bool readOnly);
+    void removeItem(const std::string& key);
+    DPL::Optional<std::string> getValue(const std::string& key) const;
+    void clear(bool removeReadOnly);
+    size_t getStorageSize() const;
+    std::string getKeyByIndex(size_t index) const;
+
+  protected:
+    int m_widgetHandle;
+    mutable DPL::DB::ThreadDatabaseSupport m_databaseInterface;
+
+  private:
+    void checkDatabase();
+    void copyPropertiesFromWrtDatabase();
+};
+typedef std::unique_ptr<WidgetInterfaceDAO> WidgetInterfaceDAOPtr;
+}
+#endif //_WIDGET_INTERFACE_DAO_H_
diff --git a/modules/widget_interface_dao/orm/orm_generator_widget_interface.h b/modules/widget_interface_dao/orm/orm_generator_widget_interface.h
new file mode 100644 (file)
index 0000000..87a3e05
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+#ifndef ORM_GENERATOR_WIDGET_INTERFACE_H_
+#define ORM_GENERATOR_WIDGET_INTERFACE_H_
+
+#define ORM_GENERATOR_DATABASE_NAME widget_interface_db_definitions
+#include <dpl/db/orm_generator.h>
+#undef ORM_GENERATOR_DATABASE_NAME
+
+#endif
diff --git a/modules/widget_interface_dao/orm/widget_interface_db b/modules/widget_interface_dao/orm/widget_interface_db
new file mode 100644 (file)
index 0000000..d33ec48
--- /dev/null
@@ -0,0 +1,17 @@
+SQL(
+    PRAGMA foreign_keys = ON;
+    BEGIN TRANSACTION;
+)
+
+CREATE_TABLE(Properties)
+    COLUMN_NOT_NULL(key,      TEXT,)
+    COLUMN_NOT_NULL(value,    TEXT,)
+    COLUMN_NOT_NULL(readonly, INTEGER, check(readonly between 0 and 1))
+    COLUMN_NOT_NULL(configxml, INTEGER, check(readonly between 0 and 1) DEFAULT 0)
+
+    TABLE_CONSTRAINTS(unique(key))
+CREATE_TABLE_END()
+
+SQL(
+    COMMIT;
+)
diff --git a/modules/widget_interface_dao/orm/widget_interface_db_definitions b/modules/widget_interface_dao/orm/widget_interface_db_definitions
new file mode 100644 (file)
index 0000000..85f627d
--- /dev/null
@@ -0,0 +1,5 @@
+DATABASE_START(widget_interface)
+
+#include "widget_interface_db"
+
+DATABASE_END()
diff --git a/modules/widget_interface_dao/orm/widget_interface_db_sql_generator.h b/modules/widget_interface_dao/orm/widget_interface_db_sql_generator.h
new file mode 100644 (file)
index 0000000..b4ce0b6
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+/*
+ * @file        wrt_db_sql_generator.h
+ * @author      Bartosz Janiak (b.janiak@samsung.com)
+ * @version     1.0
+ * @brief       Macro definitions for generating the SQL input file from
+ * database definition.
+ */
+
+//Do not include this file directly! It is used only for SQL code generation.
+
+#include <dpl/db/orm_macros.h>
+
+#include "widget_interface_db_definitions"