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 .
22 #include "dbastrings.hrc"
24 #include "connectivity/dbexception.hxx"
25 #include "connectivity/dbtools.hxx"
27 #include <com/sun/star/lang/WrappedTargetException.hpp>
28 #include <com/sun/star/lang/DisposedException.hpp>
29 #include <com/sun/star/sdbc/XRow.hpp>
31 #include <cppuhelper/exc_hlp.hxx>
32 #include <tools/diagnose_ex.h>
33 #include <unotools/sharedunocomponent.hxx>
38 /** === begin UNO using === **/
39 using namespace ::com::sun::star::uno
;
40 using ::com::sun::star::sdbc::XDatabaseMetaData
;
41 using ::com::sun::star::sdbc::SQLException
;
42 using ::com::sun::star::sdbc::XConnection
;
43 using ::com::sun::star::lang::WrappedTargetException
;
44 using ::com::sun::star::lang::XMultiServiceFactory
;
45 using ::com::sun::star::sdbc::XResultSet
;
46 using ::com::sun::star::sdbc::XStatement
;
47 using ::com::sun::star::lang::DisposedException
;
48 using ::com::sun::star::sdbc::XRow
;
49 /** === end UNO using === **/
51 ::rtl::OUString
lcl_getServiceNameForSetting(const Reference
< ::com::sun::star::sdbc::XConnection
>& _xConnection
,const ::rtl::OUString
& i_sSetting
)
53 ::rtl::OUString sSupportService
;
55 if ( dbtools::getDataSourceSetting(_xConnection
,i_sSetting
,aValue
) )
57 aValue
>>= sSupportService
;
59 return sSupportService
;
61 //====================================================================
63 //====================================================================
64 View::View( const Reference
< XConnection
>& _rxConnection
, sal_Bool _bCaseSensitive
,
65 const ::rtl::OUString
& _rCatalogName
,const ::rtl::OUString
& _rSchemaName
, const ::rtl::OUString
& _rName
)
66 :View_Base( _bCaseSensitive
, _rName
, _rxConnection
->getMetaData(), 0, ::rtl::OUString(), _rSchemaName
, _rCatalogName
)
68 m_nCommandHandle
= getProperty(PROPERTY_COMMAND
).Handle
;
71 Reference
<XMultiServiceFactory
> xFac(_rxConnection
,UNO_QUERY_THROW
);
72 static const ::rtl::OUString
s_sViewAccess(RTL_CONSTASCII_USTRINGPARAM("ViewAccessServiceName"));
73 m_xViewAccess
.set(xFac
->createInstance(lcl_getServiceNameForSetting(_rxConnection
,s_sViewAccess
)),UNO_QUERY
);
75 catch(const Exception
& )
77 DBG_UNHANDLED_EXCEPTION();
85 IMPLEMENT_FORWARD_REFCOUNT( View
, View_Base
)
86 IMPLEMENT_GET_IMPLEMENTATION_ID( View
)
88 Any SAL_CALL
View::queryInterface( const Type
& _rType
) throw(RuntimeException
)
90 if(_rType
== getCppuType( (Reference
<XAlterView
>*)0) && !m_xViewAccess
.is() )
92 Any aReturn
= View_Base::queryInterface( _rType
);
93 if ( !aReturn
.hasValue() )
94 aReturn
= View_IBASE::queryInterface( _rType
);
98 Sequence
< Type
> SAL_CALL
View::getTypes( ) throw(RuntimeException
)
100 Type aAlterType
= getCppuType( (Reference
<XAlterView
>*)0);
102 Sequence
< Type
> aTypes( ::comphelper::concatSequences(View_Base::getTypes(),View_IBASE::getTypes()) );
103 ::std::vector
<Type
> aOwnTypes
;
104 aOwnTypes
.reserve(aTypes
.getLength());
106 const Type
* pIter
= aTypes
.getConstArray();
107 const Type
* pEnd
= pIter
+ aTypes
.getLength();
108 for(;pIter
!= pEnd
;++pIter
)
110 if( (*pIter
!= aAlterType
|| m_xViewAccess
.is()) )
111 aOwnTypes
.push_back(*pIter
);
114 Type
* pTypes
= aOwnTypes
.empty() ? 0 : &aOwnTypes
[0];
115 return Sequence
< Type
>(pTypes
, aOwnTypes
.size());
118 void SAL_CALL
View::alterCommand( const ::rtl::OUString
& _rNewCommand
) throw (SQLException
, RuntimeException
)
120 OSL_ENSURE(m_xViewAccess
.is(),"Illegal call to AlterView!");
121 m_xViewAccess
->alterCommand(this,_rNewCommand
);
124 void SAL_CALL
View::getFastPropertyValue( Any
& _rValue
, sal_Int32 _nHandle
) const
126 if ( _nHandle
== m_nCommandHandle
&& m_xViewAccess
.is() )
128 // retrieve the very current command, don't rely on the base classes cached value
129 // (which we initialized empty, anyway)
130 _rValue
<<= m_xViewAccess
->getCommand(const_cast<View
*>(this));
134 View_Base::getFastPropertyValue( _rValue
, _nHandle
);
137 } // namespace dbaccess
138 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */