xref: /trunk/main/dbaccess/source/core/api/View.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2008 by Sun Microsystems, Inc.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * $RCSfile: View.cxx,v $
10  * $Revision: 1.3 $
11  *
12  * This file is part of OpenOffice.org.
13  *
14  * OpenOffice.org is free software: you can redistribute it and/or modify
15  * it under the terms of the GNU Lesser General Public License version 3
16  * only, as published by the Free Software Foundation.
17  *
18  * OpenOffice.org is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU Lesser General Public License version 3 for more details
22  * (a copy is included in the LICENSE file that accompanied this code).
23  *
24  * You should have received a copy of the GNU Lesser General Public License
25  * version 3 along with OpenOffice.org.  If not, see
26  * <http://www.openoffice.org/license.html>
27  * for a copy of the LGPLv3 License.
28  *
29  ************************************************************************/
30 
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
33 
34 #include "View.hxx"
35 #include "dbastrings.hrc"
36 
37 #include "connectivity/dbexception.hxx"
38 #include "connectivity/dbtools.hxx"
39 
40 /** === begin UNO includes === **/
41 #include <com/sun/star/lang/WrappedTargetException.hpp>
42 #include <com/sun/star/lang/DisposedException.hpp>
43 #include <com/sun/star/sdbc/XRow.hpp>
44 /** === end UNO includes === **/
45 
46 #include <cppuhelper/exc_hlp.hxx>
47 #include <tools/diagnose_ex.h>
48 #include <unotools/sharedunocomponent.hxx>
49 
50 //........................................................................
51 namespace dbaccess
52 {
53 //........................................................................
54 
55 	/** === begin UNO using === **/
56 	using namespace ::com::sun::star::uno;
57     using ::com::sun::star::sdbc::XDatabaseMetaData;
58     using ::com::sun::star::sdbc::SQLException;
59     using ::com::sun::star::sdbc::XConnection;
60     using ::com::sun::star::lang::WrappedTargetException;
61     using ::com::sun::star::lang::XMultiServiceFactory;
62     using ::com::sun::star::sdbc::XResultSet;
63     using ::com::sun::star::sdbc::XStatement;
64     using ::com::sun::star::lang::DisposedException;
65     using ::com::sun::star::sdbc::XRow;
66 	/** === end UNO using === **/
67 
68     ::rtl::OUString lcl_getServiceNameForSetting(const Reference< ::com::sun::star::sdbc::XConnection >& _xConnection,const ::rtl::OUString& i_sSetting)
69     {
70         ::rtl::OUString sSupportService;
71         Any aValue;
72         if ( dbtools::getDataSourceSetting(_xConnection,i_sSetting,aValue) )
73         {
74             aValue >>= sSupportService;
75         }
76         return sSupportService;
77     }
78 	//====================================================================
79 	//= View
80 	//====================================================================
81 	//--------------------------------------------------------------------
82     View::View( const Reference< XConnection >& _rxConnection, sal_Bool _bCaseSensitive,
83         const ::rtl::OUString& _rCatalogName,const ::rtl::OUString& _rSchemaName, const ::rtl::OUString& _rName )
84         :View_Base( _bCaseSensitive, _rName, _rxConnection->getMetaData(), 0, ::rtl::OUString(), _rSchemaName, _rCatalogName )
85     {
86         m_nCommandHandle = getProperty(PROPERTY_COMMAND).Handle;
87         try
88         {
89             Reference<XMultiServiceFactory> xFac(_rxConnection,UNO_QUERY_THROW);
90             static const ::rtl::OUString s_sViewAccess(RTL_CONSTASCII_USTRINGPARAM("ViewAccessServiceName"));
91             m_xViewAccess.set(xFac->createInstance(lcl_getServiceNameForSetting(_rxConnection,s_sViewAccess)),UNO_QUERY);
92         }
93         catch(const Exception& )
94         {
95             DBG_UNHANDLED_EXCEPTION();
96         }
97     }
98 
99 	//--------------------------------------------------------------------
100     View::~View()
101     {
102     }
103 
104     //--------------------------------------------------------------------
105     IMPLEMENT_FORWARD_REFCOUNT( View, View_Base )
106     IMPLEMENT_GET_IMPLEMENTATION_ID( View )
107     // -------------------------------------------------------------------------
108     Any SAL_CALL View::queryInterface( const Type & _rType ) throw(RuntimeException)
109     {
110 	    if(_rType == getCppuType( (Reference<XAlterView>*)0) && !m_xViewAccess.is() )
111 		    return Any();
112 	    Any aReturn = View_Base::queryInterface( _rType );
113 		if ( !aReturn.hasValue() )
114 			aReturn = View_IBASE::queryInterface( _rType );
115 		return aReturn;
116     }
117     // -------------------------------------------------------------------------
118     Sequence< Type > SAL_CALL View::getTypes(  ) throw(RuntimeException)
119     {
120 	    Type aAlterType = getCppuType( (Reference<XAlterView>*)0);
121 
122 	    Sequence< Type > aTypes( ::comphelper::concatSequences(View_Base::getTypes(),View_IBASE::getTypes()) );
123 	    ::std::vector<Type> aOwnTypes;
124 	    aOwnTypes.reserve(aTypes.getLength());
125 
126 	    const Type* pIter = aTypes.getConstArray();
127 	    const Type* pEnd = pIter + aTypes.getLength();
128 	    for(;pIter != pEnd ;++pIter)
129 	    {
130 		    if( (*pIter != aAlterType || m_xViewAccess.is()) )
131 			    aOwnTypes.push_back(*pIter);
132 	    }
133 
134 	    Type* pTypes = aOwnTypes.empty() ? 0 : &aOwnTypes[0];
135 	    return Sequence< Type >(pTypes, aOwnTypes.size());
136     }
137 
138     //--------------------------------------------------------------------
139     void SAL_CALL View::alterCommand( const ::rtl::OUString& _rNewCommand ) throw (SQLException, RuntimeException)
140     {
141         OSL_ENSURE(m_xViewAccess.is(),"Illegal call to AlterView!");
142         m_xViewAccess->alterCommand(this,_rNewCommand);
143     }
144 
145     //--------------------------------------------------------------------
146     void SAL_CALL View::getFastPropertyValue( Any& _rValue, sal_Int32 _nHandle ) const
147     {
148         if ( _nHandle == m_nCommandHandle && m_xViewAccess.is() )
149         {
150             // retrieve the very current command, don't rely on the base classes cached value
151             // (which we initialized empty, anyway)
152             _rValue <<= m_xViewAccess->getCommand(const_cast<View*>(this));
153             return;
154         }
155 
156         View_Base::getFastPropertyValue( _rValue, _nHandle );
157     }
158     // -----------------------------------------------------------------------------
159 //........................................................................
160 } // namespace dbaccess
161 //........................................................................
162