Line data Source code
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"
23 : #include <com/sun/star/lang/DisposedException.hpp>
24 : #include <comphelper/types.hxx>
25 : #include <cppuhelper/supportsservice.hxx>
26 : #include <connectivity/dbexception.hxx>
27 : #include "resource/common_res.hrc"
28 : #include "resource/sharedresources.hxx"
29 :
30 :
31 : using namespace connectivity::file;
32 : using namespace com::sun::star::uno;
33 : using namespace com::sun::star::lang;
34 : using namespace com::sun::star::beans;
35 : using namespace com::sun::star::sdbc;
36 : using namespace com::sun::star::sdbcx;
37 : using namespace com::sun::star::container;
38 :
39 14 : OFileDriver::OFileDriver(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext)
40 : : ODriver_BASE(m_aMutex)
41 14 : ,m_xContext(_rxContext)
42 : {
43 14 : }
44 :
45 3 : void OFileDriver::disposing()
46 : {
47 3 : ::osl::MutexGuard aGuard(m_aMutex);
48 :
49 :
50 3 : for (OWeakRefArray::iterator i = m_xConnections.begin(); m_xConnections.end() != i; ++i)
51 : {
52 0 : Reference< XComponent > xComp(i->get(), UNO_QUERY);
53 0 : if (xComp.is())
54 0 : xComp->dispose();
55 0 : }
56 3 : m_xConnections.clear();
57 :
58 3 : ODriver_BASE::disposing();
59 3 : }
60 :
61 : // static ServiceInfo
62 :
63 0 : OUString OFileDriver::getImplementationName_Static( ) throw(RuntimeException)
64 : {
65 0 : return OUString("com.sun.star.sdbc.driver.file.Driver");
66 : }
67 :
68 17 : Sequence< OUString > OFileDriver::getSupportedServiceNames_Static( ) throw (RuntimeException)
69 : {
70 17 : Sequence< OUString > aSNS( 2 );
71 17 : aSNS[0] = "com.sun.star.sdbc.Driver";
72 17 : aSNS[1] = "com.sun.star.sdbcx.Driver";
73 17 : return aSNS;
74 : }
75 :
76 :
77 0 : OUString SAL_CALL OFileDriver::getImplementationName( ) throw(RuntimeException, std::exception)
78 : {
79 0 : return getImplementationName_Static();
80 : }
81 :
82 0 : sal_Bool SAL_CALL OFileDriver::supportsService( const OUString& _rServiceName ) throw(RuntimeException, std::exception)
83 : {
84 0 : return cppu::supportsService(this, _rServiceName);
85 : }
86 :
87 :
88 3 : Sequence< OUString > SAL_CALL OFileDriver::getSupportedServiceNames( ) throw(RuntimeException, std::exception)
89 : {
90 3 : return getSupportedServiceNames_Static();
91 : }
92 :
93 :
94 0 : Reference< XConnection > SAL_CALL OFileDriver::connect( const OUString& url, const Sequence< PropertyValue >& info ) throw(SQLException, RuntimeException, std::exception)
95 : {
96 0 : ::osl::MutexGuard aGuard( m_aMutex );
97 0 : checkDisposed(ODriver_BASE::rBHelper.bDisposed);
98 :
99 0 : OConnection* pCon = new OConnection(this);
100 0 : Reference< XConnection > xCon = pCon;
101 0 : pCon->construct(url,info);
102 0 : m_xConnections.push_back(WeakReferenceHelper(*pCon));
103 :
104 0 : return xCon;
105 : }
106 :
107 0 : sal_Bool SAL_CALL OFileDriver::acceptsURL( const OUString& url )
108 : throw(SQLException, RuntimeException, std::exception)
109 : {
110 0 : return url.startsWith("sdbc:file:");
111 : }
112 :
113 0 : Sequence< DriverPropertyInfo > SAL_CALL OFileDriver::getPropertyInfo( const OUString& url, const Sequence< PropertyValue >& /*info*/ ) throw(SQLException, RuntimeException, std::exception)
114 : {
115 0 : if ( acceptsURL(url) )
116 : {
117 0 : ::std::vector< DriverPropertyInfo > aDriverInfo;
118 :
119 0 : Sequence< OUString > aBoolean(2);
120 0 : aBoolean[0] = "0";
121 0 : aBoolean[1] = "1";
122 :
123 : aDriverInfo.push_back(DriverPropertyInfo(
124 : OUString("CharSet")
125 : ,OUString("CharSet of the database.")
126 : ,sal_False
127 : ,OUString()
128 : ,Sequence< OUString >())
129 0 : );
130 : aDriverInfo.push_back(DriverPropertyInfo(
131 : OUString("Extension")
132 : ,OUString("Extension of the file format.")
133 : ,sal_False
134 : ,OUString(".*")
135 : ,Sequence< OUString >())
136 0 : );
137 : aDriverInfo.push_back(DriverPropertyInfo(
138 : OUString("ShowDeleted")
139 : ,OUString("Display inactive records.")
140 : ,sal_False
141 : ,OUString("0")
142 : ,aBoolean)
143 0 : );
144 : aDriverInfo.push_back(DriverPropertyInfo(
145 : OUString("EnableSQL92Check")
146 : ,OUString("Use SQL92 naming constraints.")
147 : ,sal_False
148 : ,OUString("0")
149 : ,aBoolean)
150 0 : );
151 : aDriverInfo.push_back(DriverPropertyInfo(
152 : OUString("UseRelativePath")
153 : ,OUString("Handle the connection url as relative path.")
154 : ,sal_False
155 : ,OUString("0")
156 : ,aBoolean)
157 0 : );
158 : aDriverInfo.push_back(DriverPropertyInfo(
159 : OUString("URL")
160 : ,OUString("The URL of the database document which is used to create an absolute path.")
161 : ,sal_False
162 : ,OUString()
163 : ,Sequence< OUString >())
164 0 : );
165 0 : return Sequence< DriverPropertyInfo >(&(aDriverInfo[0]),aDriverInfo.size());
166 : } // if ( acceptsURL(url) )
167 : {
168 0 : ::connectivity::SharedResources aResources;
169 0 : const OUString sMessage = aResources.getResourceString(STR_URI_SYNTAX_ERROR);
170 0 : ::dbtools::throwGenericSQLException(sMessage ,*this);
171 : } // if ( ! acceptsURL(url) )
172 0 : return Sequence< DriverPropertyInfo >();
173 : }
174 :
175 0 : sal_Int32 SAL_CALL OFileDriver::getMajorVersion( ) throw(RuntimeException, std::exception)
176 : {
177 0 : return 1;
178 : }
179 :
180 0 : sal_Int32 SAL_CALL OFileDriver::getMinorVersion( ) throw(RuntimeException, std::exception)
181 : {
182 0 : return 0;
183 : }
184 :
185 :
186 : // XDataDefinitionSupplier
187 38 : Reference< XTablesSupplier > SAL_CALL OFileDriver::getDataDefinitionByConnection( const Reference< ::com::sun::star::sdbc::XConnection >& connection ) throw(::com::sun::star::sdbc::SQLException, RuntimeException, std::exception)
188 : {
189 38 : ::osl::MutexGuard aGuard( m_aMutex );
190 38 : checkDisposed(ODriver_BASE::rBHelper.bDisposed);
191 :
192 38 : Reference< XTablesSupplier > xTab = NULL;
193 76 : Reference< ::com::sun::star::lang::XUnoTunnel> xTunnel(connection,UNO_QUERY);
194 38 : if(xTunnel.is())
195 : {
196 38 : OConnection* pSearchConnection = reinterpret_cast< OConnection* >( xTunnel->getSomething(OConnection::getUnoTunnelImplementationId()) );
197 38 : OConnection* pConnection = NULL;
198 145 : for (OWeakRefArray::iterator i = m_xConnections.begin(); m_xConnections.end() != i; ++i)
199 : {
200 145 : if (static_cast<OConnection*>( Reference< XConnection >::query(i->get().get()).get() ) == pSearchConnection)
201 : {
202 38 : pConnection = pSearchConnection;
203 38 : break;
204 : }
205 : }
206 :
207 38 : if(pConnection)
208 38 : xTab = pConnection->createCatalog();
209 : }
210 76 : return xTab;
211 : }
212 :
213 :
214 0 : Reference< XTablesSupplier > SAL_CALL OFileDriver::getDataDefinitionByURL( const OUString& url, const Sequence< PropertyValue >& info ) throw(::com::sun::star::sdbc::SQLException, RuntimeException, std::exception)
215 : {
216 0 : if ( ! acceptsURL(url) )
217 : {
218 0 : ::connectivity::SharedResources aResources;
219 0 : const OUString sMessage = aResources.getResourceString(STR_URI_SYNTAX_ERROR);
220 0 : ::dbtools::throwGenericSQLException(sMessage ,*this);
221 : }
222 0 : return getDataDefinitionByConnection(connect(url,info));
223 : }
224 :
225 :
226 8 : OOperandAttr::OOperandAttr(sal_uInt16 _nPos,const Reference< XPropertySet>& _xColumn)
227 8 : : OOperandRow(_nPos,::comphelper::getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE))))
228 8 : , m_xColumn(_xColumn)
229 : {
230 8 : }
231 :
232 :
233 :
234 :
235 :
236 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|