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_flat.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( )
47 {
48 return rtl::OUString::createFromAscii("com.sun.star.comp.sdbc.flat.ODriver");
49 }
50
51 //------------------------------------------------------------------
getImplementationName()52 ::rtl::OUString SAL_CALL ODriver::getImplementationName( )
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)
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 )
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 {
82 return url.compareTo(::rtl::OUString::createFromAscii("sdbc:flat:"),10) == 0;
83 }
84 // -----------------------------------------------------------------------------
getPropertyInfo(const::rtl::OUString & url,const Sequence<PropertyValue> & info)85 Sequence< DriverPropertyInfo > SAL_CALL ODriver::getPropertyInfo( const ::rtl::OUString& url, const Sequence< PropertyValue >& info )
86 {
87 if ( acceptsURL(url) )
88 {
89 ::std::vector< DriverPropertyInfo > aDriverInfo;
90
91 Sequence< ::rtl::OUString > aBoolean(2);
92 aBoolean[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("0"));
93 aBoolean[1] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("1"));
94
95 aDriverInfo.push_back(DriverPropertyInfo(
96 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FieldDelimiter"))
97 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Field separator."))
98 ,sal_False
99 ,::rtl::OUString()
100 ,Sequence< ::rtl::OUString >())
101 );
102 aDriverInfo.push_back(DriverPropertyInfo(
103 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("HeaderLine"))
104 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Text contains headers."))
105 ,sal_False
106 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("0"))
107 ,aBoolean)
108 );
109 aDriverInfo.push_back(DriverPropertyInfo(
110 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("StringDelimiter"))
111 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Text separator."))
112 ,sal_False
113 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("0"))
114 ,aBoolean)
115 );
116 aDriverInfo.push_back(DriverPropertyInfo(
117 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DecimalDelimiter"))
118 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Decimal separator."))
119 ,sal_False
120 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("0"))
121 ,aBoolean)
122 );
123 aDriverInfo.push_back(DriverPropertyInfo(
124 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ThousandDelimiter"))
125 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Thousands separator."))
126 ,sal_False
127 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("0"))
128 ,aBoolean)
129 );
130 return ::comphelper::concatSequences(OFileDriver::getPropertyInfo(url,info ),
131 Sequence< DriverPropertyInfo >(&aDriverInfo[0],aDriverInfo.size()));
132 }
133 ::connectivity::SharedResources aResources;
134 const ::rtl::OUString sMessage = aResources.getResourceString(STR_URI_SYNTAX_ERROR);
135 ::dbtools::throwGenericSQLException(sMessage ,*this);
136 return Sequence< DriverPropertyInfo >();
137 }
138 // -----------------------------------------------------------------------------
139