Fix GNU C++ version check
[LibreOffice.git] / dbaccess / source / core / misc / sdbcoretools.cxx
blobf213444303339ec4af26f376b627f9e1f4a20ee3
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sdbcoretools.hxx>
22 #include <com/sun/star/beans/XPropertySet.hpp>
23 #include <com/sun/star/container/XChild.hpp>
24 #include <com/sun/star/util/XModifiable.hpp>
25 #include <com/sun/star/sdb/XDocumentDataSource.hpp>
26 #include <com/sun/star/task/InteractionRequestStringResolver.hpp>
27 #include <com/sun/star/embed/XTransactedObject.hpp>
28 #include <com/sun/star/embed/ElementModes.hpp>
30 #include <comphelper/diagnose_ex.hxx>
31 #include <comphelper/interaction.hxx>
32 #include <rtl/ref.hxx>
34 namespace dbaccess
37 using namespace ::com::sun::star::uno;
38 using namespace ::com::sun::star::util;
39 using namespace ::com::sun::star::io;
40 using namespace ::com::sun::star::sdb;
41 using namespace ::com::sun::star::beans;
42 using namespace ::com::sun::star::task;
43 using namespace ::com::sun::star::embed;
44 using namespace ::com::sun::star::container;
46 void notifyDataSourceModified(const css::uno::Reference< css::uno::XInterface >& _rxObject)
48 Reference< XInterface > xDs = getDataSource( _rxObject );
49 Reference<XDocumentDataSource> xDocumentDataSource(xDs,UNO_QUERY);
50 if ( xDocumentDataSource.is() )
51 xDs = xDocumentDataSource->getDatabaseDocument();
52 Reference< XModifiable > xModi( xDs, UNO_QUERY );
53 if ( xModi.is() )
54 xModi->setModified(true);
57 Reference< XInterface > getDataSource( const Reference< XInterface >& _rxDependentObject )
59 Reference< XInterface > xParent = _rxDependentObject;
60 Reference< XInterface > xReturn;
61 while( xParent.is() )
63 xReturn = xParent;
64 Reference<XChild> xChild(xParent,UNO_QUERY);
65 xParent.set(xChild.is() ? xChild->getParent() : Reference< XInterface >(),UNO_QUERY);
67 return xReturn;
70 OUString extractExceptionMessage( const Reference<XComponentContext> & _rContext, const Any& _rError )
72 OUString sDisplayMessage;
74 try
76 Reference< XInteractionRequestStringResolver > xStringResolver = InteractionRequestStringResolver::create(_rContext);
78 ::rtl::Reference pRequest( new ::comphelper::OInteractionRequest( _rError ) );
79 ::rtl::Reference pApprove( new ::comphelper::OInteractionApprove );
80 pRequest->addContinuation( pApprove );
81 Optional< OUString > aMessage = xStringResolver->getStringFromInformationalRequest( pRequest );
82 if ( aMessage.IsPresent )
83 sDisplayMessage = aMessage.Value;
85 catch( const Exception& )
87 DBG_UNHANDLED_EXCEPTION("dbaccess");
90 if ( sDisplayMessage.isEmpty() )
92 Exception aExcept;
93 _rError >>= aExcept;
95 sDisplayMessage = _rError.getValueTypeName() +
96 ":\n" +
97 aExcept.Message;
100 return sDisplayMessage;
103 namespace tools::stor {
105 bool storageIsWritable_nothrow( const Reference< XStorage >& _rxStorage )
107 if ( !_rxStorage.is() )
108 return false;
110 sal_Int32 nMode = ElementModes::READ;
113 Reference< XPropertySet > xStorageProps( _rxStorage, UNO_QUERY_THROW );
114 xStorageProps->getPropertyValue( u"OpenMode"_ustr ) >>= nMode;
116 catch( const Exception& )
118 DBG_UNHANDLED_EXCEPTION("dbaccess");
120 return ( nMode & ElementModes::WRITE ) != 0;
123 bool commitStorageIfWriteable( const Reference< XStorage >& _rxStorage )
125 bool bSuccess = false;
126 Reference< XTransactedObject > xTrans( _rxStorage, UNO_QUERY );
127 if ( xTrans.is() )
129 if ( storageIsWritable_nothrow( _rxStorage ) )
130 xTrans->commit();
131 bSuccess = true;
133 return bSuccess;
138 } // namespace dbaccess
140 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */