Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / connectivity / source / drivers / file / FDriver.cxx
blobb88dbfdcbb2996dbb60bf9d2d11afb4e0d5176ba
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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"
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;
39 OFileDriver::OFileDriver(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext)
40 : ODriver_BASE(m_aMutex)
41 ,m_xContext(_rxContext)
45 void OFileDriver::disposing()
47 ::osl::MutexGuard aGuard(m_aMutex);
50 for (OWeakRefArray::iterator i = m_xConnections.begin(); m_xConnections.end() != i; ++i)
52 Reference< XComponent > xComp(i->get(), UNO_QUERY);
53 if (xComp.is())
54 xComp->dispose();
56 m_xConnections.clear();
58 ODriver_BASE::disposing();
61 // static ServiceInfo
63 OUString OFileDriver::getImplementationName_Static( ) throw(RuntimeException)
65 return OUString("com.sun.star.sdbc.driver.file.Driver");
68 Sequence< OUString > OFileDriver::getSupportedServiceNames_Static( ) throw (RuntimeException)
70 Sequence< OUString > aSNS( 2 );
71 aSNS[0] = "com.sun.star.sdbc.Driver";
72 aSNS[1] = "com.sun.star.sdbcx.Driver";
73 return aSNS;
77 OUString SAL_CALL OFileDriver::getImplementationName( ) throw(RuntimeException, std::exception)
79 return getImplementationName_Static();
82 sal_Bool SAL_CALL OFileDriver::supportsService( const OUString& _rServiceName ) throw(RuntimeException, std::exception)
84 return cppu::supportsService(this, _rServiceName);
88 Sequence< OUString > SAL_CALL OFileDriver::getSupportedServiceNames( ) throw(RuntimeException, std::exception)
90 return getSupportedServiceNames_Static();
94 Reference< XConnection > SAL_CALL OFileDriver::connect( const OUString& url, const Sequence< PropertyValue >& info ) throw(SQLException, RuntimeException, std::exception)
96 ::osl::MutexGuard aGuard( m_aMutex );
97 checkDisposed(ODriver_BASE::rBHelper.bDisposed);
99 OConnection* pCon = new OConnection(this);
100 Reference< XConnection > xCon = pCon;
101 pCon->construct(url,info);
102 m_xConnections.push_back(WeakReferenceHelper(*pCon));
104 return xCon;
107 sal_Bool SAL_CALL OFileDriver::acceptsURL( const OUString& url )
108 throw(SQLException, RuntimeException, std::exception)
110 return url.startsWith("sdbc:file:");
113 Sequence< DriverPropertyInfo > SAL_CALL OFileDriver::getPropertyInfo( const OUString& url, const Sequence< PropertyValue >& /*info*/ ) throw(SQLException, RuntimeException, std::exception)
115 if ( acceptsURL(url) )
117 ::std::vector< DriverPropertyInfo > aDriverInfo;
119 Sequence< OUString > aBoolean(2);
120 aBoolean[0] = "0";
121 aBoolean[1] = "1";
123 aDriverInfo.push_back(DriverPropertyInfo(
124 OUString("CharSet")
125 ,OUString("CharSet of the database.")
126 ,sal_False
127 ,OUString()
128 ,Sequence< OUString >())
130 aDriverInfo.push_back(DriverPropertyInfo(
131 OUString("Extension")
132 ,OUString("Extension of the file format.")
133 ,sal_False
134 ,OUString(".*")
135 ,Sequence< OUString >())
137 aDriverInfo.push_back(DriverPropertyInfo(
138 OUString("ShowDeleted")
139 ,OUString("Display inactive records.")
140 ,sal_False
141 ,OUString("0")
142 ,aBoolean)
144 aDriverInfo.push_back(DriverPropertyInfo(
145 OUString("EnableSQL92Check")
146 ,OUString("Use SQL92 naming constraints.")
147 ,sal_False
148 ,OUString("0")
149 ,aBoolean)
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)
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 >())
165 return Sequence< DriverPropertyInfo >(&(aDriverInfo[0]),aDriverInfo.size());
166 } // if ( acceptsURL(url) )
168 ::connectivity::SharedResources aResources;
169 const OUString sMessage = aResources.getResourceString(STR_URI_SYNTAX_ERROR);
170 ::dbtools::throwGenericSQLException(sMessage ,*this);
171 } // if ( ! acceptsURL(url) )
172 return Sequence< DriverPropertyInfo >();
175 sal_Int32 SAL_CALL OFileDriver::getMajorVersion( ) throw(RuntimeException, std::exception)
177 return 1;
180 sal_Int32 SAL_CALL OFileDriver::getMinorVersion( ) throw(RuntimeException, std::exception)
182 return 0;
186 // XDataDefinitionSupplier
187 Reference< XTablesSupplier > SAL_CALL OFileDriver::getDataDefinitionByConnection( const Reference< ::com::sun::star::sdbc::XConnection >& connection ) throw(::com::sun::star::sdbc::SQLException, RuntimeException, std::exception)
189 ::osl::MutexGuard aGuard( m_aMutex );
190 checkDisposed(ODriver_BASE::rBHelper.bDisposed);
192 Reference< XTablesSupplier > xTab = NULL;
193 Reference< ::com::sun::star::lang::XUnoTunnel> xTunnel(connection,UNO_QUERY);
194 if(xTunnel.is())
196 OConnection* pSearchConnection = reinterpret_cast< OConnection* >( xTunnel->getSomething(OConnection::getUnoTunnelImplementationId()) );
197 OConnection* pConnection = NULL;
198 for (OWeakRefArray::iterator i = m_xConnections.begin(); m_xConnections.end() != i; ++i)
200 if ((OConnection*) Reference< XConnection >::query(i->get().get()).get() == pSearchConnection)
202 pConnection = pSearchConnection;
203 break;
207 if(pConnection)
208 xTab = pConnection->createCatalog();
210 return xTab;
214 Reference< XTablesSupplier > SAL_CALL OFileDriver::getDataDefinitionByURL( const OUString& url, const Sequence< PropertyValue >& info ) throw(::com::sun::star::sdbc::SQLException, RuntimeException, std::exception)
216 if ( ! acceptsURL(url) )
218 ::connectivity::SharedResources aResources;
219 const OUString sMessage = aResources.getResourceString(STR_URI_SYNTAX_ERROR);
220 ::dbtools::throwGenericSQLException(sMessage ,*this);
222 return getDataDefinitionByConnection(connect(url,info));
226 OOperandAttr::OOperandAttr(sal_uInt16 _nPos,const Reference< XPropertySet>& _xColumn)
227 : OOperandRow(_nPos,::comphelper::getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE))))
228 , m_xColumn(_xColumn)
236 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */