1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: FDriver.cxx,v $
10 * $Revision: 1.14.56.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_connectivity.hxx"
33 #include "file/FDriver.hxx"
34 #include "file/FConnection.hxx"
35 #include "file/fcode.hxx"
36 #include <com/sun/star/lang/DisposedException.hpp>
37 #include <comphelper/types.hxx>
38 #include "connectivity/dbexception.hxx"
39 #include "resource/common_res.hrc"
40 #include "resource/sharedresources.hxx"
41 #include <rtl/logfile.hxx>
44 using namespace connectivity::file
;
45 using namespace com::sun::star::uno
;
46 using namespace com::sun::star::lang
;
47 using namespace com::sun::star::beans
;
48 using namespace com::sun::star::sdbc
;
49 using namespace com::sun::star::sdbcx
;
50 using namespace com::sun::star::container
;
51 // --------------------------------------------------------------------------------
52 OFileDriver::OFileDriver(const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& _rxFactory
)
53 : ODriver_BASE(m_aMutex
)
54 ,m_xFactory(_rxFactory
)
56 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "file", "Ocke.Janssen@sun.com", "OFileDriver::OFileDriver" );
58 // --------------------------------------------------------------------------------
59 void OFileDriver::disposing()
61 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "file", "Ocke.Janssen@sun.com", "OFileDriver::disposing" );
62 ::osl::MutexGuard
aGuard(m_aMutex
);
65 for (OWeakRefArray::iterator i
= m_xConnections
.begin(); m_xConnections
.end() != i
; ++i
)
67 Reference
< XComponent
> xComp(i
->get(), UNO_QUERY
);
71 m_xConnections
.clear();
73 ODriver_BASE::disposing();
77 //------------------------------------------------------------------------------
78 rtl::OUString
OFileDriver::getImplementationName_Static( ) throw(RuntimeException
)
80 return rtl::OUString::createFromAscii("com.sun.star.sdbc.driver.file.Driver");
82 //------------------------------------------------------------------------------
83 Sequence
< ::rtl::OUString
> OFileDriver::getSupportedServiceNames_Static( ) throw (RuntimeException
)
85 Sequence
< ::rtl::OUString
> aSNS( 2 );
86 aSNS
[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbc.Driver");
87 aSNS
[1] = ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.Driver");
91 //------------------------------------------------------------------
92 ::rtl::OUString SAL_CALL
OFileDriver::getImplementationName( ) throw(RuntimeException
)
94 return getImplementationName_Static();
97 //------------------------------------------------------------------
98 sal_Bool SAL_CALL
OFileDriver::supportsService( const ::rtl::OUString
& _rServiceName
) throw(RuntimeException
)
100 Sequence
< ::rtl::OUString
> aSupported(getSupportedServiceNames());
101 const ::rtl::OUString
* pSupported
= aSupported
.getConstArray();
102 const ::rtl::OUString
* pEnd
= pSupported
+ aSupported
.getLength();
103 for (;pSupported
!= pEnd
&& !pSupported
->equals(_rServiceName
); ++pSupported
)
106 return pSupported
!= pEnd
;
109 //------------------------------------------------------------------
110 Sequence
< ::rtl::OUString
> SAL_CALL
OFileDriver::getSupportedServiceNames( ) throw(RuntimeException
)
112 return getSupportedServiceNames_Static();
115 // --------------------------------------------------------------------------------
116 Reference
< XConnection
> SAL_CALL
OFileDriver::connect( const ::rtl::OUString
& url
, const Sequence
< PropertyValue
>& info
) throw(SQLException
, RuntimeException
)
118 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "file", "Ocke.Janssen@sun.com", "OFileDriver::connect" );
119 ::osl::MutexGuard
aGuard( m_aMutex
);
120 checkDisposed(ODriver_BASE::rBHelper
.bDisposed
);
122 OConnection
* pCon
= new OConnection(this);
123 Reference
< XConnection
> xCon
= pCon
;
124 pCon
->construct(url
,info
);
125 m_xConnections
.push_back(WeakReferenceHelper(*pCon
));
129 // --------------------------------------------------------------------------------
130 sal_Bool SAL_CALL
OFileDriver::acceptsURL( const ::rtl::OUString
& url
)
131 throw(SQLException
, RuntimeException
)
133 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "file", "Ocke.Janssen@sun.com", "OFileDriver::acceptsURL" );
134 return (!url
.compareTo(::rtl::OUString::createFromAscii("sdbc:file:"),10));
136 // --------------------------------------------------------------------------------
137 Sequence
< DriverPropertyInfo
> SAL_CALL
OFileDriver::getPropertyInfo( const ::rtl::OUString
& url
, const Sequence
< PropertyValue
>& /*info*/ ) throw(SQLException
, RuntimeException
)
139 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "file", "Ocke.Janssen@sun.com", "OFileDriver::getPropertyInfo" );
140 if ( acceptsURL(url
) )
142 ::std::vector
< DriverPropertyInfo
> aDriverInfo
;
144 Sequence
< ::rtl::OUString
> aBoolean(2);
145 aBoolean
[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("0"));
146 aBoolean
[1] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("1"));
148 aDriverInfo
.push_back(DriverPropertyInfo(
149 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CharSet"))
150 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CharSet of the database."))
153 ,Sequence
< ::rtl::OUString
>())
155 aDriverInfo
.push_back(DriverPropertyInfo(
156 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Extension"))
157 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Extension of the file format."))
159 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".*"))
160 ,Sequence
< ::rtl::OUString
>())
162 aDriverInfo
.push_back(DriverPropertyInfo(
163 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ShowDeleted"))
164 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Display inactive records."))
166 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("0"))
169 aDriverInfo
.push_back(DriverPropertyInfo(
170 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("EnableSQL92Check"))
171 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Use SQL92 naming constraints."))
173 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("0"))
176 aDriverInfo
.push_back(DriverPropertyInfo(
177 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("UseRelativePath"))
178 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Handle the connection url as relative path."))
180 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("0"))
183 aDriverInfo
.push_back(DriverPropertyInfo(
184 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("URL"))
185 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("The URL of the database document which is used to create an absolute path."))
188 ,Sequence
< ::rtl::OUString
>())
190 return Sequence
< DriverPropertyInfo
>(&(aDriverInfo
[0]),aDriverInfo
.size());
191 } // if ( acceptsURL(url) )
193 ::connectivity::SharedResources aResources
;
194 const ::rtl::OUString sMessage
= aResources
.getResourceString(STR_URI_SYNTAX_ERROR
);
195 ::dbtools::throwGenericSQLException(sMessage
,*this);
196 } // if ( ! acceptsURL(url) )
197 return Sequence
< DriverPropertyInfo
>();
199 // --------------------------------------------------------------------------------
200 sal_Int32 SAL_CALL
OFileDriver::getMajorVersion( ) throw(RuntimeException
)
202 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "file", "Ocke.Janssen@sun.com", "OFileDriver::getMajorVersion" );
205 // --------------------------------------------------------------------------------
206 sal_Int32 SAL_CALL
OFileDriver::getMinorVersion( ) throw(RuntimeException
)
208 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "file", "Ocke.Janssen@sun.com", "OFileDriver::getMinorVersion" );
211 // --------------------------------------------------------------------------------
212 // --------------------------------------------------------------------------------
213 // XDataDefinitionSupplier
214 Reference
< XTablesSupplier
> SAL_CALL
OFileDriver::getDataDefinitionByConnection( const Reference
< ::com::sun::star::sdbc::XConnection
>& connection
) throw(::com::sun::star::sdbc::SQLException
, RuntimeException
)
216 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "file", "Ocke.Janssen@sun.com", "OFileDriver::getDataDefinitionByConnection" );
217 ::osl::MutexGuard
aGuard( m_aMutex
);
218 checkDisposed(ODriver_BASE::rBHelper
.bDisposed
);
220 Reference
< XTablesSupplier
> xTab
= NULL
;
221 Reference
< ::com::sun::star::lang::XUnoTunnel
> xTunnel(connection
,UNO_QUERY
);
224 OConnection
* pSearchConnection
= reinterpret_cast< OConnection
* >( xTunnel
->getSomething(OConnection::getUnoTunnelImplementationId()) );
225 OConnection
* pConnection
= NULL
;
226 for (OWeakRefArray::iterator i
= m_xConnections
.begin(); m_xConnections
.end() != i
; ++i
)
228 if ((OConnection
*) Reference
< XConnection
>::query(i
->get().get()).get() == pSearchConnection
)
230 pConnection
= pSearchConnection
;
236 xTab
= pConnection
->createCatalog();
241 // --------------------------------------------------------------------------------
242 Reference
< XTablesSupplier
> SAL_CALL
OFileDriver::getDataDefinitionByURL( const ::rtl::OUString
& url
, const Sequence
< PropertyValue
>& info
) throw(::com::sun::star::sdbc::SQLException
, RuntimeException
)
244 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "file", "Ocke.Janssen@sun.com", "OFileDriver::getDataDefinitionByURL" );
245 if ( ! acceptsURL(url
) )
247 ::connectivity::SharedResources aResources
;
248 const ::rtl::OUString sMessage
= aResources
.getResourceString(STR_URI_SYNTAX_ERROR
);
249 ::dbtools::throwGenericSQLException(sMessage
,*this);
251 return getDataDefinitionByConnection(connect(url
,info
));
253 // -----------------------------------------------------------------------------
254 void OOperandParam::describe(const Reference
< XPropertySet
>& rColumn
, ::vos::ORef
<connectivity::OSQLColumns
> rParameterColumns
)
256 // den alten namen beibehalten
258 OSL_ENSURE(getRowPos() < rParameterColumns
->get().size(),"Invalid index for orderkey values!");
260 Reference
< XPropertySet
> xColumn
= (rParameterColumns
->get())[getRowPos()];
264 xColumn
->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME
),rColumn
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME
)));
265 xColumn
->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DEFAULTVALUE
),rColumn
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DEFAULTVALUE
)));
266 xColumn
->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PRECISION
),rColumn
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PRECISION
)));
267 xColumn
->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE
),rColumn
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE
)));
268 xColumn
->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE
),rColumn
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE
)));
269 xColumn
->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISNULLABLE
),rColumn
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISNULLABLE
)));
270 xColumn
->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISAUTOINCREMENT
),rColumn
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISAUTOINCREMENT
)));
272 catch(const Exception
&)
276 m_eDBType
= ::comphelper::getINT32(rColumn
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE
)));
278 // -----------------------------------------------------------------------------
279 OOperandAttr::OOperandAttr(sal_uInt16 _nPos
,const Reference
< XPropertySet
>& _xColumn
)
280 : OOperandRow(_nPos
,::comphelper::getINT32(_xColumn
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE
))))
281 , m_xColumn(_xColumn
)
284 // -----------------------------------------------------------------------------