1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 "flat/EDriver.hxx"
21 #include "flat/EConnection.hxx"
22 #include <com/sun/star/lang/DisposedException.hpp>
23 #include "connectivity/dbexception.hxx"
24 #include <comphelper/sequence.hxx>
25 #include "resource/common_res.hrc"
26 #include "resource/sharedresources.hxx"
27 #include "comphelper/processfactory.hxx"
30 using namespace connectivity::flat
;
31 using namespace connectivity::file
;
32 using namespace ::com::sun::star::uno
;
33 using namespace ::com::sun::star::beans
;
34 using namespace ::com::sun::star::sdbcx
;
35 using namespace ::com::sun::star::sdbc
;
36 using namespace ::com::sun::star::lang
;
41 OUString
ODriver::getImplementationName_Static( ) throw(RuntimeException
)
43 return OUString("com.sun.star.comp.sdbc.flat.ODriver");
47 OUString SAL_CALL
ODriver::getImplementationName( ) throw(RuntimeException
, std::exception
)
49 return getImplementationName_Static();
53 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> SAL_CALL
connectivity::flat::ODriver_CreateInstance(const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& _rxFactory
) throw( ::com::sun::star::uno::Exception
)
55 return *(new ODriver( comphelper::getComponentContext(_rxFactory
) ));
58 Reference
< XConnection
> SAL_CALL
ODriver::connect( const OUString
& url
, const Sequence
< PropertyValue
>& info
) throw(SQLException
, RuntimeException
, std::exception
)
60 ::osl::MutexGuard
aGuard( m_aMutex
);
61 if (ODriver_BASE::rBHelper
.bDisposed
)
62 throw DisposedException();
64 if ( ! acceptsURL(url
) )
67 OFlatConnection
* pCon
= new OFlatConnection(this);
68 pCon
->construct(url
,info
);
69 Reference
< XConnection
> xCon
= pCon
;
70 m_xConnections
.push_back(WeakReferenceHelper(*pCon
));
75 sal_Bool SAL_CALL
ODriver::acceptsURL( const OUString
& url
)
76 throw(SQLException
, RuntimeException
, std::exception
)
78 return url
.startsWith("sdbc:flat:");
81 Sequence
< DriverPropertyInfo
> SAL_CALL
ODriver::getPropertyInfo( const OUString
& url
, const Sequence
< PropertyValue
>& info
) throw(SQLException
, RuntimeException
, std::exception
)
83 if ( acceptsURL(url
) )
85 ::std::vector
< DriverPropertyInfo
> aDriverInfo
;
87 Sequence
< OUString
> aBoolean(2);
91 aDriverInfo
.push_back(DriverPropertyInfo(
92 OUString("FieldDelimiter")
93 ,OUString("Field separator.")
96 ,Sequence
< OUString
>())
98 aDriverInfo
.push_back(DriverPropertyInfo(
99 OUString("HeaderLine")
100 ,OUString("Text contains headers.")
105 aDriverInfo
.push_back(DriverPropertyInfo(
106 OUString("StringDelimiter")
107 ,OUString("Text separator.")
112 aDriverInfo
.push_back(DriverPropertyInfo(
113 OUString("DecimalDelimiter")
114 ,OUString("Decimal separator.")
119 aDriverInfo
.push_back(DriverPropertyInfo(
120 OUString("ThousandDelimiter")
121 ,OUString("Thousands separator.")
126 return ::comphelper::concatSequences(OFileDriver::getPropertyInfo(url
,info
),
127 Sequence
< DriverPropertyInfo
>(&aDriverInfo
[0],aDriverInfo
.size()));
129 ::connectivity::SharedResources aResources
;
130 const OUString sMessage
= aResources
.getResourceString(STR_URI_SYNTAX_ERROR
);
131 ::dbtools::throwGenericSQLException(sMessage
,*this);
132 return Sequence
< DriverPropertyInfo
>();
137 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */