1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_connectivity.hxx" 30 31 #include "connectivity/warningscontainer.hxx" 32 #include "connectivity/dbexception.hxx" 33 34 #include <osl/diagnose.h> 35 36 //........................................................................ 37 namespace dbtools 38 { 39 //........................................................................ 40 41 using namespace ::com::sun::star::uno; 42 using namespace ::com::sun::star::sdbc; 43 using namespace ::com::sun::star::sdb; 44 45 //==================================================================== 46 //= WarningsContainer 47 //==================================================================== 48 //-------------------------------------------------------------------- 49 static void lcl_concatWarnings( Any& _rChainLeft, const Any& _rChainRight ) 50 { 51 if ( !_rChainLeft.hasValue() ) 52 _rChainLeft = _rChainRight; 53 else 54 { 55 // to travel the chain by reference (and not by value), we need the getValue ... 56 // looks like a hack, but the meaning of getValue is documented, and it's the only chance for reference-traveling .... 57 58 OSL_ENSURE( SQLExceptionInfo( _rChainLeft ).isValid(), 59 "lcl_concatWarnings: invalid warnings chain (this will crash)!" ); 60 61 const SQLException* pChainTravel = static_cast< const SQLException* >( _rChainLeft.getValue() ); 62 SQLExceptionIteratorHelper aReferenceIterHelper( *pChainTravel ); 63 while ( aReferenceIterHelper.hasMoreElements() ) 64 pChainTravel = aReferenceIterHelper.next(); 65 66 // reached the end of the chain, and pChainTravel points to the last element 67 const_cast< SQLException* >( pChainTravel )->NextException = _rChainRight; 68 } 69 } 70 71 //-------------------------------------------------------------------- 72 WarningsContainer::~WarningsContainer() 73 { 74 } 75 76 //-------------------------------------------------------------------- 77 void WarningsContainer::appendWarning(const SQLException& _rWarning) 78 { 79 lcl_concatWarnings( m_aOwnWarnings, makeAny( _rWarning ) ); 80 } 81 82 //-------------------------------------------------------------------- 83 void WarningsContainer::appendWarning( const SQLContext& _rContext ) 84 { 85 lcl_concatWarnings( m_aOwnWarnings, makeAny( _rContext )); 86 } 87 88 //-------------------------------------------------------------------- 89 void WarningsContainer::appendWarning(const SQLWarning& _rWarning) 90 { 91 lcl_concatWarnings( m_aOwnWarnings, makeAny( _rWarning ) ); 92 } 93 94 //-------------------------------------------------------------------- 95 Any SAL_CALL WarningsContainer::getWarnings( ) const 96 { 97 Any aAllWarnings; 98 if ( m_xExternalWarnings.is() ) 99 aAllWarnings = m_xExternalWarnings->getWarnings(); 100 101 if ( m_aOwnWarnings.hasValue() ) 102 lcl_concatWarnings( aAllWarnings, m_aOwnWarnings ); 103 104 return aAllWarnings; 105 } 106 107 //-------------------------------------------------------------------- 108 void SAL_CALL WarningsContainer::clearWarnings( ) 109 { 110 if ( m_xExternalWarnings.is() ) 111 m_xExternalWarnings->clearWarnings(); 112 m_aOwnWarnings.clear(); 113 } 114 115 //-------------------------------------------------------------------- 116 void WarningsContainer::appendWarning( const ::rtl::OUString& _rWarning, const sal_Char* _pAsciiSQLState, const Reference< XInterface >& _rxContext ) 117 { 118 appendWarning( SQLWarning( _rWarning, _rxContext, ::rtl::OUString::createFromAscii( _pAsciiSQLState ), 0, Any() ) ); 119 } 120 121 //........................................................................ 122 } // namespace dbtools 123 //........................................................................ 124