xref: /AOO41X/main/connectivity/source/drivers/flat/EDriver.cxx (revision 9b5730f6ddef7eb82608ca4d31dc0d7678e652cf)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_connectivity.hxx"
26 #include "flat/EDriver.hxx"
27 #include "flat/EConnection.hxx"
28 #include <com/sun/star/lang/DisposedException.hpp>
29 #include "connectivity/dbexception.hxx"
30 #include <comphelper/sequence.hxx>
31 #include "resource/common_res.hrc"
32 #include "resource/sharedresources.hxx"
33 
34 
35 using namespace connectivity::flat;
36 using namespace connectivity::file;
37 using namespace ::com::sun::star::uno;
38 using namespace ::com::sun::star::beans;
39 using namespace ::com::sun::star::sdbcx;
40 using namespace ::com::sun::star::sdbc;
41 using namespace ::com::sun::star::lang;
42 
43 
44 // static ServiceInfo
45 //------------------------------------------------------------------------------
getImplementationName_Static()46 rtl::OUString ODriver::getImplementationName_Static(  ) throw(RuntimeException)
47 {
48     return rtl::OUString::createFromAscii("com.sun.star.comp.sdbc.flat.ODriver");
49 }
50 
51 //------------------------------------------------------------------
getImplementationName()52 ::rtl::OUString SAL_CALL ODriver::getImplementationName(  ) throw(RuntimeException)
53 {
54     return getImplementationName_Static();
55 }
56 
57 //------------------------------------------------------------------
ODriver_CreateInstance(const::com::sun::star::uno::Reference<::com::sun::star::lang::XMultiServiceFactory> & _rxFactory)58 ::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 )
59 {
60     return *(new ODriver(_rxFactory));
61 }
62 // --------------------------------------------------------------------------------
connect(const::rtl::OUString & url,const Sequence<PropertyValue> & info)63 Reference< XConnection > SAL_CALL ODriver::connect( const ::rtl::OUString& url, const Sequence< PropertyValue >& info ) throw(SQLException, RuntimeException)
64 {
65     ::osl::MutexGuard aGuard( m_aMutex );
66     if (ODriver_BASE::rBHelper.bDisposed)
67        throw DisposedException();
68 
69     if ( ! acceptsURL(url) )
70         return NULL;
71 
72     OFlatConnection* pCon = new OFlatConnection(this);
73     pCon->construct(url,info);
74         Reference< XConnection > xCon = pCon;
75         m_xConnections.push_back(WeakReferenceHelper(*pCon));
76 
77     return xCon;
78 }
79 // --------------------------------------------------------------------------------
acceptsURL(const::rtl::OUString & url)80 sal_Bool SAL_CALL ODriver::acceptsURL( const ::rtl::OUString& url )
81                 throw(SQLException, RuntimeException)
82 {
83     return url.compareTo(::rtl::OUString::createFromAscii("sdbc:flat:"),10) == 0;
84 }
85 // -----------------------------------------------------------------------------
getPropertyInfo(const::rtl::OUString & url,const Sequence<PropertyValue> & info)86 Sequence< DriverPropertyInfo > SAL_CALL ODriver::getPropertyInfo( const ::rtl::OUString& url, const Sequence< PropertyValue >& info ) throw(SQLException, RuntimeException)
87 {
88     if ( acceptsURL(url) )
89     {
90         ::std::vector< DriverPropertyInfo > aDriverInfo;
91 
92         Sequence< ::rtl::OUString > aBoolean(2);
93         aBoolean[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("0"));
94         aBoolean[1] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("1"));
95 
96         aDriverInfo.push_back(DriverPropertyInfo(
97                 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FieldDelimiter"))
98                 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Field separator."))
99                 ,sal_False
100                 ,::rtl::OUString()
101                 ,Sequence< ::rtl::OUString >())
102                 );
103         aDriverInfo.push_back(DriverPropertyInfo(
104                 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("HeaderLine"))
105                 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Text contains headers."))
106                 ,sal_False
107                 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("0"))
108                 ,aBoolean)
109                 );
110         aDriverInfo.push_back(DriverPropertyInfo(
111                 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("StringDelimiter"))
112                 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Text separator."))
113                 ,sal_False
114                 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("0"))
115                 ,aBoolean)
116                 );
117         aDriverInfo.push_back(DriverPropertyInfo(
118                 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DecimalDelimiter"))
119                 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Decimal separator."))
120                 ,sal_False
121                 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("0"))
122                 ,aBoolean)
123                 );
124         aDriverInfo.push_back(DriverPropertyInfo(
125                 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ThousandDelimiter"))
126                 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Thousands separator."))
127                 ,sal_False
128                 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("0"))
129                 ,aBoolean)
130                 );
131         return ::comphelper::concatSequences(OFileDriver::getPropertyInfo(url,info ),
132                                              Sequence< DriverPropertyInfo >(&aDriverInfo[0],aDriverInfo.size()));
133     }
134     ::connectivity::SharedResources aResources;
135     const ::rtl::OUString sMessage = aResources.getResourceString(STR_URI_SYNTAX_ERROR);
136     ::dbtools::throwGenericSQLException(sMessage ,*this);
137     return Sequence< DriverPropertyInfo >();
138 }
139 // -----------------------------------------------------------------------------
140 
141 
142