LibreOffice Module connectivity (master) 1
mysqlc_driver.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19#include "mysqlc_driver.hxx"
20#include "mysqlc_connection.hxx"
21
22using namespace css::uno;
23using namespace css::lang;
24using namespace css::beans;
25using namespace css::sdbc;
26using namespace css::sdbcx;
27using namespace connectivity::mysqlc;
28
31
32MysqlCDriver::MysqlCDriver(const Reference<XMultiServiceFactory>& _rxFactory)
34 , m_xFactory(_rxFactory)
35{
36}
37
39{
40 ::osl::MutexGuard aGuard(m_aMutex);
41
42 // when driver will be destroyed so all our connections have to be destroyed as well
43 for (auto const& connection : m_xConnections)
44 {
45 Reference<XComponent> xComp(connection.get(), UNO_QUERY);
46 if (xComp.is())
47 {
48 xComp->dispose();
49 }
50 }
51 m_xConnections.clear();
52
53 ODriver_BASE::disposing();
54}
55
56// static ServiceInfo
58{
59 return "com.sun.star.comp.sdbc.mysqlc.MysqlCDriver";
60}
61
63{
64 return { "com.sun.star.sdbc.Driver", "com.sun.star.sdbcx.Driver" };
65}
66
68
69sal_Bool SAL_CALL MysqlCDriver::supportsService(const OUString& _rServiceName)
70{
71 return cppu::supportsService(this, _rServiceName);
72}
73
74Sequence<OUString> SAL_CALL MysqlCDriver::getSupportedServiceNames()
75{
77}
78
79Reference<XConnection> SAL_CALL MysqlCDriver::connect(const OUString& url,
80 const Sequence<PropertyValue>& info)
81{
82 ::osl::MutexGuard aGuard(m_aMutex);
83
84 if (!acceptsURL(url))
85 {
86 return nullptr;
87 }
88
89 // create a new connection with the given properties and append it to our vector
91
92 pCon->construct(url, info);
93 m_xConnections.push_back(WeakReferenceHelper(*pCon));
94 return pCon;
95}
96
97sal_Bool SAL_CALL MysqlCDriver::acceptsURL(const OUString& url)
98{
99 return url.startsWith("sdbc:mysqlc:") || url.startsWith("sdbc:mysql:mysqlc:");
100}
101
102Sequence<DriverPropertyInfo> SAL_CALL
103MysqlCDriver::getPropertyInfo(const OUString& url, const Sequence<PropertyValue>& /* info */)
104{
105 if (acceptsURL(url))
106 {
107 return { { "Hostname", "Name of host", true, "localhost", {} },
108 { "Port", "Port", true, "3306", {} } };
109 }
110
111 return Sequence<DriverPropertyInfo>();
112}
113
114sal_Int32 SAL_CALL MysqlCDriver::getMajorVersion() { return MARIADBC_VERSION_MAJOR; }
115
116sal_Int32 SAL_CALL MysqlCDriver::getMinorVersion() { return MARIADBC_VERSION_MINOR; }
117
118Reference<XTablesSupplier>
119 SAL_CALL MysqlCDriver::getDataDefinitionByConnection(const Reference<XConnection>& rConnection)
120{
121 if (OConnection* pConnection = comphelper::getFromUnoTunnel<OConnection>(rConnection))
122 return pConnection->createCatalog();
123 return {};
124}
125
126Reference<XTablesSupplier> SAL_CALL
127MysqlCDriver::getDataDefinitionByURL(const OUString& rURL, const Sequence<PropertyValue>& rInfo)
128{
129 Reference<XConnection> xConnection = connect(rURL, rInfo);
130 return getDataDefinitionByConnection(xConnection);
131}
132
133namespace connectivity::mysqlc
134{
135Reference<XInterface> MysqlCDriver_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory)
136{
137 return (*(new MysqlCDriver(_rxFactory)));
138}
139
140void checkDisposed(bool _bThrow)
141{
142 if (_bThrow)
143 {
144 throw DisposedException();
145 }
146}
147}
148
149/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
OUString SAL_CALL getImplementationName() override
static OUString getImplementationName_Static()
static Sequence< OUString > getSupportedServiceNames_Static()
virtual css::uno::Reference< css::sdbcx::XTablesSupplier > SAL_CALL getDataDefinitionByConnection(const css::uno::Reference< css::sdbc::XConnection > &rxConnection) override
virtual css::uno::Reference< css::sdbcx::XTablesSupplier > SAL_CALL getDataDefinitionByURL(const OUString &rsURL, const css::uno::Sequence< css::beans::PropertyValue > &rInfo) override
Reference< css::sdbc::XConnection > SAL_CALL connect(const OUString &url, const Sequence< css::beans::PropertyValue > &info) override
Sequence< OUString > SAL_CALL getSupportedServiceNames() override
sal_Bool SAL_CALL acceptsURL(const OUString &url) override
sal_Int32 SAL_CALL getMajorVersion() override
Sequence< css::sdbc::DriverPropertyInfo > SAL_CALL getPropertyInfo(const OUString &url, const Sequence< css::beans::PropertyValue > &info) override
void SAL_CALL disposing() override
sal_Int32 SAL_CALL getMinorVersion() override
sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
std::mutex m_aMutex
void checkDisposed(bool _bThrow)
::cppu::WeakComponentImplHelper< css::sdbc::XDriver, css::sdbcx::XDataDefinitionSupplier, css::lang::XServiceInfo > ODriver_BASE
Reference< XInterface > MysqlCDriver_CreateInstance(const Reference< XMultiServiceFactory > &_rxFactory)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
unsigned char sal_Bool