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>
32 PluginDAO::PluginDAO(DbPluginHandle pluginHandle) :
33 PluginDAOReadOnly(pluginHandle)
36 PluginDAO::PluginDAO(const std::string &libraryName) :
37 PluginDAOReadOnly(libraryName)
40 DbPluginHandle PluginDAO::registerPlugin(const PluginMetafileData& metafile,
41 const std::string& pluginPath)
43 LogDebug("Registering plugin. Path: " << pluginPath);
46 DPL::DB::ORM::wrt::ScopedTransaction transaction(
47 &WrtDatabase::interface());
48 DbPluginHandle handle;
50 if (isPluginInstalled(metafile.m_libraryName)) {
51 handle = PluginDAO(metafile.m_libraryName).getPluginHandle();
52 LogInfo(" >> Library " << metafile.m_libraryName <<
53 " is already registered. Handle: " << handle);
55 LogDebug("Register Plugin: " << metafile.m_libraryName);
57 using namespace DPL::DB::ORM;
58 using namespace DPL::DB::ORM::wrt;
60 typedef PluginProperties::Row PluginPropertiesRow;
62 PluginPropertiesRow row;
63 row.Set_PluginLibraryName(
64 DPL::FromUTF8String(metafile.m_libraryName));
65 row.Set_InstallationState(INSTALLATION_IN_PROGRESS);
66 row.Set_PluginLibraryPath(
67 DPL::FromUTF8String(pluginPath));
69 WRT_DB_INSERT(insert, PluginProperties, &WrtDatabase::interface())
71 handle = static_cast<WrtDB::DbWidgetHandle>(insert->Execute());
72 LogDebug(" >> Plugin Registered. Handle: " << handle);
77 Catch(DPL::DB::SqlConnection::Exception::Base)
79 ReThrowMsg(PluginDAO::Exception::DatabaseError,
80 "Failed in RegisterPlugin");
84 void PluginDAO::registerPluginImplementedObject(const std::string& objectName,
85 DbPluginHandle pluginHandle)
87 LogDebug("Registering plugin object: " << objectName);
90 DPL::DB::ORM::wrt::ScopedTransaction transaction(
91 &WrtDatabase::interface());
93 LogDebug("Register Object: " << objectName);
95 using namespace DPL::DB::ORM;
96 using namespace DPL::DB::ORM::wrt;
98 typedef PluginImplementedObjects::Row PluginObjectsRow;
100 PluginObjectsRow row;
101 row.Set_PluginObject(DPL::FromUTF8String(objectName));
102 row.Set_PluginPropertiesId(pluginHandle);
104 WRT_DB_INSERT(insert, PluginImplementedObjects, &WrtDatabase::interface())
107 transaction.Commit();
109 Catch(DPL::DB::SqlConnection::Exception::Base)
111 ReThrowMsg(PluginDAO::Exception::DatabaseError,
112 "Failed in RegisterPluginObject");
116 void PluginDAO::registerPluginRequiredObject(const std::string& objectName,
117 DbPluginHandle pluginHandle)
119 LogDebug("Registering plugin object: " << objectName);
122 DPL::DB::ORM::wrt::ScopedTransaction transaction(
123 &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(
156 &WrtDatabase::interface());
158 using namespace DPL::DB::ORM;
159 using namespace DPL::DB::ORM::wrt;
161 typedef PluginDependencies::Row PluginDependeciesRow;
162 PluginDependeciesRow row;
164 FOREACH(it, *dependencies)
166 row.Set_PluginPropertiesId(pluginHandle);
167 row.Set_RequiredPluginPropertiesId(*it);
169 WRT_DB_INSERT(insert, PluginDependencies, &WrtDatabase::interface())
172 transaction.Commit();
175 Catch(DPL::DB::SqlConnection::Exception::Base)
177 ReThrowMsg(PluginDAO::Exception::DatabaseError,
178 "Failed in RegisterPluginObject");
182 void PluginDAO::setPluginInstallationStatus(DbPluginHandle pluginHandle,
183 PluginInstallationState state)
187 "Set installation state: " << state << " handle " << pluginHandle);
189 using namespace DPL::DB::ORM;
190 using namespace DPL::DB::ORM::wrt;
191 ScopedTransaction transaction(&WrtDatabase::interface());
193 typedef wrt::PluginProperties::Row PluginPropertiesRow;
195 PluginPropertiesRow row;
196 row.Set_InstallationState(state);
198 WRT_DB_UPDATE(update, PluginProperties, &WrtDatabase::interface())
200 Equals<PluginProperties::PluginPropertiesId>(pluginHandle));
204 transaction.Commit();
206 Catch(DPL::DB::SqlConnection::Exception::Base)
208 ReThrowMsg(PluginDAO::Exception::DatabaseError,
209 "Failed in RegisterLibraryDependencies");
213 void PluginDAO::unregisterPlugin(DbPluginHandle pluginHandle)
215 LogDebug("unregisterPlugin plugin. Handle: " << pluginHandle);
218 DPL::DB::ORM::wrt::ScopedTransaction transaction(
219 &WrtDatabase::interface());
221 if (!isPluginInstalled(pluginHandle)) {
222 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");