Mysql/MariaDB: add catalog+indexes+keys+user(s) skeleton part

+ sort objects in Library_mysqlc.mk

Change-Id: Ide8ea46424b034c109670ee5514b0afebfa376aa
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128176
Tested-by: Jenkins
Reviewed-by: Julien Nabet <serval2412@yahoo.fr>
This commit is contained in:
Julien Nabet
2022-01-11 20:53:43 +01:00
parent f523c854a5
commit 8dd86eb560
11 changed files with 477 additions and 8 deletions
+8 -8
View File
@@ -49,17 +49,17 @@ $(eval $(call gb_Library_add_defs,mysqlc,\
))
$(eval $(call gb_Library_add_exception_objects,mysqlc,\
connectivity/source/drivers/mysqlc/mysqlc_driver \
connectivity/source/drivers/mysqlc/mysqlc_services \
connectivity/source/drivers/mysqlc/mysqlc_connection \
connectivity/source/drivers/mysqlc/mysqlc_resultset \
connectivity/source/drivers/mysqlc/mysqlc_prepared_resultset \
connectivity/source/drivers/mysqlc/mysqlc_resultsetmetadata \
connectivity/source/drivers/mysqlc/mysqlc_statement \
connectivity/source/drivers/mysqlc/mysqlc_preparedstatement \
connectivity/source/drivers/mysqlc/mysqlc_databasemetadata \
connectivity/source/drivers/mysqlc/mysqlc_types \
connectivity/source/drivers/mysqlc/mysqlc_driver \
connectivity/source/drivers/mysqlc/mysqlc_general \
connectivity/source/drivers/mysqlc/mysqlc_prepared_resultset \
connectivity/source/drivers/mysqlc/mysqlc_preparedstatement \
connectivity/source/drivers/mysqlc/mysqlc_resultset \
connectivity/source/drivers/mysqlc/mysqlc_resultsetmetadata \
connectivity/source/drivers/mysqlc/mysqlc_services \
connectivity/source/drivers/mysqlc/mysqlc_statement \
connectivity/source/drivers/mysqlc/mysqlc_types \
))
$(eval $(call gb_Library_set_componentfile,mysqlc,connectivity/source/drivers/mysqlc/mysqlc,services))
@@ -0,0 +1,63 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* 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 "mysqlc_catalog.hxx"
#include "mysqlc_tables.hxx"
#include "mysqlc_users.hxx"
#include <com/sun/star/sdbc/XRow.hpp>
using namespace ::connectivity::mysqlc;
using namespace ::com::sun::star;
using namespace ::com::sun::star::sdbc;
using namespace ::com::sun::star::uno;
Catalog::Catalog(const uno::Reference<XConnection>& rConnection)
: OCatalog(rConnection)
, m_xConnection(rConnection)
{
}
//----- OCatalog -------------------------------------------------------------
void Catalog::refreshTables()
{
uno::Reference<XResultSet> xTables = m_xMetaData->getTables(Any(), "%", "%", {});
if (!xTables.is())
return;
::std::vector<OUString> aTableNames;
fillNames(xTables, aTableNames);
if (!m_pTables)
m_pTables.reset(new Tables(m_xConnection->getMetaData(), *this, m_aMutex, aTableNames));
else
m_pTables->reFill(aTableNames);
}
void Catalog::refreshViews()
{
// TODO: implement me.
// Sets m_pViews (OCatalog)
}
//----- IRefreshableGroups ---------------------------------------------------
void Catalog::refreshGroups()
{
// TODO: implement me
}
//----- IRefreshableUsers ----------------------------------------------------
void Catalog::refreshUsers()
{
// TODO: implement me
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
@@ -0,0 +1,36 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* 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/.
*/
#pragma once
#include <sdbcx/VCatalog.hxx>
namespace connectivity::mysqlc
{
class Catalog : public ::connectivity::sdbcx::OCatalog
{
css::uno::Reference<css::sdbc::XConnection> m_xConnection;
public:
explicit Catalog(const css::uno::Reference<css::sdbc::XConnection>& rConnection);
// OCatalog
virtual void refreshTables() override;
virtual void refreshViews() override;
// IRefreshableGroups
virtual void refreshGroups() override;
// IRefreshableUsers
virtual void refreshUsers() override;
};
} // namespace connectivity::mysqlc
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
@@ -0,0 +1,33 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* 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 "mysqlc_indexes.hxx"
using namespace ::connectivity;
using namespace ::connectivity::mysqlc;
using namespace ::osl;
using namespace ::std;
using namespace ::com::sun::star;
using namespace ::com::sun::star::sdbc;
Indexes::Indexes(Table* pTable, Mutex& rMutex, const vector<OUString>& rVector)
: OIndexesHelper(pTable, rMutex, rVector)
, m_pTable(pTable)
{
}
// XDrop
void Indexes::dropObject(sal_Int32 /*nPosition*/, const OUString& sIndexName)
{
// TODO IMPLEMENT ME
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
@@ -0,0 +1,33 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* 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/.
*/
#pragma once
#include "mysqlc_table.hxx"
#include <connectivity/TIndexes.hxx>
namespace connectivity::mysqlc
{
class Indexes : public ::connectivity::OIndexesHelper
{
private:
Table* m_pTable;
protected:
// XDrop
void dropObject(sal_Int32 nPosition, const OUString& sIndexName);
public:
Indexes(Table* pTable, ::osl::Mutex& rMutex, const std::vector<OUString>& rVector);
};
} // namespace connectivity::mysqlc
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
@@ -0,0 +1,55 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* 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 "mysqlc_keys.hxx"
#include "mysqlc_table.hxx"
#include <connectivity/dbtools.hxx>
using namespace ::connectivity;
using namespace ::connectivity::mysqlc;
using namespace ::dbtools;
using namespace ::osl;
using namespace ::com::sun::star;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::sdbc;
using namespace ::com::sun::star::uno;
Keys::Keys(Table* pTable, Mutex& rMutex, const ::std::vector<OUString>& rNames)
: OKeysHelper(pTable, rMutex, rNames)
, m_pTable(pTable)
{
}
//----- XDrop ----------------------------------------------------------------
void Keys::dropObject(sal_Int32 nPosition, const OUString& sName)
{
// TODO IMPLEMENT ME (should we just copy from Firebird LO code below?)
/*
if (m_pTable->isNew())
return;
uno::Reference<XPropertySet> xKey(getObject(nPosition), UNO_QUERY);
if (xKey.is())
{
const OUString sQuote
= m_pTable->getConnection()->getMetaData()->getIdentifierQuoteString();
OUString sSql("ALTER TABLE " + quoteName(sQuote, m_pTable->getName()) + " DROP CONSTRAINT "
+ quoteName(sQuote, sName));
m_pTable->getConnection()->createStatement()->execute(sSql);
}
*/
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
@@ -0,0 +1,31 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* 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/.
*/
#pragma once
#include <connectivity/TKeys.hxx>
namespace connectivity::mysqlc
{
class Table;
class Keys : public ::connectivity::OKeysHelper
{
private:
Table* m_pTable;
public:
Keys(Table* pTable, ::osl::Mutex& rMutex, const ::std::vector<OUString>& rNames);
// OKeysHelper / XDrop
void dropObject(sal_Int32 nPosition, const OUString& sName) override;
};
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
@@ -0,0 +1,55 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* 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 "mysqlc_user.hxx"
using namespace ::connectivity;
using namespace ::connectivity::mysqlc;
using namespace ::connectivity::sdbcx;
using namespace ::com::sun::star;
using namespace ::com::sun::star::sdbc;
User::User(const css::uno::Reference<css::sdbc::XConnection>& rConnection)
: OUser(true) // Case Sensitive
, m_xConnection(rConnection)
{
}
User::User(const css::uno::Reference<css::sdbc::XConnection>& rConnection, const OUString& rName)
: OUser(rName,
true) // Case Sensitive
, m_xConnection(rConnection)
{
}
void User::changePassword(const OUString&, const OUString& newPassword)
{
// TODO: implement
}
sal_Int32 User::getPrivileges(const OUString&, sal_Int32)
{
// TODO: implement.
return 0;
}
sal_Int32 User::getGrantablePrivileges(const OUString&, sal_Int32)
{
// TODO: implement.
return 0;
}
//----- IRefreshableGroups ----------------------------------------------------
void User::refreshGroups()
{
// TODO: implement.
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
@@ -0,0 +1,45 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* 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/.
*/
#pragma once
#include <sdbcx/VUser.hxx>
#include <com/sun/star/sdbc/XConnection.hpp>
namespace connectivity::mysqlc
{
/**
* This implements com.sun.star.sdbcx.Container.
*/
class User : public ::connectivity::sdbcx::OUser
{
css::uno::Reference<css::sdbc::XConnection> m_xConnection;
public:
/**
* Create a "new" descriptor, which isn't yet in the database.
*/
User(const css::uno::Reference<css::sdbc::XConnection>& rConnection);
/**
* For a user that already exists in the db.
*/
User(const css::uno::Reference<css::sdbc::XConnection>& rConnection, const OUString& rName);
// XAuthorizable
virtual void SAL_CALL changePassword(const OUString&, const OUString& newPassword) override;
virtual sal_Int32 SAL_CALL getPrivileges(const OUString&, sal_Int32) override;
virtual sal_Int32 SAL_CALL getGrantablePrivileges(const OUString&, sal_Int32) override;
// IRefreshableGroups::
virtual void refreshGroups() override;
};
} // namespace connectivity::mysqlc
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
@@ -0,0 +1,71 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* 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 "mysqlc_user.hxx"
#include "mysqlc_users.hxx"
using namespace ::connectivity;
using namespace ::connectivity::mysqlc;
using namespace ::connectivity::sdbcx;
using namespace ::cppu;
using namespace ::osl;
using namespace ::com::sun::star;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::container;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::sdbc;
using namespace ::com::sun::star::uno;
Users::Users(const uno::Reference<XDatabaseMetaData>& rMetaData, OWeakObject& rParent,
Mutex& rMutex, ::std::vector<OUString> const& rNames)
: OCollection(rParent, true, rMutex, rNames)
, m_xMetaData(rMetaData)
{
}
//----- OCollection -----------------------------------------------------------
void Users::impl_refresh()
{
// TODO: IMPLEMENT ME
}
ObjectType Users::createObject(const OUString& rName)
{
return new User(m_xMetaData->getConnection(), rName);
}
uno::Reference<XPropertySet> Users::createDescriptor()
{
// There is some internal magic so that the same class can be used as either
// a descriptor or as a normal user. See VUser.cxx for the details. In our
// case we just need to ensure we use the correct constructor.
return new User(m_xMetaData->getConnection());
}
//----- XAppend ---------------------------------------------------------------
ObjectType Users::appendObject(const OUString& rName, const uno::Reference<XPropertySet>&)
{
// TODO: set sSql as appropriate
m_xMetaData->getConnection()->createStatement()->execute(OUString());
return createObject(rName);
}
//----- XDrop -----------------------------------------------------------------
void Users::dropObject(sal_Int32 nPosition, const OUString&)
{
uno::Reference<XPropertySet> xUser(getObject(nPosition));
if (!ODescriptor::isNew(xUser))
{
// TODO: drop me
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
@@ -0,0 +1,47 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* 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/.
*/
#pragma once
#include <connectivity/sdbcx/VCollection.hxx>
#include <com/sun/star/sdbc/XDatabaseMetaData.hpp>
namespace connectivity::mysqlc
{
/**
* This implements com.sun.star.sdbcx.Container.
*/
class Users : public ::connectivity::sdbcx::OCollection
{
css::uno::Reference<css::sdbc::XDatabaseMetaData> m_xMetaData;
protected:
// OCollection
virtual void impl_refresh() override;
virtual ::connectivity::sdbcx::ObjectType createObject(const OUString& rName) override;
virtual css::uno::Reference<css::beans::XPropertySet> createDescriptor() override;
virtual ::connectivity::sdbcx::ObjectType
appendObject(const OUString& rName,
const css::uno::Reference<css::beans::XPropertySet>& rDescriptor) override;
public:
Users(const css::uno::Reference<css::sdbc::XDatabaseMetaData>& rMetaData,
::cppu::OWeakObject& rParent, ::osl::Mutex& rMutex,
::std::vector<OUString> const& rNames);
// TODO: we should also implement XDataDescriptorFactory, XRefreshable,
// XAppend, etc., but all are optional.
// XDrop
virtual void dropObject(sal_Int32 nPosition, const OUString& rName) override;
};
} // namespace connectivity::mysqlc
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */