2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 * @file plugin_dao.cpp
18 * @author Pawel Sikorski (p.sikorski@samsung.com)
19 * @author Grzegorz Krawczyk (g.krawczyk@samsung.com)
21 * @brief This file contains the definition of plugin dao class.
24 #include <dpl/wrt-dao-rw/plugin_dao.h>
25 #include <dpl/log/log.h>
26 #include <dpl/foreach.h>
27 #include <orm_generator_wrt.h>
28 #include <dpl/wrt-dao-ro/webruntime_database.h>
29 #include <dpl/wrt-dao-ro/WrtDatabase.h>
33 PluginDAO::PluginDAO(DbPluginHandle pluginHandle) :
34 PluginDAOReadOnly(pluginHandle)
38 PluginDAO::PluginDAO(const std::string &libraryName) :
39 PluginDAOReadOnly(libraryName)
43 DbPluginHandle PluginDAO::registerPlugin(const PluginMetafileData& metafile,
44 const std::string& pluginPath)
46 LogDebug("Registering plugin. Path: " << pluginPath);
49 DPL::DB::ORM::wrt::ScopedTransaction transaction(&WrtDatabase::interface());
50 DbPluginHandle handle;
52 if (isPluginInstalled(metafile.m_libraryName)) {
53 handle = PluginDAO(metafile.m_libraryName).getPluginHandle();
54 LogInfo(" >> Library " << metafile.m_libraryName <<
55 " is already registered. Handle: " << handle);
57 LogDebug("Register Plugin: " << metafile.m_libraryName);
59 using namespace DPL::DB::ORM;
60 using namespace DPL::DB::ORM::wrt;
62 typedef PluginProperties::Row PluginPropertiesRow;
64 PluginPropertiesRow row;
65 row.Set_PluginLibraryName(
66 DPL::FromUTF8String(metafile.m_libraryName));
67 row.Set_InstallationState(INSTALLATION_IN_PROGRESS);
68 row.Set_PluginLibraryPath(
69 DPL::FromUTF8String(pluginPath));
71 WRT_DB_INSERT(insert, PluginProperties, &WrtDatabase::interface())
73 handle = static_cast<WrtDB::DbWidgetHandle>(insert->Execute());
74 LogDebug(" >> Plugin Registered. Handle: " << handle);
79 Catch(DPL::DB::SqlConnection::Exception::Base)
81 ReThrowMsg(PluginDAO::Exception::DatabaseError,
82 "Failed in RegisterPlugin");
86 void PluginDAO::registerPluginImplementedObject(const std::string& objectName,
87 DbPluginHandle pluginHandle)
89 LogDebug("Registering plugin object: " << objectName);
92 DPL::DB::ORM::wrt::ScopedTransaction transaction(&WrtDatabase::interface());
94 LogDebug("Register Object: " << objectName);
96 using namespace DPL::DB::ORM;
97 using namespace DPL::DB::ORM::wrt;
99 typedef PluginImplementedObjects::Row PluginObjectsRow;
101 PluginObjectsRow row;
102 row.Set_PluginObject(DPL::FromUTF8String(objectName));
103 row.Set_PluginPropertiesId(pluginHandle);
105 WRT_DB_INSERT(insert, PluginImplementedObjects, &WrtDatabase::interface())
108 transaction.Commit();
110 Catch(DPL::DB::SqlConnection::Exception::Base)
112 ReThrowMsg(PluginDAO::Exception::DatabaseError,
113 "Failed in RegisterPluginObject");
117 void PluginDAO::registerPluginRequiredObject(const std::string& objectName,
118 DbPluginHandle pluginHandle)
120 LogDebug("Registering plugin object: " << objectName);
123 DPL::DB::ORM::wrt::ScopedTransaction transaction(&WrtDatabase::interface());
125 LogDebug("Register Object: " << objectName);
127 using namespace DPL::DB::ORM;
128 using namespace DPL::DB::ORM::wrt;
130 typedef PluginRequiredObjects::Row PluginObjectsRow;
132 PluginObjectsRow row;
133 row.Set_PluginPropertiesId(pluginHandle);
134 row.Set_PluginObject(DPL::FromUTF8String(objectName));
136 WRT_DB_INSERT(insert, PluginRequiredObjects, &WrtDatabase::interface())
139 transaction.Commit();
141 Catch(DPL::DB::SqlConnection::Exception::Base)
143 ReThrowMsg(PluginDAO::Exception::DatabaseError,
144 "Failed in RegisterPluginObject");
148 void PluginDAO::registerPluginLibrariesDependencies(
149 DbPluginHandle pluginHandle,
150 const PluginHandleSetPtr& dependencies)
152 LogDebug("Registering plugin library dependencies: " << pluginHandle);
155 DPL::DB::ORM::wrt::ScopedTransaction transaction(&WrtDatabase::interface());
157 using namespace DPL::DB::ORM;
158 using namespace DPL::DB::ORM::wrt;
160 typedef PluginDependencies::Row PluginDependeciesRow;
161 PluginDependeciesRow row;
163 FOREACH(it, *dependencies)
165 row.Set_PluginPropertiesId(pluginHandle);
166 row.Set_RequiredPluginPropertiesId(*it);
168 WRT_DB_INSERT(insert, PluginDependencies, &WrtDatabase::interface())
171 transaction.Commit();
174 Catch(DPL::DB::SqlConnection::Exception::Base)
176 ReThrowMsg(PluginDAO::Exception::DatabaseError,
177 "Failed in RegisterPluginObject");
181 void PluginDAO::setPluginInstallationStatus(DbPluginHandle pluginHandle,
182 PluginInstallationState state)
186 "Set installation state: " << state << " handle " << pluginHandle);
188 using namespace DPL::DB::ORM;
189 using namespace DPL::DB::ORM::wrt;
190 ScopedTransaction transaction(&WrtDatabase::interface());
192 typedef wrt::PluginProperties::Row PluginPropertiesRow;
194 PluginPropertiesRow row;
195 row.Set_InstallationState(state);
197 WRT_DB_UPDATE(update, PluginProperties, &WrtDatabase::interface())
199 Equals<PluginProperties::PluginPropertiesId>(pluginHandle));
203 transaction.Commit();
205 Catch(DPL::DB::SqlConnection::Exception::Base)
207 ReThrowMsg(PluginDAO::Exception::DatabaseError,
208 "Failed in RegisterLibraryDependencies");
212 void PluginDAO::unregisterPlugin(DbPluginHandle pluginHandle)
214 LogDebug("unregisterPlugin plugin. Handle: " << pluginHandle);
217 DPL::DB::ORM::wrt::ScopedTransaction transaction(
218 &WrtDatabase::interface());
220 if (!isPluginInstalled(pluginHandle)) {
221 LogInfo("PluginHandle is invalid. Handle: " << pluginHandle);
225 using namespace DPL::DB::ORM;
226 using namespace DPL::DB::ORM::wrt;
228 WRT_DB_DELETE(del, PluginProperties, &WrtDatabase::interface())
230 Equals<PluginProperties::PluginPropertiesId>(pluginHandle));
233 transaction.Commit();
234 LogDebug(" >> Plugin Unregistered. Handle: " << pluginHandle);
237 Catch(DPL::DB::SqlConnection::Exception::Base)
239 ReThrowMsg(PluginDAO::Exception::DatabaseError,
240 "Failed in UnregisterPlugin");