[Libreoffice-commits] core.git: dbaccess/Library_dbu.mk dbaccess/source dbaccess/uiconfig dbaccess/UIConfig_dbaccess.mk offapi/com offapi/type_reference

Tamas Bunth tamas.bunth at collabora.co.uk
Sat Apr 14 19:15:46 UTC 2018


 dbaccess/Library_dbu.mk                         |    1 
 dbaccess/UIConfig_dbaccess.mk                   |    1 
 dbaccess/source/core/dataaccess/datasource.cxx  |   14 ++--
 dbaccess/source/core/dataaccess/datasource.hxx  |    4 +
 dbaccess/source/core/inc/warndlg.hxx            |   29 +++++++++
 dbaccess/source/core/misc/warndlg.cxx           |   22 +++++++
 dbaccess/source/ui/dlg/migrwarndlg.cxx          |   22 +++++++
 dbaccess/source/ui/inc/migrwarndlg.hxx          |   29 +++++++++
 dbaccess/source/ui/misc/datasourceconnector.cxx |    7 ++
 dbaccess/uiconfig/ui/migrwarndlg.ui             |   73 ++++++++++++++++++++++++
 offapi/com/sun/star/sdbc/XDataSource.idl        |    5 +
 offapi/type_reference/offapi.idl                |    2 
 12 files changed, 203 insertions(+), 6 deletions(-)

New commits:
commit 5b0ceb86c342754d8f4e83408c7ae0da0e3931d3
Author: Tamas Bunth <tamas.bunth at collabora.co.uk>
Date:   Sat Apr 14 15:00:40 2018 +0200

    tdf#116944 Warn user before database migration
    
    Warn user with a pop-up dialog before migration.
    
    To do that we have to know the database URL at UI level. In order to get
    that I updated XDataSource interface with getConnectionURL().
    
    The dialog offers two options: proceed with or without migration. If the
    user choose "yes", we store that information in XDataSource. The
    migration itself will be made in buildLowConnection().
    
    Change-Id: I1f0d03da6352f7a0a8d989da79c4b2fe60a03ca1
    Reviewed-on: https://gerrit.libreoffice.org/52876
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Tamás Bunth <btomi96 at gmail.com>

diff --git a/dbaccess/Library_dbu.mk b/dbaccess/Library_dbu.mk
index 0ea52842317c..d1b5a53599bb 100644
--- a/dbaccess/Library_dbu.mk
+++ b/dbaccess/Library_dbu.mk
@@ -152,6 +152,7 @@ $(eval $(call gb_Library_add_exception_objects,dbu,\
     dbaccess/source/ui/dlg/textconnectionsettings \
     dbaccess/source/ui/dlg/UserAdmin \
     dbaccess/source/ui/dlg/UserAdminDlg \
+    dbaccess/source/ui/dlg/migrwarndlg \
     dbaccess/source/ui/misc/asyncmodaldialog \
     dbaccess/source/ui/misc/charsets \
     dbaccess/source/ui/misc/controllerframe \
diff --git a/dbaccess/UIConfig_dbaccess.mk b/dbaccess/UIConfig_dbaccess.mk
index 4ac2e8a09935..eacb9eb112c2 100644
--- a/dbaccess/UIConfig_dbaccess.mk
+++ b/dbaccess/UIConfig_dbaccess.mk
@@ -80,6 +80,7 @@ $(eval $(call gb_UIConfig_add_uifiles,dbaccess, \
     dbaccess/uiconfig/ui/useradmindialog \
     dbaccess/uiconfig/ui/useradminpage \
     dbaccess/uiconfig/ui/userdetailspage \
+    dbaccess/uiconfig/ui/migrwarndlg \
 ))
 
 # vim: set noet sw=4 ts=4:
diff --git a/dbaccess/source/core/dataaccess/datasource.cxx b/dbaccess/source/core/dataaccess/datasource.cxx
index 9093cd622925..d06413fc59dd 100644
--- a/dbaccess/source/core/dataaccess/datasource.cxx
+++ b/dbaccess/source/core/dataaccess/datasource.cxx
@@ -575,22 +575,24 @@ void ODatabaseSource::disposing()
     m_pImpl.clear();
 }
 
+OUString SAL_CALL ODatabaseSource::getConnectionUrl()
+{
+    return m_pImpl->m_sConnectURL;
+}
+
 Reference< XConnection > ODatabaseSource::buildLowLevelConnection(const OUString& _rUid, const OUString& _rPwd)
 {
     Reference< XConnection > xReturn;
 
     Reference< XDriverManager > xManager;
 
-    bool bNeedMigration = false;
     OUString sMigrEnvVal;
     osl_getEnvironment(OUString("DBACCESS_HSQL_MIGRATION").pData,
             &sMigrEnvVal.pData);
-    if( m_pImpl->m_sConnectURL == "sdbc:embedded:hsqldb" &&
-            !sMigrEnvVal.isEmpty())
-    {
+    bool bNeedMigration =  m_pImpl->m_sConnectURL == "sdbc:embedded:hsqldb" &&
+            (m_bMigationNeeded || !sMigrEnvVal.isEmpty());
+    if(bNeedMigration)
         m_pImpl->m_sConnectURL = "sdbc:embedded:firebird";
-        bNeedMigration = true;
-    }
 
     try {
         xManager.set( ConnectionPool::create( m_pImpl->m_aContext ), UNO_QUERY_THROW );
diff --git a/dbaccess/source/core/dataaccess/datasource.hxx b/dbaccess/source/core/dataaccess/datasource.hxx
index 14328e19c34f..a330cccd9625 100644
--- a/dbaccess/source/core/dataaccess/datasource.hxx
+++ b/dbaccess/source/core/dataaccess/datasource.hxx
@@ -84,6 +84,7 @@ private:
     using ODatabaseSource_Base::rBHelper;
     // note: this thing uses the ref-count of "this", see OBookmarkContainer::acquire!
     OBookmarkContainer m_Bookmarks;
+    bool m_bMigationNeeded = false;
     ::comphelper::OInterfaceContainerHelper2       m_aFlushListeners;
 
 private:
@@ -162,6 +163,9 @@ public:
     virtual css::uno::Reference< css::sdbc::XConnection > SAL_CALL getConnection( const OUString& user, const OUString& password ) override;
     virtual void SAL_CALL setLoginTimeout( sal_Int32 seconds ) override;
     virtual sal_Int32 SAL_CALL getLoginTimeout(  ) override;
+    virtual void SAL_CALL setMigrationNeeded( sal_Bool bNeeded ) override { m_bMigationNeeded = bNeeded; }
+    virtual sal_Bool SAL_CALL getMigrationNeeded() override { return m_bMigationNeeded; }
+    virtual OUString SAL_CALL getConnectionUrl() override;
 
 //::css::sdb::XBookmarksSupplier
     virtual css::uno::Reference< css::container::XNameAccess > SAL_CALL getBookmarks(  ) override;
diff --git a/dbaccess/source/core/inc/warndlg.hxx b/dbaccess/source/core/inc/warndlg.hxx
new file mode 100644
index 000000000000..54cfe88cb6a4
--- /dev/null
+++ b/dbaccess/source/core/inc/warndlg.hxx
@@ -0,0 +1,29 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+#ifndef INCLUDED_DBACCESS_SOURCE_CORE_INC_WARNDLG_HXX
+#define INCLUDED_DBACCESS_SOURCE_CORE_INC_WARNDLG_HXX
+
+#include <vcl/weld.hxx>
+
+namespace dbaccess
+{
+class MigrationWarnDialog : public weld::MessageDialogController
+{
+private:
+    std::unique_ptr<weld::Button> m_xOkBtn;
+    std::unique_ptr<weld::Button> m_xLaterBtn;
+
+public:
+    MigrationWarnDialog(weld::Window* pParent);
+};
+}
+
+#endif // INCLUDED_DBACCESS_SOURCE_CORE_INC_WARNDLG_HXX
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/dbaccess/source/core/misc/warndlg.cxx b/dbaccess/source/core/misc/warndlg.cxx
new file mode 100644
index 000000000000..e8446b6e7539
--- /dev/null
+++ b/dbaccess/source/core/misc/warndlg.cxx
@@ -0,0 +1,22 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <warndlg.hxx>
+
+namespace dbaccess
+{
+MigrationWarnDialog::MigrationWarnDialog(weld::Window* pParent)
+    : MessageDialogController(pParent, "TODOUIfile", "MigrationWarnDialog", "ask")
+    , m_xOkBtn(m_xBuilder->weld_button("yes"))
+    , m_xLaterBtn(m_xBuilder->weld_button("later"))
+{
+}
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/dbaccess/source/ui/dlg/migrwarndlg.cxx b/dbaccess/source/ui/dlg/migrwarndlg.cxx
new file mode 100644
index 000000000000..9281dc11a941
--- /dev/null
+++ b/dbaccess/source/ui/dlg/migrwarndlg.cxx
@@ -0,0 +1,22 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <migrwarndlg.hxx>
+
+namespace dbaui
+{
+MigrationWarnDialog::MigrationWarnDialog(weld::Window* pParent)
+    : MessageDialogController(pParent, "dbaccess/ui/migrwarndlg.ui", "MigrationWarnDialog")
+    , m_xOkBtn(m_xBuilder->weld_button("yes"))
+    , m_xLaterBtn(m_xBuilder->weld_button("later"))
+{
+}
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/dbaccess/source/ui/inc/migrwarndlg.hxx b/dbaccess/source/ui/inc/migrwarndlg.hxx
new file mode 100644
index 000000000000..7f18ad02f446
--- /dev/null
+++ b/dbaccess/source/ui/inc/migrwarndlg.hxx
@@ -0,0 +1,29 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+#ifndef INCLUDED_DBACCESS_SOURCE_CORE_INC_WARNDLG_HXX
+#define INCLUDED_DBACCESS_SOURCE_CORE_INC_WARNDLG_HXX
+
+#include <vcl/weld.hxx>
+
+namespace dbaui
+{
+class MigrationWarnDialog : public weld::MessageDialogController
+{
+private:
+    std::unique_ptr<weld::Button> m_xOkBtn;
+    std::unique_ptr<weld::Button> m_xLaterBtn;
+
+public:
+    MigrationWarnDialog(weld::Window* pParent);
+};
+}
+
+#endif // INCLUDED_DBACCESS_SOURCE_CORE_INC_WARNDLG_HXX
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/dbaccess/source/ui/misc/datasourceconnector.cxx b/dbaccess/source/ui/misc/datasourceconnector.cxx
index 0496a4edded4..434f000d907f 100644
--- a/dbaccess/source/ui/misc/datasourceconnector.cxx
+++ b/dbaccess/source/ui/misc/datasourceconnector.cxx
@@ -41,6 +41,7 @@
 #include <cppuhelper/exc_hlp.hxx>
 #include <strings.hrc>
 #include <strings.hxx>
+#include <migrwarndlg.hxx>
 
 namespace dbaui
 {
@@ -114,6 +115,12 @@ namespace dbaui
             DBG_UNHANDLED_EXCEPTION("dbaccess");
         }
 
+        if(_xDataSource->getConnectionUrl().startsWithIgnoreAsciiCase("sdbc:embedded:hsqldb"))
+        {
+            MigrationWarnDialog aWarnDlg{m_pErrorMessageParent->GetFrameWeld()};
+            _xDataSource->setMigrationNeeded(aWarnDlg.run() == RET_OK);
+        }
+
         // try to connect
         SQLExceptionInfo aInfo;
         try
diff --git a/dbaccess/uiconfig/ui/migrwarndlg.ui b/dbaccess/uiconfig/ui/migrwarndlg.ui
new file mode 100644
index 000000000000..8fa8e4934520
--- /dev/null
+++ b/dbaccess/uiconfig/ui/migrwarndlg.ui
@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.20.2 -->
+<interface domain="sfx">
+  <requires lib="gtk+" version="3.18"/>
+  <object class="GtkMessageDialog" id="MigrationWarnDialog">
+    <property name="can_focus">False</property>
+    <property name="type_hint">dialog</property>
+    <property name="title" translatable="yes" context="migrationwarndialog|MigrationWarnDialog">Confirm Migration</property>
+    <property name="resizable">False</property>
+    <property name="modal">True</property>
+    <child internal-child="vbox">
+      <object class="GtkBox">
+        <property name="can_focus">False</property>
+        <property name="orientation">vertical</property>
+        <property name="spacing">2</property>
+        <child internal-child="action_area">
+          <object class="GtkButtonBox">
+            <property name="can_focus">False</property>
+            <property name="layout_style">end</property>
+            <child>
+              <object class="GtkButton" id="yes">
+                <property name="label" translatable="yes" context="migrationwarndialog|yes">yes</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+              </object>
+              <packing>
+                <property name="expand">True</property>
+                <property name="fill">True</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkButton" id="later">
+                <property name="label" translatable="yes" context="migrationwarndialog|later">later</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+              </object>
+              <packing>
+                <property name="expand">True</property>
+                <property name="fill">True</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">False</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="label" translatable="yes" context="migrationwarndialog|dialogmessage">The document contains embedded HSQL data, which is deprecated.
+Would you like to migrate to Firebird now?</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+    <action-widgets>
+      <action-widget response="-5">yes</action-widget>
+      <action-widget response="-6">later</action-widget>
+    </action-widgets>
+  </object>
+</interface>
diff --git a/offapi/com/sun/star/sdbc/XDataSource.idl b/offapi/com/sun/star/sdbc/XDataSource.idl
index c169b8972031..f8b5bda8b553 100644
--- a/offapi/com/sun/star/sdbc/XDataSource.idl
+++ b/offapi/com/sun/star/sdbc/XDataSource.idl
@@ -34,6 +34,11 @@
  */
 published interface XDataSource: com::sun::star::uno::XInterface
 {
+    /** indicates whether database migration is needed or not.
+    */
+    [attribute] boolean MigrationNeeded;
+
+    string getConnectionUrl();
 
     /** attempts to establish a database connection.
         @param user
diff --git a/offapi/type_reference/offapi.idl b/offapi/type_reference/offapi.idl
index eb20847723b9..99ad946e8f05 100644
--- a/offapi/type_reference/offapi.idl
+++ b/offapi/type_reference/offapi.idl
@@ -10212,6 +10212,8 @@ module com {
    };
    module sdbc {
     published interface XDataSource {
+     [attribute] boolean MigrationNeeded;
+     string getConnectionUrl();
      interface ::com::sun::star::uno::XInterface;
      ::com::sun::star::sdbc::XConnection getConnection([in] string user, [in] string password) raises (::com::sun::star::sdbc::SQLException);
      void setLoginTimeout([in] long seconds) raises (::com::sun::star::sdbc::SQLException);


More information about the Libreoffice-commits mailing list