Replace db_manager with DatabaseManager 03/66003/2
authorMu-Woong Lee <muwoong.lee@samsung.com>
Thu, 14 Apr 2016 11:55:43 +0000 (20:55 +0900)
committerMu-Woong Lee <muwoong.lee@samsung.com>
Fri, 15 Apr 2016 01:33:53 +0000 (10:33 +0900)
Change-Id: Ifc736963fbe1a1cdce917c163f19c93ea01b0d5b
Signed-off-by: Mu-Woong Lee <muwoong.lee@samsung.com>
25 files changed:
src/custom/CustomContextProvider.cpp
src/place/recognition/user_places/location_logger.cpp
src/place/recognition/user_places/places_detector.cpp
src/place/recognition/user_places/places_detector.h
src/place/recognition/user_places/user_places.cpp
src/place/recognition/user_places/visit_detector.cpp
src/place/recognition/user_places/visit_detector.h
src/place/recognition/user_places/wifi_logger.cpp
src/statistics/app/active_window_monitor.cpp
src/statistics/app/active_window_monitor.h
src/statistics/app/app_inactive_detector/inactive_detector_storage.cpp
src/statistics/app/app_inactive_detector/inactive_detector_storage.h
src/statistics/app/db_handle.cpp
src/statistics/app/db_init.cpp
src/statistics/app/db_init.h
src/statistics/app/install_monitor.cpp
src/statistics/app/install_monitor.h
src/statistics/media/db_handle.cpp
src/statistics/media/media_content_monitor.cpp
src/statistics/media/media_content_monitor.h
src/statistics/shared/db_handle_base.cpp
src/statistics/shared/db_handle_base.h
src/statistics/social/db_handle.cpp
src/statistics/social/log_aggregator.cpp
src/statistics/social/log_aggregator.h

index 286f28e909816ed3b60785ecaf3ba01e1694d47d..b6e251bac5fe5fdfb99b5dc57d8e0ab1e02987f0 100644 (file)
 #include <types_internal.h>
 #include <ContextManager.h>
 #include <ContextProviderBase.h>
-#include <db_mgr.h>
+#include <DatabaseManager.h>
 #include <CustomContextProvider.h>
 #include "CustomBase.h"
 
 static std::map<std::string, ctx::CustomBase*> __customMap;
+static ctx::DatabaseManager __dbManager;
 
 static bool __isValidFact(std::string subject, ctx::Json& fact);
 static bool __checkValueInt(ctx::Json& tmpl, std::string key, int value);
@@ -67,12 +68,12 @@ EXTAPI bool ctx::initCustomContextProvider()
                        + "attributes TEXT DEFAULT '' NOT NULL, owner TEXT DEFAULT '' NOT NULL)";
 
        std::vector<Json> record;
-       bool ret = db_manager::execute_sync(q.c_str(), &record);
+       bool ret = __dbManager.executeSync(q.c_str(), &record);
        IF_FAIL_RETURN_TAG(ret, false, _E, "Create template table failed");
 
        // Register custom items
        std::string qSelect = "SELECT * FROM context_trigger_custom_template";
-       ret = db_manager::execute_sync(qSelect.c_str(), &record);
+       ret = __dbManager.executeSync(qSelect.c_str(), &record);
        IF_FAIL_RETURN_TAG(ret, false, _E, "Failed to query custom templates");
        IF_FAIL_RETURN(record.size() > 0, true);
 
@@ -123,7 +124,7 @@ EXTAPI int ctx::custom_context_provider::addItem(std::string subject, std::strin
                std::string q = "INSERT OR IGNORE INTO context_trigger_custom_template (subject, name, attributes, owner) VALUES ('"
                                + subject + "', '" + name +  "', '" + tmpl.str() + "', '" + owner + "'); ";
                std::vector<Json> record;
-               bool ret = db_manager::execute_sync(q.c_str(), &record);
+               bool ret = __dbManager.executeSync(q.c_str(), &record);
                IF_FAIL_RETURN_TAG(ret, false, _E, "Failed to query custom templates");
        }
 
@@ -141,7 +142,7 @@ EXTAPI int ctx::custom_context_provider::removeItem(std::string subject)
        // Remove item from custom template db
        std::string q = "DELETE FROM context_trigger_custom_template WHERE subject = '" + subject + "'";
        std::vector<Json> record;
-       bool ret = db_manager::execute_sync(q.c_str(), &record);
+       bool ret = __dbManager.executeSync(q.c_str(), &record);
        IF_FAIL_RETURN_TAG(ret, false, _E, "Failed to query custom templates");
 
        return ERR_NONE;
index ed9ea6f5586826f6cb4a3aa0c962c11583c47528..193002c376351ef0e1d3693c37c138d3e6d0be97 100644 (file)
  * limitations under the License.
  */
 
-#include "location_logger.h"
-#include <types_internal.h>
-#include "../place_recognition_types.h"
-#include <db_mgr.h>
 #include <sstream>
+#include <types_internal.h>
 #include <Json.h>
+#include <DatabaseManager.h>
+#include "../place_recognition_types.h"
 #include "user_places_params.h"
 #include "debug_utils.h"
+#include "location_logger.h"
 
 #ifdef TIZEN_ENGINEER_MODE
 #define __LOCATION_CREATE_TABLE_COLUMNS \
@@ -175,7 +175,8 @@ void ctx::LocationLogger::__log(location_accessibility_state_e state)
 
 int ctx::LocationLogger::__dbCreateTable()
 {
-       bool ret = db_manager::create_table(0, LOCATION_TABLE_NAME, __LOCATION_CREATE_TABLE_COLUMNS, NULL, NULL);
+       ctx::DatabaseManager dbManager;
+       bool ret = dbManager.createTable(0, LOCATION_TABLE_NAME, __LOCATION_CREATE_TABLE_COLUMNS, NULL, NULL);
        _D("%s -> Table Creation Request", ret ? "SUCCESS" : "FAIL");
        return 0;
 }
@@ -193,8 +194,9 @@ int ctx::LocationLogger::__dbInsertLog(LocationEvent locationEvent)
        data.set(NULL, LOCATION_COLUMN_METHOD, static_cast<int>(locationEvent.method));
 #endif /* TIZEN_ENGINEER_MODE */
 
+       ctx::DatabaseManager dbManager;
        int64_t rowId;
-       bool ret = db_manager::insert_sync(LOCATION_TABLE_NAME, data, &rowId);
+       bool ret = dbManager.insertSync(LOCATION_TABLE_NAME, data, &rowId);
        _D("%s -> DB: location table insert result", ret ? "SUCCESS" : "FAIL");
        return ret;
 }
index 88281cfefb1dbaca719f7a0425660a3227e0f30e..525fc43e8ab2786bc8e0d4aaee2818b4da873846 100644 (file)
@@ -16,7 +16,6 @@
 
 #include <sstream>
 #include <types_internal.h>
-#include <db_mgr.h>
 #include <Json.h>
 #include "similarity.h"
 #include "places_detector.h"
@@ -84,7 +83,7 @@ bool ctx::PlacesDetector::onTimerExpired(int timerId)
 std::vector<ctx::Json> ctx::PlacesDetector::__dbGetVisits()
 {
        std::vector<Json> records;
-       bool ret = db_manager::execute_sync(__GET_VISITS_QUERY, &records);
+       bool ret = __dbManager.executeSync(__GET_VISITS_QUERY, &records);
        _D("load visits execute query result: %s", ret ? "SUCCESS" : "FAIL");
        return records;
 }
@@ -92,7 +91,7 @@ std::vector<ctx::Json> ctx::PlacesDetector::__dbGetVisits()
 std::vector<ctx::Json> ctx::PlacesDetector::__dbGetPlaces()
 {
        std::vector<Json> records;
-       bool ret = db_manager::execute_sync(__GET_PLACES_QUERY, &records);
+       bool ret = __dbManager.executeSync(__GET_PLACES_QUERY, &records);
        _D("load places execute query result: %s", ret ? "SUCCESS" : "FAIL");
        return records;
 }
@@ -364,7 +363,7 @@ std::shared_ptr<ctx::graph::Graph> ctx::PlacesDetector::__graphFromVisits(const
 void ctx::PlacesDetector::__dbDeletePlaces()
 {
        std::vector<Json> records;
-       bool ret = db_manager::execute_sync(__DELETE_PLACES_QUERY, &records);
+       bool ret = __dbManager.executeSync(__DELETE_PLACES_QUERY, &records);
        _D("delete places execute query result: %s", ret ? "SUCCESS" : "FAIL");
 }
 
@@ -384,7 +383,7 @@ void ctx::PlacesDetector::__dbDeleteOlderVisitsThan(time_t threshold)
        query << " WHERE " << VISIT_COLUMN_END_TIME << " < " << threshold;
        // query << " AND 0"; // XXX: Always false condition. Uncomment it for not deleting any visit during development.
        std::vector<Json> records;
-       bool ret = db_manager::execute_sync(query.str().c_str(), &records);
+       bool ret = __dbManager.executeSync(query.str().c_str(), &records);
        _D("delete old visits execute query result: %s", ret ? "SUCCESS" : "FAIL");
 }
 
@@ -402,7 +401,7 @@ ctx::PlacesDetector::PlacesDetector(bool testMode) :
 
 void ctx::PlacesDetector::__dbCreateTable()
 {
-       bool ret = db_manager::create_table(0, PLACE_TABLE, __PLACE_TABLE_COLUMNS);
+       bool ret = __dbManager.createTable(0, PLACE_TABLE, __PLACE_TABLE_COLUMNS);
        _D("db: place Table Creation Result: %s", ret ? "SUCCESS" : "FAIL");
 }
 
@@ -421,7 +420,7 @@ void ctx::PlacesDetector::__dbInsertPlace(const Place &place)
        data.set(NULL, PLACE_COLUMN_CREATE_DATE, static_cast<int>(place.createDate));
 
        int64_t rowId;
-       bool ret = db_manager::insert_sync(PLACE_TABLE, data, &rowId);
+       bool ret = __dbManager.insertSync(PLACE_TABLE, data, &rowId);
        _D("insert place execute query result: %s", ret ? "SUCCESS" : "FAIL");
 }
 
index 510aebebb72e5affe6ff9de2a3e02fc72d6742b8..6444539bc78e1c558111f09a969f5d712c2cbdb5 100644 (file)
 #ifndef _CONTEXT_PLACE_RECOGNITION_PLACES_DETECTOR_
 #define _CONTEXT_PLACE_RECOGNITION_PLACES_DETECTOR_
 
-#include "visit_detector.h"
-#include <ITimerListener.h>
+#include <vector>
 #include <cstdint>
-#include "db_listener_iface.h"
+#include <ITimerListener.h>
+#include <DatabaseManager.h>
+#include "visit_detector.h"
 #include "user_places_types.h"
-#include <vector>
 
 namespace ctx {
 
@@ -30,6 +30,7 @@ namespace ctx {
 
        private:
                bool __testMode;
+               DatabaseManager __dbManager;
 
                double __doubleValueFromJson(Json &row, const char* key);
                Categs __visitCategsFromJson(Json &row);
index 5357fa9bd62b30ffea4e0b4695172caa8688d953..1b927c31acee6514c9ce9b4201eb7e51b22a6976 100644 (file)
@@ -20,7 +20,6 @@
 #include "user_places.h"
 #include "places_detector.h"
 #include "../place_recognition_types.h"
-#include "db_mgr.h"
 
 ctx::UserPlaces::UserPlaces(PlaceRecogMode energyMode):
        __visitDetector(nullptr),
index 57383cafd04340a5ae8c1539ed3c31088aede5d6..d63febfc2950e18c5a8cbc5ed444b351817215ed 100644 (file)
@@ -19,7 +19,6 @@
 #include <iomanip>
 #include <sstream>
 #include <types_internal.h>
-#include <db_mgr.h>
 #include <Json.h>
 #include "../place_recognition_types.h"
 #include "visit_detector.h"
@@ -361,7 +360,7 @@ std::shared_ptr<ctx::Visits> ctx::VisitDetector::getVisits()
 
 void ctx::VisitDetector::__dbCreateTable()
 {
-       bool ret = db_manager::create_table(0, VISIT_TABLE, __VISIT_TABLE_COLUMNS);
+       bool ret = __dbManager.createTable(0, VISIT_TABLE, __VISIT_TABLE_COLUMNS);
        _D("db: visit Table Creation Result: %s", ret ? "SUCCESS" : "FAIL");
 }
 
@@ -411,7 +410,7 @@ int ctx::VisitDetector::__dbInsertVisit(Visit visit)
        __putVisitCategsToJson(visit.categs, data);
 
        int64_t rowId;
-       bool ret = db_manager::insert_sync(VISIT_TABLE, data, &rowId);
+       bool ret = __dbManager.insertSync(VISIT_TABLE, data, &rowId);
        _D("db: visit table insert result: %s", ret ? "SUCCESS" : "FAIL");
        return ret;
 }
index 757774e0fb7225f9407b128753c0da7567d07112..ee6e7c24a6a4e17ac59cf564d3015ff47d3cec93 100644 (file)
@@ -24,6 +24,7 @@
 #include <unordered_set>
 #include "user_places_types.h"
 #include <Json.h>
+#include <DatabaseManager.h>
 #include "visit_listener_iface.h"
 #include "location_logger.h"
 #include "location_listener_iface.h"
@@ -49,6 +50,7 @@ namespace ctx {
                int __tolerance;
                bool __entranceToPlace;
                int __periodSeconds;
+               DatabaseManager __dbManager;
 
                // fields that  are used only in case of entrance detection
                std::shared_ptr<MacSet> __representativesMacs; // macs that represent the current place
index 4c3742af1ae0121c371af46782d3f783f034c205..e1d14282d0666a3993e3ae4a1993c0207215dd55 100644 (file)
  * limitations under the License.
  */
 
-#include "wifi_logger.h"
+#include <sstream>
 #include <types_internal.h>
+#include <DatabaseManager.h>
 #include "../place_recognition_types.h"
-#include <db_mgr.h>
-#include <sstream>
 #include "debug_utils.h"
+#include "wifi_logger.h"
 
 #define __WIFI_CREATE_TABLE_COLUMNS \
        WIFI_COLUMN_TIMESTAMP " timestamp NOT NULL, "\
@@ -35,7 +35,8 @@
 
 int ctx::WifiLogger::__dbCreateTable()
 {
-       bool ret = db_manager::create_table(0, WIFI_TABLE_NAME, __WIFI_CREATE_TABLE_COLUMNS, NULL, NULL);
+       ctx::DatabaseManager dbManager;
+       bool ret = dbManager.createTable(0, WIFI_TABLE_NAME, __WIFI_CREATE_TABLE_COLUMNS, NULL, NULL);
        _D("Table Creation Request: %s", ret ? "SUCCESS" : "FAIL");
        return ret;
 }
@@ -43,6 +44,7 @@ int ctx::WifiLogger::__dbCreateTable()
 int ctx::WifiLogger::__dbInsertLogs()
 {
        if (__logs.size() > 0) {
+               ctx::DatabaseManager dbManager;
                std::stringstream query;
                const char* separator = " ";
                query << "BEGIN TRANSACTION; \
@@ -56,7 +58,7 @@ int ctx::WifiLogger::__dbInsertLogs()
                __logs.clear();
                query << "; \
                                END TRANSACTION;";
-               bool ret = ctx::db_manager::execute(0, query.str().c_str(), NULL);
+               bool ret = dbManager.execute(0, query.str().c_str(), NULL);
                _D("DB insert request: %s", ret ? "SUCCESS" : "FAIL");
                return ret;
        }
index f429a9c14ebc07f319aaf50142be02eaabebb432..2b7b1ee87243e04831a81647ccb439a8595d759f 100644 (file)
@@ -18,7 +18,6 @@
 #include <time.h>
 #include <app_manager.h>
 
-#include <db_mgr.h>
 #include <Json.h>
 #include <types_internal.h>
 #include "../shared/system_info.h"
@@ -99,7 +98,7 @@ void ctx::app_use_monitor::create_record(std::string app_id)
        if (ctx::system_info::get_wifi_bssid(bssid))
                data.set(NULL, STATS_BSSID, bssid);
 
-       db_manager::insert(0, APP_TABLE_USAGE_LOG, data, NULL);
+       __dbManager.insert(0, APP_TABLE_USAGE_LOG, data, NULL);
 }
 
 void ctx::app_use_monitor::finish_record(std::string app_id)
@@ -113,7 +112,7 @@ void ctx::app_use_monitor::finish_record(std::string app_id)
                        "SELECT MAX(" STATS_COL_ROW_ID ") FROM " APP_TABLE_USAGE_LOG \
                        " WHERE " STATS_APP_ID " = '" << app_id << "'" \
                        " AND " STATS_DURATION " = 0)";
-       db_manager::execute(0, query.str().c_str(), NULL);
+       __dbManager.execute(0, query.str().c_str(), NULL);
 }
 
 bool ctx::app_use_monitor::is_skippable(std::string app_id)
@@ -145,5 +144,5 @@ void ctx::app_use_monitor::remove_expired()
        std::stringstream query;
        query << "DELETE FROM " APP_TABLE_USAGE_LOG " WHERE " \
                STATS_UNIV_TIME " < strftime('%s', 'now') - " << LOG_RETENTION_PERIOD;
-       db_manager::execute(0, query.str().c_str(), NULL);
+       __dbManager.execute(0, query.str().c_str(), NULL);
 }
index 7b5e3a0bff860310d9012e6b49f940b4907d8319..d86a1410f4f3c89723b3d58d5a47da582eba2e53 100644 (file)
@@ -20,6 +20,7 @@
 #include <string>
 #include <sstream>
 #include <DBusSignalWatcher.h>
+#include <DatabaseManager.h>
 
 namespace ctx {
 
@@ -28,6 +29,7 @@ namespace ctx {
                int64_t signal_id;
                int last_cleanup_time;
                DBusSignalWatcher __dbusWatcher;
+               DatabaseManager __dbManager;
 
                bool start_logging(void);
                void stop_logging(void);
index c2207a69ffddc0adf656637b2a2cd8ede9bf887d..0feb2b711322b8fc05a366fab5598464404c43c2 100644 (file)
 #include "inactive_detector_storage_queries.h"
 #include "inactive_detector_classificator.h"
 #include "app_inactive_detector_types.h"
-#include "db_mgr.h"
-#include <db_mgr.h>
 
 /*int ctx::inactive_detector_storage::create_table()
 {
-       bool ret = db_manager::create_table(0, WIFI_TABLE_NAME, WIFI_CREATE_TABLE_COLUMNS, NULL, NULL);
+       bool ret = __dbManager.create_table(0, WIFI_TABLE_NAME, WIFI_CREATE_TABLE_COLUMNS, NULL, NULL);
        _D("Table Creation Request: %s", ret ? "SUCCESS" : "FAIL");
        return ret;
 }*/
@@ -46,7 +44,7 @@ int ctx::inactive_detector_storage::read(
 
        IF_FAIL_RETURN(!query.empty(), ERR_OPERATION_FAILED);
 
-       bool ret = db_manager::execute(
+       bool ret = __dbManager.execute(
                STR_EQ(subject, APP_INACTIVE_SUBJ_GET_APPS_INACTIVE) ?
                        APP_INACTIVE_QUERY_ID_GET_APPS_INACTIVE :
                        APP_INACTIVE_QUERY_ID_GET_APPS_ACTIVE,
@@ -165,7 +163,7 @@ void ctx::inactive_detector_storage::json_to_object(std::vector<Json>& records,
        }
 }
 
-void ctx::inactive_detector_storage::on_query_result_received(unsigned int query_id,
+void ctx::inactive_detector_storage::onExecuted(unsigned int query_id,
        int error,
        std::vector<Json>& records)
 {
@@ -192,7 +190,7 @@ void ctx::inactive_detector_storage::on_query_result_received(unsigned int query
                        {
                                std::string query;
                                query = query_update_apps(apps_with_weights);
-                               bool ret = db_manager::execute(APP_INACTIVE_QUERY_ID_UPDATE_CLUSTERS,
+                               bool ret = __dbManager.execute(APP_INACTIVE_QUERY_ID_UPDATE_CLUSTERS,
                                        query.c_str(),
                                        this);
                                _D("load visits execute query result: %s", ret ? "SUCCESS" : "FAIL");
@@ -241,7 +239,7 @@ int ctx::inactive_detector_storage::get_apps_info_w_weights(
 
        inject_params(query, placeholder, timestamp_str);
 
-       bool ret = db_manager::execute(APP_INACTIVE_QUERY_ID_GET_APPS_WEIGHT,
+       bool ret = __dbManager.execute(APP_INACTIVE_QUERY_ID_GET_APPS_WEIGHT,
                query.c_str(),
                this);
        _D("load visits execute query result: %s", ret ? "SUCCESS" : "FAIL");
index 7b03c8514b40054b1d67034cb61df6eabe8ab3d1..6292768aa82cb33d038825eea2ff009b2f190f3b 100644 (file)
 #include <vector>
 #include "app_inactive_detector_types.h"
 #include <Json.h>
-#include <db_listener_iface.h>
+#include <DatabaseManager.h>
 
 namespace ctx {
 
-       class inactive_detector_storage : public db_listener_iface
+       class inactive_detector_storage : public IDatabaseListener
        {
                private:
                        //int type;  //TODO: enum
@@ -42,10 +42,12 @@ namespace ctx {
 
                        std::string subquery_form_values(std::vector<app_t> *apps_with_weights);
 
-                       void on_creation_result_received(unsigned int query_id, int error) {}
-                       void on_insertion_result_received(unsigned int query_id, int error, int64_t row_id) {}
-                       void on_query_result_received(unsigned int query_id, int error, std::vector<Json>& records);// {}
-               
+                       void onTableCreated(unsigned int query_id, int error) {}
+                       void onInserted(unsigned int query_id, int error, int64_t row_id) {}
+                       void onExecuted(unsigned int query_id, int error, std::vector<Json>& records);
+
+                       DatabaseManager __dbManager;
+
                public:
                        inactive_detector_storage();
                        ~inactive_detector_storage();
index fdabb05c798f6d11d485af657dc98c2a8546f40a..bddb70f76f43629468ba349172c074d3ba83c520 100644 (file)
@@ -17,7 +17,6 @@
 #include <sstream>
 #include <types_internal.h>
 #include <ContextManager.h>
-#include <db_mgr.h>
 #include "app_stats_types.h"
 #include "db_handle.h"
 
index 170158535bbfd37797dc6140185b6928f43fe903..1b2d0dff620f433406abecd5572b3d6e60bfa8ae 100644 (file)
@@ -17,7 +17,6 @@
 #include <sstream>
 #include <Json.h>
 #include <types_internal.h>
-#include <db_mgr.h>
 #include "app_stats_types.h"
 #include "db_init.h"
 
@@ -38,16 +37,16 @@ void ctx::app_db_initializer::create_table()
        static bool done = false;
        IF_FAIL_VOID(!done);
 
-       db_manager::create_table(0, APP_TABLE_USAGE_LOG, APP_TABLE_USAGE_LOG_COLUMNS, NULL, NULL);
-       db_manager::create_table(0, APP_TABLE_REMOVABLE_APP, APP_TABLE_REMOVABLE_APP_COLUMNS, NULL, NULL);
-       db_manager::execute(0, APP_TEMP_USAGE_FREQ_SQL, NULL);
+       __dbManager.createTable(0, APP_TABLE_USAGE_LOG, APP_TABLE_USAGE_LOG_COLUMNS, NULL, NULL);
+       __dbManager.createTable(0, APP_TABLE_REMOVABLE_APP, APP_TABLE_REMOVABLE_APP_COLUMNS, NULL, NULL);
+       __dbManager.execute(0, APP_TEMP_USAGE_FREQ_SQL, NULL);
 
        done = true;
 }
 
 void ctx::app_db_initializer::check_app_list()
 {
-       db_manager::execute(EMPTY_CHECKER_QID, "SELECT * FROM " APP_TABLE_REMOVABLE_APP " LIMIT 1", this);
+       __dbManager.execute(EMPTY_CHECKER_QID, "SELECT * FROM " APP_TABLE_REMOVABLE_APP " LIMIT 1", this);
 }
 
 void ctx::app_db_initializer::duplicate_app_list()
@@ -79,19 +78,21 @@ bool ctx::app_db_initializer::package_info_cb(package_info_h package_info, void
 bool ctx::app_db_initializer::app_info_cb(package_info_app_component_type_e comp_type, const char *app_id, void *user_data)
 {
        Json data;
+       DatabaseManager dbManager;
+
        data.set(NULL, STATS_APP_ID, app_id);
-       return db_manager::insert(0, APP_TABLE_REMOVABLE_APP, data, NULL);
+       return dbManager.insert(0, APP_TABLE_REMOVABLE_APP, data, NULL);
 }
 
-void ctx::app_db_initializer::on_creation_result_received(unsigned int query_id, int error)
+void ctx::app_db_initializer::onTableCreated(unsigned int query_id, int error)
 {
 }
 
-void ctx::app_db_initializer::on_insertion_result_received(unsigned int query_id, int error, int64_t row_id)
+void ctx::app_db_initializer::onInserted(unsigned int query_id, int error, int64_t row_id)
 {
 }
 
-void ctx::app_db_initializer::on_query_result_received(unsigned int query_id, int error, std::vector<Json>& records)
+void ctx::app_db_initializer::onExecuted(unsigned int query_id, int error, std::vector<Json>& records)
 {
        if (query_id != EMPTY_CHECKER_QID) {
                _E("Unknown Query ID: %d", query_id);
index 2bd20ad1e0737fdbbd639086fa88d774d7c62171..cd5b39ef1b2a7a18865a402ae69d069220efac7e 100644 (file)
 #define __CONTEXT_APP_DB_INITIALIZER_H__
 
 #include <package_manager.h>
-#include <db_listener_iface.h>
+#include <DatabaseManager.h>
 
 namespace ctx {
 
-       class app_db_initializer : public db_listener_iface {
+       class app_db_initializer : public IDatabaseListener {
                private:
                        void create_table();
                        void check_app_list();
                        void duplicate_app_list();
 
-                       void on_creation_result_received(unsigned int query_id, int error);
-                       void on_insertion_result_received(unsigned int query_id, int error, int64_t row_id);
-                       void on_query_result_received(unsigned int query_id, int error, std::vector<Json>& records);
+                       void onTableCreated(unsigned int query_id, int error);
+                       void onInserted(unsigned int query_id, int error, int64_t row_id);
+                       void onExecuted(unsigned int query_id, int error, std::vector<Json>& records);
 
                        static bool package_info_cb(package_info_h package_info, void *user_data);
                        static bool app_info_cb(package_info_app_component_type_e comp_type, const char *app_id, void *user_data);
 
+                       DatabaseManager __dbManager;
+
                public:
                        app_db_initializer();
                        ~app_db_initializer();
index d4b92ce674ef67494aaa099cf10e1e17ae0f6a27..4efbb091e6bb6afd09e1ceb8e3d5ed5e1508920f 100644 (file)
@@ -18,7 +18,7 @@
 #include <glib.h>
 #include <Json.h>
 #include <types_internal.h>
-#include <db_mgr.h>
+#include <DatabaseManager.h>
 #include "app_stats_types.h"
 #include "install_monitor.h"
 
@@ -80,13 +80,15 @@ void ctx::app_install_monitor::package_event_cb(const char *type, const char *pa
 
 bool ctx::app_install_monitor::app_info_cb(package_info_app_component_type_e comp_type, const char *app_id, void *user_data)
 {
+       DatabaseManager dbManager;
+
        if (last_event_type == PACKAGE_MANAGER_EVENT_TYPE_INSTALL) {
                Json data;
                data.set(NULL, STATS_APP_ID, app_id);
-               db_manager::insert(0, APP_TABLE_REMOVABLE_APP, data, NULL);
+               dbManager.insert(0, APP_TABLE_REMOVABLE_APP, data, NULL);
        } else if (last_event_type == PACKAGE_MANAGER_EVENT_TYPE_UNINSTALL) {
-               db_manager::execute(0, create_deletion_query(APP_TABLE_REMOVABLE_APP, app_id).c_str(), NULL);
-               db_manager::execute(0, create_deletion_query(APP_TABLE_USAGE_LOG, app_id).c_str(), NULL);
+               dbManager.execute(0, create_deletion_query(APP_TABLE_REMOVABLE_APP, app_id).c_str(), NULL);
+               dbManager.execute(0, create_deletion_query(APP_TABLE_USAGE_LOG, app_id).c_str(), NULL);
        }
 
        return true;
index cba445db5aede4e1b8ac64a5f2e7f719b0c6ca94..73b374de5aa5edae67a455b94f68fa1fd7bc6c79 100644 (file)
 #define __CONTEXT_APP_INSTALL_MONITOR_H__
 
 #include <package_manager.h>
-#include <db_listener_iface.h>
 
 namespace ctx {
 
-       class app_install_monitor : public db_listener_iface {
+       class app_install_monitor : public IDatabaseListener {
        private:
                package_manager_h pkgmgr_h;
 
                bool start_monitoring();
                void stop_monitoring();
 
-               void on_creation_result_received(unsigned int query_id, int error) {}
-               void on_insertion_result_received(unsigned int query_id, int error, int64_t row_id) {}
-               void on_query_result_received(unsigned int query_id, int error, std::vector<Json>& records) {}
+               void onTableCreated(unsigned int query_id, int error) {}
+               void onInserted(unsigned int query_id, int error, int64_t row_id) {}
+               void onExecuted(unsigned int query_id, int error, std::vector<Json>& records) {}
 
                static std::string create_deletion_query(const char* table_name, const char* app_id);
                static void package_event_cb(const char *type, const char *package, package_manager_event_type_e event_type, package_manager_event_state_e event_state, int progress, package_manager_error_e error, void *user_data);
index 81a1d800c311b819b0fa2788948c39c2afdd6796..9561f69d16d6b2e645d9d810dd5c4d8371eef87b 100644 (file)
@@ -17,7 +17,6 @@
 #include <sstream>
 #include <types_internal.h>
 #include <ContextManager.h>
-#include <db_mgr.h>
 #include "../shared/system_info.h"
 #include "media_stats_types.h"
 #include "db_handle.h"
index 156d9b57a08452630fed9e553609ea8fd742ac76..6ae9f1361ceb43b1d4354717e572da36eecc7f04 100644 (file)
@@ -16,7 +16,6 @@
 
 #include <time.h>
 #include <types_internal.h>
-#include <db_mgr.h>
 #include "../shared/system_info.h"
 #include "media_stats_types.h"
 #include "db_handle.h"
@@ -29,8 +28,8 @@ ctx::media_content_monitor::media_content_monitor()
        : started(false)
        , last_cleanup_time(0)
 {
-       db_manager::create_table(0, MEDIA_TABLE_NAME, MEDIA_TABLE_COLUMNS, NULL, NULL);
-       db_manager::execute(0, MEDIA_PLAYCOUNT_TABLE_SCHEMA, NULL);
+       __dbManager.createTable(0, MEDIA_TABLE_NAME, MEDIA_TABLE_COLUMNS, NULL, NULL);
+       __dbManager.execute(0, MEDIA_PLAYCOUNT_TABLE_SCHEMA, NULL);
 
        started = start_monitoring();
 }
@@ -118,10 +117,10 @@ void ctx::media_content_monitor::update_play_count(const char *uuid, int type, i
                "SELECT MediaType FROM Log_MediaPlayCount" \
                " WHERE UUID = '" << uuid << "' AND Diff > 0;";
 
-       db_manager::execute(0, query.str().c_str(), this);
+       __dbManager.execute(0, query.str().c_str(), this);
 }
 
-void ctx::media_content_monitor::on_query_result_received(unsigned int query_id, int error, std::vector<Json>& records)
+void ctx::media_content_monitor::onExecuted(unsigned int query_id, int error, std::vector<Json>& records)
 {
        IF_FAIL_VOID(!records.empty());
 
@@ -146,5 +145,5 @@ void ctx::media_content_monitor::insert_log(int media_type)
                data.set(NULL, STATS_MEDIA_VOLUME, media_volume);
        }
 
-       db_manager::insert(0, MEDIA_TABLE_NAME, data, NULL);
+       __dbManager.insert(0, MEDIA_TABLE_NAME, data, NULL);
 }
index 4bd97dba135a0ef2eeebf163218c53dc0965868f..260f84f5485ac38de95b0e70879df0b60324a409 100644 (file)
 
 #include <sstream>
 #include <media_content.h>
-#include <db_listener_iface.h>
+#include <DatabaseManager.h>
 
 namespace ctx {
 
-       class media_content_monitor : public db_listener_iface {
+       class media_content_monitor : public IDatabaseListener {
        private:
                bool started;
                int last_cleanup_time;
+               DatabaseManager __dbManager;
 
                bool start_monitoring();
                void stop_monitoring();
@@ -35,9 +36,9 @@ namespace ctx {
                void update_play_count(const char *uuid, int type, int count);
                void insert_log(int media_type);
 
-               void on_creation_result_received(unsigned int query_id, int error) {}
-               void on_insertion_result_received(unsigned int query_id, int error, int64_t row_id) {}
-               void on_query_result_received(unsigned int query_id, int error, std::vector<Json>& records);
+               void onTableCreated(unsigned int query_id, int error) {}
+               void onInserted(unsigned int query_id, int error, int64_t row_id) {}
+               void onExecuted(unsigned int query_id, int error, std::vector<Json>& records);
 
                static void on_media_content_db_updated(media_content_error_e error, int pid,
                                media_content_db_update_item_type_e update_item,
index 159c5ca6b9518a8a81ab23465d6a251833f042e0..e8d60d7681cd7c9ce03e4b27a1e4bcf94adc9b4f 100644 (file)
@@ -17,7 +17,6 @@
 #include <sstream>
 #include <types_internal.h>
 #include <ContextManager.h>
-#include <db_mgr.h>
 #include "common_types.h"
 #include "db_handle_base.h"
 
@@ -43,7 +42,7 @@ int ctx::stats_db_handle_base::generate_qid()
 
 bool ctx::stats_db_handle_base::execute_query(const char* subject, ctx::Json filter, const char* query)
 {
-       bool ret = db_manager::execute(generate_qid(), query, this);
+       bool ret = __dbManager.execute(generate_qid(), query, this);
        IF_FAIL_RETURN(ret, false);
 
        req_subject = subject;
@@ -188,11 +187,11 @@ std::string ctx::stats_db_handle_base::create_sql_common_setting(ctx::Json filte
        return query.str();
 }
 
-void ctx::stats_db_handle_base::on_creation_result_received(unsigned int query_id, int error)
+void ctx::stats_db_handle_base::onTableCreated(unsigned int query_id, int error)
 {
 }
 
-void ctx::stats_db_handle_base::on_insertion_result_received(unsigned int query_id, int error, int64_t row_id)
+void ctx::stats_db_handle_base::onInserted(unsigned int query_id, int error, int64_t row_id)
 {
        delete this;
 }
@@ -207,7 +206,7 @@ void ctx::stats_db_handle_base::json_vector_to_array(std::vector<Json> &vec_json
        }
 }
 
-void ctx::stats_db_handle_base::on_query_result_received(unsigned int query_id, int error, std::vector<Json>& records)
+void ctx::stats_db_handle_base::onExecuted(unsigned int query_id, int error, std::vector<Json>& records)
 {
        if (is_trigger_item) {
                if (records.size() == 1) {
index 7c883806e3d61164ce34ec48f457b3f931eaa637..8c9a201dddb5b767b8f72fee263fe575500f805c 100644 (file)
 
 #include <string>
 #include <Json.h>
-#include <db_listener_iface.h>
+#include <DatabaseManager.h>
 
 namespace ctx {
-       class stats_db_handle_base : public db_listener_iface {
+       class stats_db_handle_base : public IDatabaseListener {
                protected:
                        bool is_trigger_item;
                        std::string req_subject;
                        ctx::Json req_filter;
+                       DatabaseManager __dbManager;
 
                        stats_db_handle_base();
                        ~stats_db_handle_base();
@@ -42,9 +43,9 @@ namespace ctx {
                private:
                        void json_vector_to_array(std::vector<Json> &vec_json, ctx::Json &json_result);
 
-                       void on_creation_result_received(unsigned int query_id, int error);
-                       void on_insertion_result_received(unsigned int query_id, int error, int64_t row_id);
-                       void on_query_result_received(unsigned int query_id, int error, std::vector<Json>& records);
+                       void onTableCreated(unsigned int query_id, int error);
+                       void onInserted(unsigned int query_id, int error, int64_t row_id);
+                       void onExecuted(unsigned int query_id, int error, std::vector<Json>& records);
        };
 }
 
index 1199a32551dba5428772c2ca58ca695894418878..6dfa677009afe45114bd5b8898396e99406c6d15 100644 (file)
@@ -18,7 +18,6 @@
 #include <contacts.h>
 #include <types_internal.h>
 #include <ContextManager.h>
-#include <db_mgr.h>
 #include "social_stats_types.h"
 #include "db_handle.h"
 
index fadd8cfa43b39733047c9ec6c709b1212cd75d38..9d58c1a1f2903739fb779dced25074ba89205236 100644 (file)
@@ -16,7 +16,6 @@
 
 #include <sstream>
 #include <Json.h>
-#include <db_mgr.h>
 #include <types_internal.h>
 #include "social_stats_types.h"
 #include "log_aggregator.h"
@@ -39,8 +38,8 @@ void ctx::contact_log_aggregator::create_table()
        static bool done = false;
        IF_FAIL_VOID(!done);
 
-       db_manager::create_table(0, SOCIAL_TABLE_CONTACT_LOG, SOCIAL_TABLE_CONTACT_LOG_COLUMNS, NULL, NULL);
-       db_manager::execute(0, SOCIAL_TEMP_CONTACT_FREQ_SQL, NULL);
+       __dbManager.createTable(0, SOCIAL_TABLE_CONTACT_LOG, SOCIAL_TABLE_CONTACT_LOG_COLUMNS, NULL, NULL);
+       __dbManager.execute(0, SOCIAL_TEMP_CONTACT_FREQ_SQL, NULL);
 
        done = true;
 }
@@ -53,13 +52,13 @@ bool ctx::contact_log_aggregator::onTimerExpired(int timer)
 
 void ctx::contact_log_aggregator::aggregate_contact_log()
 {
-       db_manager::execute(0,
+       __dbManager.execute(0,
                        "SELECT IFNULL(MAX(" STATS_UNIV_TIME "),0) AS " STATS_LAST_TIME \
                        ", (strftime('%s', 'now', 'localtime')) - (strftime('%s', 'now')) AS " TIME_DIFFERENCE \
                        " FROM " SOCIAL_TABLE_CONTACT_LOG, this);
 }
 
-void ctx::contact_log_aggregator::on_query_result_received(unsigned int query_id, int error, std::vector<Json>& records)
+void ctx::contact_log_aggregator::onExecuted(unsigned int query_id, int error, std::vector<Json>& records)
 {
        IF_FAIL_VOID_TAG(!records.empty(), _E, "Invalid query result");
 
@@ -154,7 +153,7 @@ void ctx::contact_log_aggregator::insert_contact_log_list(contacts_list_h list)
                data.set(NULL, STATS_UNIV_TIME, accesstime);
                data.set(NULL, STATS_LOCAL_TIME, accesstime + time_diff);
 
-               db_manager::insert(0, SOCIAL_TABLE_CONTACT_LOG, data, NULL);
+               __dbManager.insert(0, SOCIAL_TABLE_CONTACT_LOG, data, NULL);
 
        } while(contacts_list_next(list) == CONTACTS_ERROR_NONE);
 }
@@ -164,5 +163,5 @@ void ctx::contact_log_aggregator::remove_expired_log()
        std::stringstream query;
        query << "DELETE FROM " SOCIAL_TABLE_CONTACT_LOG " WHERE " \
                STATS_UNIV_TIME " < strftime('%s', 'now') - " << LOG_RETENTION_PERIOD;
-       db_manager::execute(0, query.str().c_str(), NULL);
+       __dbManager.execute(0, query.str().c_str(), NULL);
 }
index 6f7583f8afb8b68383c3b9b89305ea0fe6fb14c5..a73c44b4142f607256114940c78f727632d21b72 100644 (file)
 #define __CONTEXT_SOCIAL_CONTACT_LOG_AGGREGATOR_H__
 
 #include <contacts.h>
-#include <db_listener_iface.h>
+#include <DatabaseManager.h>
 #include <TimerManager.h>
 
 namespace ctx {
 
-       class contact_log_aggregator : public db_listener_iface, public ITimerListener {
+       class contact_log_aggregator : public IDatabaseListener, public ITimerListener {
                private:
                        int timer_id;
                        int time_diff;
                        TimerManager __timerManager;
+                       DatabaseManager __dbManager;
+
                        void create_table();
                        void get_updated_contact_log_list(int last_time, contacts_list_h *list);
                        void insert_contact_log_list(contacts_list_h list);
@@ -40,9 +42,9 @@ namespace ctx {
 
                        void aggregate_contact_log();
 
-                       void on_creation_result_received(unsigned int query_id, int error) {}
-                       void on_insertion_result_received(unsigned int query_id, int error, int64_t row_id) {}
-                       void on_query_result_received(unsigned int query_id, int error, std::vector<Json>& records);
+                       void onTableCreated(unsigned int queryId, int error) {}
+                       void onInserted(unsigned int queryId, int error, int64_t rowId) {}
+                       void onExecuted(unsigned int query_id, int error, std::vector<Json>& records);
                        bool onTimerExpired(int timer_id);
 
        };      /* class phone_contact_log_aggregator */