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