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 DPL::FromUTF8String(metafile.m_featuresInstallURI));
73 DPL::FromUTF8String(metafile.m_featuresKeyCN));
75 DPL::FromUTF8String(metafile.m_featuresRootCN));
76 row.Set_RootKeyFingerprint(
77 DPL::FromUTF8String(metafile.m_featuresRootFingerprint));
79 WRT_DB_INSERT(insert, PluginProperties, &WrtDatabase::interface())
81 handle = insert->Execute();
82 LogDebug(" >> Plugin Registered. Handle: " << handle);
87 Catch(DPL::DB::SqlConnection::Exception::Base)
89 ReThrowMsg(PluginDAO::Exception::DatabaseError,
90 "Failed in RegisterPlugin");
94 void PluginDAO::registerPluginImplementedObject(const std::string& objectName,
95 DbPluginHandle pluginHandle)
97 LogDebug("Registering plugin object: " << objectName);
100 DPL::DB::ORM::wrt::ScopedTransaction transaction(&WrtDatabase::interface());
102 LogDebug("Register Object: " << objectName);
104 using namespace DPL::DB::ORM;
105 using namespace DPL::DB::ORM::wrt;
107 typedef PluginImplementedObjects::Row PluginObjectsRow;
109 PluginObjectsRow row;
110 row.Set_PluginObject(DPL::FromUTF8String(objectName));
111 row.Set_PluginPropertiesId(pluginHandle);
113 WRT_DB_INSERT(insert, PluginImplementedObjects, &WrtDatabase::interface())
116 transaction.Commit();
118 Catch(DPL::DB::SqlConnection::Exception::Base)
120 ReThrowMsg(PluginDAO::Exception::DatabaseError,
121 "Failed in RegisterPluginObject");
125 void PluginDAO::registerPluginRequiredObject(const std::string& objectName,
126 DbPluginHandle pluginHandle)
128 LogDebug("Registering plugin object: " << objectName);
131 DPL::DB::ORM::wrt::ScopedTransaction transaction(&WrtDatabase::interface());
133 LogDebug("Register Object: " << objectName);
135 using namespace DPL::DB::ORM;
136 using namespace DPL::DB::ORM::wrt;
138 typedef PluginRequiredObjects::Row PluginObjectsRow;
140 PluginObjectsRow row;
141 row.Set_PluginPropertiesId(pluginHandle);
142 row.Set_PluginObject(DPL::FromUTF8String(objectName));
144 WRT_DB_INSERT(insert, PluginRequiredObjects, &WrtDatabase::interface())
147 transaction.Commit();
149 Catch(DPL::DB::SqlConnection::Exception::Base)
151 ReThrowMsg(PluginDAO::Exception::DatabaseError,
152 "Failed in RegisterPluginObject");
156 void PluginDAO::registerPluginLibrariesDependencies(
157 DbPluginHandle pluginHandle,
158 const PluginHandleSetPtr& dependencies)
160 LogDebug("Registering plugin library dependencies: " << pluginHandle);
163 DPL::DB::ORM::wrt::ScopedTransaction transaction(&WrtDatabase::interface());
165 using namespace DPL::DB::ORM;
166 using namespace DPL::DB::ORM::wrt;
168 typedef PluginDependencies::Row PluginDependeciesRow;
169 PluginDependeciesRow row;
171 FOREACH(it, *dependencies)
173 row.Set_PluginPropertiesId(pluginHandle);
174 row.Set_RequiredPluginPropertiesId(*it);
176 WRT_DB_INSERT(insert, PluginDependencies, &WrtDatabase::interface())
179 transaction.Commit();
182 Catch(DPL::DB::SqlConnection::Exception::Base)
184 ReThrowMsg(PluginDAO::Exception::DatabaseError,
185 "Failed in RegisterPluginObject");
189 void PluginDAO::setPluginInstallationStatus(DbPluginHandle pluginHandle,
190 PluginInstallationState state)
194 "Set installation state: " << state << " handle " << pluginHandle);
196 using namespace DPL::DB::ORM;
197 using namespace DPL::DB::ORM::wrt;
198 ScopedTransaction transaction(&WrtDatabase::interface());
200 typedef wrt::PluginProperties::Row PluginPropertiesRow;
202 PluginPropertiesRow row;
203 row.Set_InstallationState(state);
205 WRT_DB_UPDATE(update, PluginProperties, &WrtDatabase::interface())
207 Equals<PluginProperties::PluginPropertiesId>(pluginHandle));
211 transaction.Commit();
213 Catch(DPL::DB::SqlConnection::Exception::Base)
215 ReThrowMsg(PluginDAO::Exception::DatabaseError,
216 "Failed in RegisterLibraryDependencies");