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