xref: /aoo41x/main/dbaccess/source/core/api/View.cxx (revision 96de5490)
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_dbaccess.hxx"
26 
27 #include "View.hxx"
28 #include "dbastrings.hrc"
29 
30 #include "connectivity/dbexception.hxx"
31 #include "connectivity/dbtools.hxx"
32 
33 /** === begin UNO includes === **/
34 #include <com/sun/star/lang/WrappedTargetException.hpp>
35 #include <com/sun/star/lang/DisposedException.hpp>
36 #include <com/sun/star/sdbc/XRow.hpp>
37 /** === end UNO includes === **/
38 
39 #include <cppuhelper/exc_hlp.hxx>
40 #include <tools/diagnose_ex.h>
41 #include <unotools/sharedunocomponent.hxx>
42 
43 //........................................................................
44 namespace dbaccess
45 {
46 //........................................................................
47 
48 	/** === begin UNO using === **/
49 	using namespace ::com::sun::star::uno;
50     using ::com::sun::star::sdbc::XDatabaseMetaData;
51     using ::com::sun::star::sdbc::SQLException;
52     using ::com::sun::star::sdbc::XConnection;
53     using ::com::sun::star::lang::WrappedTargetException;
54     using ::com::sun::star::lang::XMultiServiceFactory;
55     using ::com::sun::star::sdbc::XResultSet;
56     using ::com::sun::star::sdbc::XStatement;
57     using ::com::sun::star::lang::DisposedException;
58     using ::com::sun::star::sdbc::XRow;
59 	/** === end UNO using === **/
60 
lcl_getServiceNameForSetting(const Reference<::com::sun::star::sdbc::XConnection> & _xConnection,const::rtl::OUString & i_sSetting)61     ::rtl::OUString lcl_getServiceNameForSetting(const Reference< ::com::sun::star::sdbc::XConnection >& _xConnection,const ::rtl::OUString& i_sSetting)
62     {
63         ::rtl::OUString sSupportService;
64         Any aValue;
65         if ( dbtools::getDataSourceSetting(_xConnection,i_sSetting,aValue) )
66         {
67             aValue >>= sSupportService;
68         }
69         return sSupportService;
70     }
71 	//====================================================================
72 	//= View
73 	//====================================================================
74 	//--------------------------------------------------------------------
View(const Reference<XConnection> & _rxConnection,sal_Bool _bCaseSensitive,const::rtl::OUString & _rCatalogName,const::rtl::OUString & _rSchemaName,const::rtl::OUString & _rName)75     View::View( const Reference< XConnection >& _rxConnection, sal_Bool _bCaseSensitive,
76         const ::rtl::OUString& _rCatalogName,const ::rtl::OUString& _rSchemaName, const ::rtl::OUString& _rName )
77         :View_Base( _bCaseSensitive, _rName, _rxConnection->getMetaData(), 0, ::rtl::OUString(), _rSchemaName, _rCatalogName )
78     {
79         m_nCommandHandle = getProperty(PROPERTY_COMMAND).Handle;
80         try
81         {
82             Reference<XMultiServiceFactory> xFac(_rxConnection,UNO_QUERY_THROW);
83             static const ::rtl::OUString s_sViewAccess(RTL_CONSTASCII_USTRINGPARAM("ViewAccessServiceName"));
84             m_xViewAccess.set(xFac->createInstance(lcl_getServiceNameForSetting(_rxConnection,s_sViewAccess)),UNO_QUERY);
85         }
86         catch(const Exception& )
87         {
88             DBG_UNHANDLED_EXCEPTION();
89         }
90     }
91 
92 	//--------------------------------------------------------------------
~View()93     View::~View()
94     {
95     }
96 
97     //--------------------------------------------------------------------
IMPLEMENT_FORWARD_REFCOUNT(View,View_Base)98     IMPLEMENT_FORWARD_REFCOUNT( View, View_Base )
99     IMPLEMENT_GET_IMPLEMENTATION_ID( View )
100     // -------------------------------------------------------------------------
101     Any SAL_CALL View::queryInterface( const Type & _rType ) throw(RuntimeException)
102     {
103 	    if(_rType == getCppuType( (Reference<XAlterView>*)0) && !m_xViewAccess.is() )
104 		    return Any();
105 	    Any aReturn = View_Base::queryInterface( _rType );
106 		if ( !aReturn.hasValue() )
107 			aReturn = View_IBASE::queryInterface( _rType );
108 		return aReturn;
109     }
110     // -------------------------------------------------------------------------
getTypes()111     Sequence< Type > SAL_CALL View::getTypes(  ) throw(RuntimeException)
112     {
113 	    Type aAlterType = getCppuType( (Reference<XAlterView>*)0);
114 
115 	    Sequence< Type > aTypes( ::comphelper::concatSequences(View_Base::getTypes(),View_IBASE::getTypes()) );
116 	    ::std::vector<Type> aOwnTypes;
117 	    aOwnTypes.reserve(aTypes.getLength());
118 
119 	    const Type* pIter = aTypes.getConstArray();
120 	    const Type* pEnd = pIter + aTypes.getLength();
121 	    for(;pIter != pEnd ;++pIter)
122 	    {
123 		    if( (*pIter != aAlterType || m_xViewAccess.is()) )
124 			    aOwnTypes.push_back(*pIter);
125 	    }
126 
127 	    Type* pTypes = aOwnTypes.empty() ? 0 : &aOwnTypes[0];
128 	    return Sequence< Type >(pTypes, aOwnTypes.size());
129     }
130 
131     //--------------------------------------------------------------------
alterCommand(const::rtl::OUString & _rNewCommand)132     void SAL_CALL View::alterCommand( const ::rtl::OUString& _rNewCommand ) throw (SQLException, RuntimeException)
133     {
134         OSL_ENSURE(m_xViewAccess.is(),"Illegal call to AlterView!");
135         m_xViewAccess->alterCommand(this,_rNewCommand);
136     }
137 
138     //--------------------------------------------------------------------
getFastPropertyValue(Any & _rValue,sal_Int32 _nHandle) const139     void SAL_CALL View::getFastPropertyValue( Any& _rValue, sal_Int32 _nHandle ) const
140     {
141         if ( _nHandle == m_nCommandHandle && m_xViewAccess.is() )
142         {
143             // retrieve the very current command, don't rely on the base classes cached value
144             // (which we initialized empty, anyway)
145             _rValue <<= m_xViewAccess->getCommand(const_cast<View*>(this));
146             return;
147         }
148 
149         View_Base::getFastPropertyValue( _rValue, _nHandle );
150     }
151     // -----------------------------------------------------------------------------
152 //........................................................................
153 } // namespace dbaccess
154 //........................................................................
155