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 .
21 #include "dbastrings.hrc"
23 #include "connectivity/dbexception.hxx"
24 #include "connectivity/dbtools.hxx"
26 #include <com/sun/star/lang/WrappedTargetException.hpp>
27 #include <com/sun/star/lang/DisposedException.hpp>
28 #include <com/sun/star/lang/XMultiServiceFactory.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 using namespace ::com::sun::star::uno
;
39 using ::com::sun::star::sdbc::XDatabaseMetaData
;
40 using ::com::sun::star::sdbc::SQLException
;
41 using ::com::sun::star::sdbc::XConnection
;
42 using ::com::sun::star::lang::WrappedTargetException
;
43 using ::com::sun::star::lang::XMultiServiceFactory
;
44 using ::com::sun::star::sdbc::XResultSet
;
45 using ::com::sun::star::sdbc::XStatement
;
46 using ::com::sun::star::lang::DisposedException
;
47 using ::com::sun::star::sdbc::XRow
;
49 OUString
lcl_getServiceNameForSetting(const Reference
< ::com::sun::star::sdbc::XConnection
>& _xConnection
,const OUString
& i_sSetting
)
51 OUString sSupportService
;
53 if ( dbtools::getDataSourceSetting(_xConnection
,i_sSetting
,aValue
) )
55 aValue
>>= sSupportService
;
57 return sSupportService
;
60 View::View( const Reference
< XConnection
>& _rxConnection
, bool _bCaseSensitive
,
61 const OUString
& _rCatalogName
,const OUString
& _rSchemaName
, const OUString
& _rName
)
62 :View_Base( _bCaseSensitive
, _rName
, _rxConnection
->getMetaData(), 0, OUString(), _rSchemaName
, _rCatalogName
)
64 m_nCommandHandle
= getProperty(PROPERTY_COMMAND
).Handle
;
67 Reference
<XMultiServiceFactory
> xFac(_rxConnection
,UNO_QUERY_THROW
);
68 static const char s_sViewAccess
[] = "ViewAccessServiceName";
69 m_xViewAccess
.set(xFac
->createInstance(lcl_getServiceNameForSetting(_rxConnection
,s_sViewAccess
)),UNO_QUERY
);
71 catch(const Exception
& )
73 DBG_UNHANDLED_EXCEPTION();
81 IMPLEMENT_FORWARD_REFCOUNT( View
, View_Base
)
82 IMPLEMENT_GET_IMPLEMENTATION_ID( View
)
84 Any SAL_CALL
View::queryInterface( const Type
& _rType
) throw(RuntimeException
, std::exception
)
86 if(_rType
== cppu::UnoType
<XAlterView
>::get()&& !m_xViewAccess
.is() )
88 Any aReturn
= View_Base::queryInterface( _rType
);
89 if ( !aReturn
.hasValue() )
90 aReturn
= View_IBASE::queryInterface( _rType
);
94 Sequence
< Type
> SAL_CALL
View::getTypes( ) throw(RuntimeException
, std::exception
)
96 Type aAlterType
= cppu::UnoType
<XAlterView
>::get();
98 Sequence
< Type
> aTypes( ::comphelper::concatSequences(View_Base::getTypes(),View_IBASE::getTypes()) );
99 ::std::vector
<Type
> aOwnTypes
;
100 aOwnTypes
.reserve(aTypes
.getLength());
102 const Type
* pIter
= aTypes
.getConstArray();
103 const Type
* pEnd
= pIter
+ aTypes
.getLength();
104 for(;pIter
!= pEnd
;++pIter
)
106 if( (*pIter
!= aAlterType
|| m_xViewAccess
.is()) )
107 aOwnTypes
.push_back(*pIter
);
110 return Sequence
< Type
>(aOwnTypes
.data(), aOwnTypes
.size());
113 void SAL_CALL
View::alterCommand( const OUString
& _rNewCommand
) throw (SQLException
, RuntimeException
, std::exception
)
115 OSL_ENSURE(m_xViewAccess
.is(),"Illegal call to AlterView!");
116 m_xViewAccess
->alterCommand(this,_rNewCommand
);
119 void SAL_CALL
View::getFastPropertyValue( Any
& _rValue
, sal_Int32 _nHandle
) const
121 if ( _nHandle
== m_nCommandHandle
&& m_xViewAccess
.is() )
123 // retrieve the very current command, don't rely on the base classes cached value
124 // (which we initialized empty, anyway)
125 _rValue
<<= m_xViewAccess
->getCommand(const_cast<View
*>(this));
129 View_Base::getFastPropertyValue( _rValue
, _nHandle
);
132 } // namespace dbaccess
134 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */