summaryrefslogtreecommitdiffstats
path: root/connectivity/source/drivers/mysqlc/mysqlc_driver.cxx
blob: 37a14e822aff91582e6184ffa2b625117073cf4a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/* -*- 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/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */
#include "mysqlc_driver.hxx"
#include "mysqlc_connection.hxx"

using namespace css::uno;
using namespace css::lang;
using namespace css::beans;
using namespace css::sdbc;
using namespace css::sdbcx;
using namespace connectivity::mysqlc;

#include <cppuhelper/supportsservice.hxx>
#include <comphelper/servicehelper.hxx>

MysqlCDriver::MysqlCDriver(const Reference<XMultiServiceFactory>& _rxFactory)
    : ODriver_BASE(m_aMutex)
    , m_xFactory(_rxFactory)
{
}

void MysqlCDriver::disposing()
{
    ::osl::MutexGuard aGuard(m_aMutex);

    // when driver will be destroyed so all our connections have to be destroyed as well
    for (auto const& connection : m_xConnections)
    {
        Reference<XComponent> xComp(connection.get(), UNO_QUERY);
        if (xComp.is())
        {
            xComp->dispose();
        }
    }
    m_xConnections.clear();

    ODriver_BASE::disposing();
}

// static ServiceInfo
OUString MysqlCDriver::getImplementationName_Static()
{
    return "com.sun.star.comp.sdbc.mysqlc.MysqlCDriver";
}

Sequence<OUString> MysqlCDriver::getSupportedServiceNames_Static()
{
    return { "com.sun.star.sdbc.Driver", "com.sun.star.sdbcx.Driver" };
}

OUString SAL_CALL MysqlCDriver::getImplementationName() { return getImplementationName_Static(); }

sal_Bool SAL_CALL MysqlCDriver::supportsService(const OUString& _rServiceName)
{
    return cppu::supportsService(this, _rServiceName);
}

Sequence<OUString> SAL_CALL MysqlCDriver::getSupportedServiceNames()
{
    return getSupportedServiceNames_Static();
}

Reference<XConnection> SAL_CALL MysqlCDriver::connect(const OUString& url,
                                                      const Sequence<PropertyValue>& info)
{
    ::osl::MutexGuard aGuard(m_aMutex);

    if (!acceptsURL(url))
    {
        return nullptr;
    }

    // create a new connection with the given properties and append it to our vector
    rtl::Reference<OConnection> pCon = new OConnection(*this);

    pCon->construct(url, info);
    m_xConnections.push_back(WeakReferenceHelper(*pCon));
    return pCon;
}

sal_Bool SAL_CALL MysqlCDriver::acceptsURL(const OUString& url)
{
    return url.startsWith("sdbc:mysqlc:") || url.startsWith("sdbc:mysql:mysqlc:");
}

Sequence<DriverPropertyInfo> SAL_CALL
MysqlCDriver::getPropertyInfo(const OUString& url, const Sequence<PropertyValue>& /* info */)
{
    if (acceptsURL(url))
    {
        return { { "Hostname", "Name of host", true, "localhost", {} },
                 { "Port", "Port", true, "3306", {} } };
    }

    return Sequence<DriverPropertyInfo>();
}

sal_Int32 SAL_CALL MysqlCDriver::getMajorVersion() { return MARIADBC_VERSION_MAJOR; }

sal_Int32 SAL_CALL MysqlCDriver::getMinorVersion() { return MARIADBC_VERSION_MINOR; }

Reference<XTablesSupplier>
    SAL_CALL MysqlCDriver::getDataDefinitionByConnection(const Reference<XConnection>& rConnection)
{
    if (OConnection* pConnection = comphelper::getFromUnoTunnel<OConnection>(rConnection))
        return pConnection->createCatalog();
    return {};
}

Reference<XTablesSupplier> SAL_CALL
MysqlCDriver::getDataDefinitionByURL(const OUString& rURL, const Sequence<PropertyValue>& rInfo)
{
    Reference<XConnection> xConnection = connect(rURL, rInfo);
    return getDataDefinitionByConnection(xConnection);
}

namespace connectivity::mysqlc
{
Reference<XInterface> MysqlCDriver_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory)
{
    return (*(new MysqlCDriver(_rxFactory)));
}

void checkDisposed(bool _bThrow)
{
    if (_bThrow)
    {
        throw DisposedException();
    }
}
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */