xref: /aoo42x/main/dbaccess/source/core/api/View.cxx (revision 96de5490)
1*96de5490SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*96de5490SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*96de5490SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*96de5490SAndrew Rist  * distributed with this work for additional information
6*96de5490SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*96de5490SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*96de5490SAndrew Rist  * "License"); you may not use this file except in compliance
9*96de5490SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*96de5490SAndrew Rist  *
11*96de5490SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*96de5490SAndrew Rist  *
13*96de5490SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*96de5490SAndrew Rist  * software distributed under the License is distributed on an
15*96de5490SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*96de5490SAndrew Rist  * KIND, either express or implied.  See the License for the
17*96de5490SAndrew Rist  * specific language governing permissions and limitations
18*96de5490SAndrew Rist  * under the License.
19*96de5490SAndrew Rist  *
20*96de5490SAndrew Rist  *************************************************************/
21*96de5490SAndrew Rist 
22*96de5490SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_dbaccess.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "View.hxx"
28cdf0e10cSrcweir #include "dbastrings.hrc"
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #include "connectivity/dbexception.hxx"
31cdf0e10cSrcweir #include "connectivity/dbtools.hxx"
32cdf0e10cSrcweir 
33cdf0e10cSrcweir /** === begin UNO includes === **/
34cdf0e10cSrcweir #include <com/sun/star/lang/WrappedTargetException.hpp>
35cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp>
36cdf0e10cSrcweir #include <com/sun/star/sdbc/XRow.hpp>
37cdf0e10cSrcweir /** === end UNO includes === **/
38cdf0e10cSrcweir 
39cdf0e10cSrcweir #include <cppuhelper/exc_hlp.hxx>
40cdf0e10cSrcweir #include <tools/diagnose_ex.h>
41cdf0e10cSrcweir #include <unotools/sharedunocomponent.hxx>
42cdf0e10cSrcweir 
43cdf0e10cSrcweir //........................................................................
44cdf0e10cSrcweir namespace dbaccess
45cdf0e10cSrcweir {
46cdf0e10cSrcweir //........................................................................
47cdf0e10cSrcweir 
48cdf0e10cSrcweir 	/** === begin UNO using === **/
49cdf0e10cSrcweir 	using namespace ::com::sun::star::uno;
50cdf0e10cSrcweir     using ::com::sun::star::sdbc::XDatabaseMetaData;
51cdf0e10cSrcweir     using ::com::sun::star::sdbc::SQLException;
52cdf0e10cSrcweir     using ::com::sun::star::sdbc::XConnection;
53cdf0e10cSrcweir     using ::com::sun::star::lang::WrappedTargetException;
54cdf0e10cSrcweir     using ::com::sun::star::lang::XMultiServiceFactory;
55cdf0e10cSrcweir     using ::com::sun::star::sdbc::XResultSet;
56cdf0e10cSrcweir     using ::com::sun::star::sdbc::XStatement;
57cdf0e10cSrcweir     using ::com::sun::star::lang::DisposedException;
58cdf0e10cSrcweir     using ::com::sun::star::sdbc::XRow;
59cdf0e10cSrcweir 	/** === end UNO using === **/
60cdf0e10cSrcweir 
lcl_getServiceNameForSetting(const Reference<::com::sun::star::sdbc::XConnection> & _xConnection,const::rtl::OUString & i_sSetting)61cdf0e10cSrcweir     ::rtl::OUString lcl_getServiceNameForSetting(const Reference< ::com::sun::star::sdbc::XConnection >& _xConnection,const ::rtl::OUString& i_sSetting)
62cdf0e10cSrcweir     {
63cdf0e10cSrcweir         ::rtl::OUString sSupportService;
64cdf0e10cSrcweir         Any aValue;
65cdf0e10cSrcweir         if ( dbtools::getDataSourceSetting(_xConnection,i_sSetting,aValue) )
66cdf0e10cSrcweir         {
67cdf0e10cSrcweir             aValue >>= sSupportService;
68cdf0e10cSrcweir         }
69cdf0e10cSrcweir         return sSupportService;
70cdf0e10cSrcweir     }
71cdf0e10cSrcweir 	//====================================================================
72cdf0e10cSrcweir 	//= View
73cdf0e10cSrcweir 	//====================================================================
74cdf0e10cSrcweir 	//--------------------------------------------------------------------
View(const Reference<XConnection> & _rxConnection,sal_Bool _bCaseSensitive,const::rtl::OUString & _rCatalogName,const::rtl::OUString & _rSchemaName,const::rtl::OUString & _rName)75cdf0e10cSrcweir     View::View( const Reference< XConnection >& _rxConnection, sal_Bool _bCaseSensitive,
76cdf0e10cSrcweir         const ::rtl::OUString& _rCatalogName,const ::rtl::OUString& _rSchemaName, const ::rtl::OUString& _rName )
77cdf0e10cSrcweir         :View_Base( _bCaseSensitive, _rName, _rxConnection->getMetaData(), 0, ::rtl::OUString(), _rSchemaName, _rCatalogName )
78cdf0e10cSrcweir     {
79cdf0e10cSrcweir         m_nCommandHandle = getProperty(PROPERTY_COMMAND).Handle;
80cdf0e10cSrcweir         try
81cdf0e10cSrcweir         {
82cdf0e10cSrcweir             Reference<XMultiServiceFactory> xFac(_rxConnection,UNO_QUERY_THROW);
83cdf0e10cSrcweir             static const ::rtl::OUString s_sViewAccess(RTL_CONSTASCII_USTRINGPARAM("ViewAccessServiceName"));
84cdf0e10cSrcweir             m_xViewAccess.set(xFac->createInstance(lcl_getServiceNameForSetting(_rxConnection,s_sViewAccess)),UNO_QUERY);
85cdf0e10cSrcweir         }
86cdf0e10cSrcweir         catch(const Exception& )
87cdf0e10cSrcweir         {
88cdf0e10cSrcweir             DBG_UNHANDLED_EXCEPTION();
89cdf0e10cSrcweir         }
90cdf0e10cSrcweir     }
91cdf0e10cSrcweir 
92cdf0e10cSrcweir 	//--------------------------------------------------------------------
~View()93cdf0e10cSrcweir     View::~View()
94cdf0e10cSrcweir     {
95cdf0e10cSrcweir     }
96cdf0e10cSrcweir 
97cdf0e10cSrcweir     //--------------------------------------------------------------------
IMPLEMENT_FORWARD_REFCOUNT(View,View_Base)98cdf0e10cSrcweir     IMPLEMENT_FORWARD_REFCOUNT( View, View_Base )
99cdf0e10cSrcweir     IMPLEMENT_GET_IMPLEMENTATION_ID( View )
100cdf0e10cSrcweir     // -------------------------------------------------------------------------
101cdf0e10cSrcweir     Any SAL_CALL View::queryInterface( const Type & _rType ) throw(RuntimeException)
102cdf0e10cSrcweir     {
103cdf0e10cSrcweir 	    if(_rType == getCppuType( (Reference<XAlterView>*)0) && !m_xViewAccess.is() )
104cdf0e10cSrcweir 		    return Any();
105cdf0e10cSrcweir 	    Any aReturn = View_Base::queryInterface( _rType );
106cdf0e10cSrcweir 		if ( !aReturn.hasValue() )
107cdf0e10cSrcweir 			aReturn = View_IBASE::queryInterface( _rType );
108cdf0e10cSrcweir 		return aReturn;
109cdf0e10cSrcweir     }
110cdf0e10cSrcweir     // -------------------------------------------------------------------------
getTypes()111cdf0e10cSrcweir     Sequence< Type > SAL_CALL View::getTypes(  ) throw(RuntimeException)
112cdf0e10cSrcweir     {
113cdf0e10cSrcweir 	    Type aAlterType = getCppuType( (Reference<XAlterView>*)0);
114cdf0e10cSrcweir 
115cdf0e10cSrcweir 	    Sequence< Type > aTypes( ::comphelper::concatSequences(View_Base::getTypes(),View_IBASE::getTypes()) );
116cdf0e10cSrcweir 	    ::std::vector<Type> aOwnTypes;
117cdf0e10cSrcweir 	    aOwnTypes.reserve(aTypes.getLength());
118cdf0e10cSrcweir 
119cdf0e10cSrcweir 	    const Type* pIter = aTypes.getConstArray();
120cdf0e10cSrcweir 	    const Type* pEnd = pIter + aTypes.getLength();
121cdf0e10cSrcweir 	    for(;pIter != pEnd ;++pIter)
122cdf0e10cSrcweir 	    {
123cdf0e10cSrcweir 		    if( (*pIter != aAlterType || m_xViewAccess.is()) )
124cdf0e10cSrcweir 			    aOwnTypes.push_back(*pIter);
125cdf0e10cSrcweir 	    }
126cdf0e10cSrcweir 
127cdf0e10cSrcweir 	    Type* pTypes = aOwnTypes.empty() ? 0 : &aOwnTypes[0];
128cdf0e10cSrcweir 	    return Sequence< Type >(pTypes, aOwnTypes.size());
129cdf0e10cSrcweir     }
130cdf0e10cSrcweir 
131cdf0e10cSrcweir     //--------------------------------------------------------------------
alterCommand(const::rtl::OUString & _rNewCommand)132cdf0e10cSrcweir     void SAL_CALL View::alterCommand( const ::rtl::OUString& _rNewCommand ) throw (SQLException, RuntimeException)
133cdf0e10cSrcweir     {
134cdf0e10cSrcweir         OSL_ENSURE(m_xViewAccess.is(),"Illegal call to AlterView!");
135cdf0e10cSrcweir         m_xViewAccess->alterCommand(this,_rNewCommand);
136cdf0e10cSrcweir     }
137cdf0e10cSrcweir 
138cdf0e10cSrcweir     //--------------------------------------------------------------------
getFastPropertyValue(Any & _rValue,sal_Int32 _nHandle) const139cdf0e10cSrcweir     void SAL_CALL View::getFastPropertyValue( Any& _rValue, sal_Int32 _nHandle ) const
140cdf0e10cSrcweir     {
141cdf0e10cSrcweir         if ( _nHandle == m_nCommandHandle && m_xViewAccess.is() )
142cdf0e10cSrcweir         {
143cdf0e10cSrcweir             // retrieve the very current command, don't rely on the base classes cached value
144cdf0e10cSrcweir             // (which we initialized empty, anyway)
145cdf0e10cSrcweir             _rValue <<= m_xViewAccess->getCommand(const_cast<View*>(this));
146cdf0e10cSrcweir             return;
147cdf0e10cSrcweir         }
148cdf0e10cSrcweir 
149cdf0e10cSrcweir         View_Base::getFastPropertyValue( _rValue, _nHandle );
150cdf0e10cSrcweir     }
151cdf0e10cSrcweir     // -----------------------------------------------------------------------------
152cdf0e10cSrcweir //........................................................................
153cdf0e10cSrcweir } // namespace dbaccess
154cdf0e10cSrcweir //........................................................................
155