23#include <core_resource.hxx>
25#include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp>
26#include <com/sun/star/sdbcx/XAppend.hpp>
27#include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
28#include <com/sun/star/container/XNameContainer.hpp>
29#include <com/sun/star/frame/XStorable.hpp>
30#include <com/sun/star/container/XHierarchicalNameContainer.hpp>
31#include <com/sun/star/lang/XSingleServiceFactory.hpp>
32#include <com/sun/star/sdb/CommandType.hpp>
33#include <com/sun/star/sdb/SQLContext.hpp>
34#include <com/sun/star/sdbcx/XTablesSupplier.hpp>
35#include <com/sun/star/sdbcx/XViewsSupplier.hpp>
36#include <com/sun/star/sdb/XQueryDefinitionsSupplier.hpp>
37#include <com/sun/star/sdbcx/XDrop.hpp>
52#include <com/sun/star/sdb/XReportDocumentsSupplier.hpp>
53#include <com/sun/star/sdb/XFormDocumentsSupplier.hpp>
56#include <osl/diagnose.h>
58#include <osl/mutex.hxx>
84 OSL_ENSURE(xSup.is(),
"OApplicationController::deleteTable: no XTablesSupplier!");
93 std::vector< OUString>::const_iterator aEnd = _rList.end();
94 for (std::vector< OUString>::const_iterator aIter = _rList.begin(); aIter != aEnd; ++aIter)
96 OUString sTableName = *aIter;
102 bool bUserConfirmedDelete =
110 if ( xTables->hasByName(sTableName) )
111 xDrop->dropByName(sTableName);
117 if ( xViewsSup.is() )
119 xViews = xViewsSup->getViews();
120 if ( xViews.is() && xViews->hasByName(sTableName) )
122 xDrop.set(xViews,UNO_QUERY);
124 xDrop->dropByName(sTableName);
129 catch(SQLContext& e) { aErrorInfo = e; }
130 catch(SQLWarning& e) { aErrorInfo = e; }
131 catch(SQLException& e) { aErrorInfo = e; }
132 catch(WrappedTargetException& e)
135 if(e.TargetException >>= aSql)
138 OSL_FAIL(
"OApplicationController::implDropTable: something strange happened!");
159 VclMessageType::Warning, VclButtonsType::Ok,
181 std::set< OUString > aDeleteNames(_rList.begin(), _rList.end());
183 std::set< OUString >::size_type
nCount = aDeleteNames.size();
184 for ( std::set< OUString >::size_type nObjectsLeft =
nCount; !aDeleteNames.empty(); )
186 std::set< OUString >::const_iterator aThisRound = aDeleteNames.begin();
192 if ( nObjectsLeft > 1 )
195 eResult = aDlg.run();
198 bool bSuccess =
false;
200 bool bUserConfirmedDelete =
204 if ( bUserConfirmedDelete
210 if ( xHierarchyName.is() )
211 xHierarchyName->removeByHierarchicalName( *aThisRound );
213 xNames->removeByName( *aThisRound );
220 OSL_ENSURE( aThisRound->getLength() - 1 >= 0,
"OApplicationController::deleteObjects: empty name?" );
221 OUString sSmallestSiblingName = *aThisRound + OUStringChar(
sal_Unicode(
'/' + 1) );
223 std::set< OUString >::const_iterator aUpperChildrenBound = aDeleteNames.lower_bound( sSmallestSiblingName );
224 for ( std::set< OUString >::const_iterator aObsolete = aThisRound;
225 aObsolete != aUpperChildrenBound;
228 std::set< OUString >::const_iterator aNextObsolete = aObsolete; ++aNextObsolete;
229 aDeleteNames.erase( aObsolete );
231 aObsolete = aNextObsolete;
234 catch(
const SQLException&)
238 catch(
const WrappedTargetException& e)
241 if ( e.TargetException >>= aSql )
244 OSL_FAIL(
"OApplicationController::deleteObjects: something strange happened!" );
256 aDeleteNames.erase( aThisRound );
265 ::osl::MutexGuard aGuard(
getMutex() );
270 std::vector< OUString> aList;
305 ::osl::MutexGuard aGuard(
getMutex() );
316 OUString sConnectingContext(
DBA_RES(STR_COULDNOTCONNECT_DATASOURCE));
329 ::osl::MutexGuard aGuard(
getMutex() );
341 OSL_FAIL(
"dbaui::OApplicationController::ensureConnection could not dispose of temporary unused connection" );
354 catch(
const SQLException& )
356 aError = ::cppu::getCaughtException();
366 *_pErrorInfo = aError;
383 return !xStore.is() || xStore->isReadonly();
388 bool bIsConnectionReadOnly =
true;
395 catch(
const SQLException&)
401 return bIsConnectionReadOnly;
414 xElements.set( xSupp->getReportDocuments(), UNO_SET_THROW );
421 xElements.set( xSupp->getFormDocuments(), UNO_SET_THROW );
436 xElements.set( xSup->getTables(), UNO_SET_THROW );
456 ::osl::MutexGuard aGuard(
getMutex() );
466 "OApplicationController::getDocumentsAccess: only forms and reports are supported here!" );
474 OSL_ENSURE( xDocContainer.is(),
"OApplicationController::getDocumentsAccess: invalid container!" );
485 bool bSuccess =
false;
489 ::osl::MutexGuard aGuard(
getMutex() );
499 if ( xConnection.
is() )
500 xMetaData = xConnection->getMetaData();
503 if ( !
sName.isEmpty() )
523 catch(
const SQLException&)
536 bool bSuccess =
false;
540 ::osl::MutexGuard aGuard(
getMutex() );
548 std::vector< OUString> aList;
551 if ( xElements.is() && !aList.empty() )
563 catch(
const SQLException&)
579 ::osl::MutexGuard aGuard(
getMutex() );
605 catch(
const SQLException&)
623 if ( _rPasteData.
has(DataAccessDescriptorProperty::CommandType) )
624 _rPasteData[DataAccessDescriptorProperty::CommandType] >>= nCommandType;
631 bool bEscapeProcessing =
true;
633 _rPasteData[DataAccessDescriptorProperty::Command] >>= sCommand;
634 if ( _rPasteData.
has(DataAccessDescriptorProperty::EscapeProcessing) )
635 _rPasteData[DataAccessDescriptorProperty::EscapeProcessing] >>= bEscapeProcessing;
638 bool bValidDescriptor =
false;
641 bValidDescriptor = sDataSourceName.getLength() && sCommand.getLength();
642 else if (CommandType::COMMAND == nCommandType)
643 bValidDescriptor = !sCommand.isEmpty();
644 if (!bValidDescriptor)
646 OSL_FAIL(
"OApplicationController::paste: invalid descriptor!");
651 OUString sTargetName;
655 sTargetName = sCommand;
657 if ( sTargetName.isEmpty() )
659 OUString sDefaultName =
DBA_RES(STR_QRY_TITLE);
660 sDefaultName = sDefaultName.getToken( 0,
' ' );
663 sTargetName = ::dbtools::createUniqueName( xQueries, sDefaultName,
false );
675 bool bSuccess =
false;
683 if ( xQueries->hasByName( sCommand ) )
685 xQuery.set( xQueries->getByName(sCommand), UNO_QUERY_THROW );
689 catch(SQLException&) {
throw; }
697 OSL_FAIL(
"OApplicationController::paste: could not extract the source query object!");
705 if (!xQueryFactory.is())
707 OSL_FAIL(
"OApplicationController::paste: invalid destination query container!");
717 bool bNeedAskForName = ( sCommand.isEmpty() )
719 || ( !aNameChecker.
isNameValid( sTargetName, aDummy ) );
722 if ( bNeedAskForName )
734 sTargetName = aAskForName.
getName();
739 OSL_ENSURE(xNewQuery.is(),
"OApplicationController::paste: invalid object created by factory!");
744 ::comphelper::copyProperties(xQuery,xNewQuery);
751 xDestQueries->insertByName( sTargetName,
Any(xNewQuery) );
752 xNewQuery.set(xDestQueries->getByName( sTargetName),UNO_QUERY);
753 if ( xQuery.is() && xNewQuery.is() )
757 if ( xSrcColSup.is() && xDstColSup.is() )
763 if ( xSrcNameAccess.is() && xDstNameAccess.is() && xSrcNameAccess->hasElements() && xAppend.is() )
768 const OUString* pIter =
aSeq.getConstArray();
769 const OUString* pEnd = pIter +
aSeq.getLength();
770 for( ; pIter != pEnd ; ++pIter)
773 ::comphelper::copyProperties(xSrcProp,xDstProp);
774 xAppend->appendByDescriptor(xDstProp);
782 SAL_WARN(
"dbaccess",
"There should be a sequence in it!");
785 else if ( _rPasteData.
has(DataAccessDescriptorProperty::Component) )
788 _rPasteData[DataAccessDescriptorProperty::Component] >>= xContent;
806 xNames.set(xSet->getQueryDefinitions(),UNO_QUERY);
816 _rFormatIds.push_back(SotClipboardFormatId::DBACCESS_TABLE);
817 _rFormatIds.push_back(SotClipboardFormatId::RTF);
818 _rFormatIds.push_back(SotClipboardFormatId::HTML);
821 _rFormatIds.push_back(SotClipboardFormatId::DBACCESS_QUERY);
835 m_nAsyncDrop =
nullptr;
837 ::osl::MutexGuard aGuard(
getMutex() );
839 if ( m_aAsyncDrop.nType ==
E_TABLE )
842 if ( xConnection.
is() )
843 m_aTableCopyHelper.asyncCopyTagTable( m_aAsyncDrop, getDatabaseName(), xConnection );
847 if ( paste(m_aAsyncDrop.nType,m_aAsyncDrop.aDroppedData,m_aAsyncDrop.aUrl,m_aAsyncDrop.nAction ==
DND_ACTION_MOVE)
851 m_aAsyncDrop.aDroppedData[DataAccessDescriptorProperty::Component] >>= xContent;
852 std::vector< OUString> aList;
854 OUString
sName = xContent->getIdentifier()->getContentIdentifier();
858 aList.push_back(
sName.copy(sErase.size() + 1));
859 deleteObjects( m_aAsyncDrop.nType, aList,
false );
864 m_aAsyncDrop.aDroppedData.clear();
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, const ILibreOfficeKitNotifier *pNotifier=nullptr)
class implementing the IObjectNameCheck interface, and checking a given name for being valid as eithe...
virtual bool isNameValid(const OUString &_rObjectName, ::dbtools::SQLExceptionInfo &_out_rErrorToDisplay) const override
determines whether a given object name is valid
css::uno::Reference< css::container::XNameContainer > getQueryDefinitions() const
returns the query definitions of the active data source.
void deleteTables(const std::vector< OUString > &_rList)
deletes tables.
const TransferableDataHelper & getViewClipboard() const
returns the system clipboard.
bool insertHierarchyElement(ElementType _eType, const OUString &_sParentFolder, bool _bCollection=true, const css::uno::Reference< css::ucb::XContent > &_xContent=css::uno::Reference< css::ucb::XContent >(), bool _bMove=false)
Inserts a new object into the hierarchy given be the type.
static void getSupportedFormats(ElementType _eType, std::vector< SotClipboardFormatId > &_rFormatIds)
fills the vector with all supported formats
void deleteObjects(ElementType _eType, const std::vector< OUString > &_rList, bool _bConfirm)
deletes queries, forms, or reports
bool isConnectionReadOnly() const
checks if the connection for the selected data source is read only.
css::uno::Reference< css::sdbc::XDatabaseMetaData > m_xMetaData
virtual bool isDataSourceReadOnly() const override
checks if the selected data source is read only
bool copySQLObject(ODataClipboard &rExchange)
fills rExchange with current object if it's a Table or Query
const SharedConnection & ensureConnection(::dbtools::SQLExceptionInfo *_pErrorInfo=nullptr)
retrieves the current connection, creates it if necessary
bool paste(ElementType _eType, const svx::ODataAccessDescriptor &_rPasteData, const OUString &_sParentFolder=OUString(), bool _bMove=false)
pastes a query, form or report into the data source
rtl::Reference< TransferableHelper > copyObject()
copies the current object into clipboard
void deleteEntries()
deletes the entries selected.
const SharedConnection & getConnection() const
retrieves the current connection
css::uno::Reference< css::beans::XPropertySet > m_xDataSource
void getSelectionElementNames(std::vector< OUString > &_rNames) const
fills the list with the selected entries.
std::unique_ptr< OLinkedDocumentsAccess > getDocumentsAccess(ElementType _eType)
returns the document access for the specific type
virtual void SAL_CALL connect() override
css::uno::Reference< css::frame::XModel > m_xModel
bool copyDocObject(svx::OComponentTransferable &rExchange)
fills rExchange with current object if it's a Form or Report
OUString getStrippedDatabaseName() const
returns the stripped database name.
OUString getDatabaseName() const
returns the database name
css::uno::Reference< css::container::XNameAccess > getElements(ElementType _eType)
returns the nameaccess
::rtl::Reference< SubComponentManager > m_pSubComponentManager
bool isTableFormat() const
returns <TRUE> if the clipboard supports a table format, otherwise <FALSE>.
OApplicationView * getContainer() const
SharedConnection m_xDataSourceConnection
OUString getQualifiedName(const weld::TreeIter *_pEntry) const
return the qualified name.
void getSelectionElementNames(std::vector< OUString > &_rNames) const
returns the element names which are selected
ElementType getElementType() const
return the element of currently select entry
void Update(const OUString &_rDatasource, const sal_Int32 _nCommandType, const OUString &_rCommand, const css::uno::Reference< css::sdbc::XConnection > &_rxConnection, const css::uno::Reference< css::util::XNumberFormatter > &_rxFormatter, const css::uno::Reference< css::uno::XComponentContext > &_rxORB)
weld::Window * getFrameWeld() const
void showError(const ::dbtools::SQLExceptionInfo &_rInfo)
::osl::Mutex & getMutex() const
const css::uno::Reference< css::uno::XComponentContext > & getORB() const
const OUString & getName() const
static bool isTableFormat(const TransferableDataHelper &_rClipboard)
returns <TRUE> if the clipboard supports a table format, otherwise <FALSE>.
void Update(const OUString &rDatasourceOrLocation, const css::uno::Reference< css::ucb::XContent > &xContent)
bool has(DataAccessDescriptorProperty _eWhich) const
OUString getDataSource() const
void reset(const css::uno::Reference< INTERFACE > &_rxComponent, AssignmentMode _eMode=TakeOwnership)
#define DBG_UNHANDLED_EXCEPTION(...)
Sequence< sal_Int8 > aSeq
#define SAL_WARN(area, stream)
IMPL_LINK_NOARG(OApplicationController, OnClipboardChanged, TransferableDataHelper *, void)
css::uno::Reference< css::sdbc::XDataSource > getDataSourceByName(const OUString &_rDataSourceName, weld::Window *_pErrorMessageParent, const css::uno::Reference< css::uno::XComponentContext > &_rxContext, ::dbtools::SQLExceptionInfo *_pErrorInfo)
retrieves a data source given by name or URL, and displays an error if this fails
css::uno::Reference< css::util::XNumberFormatter > getNumberFormatter(const css::uno::Reference< css::sdbc::XConnection > &_rxConnection, const css::uno::Reference< css::uno::XComponentContext > &_rxContext)
creates a number formatter
sal_Int32 askForUserAction(weld::Window *pParent, TranslateId pTitle, TranslateId pText, bool bAll, std::u16string_view rName)
returns the configuration node name of user defined drivers.
::osl::Mutex & getMutex()
std::basic_string_view< charT, traits > getToken(std::basic_string_view< charT, traits > sv, charT delimiter, std::size_t &position)
constexpr OUStringLiteral PROPERTY_COMMAND(u"Command")
constexpr OUStringLiteral PROPERTY_ESCAPE_PROCESSING(u"EscapeProcessing")