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 "calc/CDriver.hxx"
27 #include "calc/CConnection.hxx"
28 #include <com/sun/star/lang/DisposedException.hpp>
29 #include "connectivity/dbexception.hxx"
30 #include "resource/sharedresources.hxx"
31 #include "resource/calc_res.hrc"
32
33 using namespace connectivity::calc;
34 using namespace connectivity::file;
35 using namespace ::com::sun::star::uno;
36 using namespace ::com::sun::star::beans;
37 using namespace ::com::sun::star::sdbcx;
38 using namespace ::com::sun::star::sdbc;
39 using namespace ::com::sun::star::lang;
40
41
42 //------------------------------------------------------------------------------
43 // static ServiceInfo
44
getImplementationName_Static()45 rtl::OUString ODriver::getImplementationName_Static( ) throw(RuntimeException)
46 {
47 return rtl::OUString::createFromAscii("com.sun.star.comp.sdbc.calc.ODriver");
48 }
49
getImplementationName()50 ::rtl::OUString SAL_CALL ODriver::getImplementationName( ) throw(RuntimeException)
51 {
52 return getImplementationName_Static();
53 }
54
55 // service names from file::OFileDriver
56
57 //------------------------------------------------------------------
58
59 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL
ODriver_CreateInstance(const::com::sun::star::uno::Reference<::com::sun::star::lang::XMultiServiceFactory> & _rxFactory)60 connectivity::calc::ODriver_CreateInstance(const ::com::sun::star::uno::Reference<
61 ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory) throw( ::com::sun::star::uno::Exception )
62 {
63 return *(new ODriver(_rxFactory));
64 }
65
connect(const::rtl::OUString & url,const Sequence<PropertyValue> & info)66 Reference< XConnection > SAL_CALL ODriver::connect( const ::rtl::OUString& url,
67 const Sequence< PropertyValue >& info ) throw(SQLException, RuntimeException)
68 {
69 ::osl::MutexGuard aGuard( m_aMutex );
70 if (ODriver_BASE::rBHelper.bDisposed)
71 throw DisposedException();
72
73 if ( ! acceptsURL(url) )
74 return NULL;
75
76 OCalcConnection* pCon = new OCalcConnection(this);
77 pCon->construct(url,info);
78 Reference< XConnection > xCon = pCon;
79 m_xConnections.push_back(WeakReferenceHelper(*pCon));
80
81 return xCon;
82 }
83
acceptsURL(const::rtl::OUString & url)84 sal_Bool SAL_CALL ODriver::acceptsURL( const ::rtl::OUString& url )
85 throw(SQLException, RuntimeException)
86 {
87 return url.compareTo(::rtl::OUString::createFromAscii("sdbc:calc:"),10) == 0;
88 }
89
getPropertyInfo(const::rtl::OUString & url,const Sequence<PropertyValue> &)90 Sequence< DriverPropertyInfo > SAL_CALL ODriver::getPropertyInfo( const ::rtl::OUString& url, const Sequence< PropertyValue >& /*info*/ ) throw(SQLException, RuntimeException)
91 {
92 if ( !acceptsURL(url) )
93 {
94 SharedResources aResources;
95 const ::rtl::OUString sMessage = aResources.getResourceString(STR_URI_SYNTAX_ERROR);
96 ::dbtools::throwGenericSQLException(sMessage ,*this);
97 }
98 return Sequence< DriverPropertyInfo >();
99 }
100 // -----------------------------------------------------------------------------
101
102