Update ooo320-m1
[ooovba.git] / connectivity / source / commontools / warningscontainer.cxx
blobf2c8156e0c78fc91555816be077a15c51cf5ec07
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: warnings.cxx,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
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.
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).
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.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_connectivity.hxx"
34 #include "connectivity/warningscontainer.hxx"
35 #include "connectivity/dbexception.hxx"
37 #include <osl/diagnose.h>
39 //........................................................................
40 namespace dbtools
42 //........................................................................
44 using namespace ::com::sun::star::uno;
45 using namespace ::com::sun::star::sdbc;
46 using namespace ::com::sun::star::sdb;
48 //====================================================================
49 //= WarningsContainer
50 //====================================================================
51 //--------------------------------------------------------------------
52 static void lcl_concatWarnings( Any& _rChainLeft, const Any& _rChainRight )
54 if ( !_rChainLeft.hasValue() )
55 _rChainLeft = _rChainRight;
56 else
58 // to travel the chain by reference (and not by value), we need the getValue ...
59 // looks like a hack, but the meaning of getValue is documented, and it's the only chance for reference-traveling ....
61 OSL_ENSURE( SQLExceptionInfo( _rChainLeft ).isValid(),
62 "lcl_concatWarnings: invalid warnings chain (this will crash)!" );
64 const SQLException* pChainTravel = static_cast< const SQLException* >( _rChainLeft.getValue() );
65 SQLExceptionIteratorHelper aReferenceIterHelper( *pChainTravel );
66 while ( aReferenceIterHelper.hasMoreElements() )
67 pChainTravel = aReferenceIterHelper.next();
69 // reached the end of the chain, and pChainTravel points to the last element
70 const_cast< SQLException* >( pChainTravel )->NextException = _rChainRight;
74 //--------------------------------------------------------------------
75 WarningsContainer::~WarningsContainer()
79 //--------------------------------------------------------------------
80 void WarningsContainer::appendWarning(const SQLException& _rWarning)
82 lcl_concatWarnings( m_aOwnWarnings, makeAny( _rWarning ) );
85 //--------------------------------------------------------------------
86 void WarningsContainer::appendWarning( const SQLContext& _rContext )
88 lcl_concatWarnings( m_aOwnWarnings, makeAny( _rContext ));
91 //--------------------------------------------------------------------
92 void WarningsContainer::appendWarning(const SQLWarning& _rWarning)
94 lcl_concatWarnings( m_aOwnWarnings, makeAny( _rWarning ) );
97 //--------------------------------------------------------------------
98 Any SAL_CALL WarningsContainer::getWarnings( ) const
100 Any aAllWarnings;
101 if ( m_xExternalWarnings.is() )
102 aAllWarnings = m_xExternalWarnings->getWarnings();
104 if ( m_aOwnWarnings.hasValue() )
105 lcl_concatWarnings( aAllWarnings, m_aOwnWarnings );
107 return aAllWarnings;
110 //--------------------------------------------------------------------
111 void SAL_CALL WarningsContainer::clearWarnings( )
113 if ( m_xExternalWarnings.is() )
114 m_xExternalWarnings->clearWarnings();
115 m_aOwnWarnings.clear();
118 //--------------------------------------------------------------------
119 void WarningsContainer::appendWarning( const ::rtl::OUString& _rWarning, const sal_Char* _pAsciiSQLState, const Reference< XInterface >& _rxContext )
121 appendWarning( SQLWarning( _rWarning, _rxContext, ::rtl::OUString::createFromAscii( _pAsciiSQLState ), 0, Any() ) );
124 //........................................................................
125 } // namespace dbtools
126 //........................................................................