LibreOffice Module connectivity (master) 1
FDriver.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
20#include <file/FDriver.hxx>
21#include <file/FConnection.hxx>
22#include <file/fcode.hxx>
24#include <comphelper/types.hxx>
27#include <strings.hrc>
29#include <utility>
30
31
32using namespace connectivity::file;
33using namespace com::sun::star::uno;
34using namespace com::sun::star::lang;
35using namespace com::sun::star::beans;
36using namespace com::sun::star::sdbc;
37using namespace com::sun::star::sdbcx;
38using namespace com::sun::star::container;
39
40OFileDriver::OFileDriver(css::uno::Reference< css::uno::XComponentContext > _xContext)
42 ,m_xContext(std::move(_xContext))
43{
44}
45
47{
48 ::osl::MutexGuard aGuard(m_aMutex);
49
50
51 for (auto const& connection : m_xConnections)
52 {
53 Reference< XComponent > xComp(connection.get(), UNO_QUERY);
54 if (xComp.is())
55 xComp->dispose();
56 }
57 m_xConnections.clear();
58
59 ODriver_BASE::disposing();
60}
61
62// XServiceInfo
63
65{
66 return "com.sun.star.sdbc.driver.file.Driver";
67}
68
69sal_Bool SAL_CALL OFileDriver::supportsService( const OUString& _rServiceName )
70{
71 return cppu::supportsService(this, _rServiceName);
72}
73
74
76{
77 return { "com.sun.star.sdbc.Driver", "com.sun.star.sdbcx.Driver" };
78}
79
80
82{
83 ::osl::MutexGuard aGuard( m_aMutex );
84 checkDisposed(ODriver_BASE::rBHelper.bDisposed);
85
87 pCon->construct(url,info);
88 m_xConnections.push_back(WeakReferenceHelper(*pCon));
89
90 return pCon;
91}
92
93sal_Bool SAL_CALL OFileDriver::acceptsURL( const OUString& url )
94{
95 return url.startsWith("sdbc:file:");
96}
97
99{
100 if ( acceptsURL(url) )
101 {
102
103 Sequence< OUString > aBoolean { "0", "1" };
104
105 return
106 {
107 {
108 "CharSet"
109 ,"CharSet of the database."
110 ,false
111 ,{}
112 ,{}
113 },
114 {
115 "Extension"
116 ,"Extension of the file format."
117 ,false
118 ,".*"
119 ,{}
120 },
121 {
122 "ShowDeleted"
123 ,"Display inactive records."
124 ,false
125 ,"0"
126 ,aBoolean
127 },
128 {
129 "EnableSQL92Check"
130 ,"Use SQL92 naming constraints."
131 ,false
132 ,"0"
133 ,aBoolean
134 },
135 {
136 "UseRelativePath"
137 ,"Handle the connection url as relative path."
138 ,false
139 ,"0"
140 ,aBoolean
141 },
142 {
143 "URL"
144 ,"The URL of the database document which is used to create an absolute path."
145 ,false
146 ,{}
147 ,{}
148 }
149 };
150 } // if ( acceptsURL(url) )
151 {
153 const OUString sMessage = aResources.getResourceString(STR_URI_SYNTAX_ERROR);
155 } // if ( ! acceptsURL(url) )
157}
158
159sal_Int32 SAL_CALL OFileDriver::getMajorVersion( )
160{
161 return 1;
162}
163
164sal_Int32 SAL_CALL OFileDriver::getMinorVersion( )
165{
166 return 0;
167}
168
169
170// XDataDefinitionSupplier
172{
173 ::osl::MutexGuard aGuard( m_aMutex );
174 checkDisposed(ODriver_BASE::rBHelper.bDisposed);
175
176 if (OConnection* pSearchConnection = comphelper::getFromUnoTunnel<OConnection>(connection))
177 {
178 for (auto const& elem : m_xConnections)
179 {
180 if (static_cast<OConnection*>( Reference< XConnection >::query(elem.get()).get() ) == pSearchConnection)
181 return pSearchConnection->createCatalog();
182 }
183 }
184 return {};
185}
186
187
189{
190 if ( ! acceptsURL(url) )
191 {
193 const OUString sMessage = aResources.getResourceString(STR_URI_SYNTAX_ERROR);
195 }
196 return getDataDefinitionByConnection(connect(url,info));
197}
198
199
201 : OOperandRow(_nPos,::comphelper::getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE))))
202{
203}
204
205
206/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< XComponentContext > m_xContext
helper class for accessing resources shared by different libraries in the connectivity module
OUString getResourceString(TranslateId pResId) const
loads a string from the shared resource file
virtual css::uno::Reference< css::sdbcx::XTablesSupplier > SAL_CALL getDataDefinitionByURL(const OUString &url, const css::uno::Sequence< css::beans::PropertyValue > &info) override
Definition: FDriver.cxx:188
virtual OUString SAL_CALL getImplementationName() override
Definition: FDriver.cxx:64
virtual css::uno::Reference< css::sdbcx::XTablesSupplier > SAL_CALL getDataDefinitionByConnection(const css::uno::Reference< css::sdbc::XConnection > &connection) override
Definition: FDriver.cxx:171
virtual sal_Bool SAL_CALL acceptsURL(const OUString &url) override
Definition: FDriver.cxx:93
connectivity::OWeakRefArray m_xConnections
Definition: FDriver.hxx:40
virtual sal_Int32 SAL_CALL getMajorVersion() override
Definition: FDriver.cxx:159
virtual void SAL_CALL disposing() override
Definition: FDriver.cxx:46
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: FDriver.cxx:75
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
Definition: FDriver.cxx:69
virtual sal_Int32 SAL_CALL getMinorVersion() override
Definition: FDriver.cxx:164
virtual css::uno::Reference< css::sdbc::XConnection > SAL_CALL connect(const OUString &url, const css::uno::Sequence< css::beans::PropertyValue > &info) override
Definition: FDriver.cxx:81
virtual css::uno::Sequence< css::sdbc::DriverPropertyInfo > SAL_CALL getPropertyInfo(const OUString &url, const css::uno::Sequence< css::beans::PropertyValue > &info) override
Definition: FDriver.cxx:98
OOperandAttr(sal_uInt16 _nPos, const css::uno::Reference< css::beans::XPropertySet > &_xColumn)
Definition: FDriver.cxx:200
std::mutex m_aMutex
sal_Int32 getINT32(const Any &_rAny)
::cppu::WeakComponentImplHelper< css::sdbc::XDriver, css::lang::XServiceInfo, css::sdbcx::XDataDefinitionSupplier > ODriver_BASE
Definition: FDriver.hxx:33
void checkDisposed(bool _bThrow)
Definition: dbtools.cxx:1951
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
void throwGenericSQLException(const OUString &_rMsg, const css::uno::Reference< css::uno::XInterface > &_rxSource)
throw a generic SQLException, i.e.
bool getPropertyValue(ValueType &rValue, css::uno::Reference< css::beans::XPropertySet > const &xPropSet, OUString const &propName)
#define PROPERTY_ID_TYPE
Definition: propertyids.hxx:51
OUString sMessage
unsigned char sal_Bool
Reference< XComponentContext > _xContext
sal_Int32 _nPos