From: Jihoon Chung Date: Fri, 9 Aug 2013 12:42:25 +0000 (+0900) Subject: Remove widget interface DAO code X-Git-Tag: submit/tizen_2.2/20130927.091410^2~7 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fframework%2Fweb%2Fwrt-plugins-common.git;a=commitdiff_plain;h=c1ed900f28a60ccc1b7d1465de40b3d4f011f94d Remove widget interface DAO code [Issue#] N/A [Problem] N/A [Cause] N/A [Solution] Widget interface dao is moved to wrt-commons This commit clean-up dao code and replace to use library which is supported by wrt-commons [SCMRequest] must be imported with wrt-commons https://review.tizendev.org/gerrit/#/c/86092/ Change-Id: I54828427a8cc22e1b385934d2aca306fa4dc44a9 --- diff --git a/.gitignore b/.gitignore index 9fdb538..f32cf97 100644 --- a/.gitignore +++ b/.gitignore @@ -35,8 +35,4 @@ pkgconfigs/*.pc *.swp cmake_build/* -src/modules/slp2.0/WidgetInterfaceDAO/.widget_interface.db -src/modules/slp2.0/WidgetInterfaceDAO/.widget_interface.db-journal -src/modules/slp2.0/WidgetInterfaceDAO/widget_interface_db.sql - -/bin \ No newline at end of file +/bin diff --git a/CMakeLists.txt b/CMakeLists.txt index 8777310..dd78270 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -144,7 +144,7 @@ endmacro(configure_and_install_pkg) configure_and_install_pkg(wrt-plugins-commons-javascript.pc) configure_and_install_pkg(wrt-plugins-commons.pc) configure_and_install_pkg(wrt-plugins-filesystem.pc) -configure_and_install_pkg(wrt-plugins-widget-interface-dao.pc) +configure_and_install_pkg(wrt-plugins-widget-interface.pc) configure_and_install_pkg(wrt-plugins-widgetdb.pc) configure_and_install_pkg(wrt-plugins-plugin-manager.pc) configure_and_install_pkg(wrt-plugin-loading.pc) diff --git a/packaging/wrt-plugins-common.spec b/packaging/wrt-plugins-common.spec index f1c0916..df52c41 100644 --- a/packaging/wrt-plugins-common.spec +++ b/packaging/wrt-plugins-common.spec @@ -15,11 +15,11 @@ BuildRequires: pkgconfig(dpl-event-efl) BuildRequires: pkgconfig(ewebkit2) BuildRequires: pkgconfig(dpl-wrt-dao-ro) BuildRequires: pkgconfig(dpl-wrt-dao-rw) -BuildRequires: pkgconfig(dpl-db-efl) BuildRequires: pkgconfig(libpcrecpp) BuildRequires: pkgconfig(icu-i18n) BuildRequires: pkgconfig(libxml-2.0) BuildRequires: pkgconfig(cert-svc-vcore) +BuildRequires: pkgconfig(wrt-commons-widget-interface-dao) Requires: ldconfig %description @@ -76,7 +76,6 @@ touch /opt/share/widget/plugin-installation-required %{_libdir}/*.so %{_libdir}/*.so.* %{_libdir}/wrt-plugins/w3c-widget-interface/libwrt-plugins-w3c-widget-interface.so -%attr(644,root,root) /usr/share/wrt-plugins-common/widget_interface_db.sql %attr(755,root,root) %{_bindir}/wrt-popup-ace-runtime %attr(755,root,root) %{_bindir}/wrt-popup-wrt-runtime %attr(755,root,root) %{_bindir}/wrt-plugins-installer diff --git a/pkgconfigs/wrt-plugins-widget-interface-dao.pc.in b/pkgconfigs/wrt-plugins-widget-interface.pc.in similarity index 57% rename from pkgconfigs/wrt-plugins-widget-interface-dao.pc.in rename to pkgconfigs/wrt-plugins-widget-interface.pc.in index b4ca655..8792516 100644 --- a/pkgconfigs/wrt-plugins-widget-interface-dao.pc.in +++ b/pkgconfigs/wrt-plugins-widget-interface.pc.in @@ -7,6 +7,6 @@ includedir=${prefix}/include/${project_name} Name: WebRuntime DeviceApis Widget Interface module Description: WebRuntime Widget Interface module Version: @CMAKE_PROJECT_VERSION@ -Requires: dpl-efl dpl-db-efl wrt-plugins-commons dpl-wrt-dao-ro wrt-plugins-localstorage -Libs: -L${libdir} -lwrt-plugins-widget-interface-dao -Cflags: -I${includedir}/WidgetInterfaceDAO +Requires: dpl-efl wrt-plugins-commons dpl-wrt-dao-ro wrt-plugins-localstorage wrt-commons-widget-interface-dao +Libs: -L${libdir} -lwrt-plugins-widget-interface +Cflags: -I${includedir}/WidgetInterface diff --git a/src/Commons/CMakeLists.txt b/src/Commons/CMakeLists.txt index 4d6e3b1..6b58193 100644 --- a/src/Commons/CMakeLists.txt +++ b/src/Commons/CMakeLists.txt @@ -22,9 +22,9 @@ macro(install_wrtaccess_header_file HEADER_FILE) DESTINATION ${DESTINATION_HEADERS_NON_JS}/WrtAccess) endmacro() -macro(install_widget_interface_dao_header_file HEADER_FILE) +macro(install_widget_interface_header_file HEADER_FILE) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${HEADER_FILE} - DESTINATION ${DESTINATION_HEADERS_NON_JS}/WidgetInterfaceDAO) + DESTINATION ${DESTINATION_HEADERS_NON_JS}/WidgetInterface) endmacro() include_config_file(WrtAccess) diff --git a/src/modules/API/LocalStorage/LocalStorageMgr.cpp b/src/modules/API/LocalStorage/LocalStorageMgr.cpp index 7cb7492..04e9cc8 100644 --- a/src/modules/API/LocalStorage/LocalStorageMgr.cpp +++ b/src/modules/API/LocalStorage/LocalStorageMgr.cpp @@ -22,14 +22,14 @@ * @brief */ #include "LocalStorageMgr.h" -#include +#include namespace WrtDeviceApis { namespace LocalStorage { namespace Api { ILocalStoragePtr getLocalStorage(int widgetId) { - return ILocalStoragePtr(new WrtDeviceApis::WidgetInterfaceDAO(widgetId)); + return ILocalStoragePtr(new WrtDeviceApis::WidgetInterfaceObject(widgetId)); } } // Api } // LocalStorage diff --git a/src/modules/packages/CMakeLists.txt b/src/modules/packages/CMakeLists.txt index beadcd3..ed3e799 100644 --- a/src/modules/packages/CMakeLists.txt +++ b/src/modules/packages/CMakeLists.txt @@ -16,7 +16,7 @@ set(TARGET_MODULE_FILESYSTEM "wrt-plugins-filesystem") set(TARGET_MODULE_WIDGET "wrt-plugins-widget") set(TARGET_MODULE_LOCALSTORAGE "wrt-plugins-localstorage") -set(TARGET_MODULE_WIDGET_INTERFACE_DAO "wrt-plugins-widget-interface-dao") +set(TARGET_MODULE_WIDGET_INTERFACE "wrt-plugins-widget-interface") set(TARGET_MODULE_STORAGEEVENT "wrt-plugins-storageevent") set(TARGET_MODULE_TIZEN_SERVICE_EVENT "wrt-plugins-tizen-service-event") set(TARGET_MODULE_SOFTKEYBOARD_CHANGE_EVENT "wrt-plugins-softkeyboardchange-event") @@ -26,7 +26,7 @@ set(TARGET_MODULE_PLUGIN_MANAGER "wrt-plugins-plugin-manager") add_subdirectory(Filesystem) add_subdirectory(Widget) add_subdirectory(LocalStorage) -add_subdirectory(WidgetInterfaceDAO) +add_subdirectory(WidgetInterface) add_subdirectory(WidgetDB) add_subdirectory(PluginManager) add_subdirectory(StorageEvent) diff --git a/src/modules/packages/LocalStorage/CMakeLists.txt b/src/modules/packages/LocalStorage/CMakeLists.txt index 2b0a894..90d648a 100644 --- a/src/modules/packages/LocalStorage/CMakeLists.txt +++ b/src/modules/packages/LocalStorage/CMakeLists.txt @@ -23,6 +23,6 @@ add_library(${TARGET_NAME} STATIC ${SRCS}) target_link_libraries(${TARGET_NAME} ${LIBS_COMMONS} ${TARGET_COMMONS} - ${TARGET_MODULE_WIDGET_INTERFACE_DAO} + ${TARGET_MODULE_WIDGET_INTERFACE} ) diff --git a/src/modules/packages/WidgetInterfaceDAO/CMakeLists.txt b/src/modules/packages/WidgetInterface/CMakeLists.txt similarity index 80% rename from src/modules/packages/WidgetInterfaceDAO/CMakeLists.txt rename to src/modules/packages/WidgetInterface/CMakeLists.txt index 2a6d20e..0ebb5e2 100644 --- a/src/modules/packages/WidgetInterfaceDAO/CMakeLists.txt +++ b/src/modules/packages/WidgetInterface/CMakeLists.txt @@ -15,29 +15,29 @@ macro(install_header_file HEADER_FILE) INSTALL(FILES ${API_WIDGET_INTERFACE_PATH}/${HEADER_FILE} - DESTINATION ${DESTINATION_HEADER_PREFIX}/WidgetInterfaceDAO) + DESTINATION ${DESTINATION_HEADER_PREFIX}/WidgetInterface) endmacro() pkg_search_module(dpl-wrt-dao-ro REQUIRED dpl-wrt-dao-ro) -pkg_search_module(dpl-db REQUIRED dpl-db-efl) +pkg_search_module(wrt-commons-widget-interface-dao REQUIRED wrt-commons-widget-interface-dao) include_directories( ${WIDGET_INTERFACE_INCLUDE_DIRS} ${dpl-wrt-dao-ro_INCLUDE_DIRS} - ${dpl-db_INCLUDE_DIRS}) + ${wrt-commons-widget-interface-dao_INCLUDE_DIRS}) -set(TARGET_NAME ${TARGET_MODULE_WIDGET_INTERFACE_DAO}) +set(TARGET_NAME ${TARGET_MODULE_WIDGET_INTERFACE}) set(SRCS - ${SRCS_WIDGET_INTERFACE_DAO} + ${SRCS_WIDGET_INTERFACE} ) add_library(${TARGET_NAME} SHARED ${SRCS}) target_link_libraries(${TARGET_NAME} ${LIBS_COMMONS} - ${dpl-db_LIBRARIES} ${dpl-wrt-dao-ro_LIBRARIES} + ${wrt-commons-widget-interface-dao_LIBRARIES} ) set_target_properties(${TARGET_NAME} PROPERTIES SOVERSION ${CMAKE_PROJECT_API_VERSION} @@ -47,4 +47,4 @@ set_target_properties(${TARGET_NAME} PROPERTIES INSTALL(TARGETS ${TARGET_NAME} LIBRARY DESTINATION ${DESTINATION_LIB_PREFIX}) -install_header_file(WidgetInterfaceDAO.h) +install_header_file(WidgetInterface.h) diff --git a/src/modules/tizen/CMakeLists.txt b/src/modules/tizen/CMakeLists.txt index 85b3a95..3cfc293 100644 --- a/src/modules/tizen/CMakeLists.txt +++ b/src/modules/tizen/CMakeLists.txt @@ -25,7 +25,7 @@ include_config_file(Filesystem) include_config_file(Widget) include_config_file(LocalStorage) -include_config_file(WidgetInterfaceDAO) -add_subdirectory(WidgetInterfaceDAO) +include_config_file(WidgetInterface) +add_subdirectory(WidgetInterface) include_config_file(WidgetDB) include_config_file(PluginManager) diff --git a/src/modules/tizen/WidgetInterface/CMakeLists.txt b/src/modules/tizen/WidgetInterface/CMakeLists.txt new file mode 100644 index 0000000..883f3d1 --- /dev/null +++ b/src/modules/tizen/WidgetInterface/CMakeLists.txt @@ -0,0 +1,6 @@ + +get_current_path() + +pkg_search_module(wrt-commons-widget-interface-dao REQUIRED wrt-commons-widget-interface-dao) + +include_directories(${CURRENT_PATH}) diff --git a/src/modules/tizen/WidgetInterface/WidgetInterface.cpp b/src/modules/tizen/WidgetInterface/WidgetInterface.cpp new file mode 100644 index 0000000..cfd9c8c --- /dev/null +++ b/src/modules/tizen/WidgetInterface/WidgetInterface.cpp @@ -0,0 +1,139 @@ +/* + * 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 "WidgetInterface.h" +#include +#include +#include +#include +#include +#include +#include + +namespace WrtDeviceApis { +using namespace WidgetInterfaceDB; + +WidgetInterfaceObject::WidgetInterfaceObject(int widgetHandle) +{ + Try + { + m_dao.reset(new WidgetInterfaceDAO(widgetHandle)); + } + Catch(WidgetInterfaceDAO::Exception::DatabaseError) + { + ReThrow(Commons::PlatformException); + } +} + +WidgetInterfaceObject::~WidgetInterfaceObject() +{ + m_dao.reset(); +} + +void WidgetInterfaceObject::setItem(const std::string& key, + const std::string& value, + bool readOnly) +{ + Try + { + m_dao->setItem(key, value, readOnly); + } + Catch(WidgetInterfaceDAO::Exception::DatabaseError) + { + ReThrow(Commons::PlatformException); + } + Catch(WidgetInterfaceDAO::Exception::LocalStorageValueNoModifableException) + { + LogError("Cannot delete item. Item is readonly"); + ReThrow(Commons::LocalStorageValueNoModifableException); + } +} + +void WidgetInterfaceObject::removeItem(const std::string& key) +{ + Try + { + m_dao->removeItem(key); + } + Catch(WidgetInterfaceDAO::Exception::DatabaseError) + { + ReThrow(Commons::PlatformException); + } + Catch(WidgetInterfaceDAO::Exception::LocalStorageValueNoModifableException) + { + LogError("Cannot delete item. Item is readonly"); + ReThrow(Commons::LocalStorageValueNoModifableException); + } +} + +DPL::Optional WidgetInterfaceObject::getValue( + const std::string& key) const +{ + Try + { + return m_dao->getValue(key); + } + Catch(WidgetInterfaceDAO::Exception::DatabaseError) + { + ReThrow(Commons::PlatformException); + } +} + +void WidgetInterfaceObject::clear(bool removeReadOnly) +{ + Try + { + m_dao->clear(removeReadOnly); + } + Catch(WidgetInterfaceDAO::Exception::DatabaseError) + { + ReThrow(Commons::PlatformException); + } +} + +size_t WidgetInterfaceObject::getStorageSize() const +{ + Try + { + return m_dao->getStorageSize(); + } + Catch(WidgetInterfaceDAO::Exception::DatabaseError) + { + ReThrow(Commons::PlatformException); + } +} + +std::string WidgetInterfaceObject::getKeyByIndex(size_t index) const +{ + Try + { + return m_dao->getKeyByIndex(index); + } + Catch(WidgetInterfaceDAO::Exception::DatabaseError) + { + ReThrow(Commons::PlatformException); + } + Catch(WidgetInterfaceDAO::Exception::InvalidArgumentException) + { + ReThrow(Commons::InvalidArgumentException); + } +} +} diff --git a/src/modules/tizen/WidgetInterfaceDAO/WidgetInterfaceDAO.h b/src/modules/tizen/WidgetInterface/WidgetInterface.h similarity index 63% rename from src/modules/tizen/WidgetInterfaceDAO/WidgetInterfaceDAO.h rename to src/modules/tizen/WidgetInterface/WidgetInterface.h index b4141c0..1dacf49 100644 --- a/src/modules/tizen/WidgetInterfaceDAO/WidgetInterfaceDAO.h +++ b/src/modules/tizen/WidgetInterface/WidgetInterface.h @@ -19,28 +19,24 @@ * @brief */ -#ifndef WRTDEVICEAPIS_COMMONS_WIDGET_INTERFACE_DAO_H_ -#define WRTDEVICEAPIS_COMMONS_WIDGET_INTERFACE_DAO_H_ +#ifndef WRTDEVICEAPIS_COMMONS_WIDGET_INTERFACE_H_ +#define WRTDEVICEAPIS_COMMONS_WIDGET_INTERFACE_H_ #include -#include -#include +#include +#include #include namespace WrtDeviceApis { -class WidgetInterfaceDAO : +class WidgetInterfaceObject : public LocalStorage::Api::ILocalStorage { public: - WidgetInterfaceDAO(int widgetHandle); - virtual ~WidgetInterfaceDAO(); + WidgetInterfaceObject(int widgetHandle); + virtual ~WidgetInterfaceObject(); 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 getValue(const std::string& key) const; @@ -48,15 +44,9 @@ class WidgetInterfaceDAO : size_t getStorageSize() const; std::string getKeyByIndex(size_t index) const; - protected: - int m_widgetHandle; - mutable DPL::DB::ThreadDatabaseSupport m_databaseInterface; - private: - bool checkDatabase(); - bool copyPropertiesFromWrtDatabase(); - static std::string databaseFileName(int widgetHandle); + WidgetInterfaceDB::WidgetInterfaceDAOPtr m_dao; }; } -#endif //WRTDEVICEAPIS_COMMONS_WIDGET_INTERFACE_DAO_H_ \ No newline at end of file +#endif //WRTDEVICEAPIS_COMMONS_WIDGET_INTERFACE_H_ diff --git a/src/modules/tizen/WidgetInterfaceDAO/config.cmake b/src/modules/tizen/WidgetInterface/config.cmake similarity index 71% rename from src/modules/tizen/WidgetInterfaceDAO/config.cmake rename to src/modules/tizen/WidgetInterface/config.cmake index e910088..a69d23e 100644 --- a/src/modules/tizen/WidgetInterfaceDAO/config.cmake +++ b/src/modules/tizen/WidgetInterface/config.cmake @@ -11,7 +11,7 @@ SET(API_WIDGET_INTERFACE_PATH PARENT_SCOPE ) -set(SRCS_WIDGET_INTERFACE_DAO - ${CURRENT_PATH}/WidgetInterfaceDAO.cpp +set(SRCS_WIDGET_INTERFACE + ${CURRENT_PATH}/WidgetInterface.cpp PARENT_SCOPE ) diff --git a/src/modules/tizen/WidgetInterfaceDAO/CMakeLists.txt b/src/modules/tizen/WidgetInterfaceDAO/CMakeLists.txt deleted file mode 100644 index 60886cf..0000000 --- a/src/modules/tizen/WidgetInterfaceDAO/CMakeLists.txt +++ /dev/null @@ -1,22 +0,0 @@ - -get_current_path() - -pkg_search_module(dpl-db REQUIRED dpl-db-efl) - -include_directories(${CURRENT_PATH}) - -STRING(REPLACE ";" ":" SQL_GENERATOR_INCLUDE_DIRS "${dpl-db_INCLUDE_DIRS}") - -ADD_CUSTOM_COMMAND( OUTPUT ${CURRENT_PATH}/widget_interface_db.sql - COMMAND rm -f ${CURRENT_PATH}/.widget_interface.db - COMMAND rm -f ${CURRENT_PATH}/widget_interface_db.sql - COMMAND CPATH=${SQL_GENERATOR_INCLUDE_DIRS} gcc -Wall -E ${CURRENT_PATH}/widget_interface_db_sql_generator.h | grep --invert-match "^#" > ${CURRENT_PATH}/widget_interface_db.sql - COMMAND sqlite3 ${CURRENT_PATH}/.widget_interface.db ".read ${CURRENT_PATH}/widget_interface_db.sql" || rm -f ${CURRENT_PATH}/.widget_interface.db - DEPENDS ${CURRENT_PATH}/widget_interface_db_sql_generator.h ${CURRENT_PATH}/widget_interface_db -) - -ADD_CUSTOM_TARGET(Sqlite3Db ALL DEPENDS ${CURRENT_PATH}/widget_interface_db.sql) - -INSTALL(FILES ${CURRENT_PATH}/widget_interface_db.sql - DESTINATION share/wrt-plugins-common/ -) diff --git a/src/modules/tizen/WidgetInterfaceDAO/WidgetInterfaceDAO.cpp b/src/modules/tizen/WidgetInterfaceDAO/WidgetInterfaceDAO.cpp deleted file mode 100644 index 35504bf..0000000 --- a/src/modules/tizen/WidgetInterfaceDAO/WidgetInterfaceDAO.cpp +++ /dev/null @@ -1,340 +0,0 @@ -/* - * 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 "WidgetInterfaceDAO.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "orm_generator_widget_interface.h" -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"; -} - -namespace WrtDeviceApis { -WidgetInterfaceDAO::WidgetInterfaceDAO(int widgetHandle) : - m_widgetHandle(widgetHandle), - m_databaseInterface(databaseFileName(widgetHandle), DATABASE_FLAGS) -{ - if (!checkDatabase()) { - LogError("There is a problem with database"); - } - m_databaseInterface.AttachToThread(DPL::DB::SqlConnection::Flag::RW); -} - -WidgetInterfaceDAO::~WidgetInterfaceDAO() -{ - m_databaseInterface.DetachFromThread(); -} - -bool WidgetInterfaceDAO::checkDatabase() -{ - using namespace WrtDB::GlobalConfig; - 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(GetWrtWidgetInterfaceDatabaseFilePath(), std::ios_base::in); - if (!file) { - LogError("Cannot create database. SQL file is missing."); - return false; - } - - std::stringstream buffer; - buffer << file.rdbuf(); - - file.close(); - - Try - { - DPL::DB::SqlConnection con(databaseFile, - DATABASE_FLAGS, DATABASE_OPTIONS); - con.ExecCommand(buffer.str().c_str()); - } - Catch(DPL::DB::SqlConnection::Exception::Base) - { - LogError("Cannot create database"); - return false; - } - copyPropertiesFromWrtDatabase(); - } - return true; -} - -bool WidgetInterfaceDAO::copyPropertiesFromWrtDatabase() -{ - using namespace DPL::DB::ORM; - using namespace DPL::DB::ORM::widget_interface; - - bool result = true; - WrtDB::WrtDatabase::attachToThreadRO(); - m_databaseInterface.AttachToThread(DPL::DB::SqlConnection::Flag::RW); - - Try - { - WrtDB::PropertyDAOReadOnly::WidgetPreferenceList existing = - WrtDB::PropertyDAOReadOnly::GetPropertyList(m_widgetHandle); - - Try - { - //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); - } - } - } - Catch(Commons::Exception) - { - LogError("Cannot copy properties read from config.xml"); - result = false; - } - } - Catch(DPL::DB::SqlConnection::Exception::Base) - { - LogError("Cannot copy properties read from config.xml"); - result = false; - } - WrtDB::WrtDatabase::detachFromThread(); - m_databaseInterface.DetachFromThread(); - return result; -} - -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) -{ - using namespace DPL::DB::ORM; - using namespace DPL::DB::ORM::widget_interface; - - Try - { - ScopedTransaction tran(&m_databaseInterface); - //check if key exists - Properties::Select select(&m_databaseInterface); - select.Where( - Equals(DPL::FromUTF8String(key))); - std::list 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(Commons::LocalStorageValueNoModifableException); - } - row.Set_value(DPL::FromUTF8String(value)); - row.Set_readonly(readOnly ? 1 : 0); - Properties::Update update(&m_databaseInterface); - update.Where(Equals(DPL::FromUTF8String(key))); - update.Values(row); - update.Execute(); - } - tran.Commit(); - } - Catch(DPL::DB::SqlConnection::Exception::Base) - { - LogError("Cannot set item " << key << " with value " << value); - ReThrow(Commons::PlatformException); - } -} - -void WidgetInterfaceDAO::removeItem(const std::string& key) -{ - using namespace DPL::DB::ORM; - using namespace DPL::DB::ORM::widget_interface; - - Try - { - Properties::Select select(&m_databaseInterface); - select.Where(Equals(DPL::FromUTF8String(key))); - bool readonly = select.GetSingleValue(); - if (readonly) { - ThrowMsg(Commons::LocalStorageValueNoModifableException, - "Cannot delete item. Item is readonly"); - } - Properties::Delete deleteItem(&m_databaseInterface); - deleteItem.Where(Equals(DPL::FromUTF8String(key))); - deleteItem.Execute(); - } - Catch(DPL::DB::SqlConnection::Exception::Base) - { - LogError("Cannot delete item " << key); - ReThrow(Commons::PlatformException); - } -} - -DPL::Optional WidgetInterfaceDAO::getValue( - const std::string& key) const -{ - using namespace DPL::DB::ORM; - using namespace DPL::DB::ORM::widget_interface; - - Try - { - Properties::Select select(&m_databaseInterface); - select.Where(Equals(DPL::FromUTF8String(key))); - std::list value = select.GetValueList(); - if (value.empty()) { - return DPL::Optional(); - } - return DPL::Optional(DPL::ToUTF8String(value.front())); - } - Catch(DPL::DB::SqlConnection::Exception::Base) - { - LogError("Not found item " << key); - ReThrow(Commons::PlatformException); - } -} - -void WidgetInterfaceDAO::clear(bool removeReadOnly) -{ - using namespace DPL::DB::ORM; - using namespace DPL::DB::ORM::widget_interface; - Try - { - Properties::Delete deleteItem(&m_databaseInterface); - if (!removeReadOnly) { - deleteItem.Where(Equals(0)); - } - deleteItem.Execute(); - } - Catch(DPL::DB::SqlConnection::Exception::Base) - { - LogError("Cannot delete all items"); - ReThrow(Commons::PlatformException); - } -} - -size_t WidgetInterfaceDAO::getStorageSize() const -{ - using namespace DPL::DB::ORM; - using namespace DPL::DB::ORM::widget_interface; - - Try - { - Properties::Select select(&m_databaseInterface); - std::list list = - select.GetValueList(); - return list.size(); - } - Catch(DPL::DB::SqlConnection::Exception::Base) - { - LogError("Cannot get item count"); - ReThrow(Commons::PlatformException); - } - return 0; -} - -std::string WidgetInterfaceDAO::getKeyByIndex(size_t index) const -{ - using namespace DPL::DB::ORM; - using namespace DPL::DB::ORM::widget_interface; - - Try - { - Properties::Select select(&m_databaseInterface); - select.OrderBy("key"); - std::list list = - select.GetValueList(); - if (index >= list.size()) { - Throw(Commons::InvalidArgumentException); - } - for (size_t i = 0; i < index; ++i) { - list.pop_front(); - } - return DPL::ToUTF8String(list.front()); - } - Catch(DPL::DB::SqlConnection::Exception::Base) - { - LogError("Cannot get item count"); - ReThrow(Commons::PlatformException); - } -} - -std::string WidgetInterfaceDAO::databaseFileName(int widgetHandle) -{ - using namespace DPL::DB::ORM; - using namespace WrtDB::WidgetConfig; - using namespace WrtDB::GlobalConfig; - - WrtDB::WrtDatabase::attachToThreadRO(); - - std::stringstream filename; - Try - { - WrtDB::WidgetDAOReadOnly widgetDAO(widgetHandle); - WrtDB::TizenPkgId pkgid = widgetDAO.getTizenPkgId(); - - filename << GetWidgetPersistentStoragePath(pkgid) - << "/" - << GetWidgetInterfaceDatabaseFile(); - } - Catch(DPL::DB::SqlConnection::Exception::Base) - { - LogError("Cannot get item count"); - ReThrow(Commons::PlatformException); - } - WrtDB::WrtDatabase::detachFromThread(); - return filename.str(); -} -} diff --git a/src/modules/tizen/WidgetInterfaceDAO/orm_generator_widget_interface.h b/src/modules/tizen/WidgetInterfaceDAO/orm_generator_widget_interface.h deleted file mode 100644 index 87a3e05..0000000 --- a/src/modules/tizen/WidgetInterfaceDAO/orm_generator_widget_interface.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - * 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 -#undef ORM_GENERATOR_DATABASE_NAME - -#endif diff --git a/src/modules/tizen/WidgetInterfaceDAO/widget_interface_db b/src/modules/tizen/WidgetInterfaceDAO/widget_interface_db deleted file mode 100644 index d33ec48..0000000 --- a/src/modules/tizen/WidgetInterfaceDAO/widget_interface_db +++ /dev/null @@ -1,17 +0,0 @@ -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/src/modules/tizen/WidgetInterfaceDAO/widget_interface_db_definitions b/src/modules/tizen/WidgetInterfaceDAO/widget_interface_db_definitions deleted file mode 100644 index 85f627d..0000000 --- a/src/modules/tizen/WidgetInterfaceDAO/widget_interface_db_definitions +++ /dev/null @@ -1,5 +0,0 @@ -DATABASE_START(widget_interface) - -#include "widget_interface_db" - -DATABASE_END() diff --git a/src/modules/tizen/WidgetInterfaceDAO/widget_interface_db_sql_generator.h b/src/modules/tizen/WidgetInterfaceDAO/widget_interface_db_sql_generator.h deleted file mode 100644 index b4ce0b6..0000000 --- a/src/modules/tizen/WidgetInterfaceDAO/widget_interface_db_sql_generator.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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 - -#include "widget_interface_db_definitions"