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: EDriver.cxx,v $
10 * $Revision: 1.10.56.1 $
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 "flat/EDriver.hxx"
34 #include "flat/EConnection.hxx"
35 #include <com/sun/star/lang/DisposedException.hpp>
36 #include "connectivity/dbexception.hxx"
37 #include <comphelper/sequence.hxx>
38 #include "resource/common_res.hrc"
39 #include "resource/sharedresources.hxx"
42 using namespace connectivity::flat
;
43 using namespace connectivity::file
;
44 using namespace ::com::sun::star::uno
;
45 using namespace ::com::sun::star::beans
;
46 using namespace ::com::sun::star::sdbcx
;
47 using namespace ::com::sun::star::sdbc
;
48 using namespace ::com::sun::star::lang
;
52 //------------------------------------------------------------------------------
53 rtl::OUString
ODriver::getImplementationName_Static( ) throw(RuntimeException
)
55 return rtl::OUString::createFromAscii("com.sun.star.comp.sdbc.flat.ODriver");
58 //------------------------------------------------------------------
59 ::rtl::OUString SAL_CALL
ODriver::getImplementationName( ) throw(RuntimeException
)
61 return getImplementationName_Static();
64 //------------------------------------------------------------------
65 ::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
)
67 return *(new ODriver(_rxFactory
));
69 // --------------------------------------------------------------------------------
70 Reference
< XConnection
> SAL_CALL
ODriver::connect( const ::rtl::OUString
& url
, const Sequence
< PropertyValue
>& info
) throw(SQLException
, RuntimeException
)
72 ::osl::MutexGuard
aGuard( m_aMutex
);
73 if (ODriver_BASE::rBHelper
.bDisposed
)
74 throw DisposedException();
76 if ( ! acceptsURL(url
) )
79 OFlatConnection
* pCon
= new OFlatConnection(this);
80 pCon
->construct(url
,info
);
81 Reference
< XConnection
> xCon
= pCon
;
82 m_xConnections
.push_back(WeakReferenceHelper(*pCon
));
86 // --------------------------------------------------------------------------------
87 sal_Bool SAL_CALL
ODriver::acceptsURL( const ::rtl::OUString
& url
)
88 throw(SQLException
, RuntimeException
)
90 return url
.compareTo(::rtl::OUString::createFromAscii("sdbc:flat:"),10) == 0;
92 // -----------------------------------------------------------------------------
93 Sequence
< DriverPropertyInfo
> SAL_CALL
ODriver::getPropertyInfo( const ::rtl::OUString
& url
, const Sequence
< PropertyValue
>& info
) throw(SQLException
, RuntimeException
)
95 if ( acceptsURL(url
) )
97 ::std::vector
< DriverPropertyInfo
> aDriverInfo
;
99 Sequence
< ::rtl::OUString
> aBoolean(2);
100 aBoolean
[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("0"));
101 aBoolean
[1] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("1"));
103 aDriverInfo
.push_back(DriverPropertyInfo(
104 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FieldDelimiter"))
105 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Field separator."))
108 ,Sequence
< ::rtl::OUString
>())
110 aDriverInfo
.push_back(DriverPropertyInfo(
111 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("HeaderLine"))
112 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Text contains headers."))
114 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("0"))
117 aDriverInfo
.push_back(DriverPropertyInfo(
118 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("StringDelimiter"))
119 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Text separator."))
121 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("0"))
124 aDriverInfo
.push_back(DriverPropertyInfo(
125 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DecimalDelimiter"))
126 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Decimal separator."))
128 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("0"))
131 aDriverInfo
.push_back(DriverPropertyInfo(
132 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ThousandDelimiter"))
133 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Thousands separator."))
135 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("0"))
138 return ::comphelper::concatSequences(OFileDriver::getPropertyInfo(url
,info
),
139 Sequence
< DriverPropertyInfo
>(&aDriverInfo
[0],aDriverInfo
.size()));
141 ::connectivity::SharedResources aResources
;
142 const ::rtl::OUString sMessage
= aResources
.getResourceString(STR_URI_SYNTAX_ERROR
);
143 ::dbtools::throwGenericSQLException(sMessage
,*this);
144 return Sequence
< DriverPropertyInfo
>();
146 // -----------------------------------------------------------------------------