message); \
}
-#define CHECK_WIDGET_EXISTENCE(macro_transaction, macro_handle) \
- if (!WidgetDAO::isWidgetInstalled(macro_handle)) \
- { \
- macro_transaction.Commit(); \
- LogWarning("Cannot find widget. Handle: " << macro_handle); \
- ThrowMsg(WidgetDAO::Exception::WidgetNotExist, \
- "Cannot find widget. Handle: " << macro_handle); \
- }
-
-
-WidgetDAO::WidgetDAO(DbWidgetHandle widgetHandle) :
- WidgetDAOReadOnly(widgetHandle)
-{
-}
-
WidgetDAO::WidgetDAO(DPL::OptionalString widgetGUID) :
WidgetDAOReadOnly(WidgetDAOReadOnly::getHandle(widgetGUID))
{
{
}
+WidgetDAO::WidgetDAO(DbWidgetHandle handle) :
+ WidgetDAOReadOnly(handle)
+{
+}
+
WidgetDAO::~WidgetDAO()
{
}
}
void WidgetDAO::registerWidget(
- const DbWidgetHandle& widgetHandle,
+ const WidgetPkgName & widgetPkgname,
const WidgetRegisterInfo &widgetRegInfo,
const IWacSecurity &wacSecurity)
{
SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
{
DPL::DB::ORM::wrt::ScopedTransaction transaction(&WrtDatabase::interface());
+ DbWidgetHandle widgetHandle = registerWidgetInternal(widgetPkgname, widgetRegInfo, wacSecurity);
+ registerExternalLocations(widgetHandle, widgetRegInfo.externalLocations);
+ //TODO: remove construction from handle and move that call to registerWidgetInternal
+ // in new version external fiels should be register together with other informations
+ transaction.Commit();
+ }
+ SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to register widget")
+}
- //Register into WidgetInfo has to be first
- //as all other tables depend upon that
- registerWidgetInfo(widgetHandle, widgetRegInfo, wacSecurity);
+void WidgetDAO::registerWidget(
+ WrtDB::DbWidgetHandle handle,
+ const WidgetRegisterInfo & widgetRegInfo,
+ const IWacSecurity &wacSecurity)
+{
+ LogDebug("Registering widget");
+ SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
+ {
+ DPL::DB::ORM::wrt::ScopedTransaction transaction(&WrtDatabase::interface());
+ registerWidgetInternal(L"", widgetRegInfo, wacSecurity, handle);
+ transaction.Commit();
+ }
+ SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to register widget")
+}
+
+DbWidgetHandle WidgetDAO::registerWidget(
+ const WidgetRegisterInfo &pWidgetRegisterInfo,
+ const IWacSecurity &wacSecurity)
+{
+ //make it more precise due to very fast tests
+ struct timeval tv;
+ gettimeofday(&tv, NULL);
+ srand(time(NULL) + tv.tv_usec);
+ DbWidgetHandle widgetHandle;
+ do {
+ widgetHandle = rand();
+ } while (isWidgetInstalled(widgetHandle));
+
+ registerWidget(widgetHandle, pWidgetRegisterInfo, wacSecurity);
+ return widgetHandle;
+}
- registerWidgetExtendedInfo(widgetHandle, widgetRegInfo);
+DbWidgetHandle WidgetDAO::registerWidgetInternal(
+ const WidgetPkgName & widgetName,
+ const WidgetRegisterInfo &widgetRegInfo,
+ const IWacSecurity &wacSecurity,
+ const DPL::Optional<DbWidgetHandle> handle)
+{
+ //Register into WidgetInfo has to be first
+ //as all other tables depend upon that
+ DbWidgetHandle widgetHandle = registerWidgetInfo(widgetName, widgetRegInfo, wacSecurity, handle);
- registerWidgetLocalizedInfo(widgetHandle, widgetRegInfo);
+ registerWidgetExtendedInfo(widgetHandle, widgetRegInfo);
- registerWidgetIcons(widgetHandle, widgetRegInfo);
+ registerWidgetLocalizedInfo(widgetHandle, widgetRegInfo);
- registerWidgetStartFile(widgetHandle, widgetRegInfo);
+ registerWidgetIcons(widgetHandle, widgetRegInfo);
- PropertyDAO::RegisterProperties(widgetHandle, widgetRegInfo);
+ registerWidgetStartFile(widgetHandle, widgetRegInfo);
- registerWidgetFeatures(widgetHandle, widgetRegInfo);
+ PropertyDAO::RegisterProperties(widgetHandle, widgetRegInfo);
- registerWidgetWindowModes(widgetHandle, widgetRegInfo);
+ registerWidgetFeatures(widgetHandle, widgetRegInfo);
- registerWidgetWarpInfo(widgetHandle, widgetRegInfo);
+ registerWidgetWindowModes(widgetHandle, widgetRegInfo);
- registerWidgetCertificates(widgetHandle, wacSecurity);
+ registerWidgetWarpInfo(widgetHandle, widgetRegInfo);
- CertificateChainList list;
- wacSecurity.getCertificateChainList(list, SIGNATURE_DISTRIBUTOR);
- registerCertificatesChains(widgetHandle, SIGNATURE_DISTRIBUTOR, list);
+ registerWidgetCertificates(widgetHandle, wacSecurity);
- list.clear();
- wacSecurity.getCertificateChainList(list, SIGNATURE_AUTHOR);
- registerCertificatesChains(widgetHandle, SIGNATURE_AUTHOR, list);
+ CertificateChainList list;
+ wacSecurity.getCertificateChainList(list, SIGNATURE_DISTRIBUTOR);
+ registerCertificatesChains(widgetHandle, SIGNATURE_DISTRIBUTOR, list);
- registerWidgetSettings(widgetHandle, widgetRegInfo);
+ list.clear();
+ wacSecurity.getCertificateChainList(list, SIGNATURE_AUTHOR);
+ registerCertificatesChains(widgetHandle, SIGNATURE_AUTHOR, list);
- registerAppService(widgetHandle, widgetRegInfo);
+ registerWidgetSettings(widgetHandle, widgetRegInfo);
- registerEncryptedResouceInfo(widgetHandle, widgetRegInfo);
+ registerAppService(widgetHandle, widgetRegInfo);
+ registerEncryptedResouceInfo(widgetHandle, widgetRegInfo);
+
+ return widgetHandle;
+}
+
+void WidgetDAO::registerOrUpdateWidget(
+ const WidgetPkgName & widgetName,
+ const WidgetRegisterInfo &widgetRegInfo,
+ const IWacSecurity &wacSecurity)
+{
+ LogDebug("Reregistering widget");
+ SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
+ {
+ DPL::DB::ORM::wrt::ScopedTransaction transaction(&WrtDatabase::interface());
+
+ unregisterWidgetInternal(widgetName);
+ DbWidgetHandle widgetHandle = registerWidgetInternal(widgetName, widgetRegInfo, wacSecurity);
+ registerExternalLocations(widgetHandle, widgetRegInfo.externalLocations);
+ //TODO: remove construction from handle and move that call to registerWidgetInternal
+ // in new version external fiels should be register together with other informations
transaction.Commit();
}
- SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to register widget")
+ SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to reregister widget")
}
#define DO_INSERT(row, table) \
DO_INSERT(row, WidgetExtendedInfo)
}
-void WidgetDAO::registerWidgetInfo(
- const DbWidgetHandle& widgetHandle,
+DbWidgetHandle WidgetDAO::registerWidgetInfo(
+ const WidgetPkgName & widgetName,
const WidgetRegisterInfo ®Info,
- const IWacSecurity &wacSecurity)
+ const IWacSecurity &wacSecurity,
+ const DPL::Optional<DbWidgetHandle> handle)
{
using namespace DPL::DB::ORM;
using namespace DPL::DB::ORM::wrt;
// Because of that, "Optional" is not used there
WidgetInfo::Row row;
- row.Set_app_id(widgetHandle);
+ if(!!handle)
+ {
+ row.Set_app_id(*handle);
+ }
row.Set_widget_type(regInfo.type.appType);
row.Set_widget_id(widgetConfigurationInfo.widget_id);
row.Set_defaultlocale(widgetConfigurationInfo.defaultlocale);
row.Set_recognized(wacSecurity.isRecognized());
row.Set_wac_signed(wacSecurity.isWacSigned());
row.Set_distributor_signed(wacSecurity.isDistributorSigned());
+ row.Set_pkgname(widgetName);
{
std::stringstream tmp;
tmp << regInfo.minVersion;
ReThrowMsg(WidgetDAO::Exception::DatabaseError,
"Failed to register widget info.");
}
+
+ if(!handle)
+ {
+ //get autoincremented value of widgetHandle
+ WRT_DB_SELECT(select, WidgetInfo, &WrtDatabase::interface())
+ select->Where(Equals<WidgetInfo::pkgname>(widgetName));
+ return select->GetSingleValue<WidgetInfo::app_id>();
+ }
+ else
+ {
+ return *handle;
+ }
}
void WidgetDAO::registerWidgetLocalizedInfo(DbWidgetHandle widgetHandle,
void WidgetDAO::registerExternalLocations(const ExternalLocationList & externals)
{
+ registerExternalLocations(m_widgetHandle, externals);
+}
+
+void WidgetDAO::registerExternalLocations(DbWidgetHandle widgetHandle,
+ const ExternalLocationList & externals)
+{
SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
{
using namespace DPL::DB::ORM;
using namespace DPL::DB::ORM::wrt;
DPL::DB::ORM::wrt::ScopedTransaction transaction(&WrtDatabase::interface());
- LogDebug("Inserting external files for widgetHandle: " << m_widgetHandle);
+ LogDebug("Inserting external files for widgetHandle: " << widgetHandle);
FOREACH(it, externals)
{
WidgetExternalLocations::Row row;
- row.Set_app_id(m_widgetHandle);
+ row.Set_app_id(widgetHandle);
row.Set_path(DPL::FromUTF8String(*it));
DO_INSERT(row, WidgetExternalLocations)
del->Execute();
}
-#undef DO_INSERT
-
-void WidgetDAO::unregisterWidget(DbWidgetHandle widgetHandle)
+void WidgetDAO::unregisterWidget(const WidgetPkgName & pkgName)
{
- LogDebug("Unregistering widget from DB. Handle: " << widgetHandle);
+ LogDebug("Unregistering widget from DB. PkgName: " << pkgName);
SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
{
DPL::DB::ORM::wrt::ScopedTransaction transaction(&WrtDatabase::interface());
+ unregisterWidgetInternal(pkgName);
+ transaction.Commit();
+ }
+ SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to unregister widget")
+}
+
+void WidgetDAO::unregisterWidget(WrtDB::DbWidgetHandle handle)
+{
+ LogDebug("Unregistering widget from DB. Handle: " << handle);
+ SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
+ {
using namespace DPL::DB::ORM;
using namespace DPL::DB::ORM::wrt;
-
- CHECK_WIDGET_EXISTENCE(transaction, widgetHandle)
+ ScopedTransaction transaction(&WrtDatabase::interface());
// Delete from table Widget Info
- {
- WRT_DB_DELETE(del, WidgetInfo, &WrtDatabase::interface())
- del->Where(Equals<WidgetInfo::app_id>(widgetHandle));
- del->Execute();
- }
-
- // Deleting in other tables is done via "delete cascade" in SQL
+ WRT_DB_DELETE(del, WidgetInfo, &WrtDatabase::interface())
+ del->Where(Equals<WidgetInfo::app_id>(handle));
+ del->Execute();
transaction.Commit();
}
SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to unregister widget")
}
+void WidgetDAO::unregisterWidgetInternal(
+ const WidgetPkgName & pkgName)
+{
+ using namespace DPL::DB::ORM;
+ using namespace DPL::DB::ORM::wrt;
+
+ DbWidgetHandle handle = getHandle(pkgName);
+
+ // Delete from table Widget Info
+ WRT_DB_DELETE(del, WidgetInfo, &WrtDatabase::interface())
+ del->Where(Equals<WidgetInfo::app_id>(handle));
+ del->Execute();
+
+ // Deleting in other tables is done via "delete cascade" in SQL
+}
+
+#undef DO_INSERT
+
#undef SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
#undef SQL_CONNECTION_EXCEPTION_HANDLER_END
-#undef CHECK_WIDGET_EXISTENCE
} // namespace WrtDB
public:
typedef std::list<DPL::String> LanguageTagsList;
- /**
- * This is a constructor.
- *
- * @param[in] widgetHandle application id of widget.
- * @param[in] widgetGUID application guid of widget.
- */
- WidgetDAO(DbWidgetHandle widgetHandle);
+ WidgetDAO(DbWidgetHandle handle);
WidgetDAO(DPL::OptionalString widgetGUID);
WidgetDAO(DPL::String pkgName);
virtual ~WidgetDAO();
/**
- * This method registers the widget information to the DB when it is installed.
+ * This method registers the widget information in the DB when it is installed.
*
* @see WidgetRegisterInfo
* @see UnRegisterWidget()
- * @param[in] widgetHandle Widget ID that will be registered.
+ * @param[in] widgetPkgname Widget Pkgname that will be registered.
* @param[in] pWidgetRegisterInfo Specified the widget's information needed to be registered.
* @param[in] wacSecurity Widget's security certificates.
*/
static void registerWidget(
- const DbWidgetHandle& widgetHandle,
- const WidgetRegisterInfo &pWidgetRegisterInfo,
+ const WidgetPkgName & widgetPkgname,
+ const WidgetRegisterInfo &widgetRegInfo,
const IWacSecurity &wacSecurity);
+ static void registerWidget(
+ WrtDB::DbWidgetHandle handle,
+ const WidgetRegisterInfo &widgetRegInfo,
+ const IWacSecurity &wacSecurity) __attribute__((deprecated));
+
static DbWidgetHandle registerWidget(
- const WidgetRegisterInfo &pWidgetRegisterInfo,
- const IWacSecurity &wacSecurity) __attribute__((deprecated))
- {
- //make it more precise due to very fast tests
- struct timeval tv;
- gettimeofday(&tv, NULL);
- srand(time(NULL) + tv.tv_usec);
- DbWidgetHandle widgetHandle;
- do {
- widgetHandle = rand();
- } while (isWidgetInstalled(widgetHandle));
-
- registerWidget(widgetHandle, pWidgetRegisterInfo, wacSecurity);
- return widgetHandle;
- }
+ const WidgetRegisterInfo &pWidgetRegisterInfo,
+ const IWacSecurity &wacSecurity) __attribute__((deprecated));
+
+ /**
+ * This method re-registers the widget information to the DB when it is installed.
+ *
+ * It performs unregistration and new registration of widget in db in one transaction.
+ *
+ * @see WidgetRegisterInfo
+ * @param[in] widgetName Widget pkgname that will be registered.
+ * @param[in] pWidgetRegisterInfo Specified the widget's information needed to be registered.
+ * @param[in] wacSecurity Widget's security certificates.
+ */
+ static void registerOrUpdateWidget(
+ const WidgetPkgName & widgetName,
+ const WidgetRegisterInfo &widgetRegInfo,
+ const IWacSecurity &wacSecurity);
/**
* This method removes a widget's information from EmDB.
*
* @see RegisterWidget()
- * @param[in] widgetHandle widget's app id
- * @return true if succeed, false if fail.
+ * @param[in] pkgName widgets name to be unregistered
*/
- static void unregisterWidget(DbWidgetHandle widgetHandle);
+ static void unregisterWidget(const WidgetPkgName & pkgName);
+
+ static void unregisterWidget(WrtDB::DbWidgetHandle handle) __attribute__((deprecated));
/* This method removes widget property
*/
void removeProperty(const PropertyDAOReadOnly::WidgetPropertyKey &key);
/**
- * @brief registerExternalLocations Inserts new rows to WidgetExternalLocations
- * @param externals list of files
- */
- void registerExternalLocations(const ExternalLocationList & externals);
-
- /**
* @brief registerExternalLocations Removes rows from WidgetExternalLocations
*/
void unregisterAllExternalLocations();
*/
void updateFeatureRejectStatus(const DbWidgetFeature &widgetFeature);
+ void registerExternalLocations(const ExternalLocationList & externals) __attribute__((deprecated));
+
private:
//Methods used during widget registering
- static void registerWidgetInfo(
- const DbWidgetHandle& widgetHandle,
+ static DbWidgetHandle registerWidgetInfo(
+ const WidgetPkgName & widgetName,
const WidgetRegisterInfo ®Info,
- const IWacSecurity &wacSecurity);
+ const IWacSecurity &wacSecurity,
+ const DPL::Optional<DbWidgetHandle> handle = DPL::Optional<DbWidgetHandle>());
static void registerWidgetExtendedInfo(
DbWidgetHandle widgetHandle,
const WidgetRegisterInfo ®Info);
static void registerEncryptedResouceInfo(
DbWidgetHandle widgetHandle,
const WidgetRegisterInfo ®Info);
+ /**
+ * @brief registerExternalLocations Inserts new rows to WidgetExternalLocations
+ * @param externals list of files
+ */
+ static void registerExternalLocations(DbWidgetHandle widgetHandle,
+ const ExternalLocationList & externals);
+
+ static DbWidgetHandle registerWidgetInternal(
+ const WidgetPkgName & widgetName,
+ const WidgetRegisterInfo &widgetRegInfo,
+ const IWacSecurity &wacSecurity,
+ const DPL::Optional<DbWidgetHandle> handle = DPL::Optional<DbWidgetHandle>());
+ static void unregisterWidgetInternal(
+ const WidgetPkgName & pkgName);
};
} // namespace WrtDB