2010-10-12 15:59:03 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-06-14 17:39:53 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2006-07-10 14:38:03 +00:00
|
|
|
|
2017-10-23 22:42:52 +02:00
|
|
|
#include <core_resource.hxx>
|
|
|
|
#include <defaultobjectnamecheck.hxx>
|
2006-07-10 14:38:03 +00:00
|
|
|
|
2017-10-23 22:42:52 +02:00
|
|
|
#include <strings.hrc>
|
2006-07-10 14:38:03 +00:00
|
|
|
|
|
|
|
#include <com/sun/star/lang/IllegalArgumentException.hpp>
|
|
|
|
#include <com/sun/star/sdb/CommandType.hpp>
|
|
|
|
#include <com/sun/star/sdb/tools/XConnectionTools.hpp>
|
2019-02-23 10:37:14 +01:00
|
|
|
#include <com/sun/star/sdbc/SQLException.hpp>
|
2006-07-10 14:38:03 +00:00
|
|
|
|
|
|
|
#include <connectivity/dbexception.hxx>
|
|
|
|
#include <connectivity/dbmetadata.hxx>
|
|
|
|
|
|
|
|
#include <rtl/ustrbuf.hxx>
|
|
|
|
|
|
|
|
#include <tools/diagnose_ex.h>
|
|
|
|
#include <cppuhelper/exc_hlp.hxx>
|
|
|
|
|
2015-09-17 11:30:13 +01:00
|
|
|
#include <memory>
|
2006-07-10 14:38:03 +00:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace dbaui
|
|
|
|
{
|
|
|
|
|
|
|
|
using ::com::sun::star::uno::Reference;
|
|
|
|
using ::com::sun::star::lang::IllegalArgumentException;
|
|
|
|
using ::com::sun::star::container::XHierarchicalNameAccess;
|
|
|
|
using ::com::sun::star::sdbc::SQLException;
|
|
|
|
using ::com::sun::star::uno::Exception;
|
|
|
|
using ::com::sun::star::sdbc::XConnection;
|
|
|
|
using ::com::sun::star::sdb::tools::XObjectNames;
|
|
|
|
using ::com::sun::star::sdb::tools::XConnectionTools;
|
|
|
|
using ::com::sun::star::uno::UNO_QUERY;
|
|
|
|
|
|
|
|
using namespace dbtools;
|
|
|
|
|
|
|
|
namespace CommandType = ::com::sun::star::sdb::CommandType;
|
|
|
|
|
2013-08-17 23:43:14 +02:00
|
|
|
// helper
|
2006-07-10 14:38:03 +00:00
|
|
|
namespace
|
|
|
|
{
|
2013-07-13 20:12:42 +01:00
|
|
|
void lcl_fillNameExistsError( const OUString& _rObjectName, SQLExceptionInfo& _out_rErrorToDisplay )
|
2006-07-10 14:38:03 +00:00
|
|
|
{
|
|
|
|
SQLException aError;
|
2017-06-11 20:56:30 +01:00
|
|
|
OUString sErrorMessage = DBA_RES(STR_NAMED_OBJECT_ALREADY_EXISTS);
|
2013-07-13 20:12:42 +01:00
|
|
|
aError.Message = sErrorMessage.replaceAll("$#$", _rObjectName);
|
2006-07-10 14:38:03 +00:00
|
|
|
_out_rErrorToDisplay = aError;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-08-17 23:43:14 +02:00
|
|
|
// HierarchicalNameCheck_Impl
|
2006-07-10 14:38:03 +00:00
|
|
|
struct HierarchicalNameCheck_Impl
|
|
|
|
{
|
|
|
|
Reference< XHierarchicalNameAccess > xHierarchicalNames;
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString sRelativeRoot;
|
2006-07-10 14:38:03 +00:00
|
|
|
};
|
|
|
|
|
2013-08-17 23:43:14 +02:00
|
|
|
// HierarchicalNameCheck
|
2013-04-07 12:06:47 +02:00
|
|
|
HierarchicalNameCheck::HierarchicalNameCheck( const Reference< XHierarchicalNameAccess >& _rxNames, const OUString& _rRelativeRoot )
|
2006-07-10 14:38:03 +00:00
|
|
|
:m_pImpl( new HierarchicalNameCheck_Impl )
|
|
|
|
{
|
|
|
|
m_pImpl->xHierarchicalNames = _rxNames;
|
|
|
|
m_pImpl->sRelativeRoot = _rRelativeRoot;
|
|
|
|
|
|
|
|
if ( !m_pImpl->xHierarchicalNames.is() )
|
|
|
|
throw IllegalArgumentException();
|
|
|
|
}
|
|
|
|
|
|
|
|
HierarchicalNameCheck::~HierarchicalNameCheck()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
bool HierarchicalNameCheck::isNameValid( const OUString& _rObjectName, SQLExceptionInfo& _out_rErrorToDisplay ) const
|
2006-07-10 14:38:03 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2013-04-07 12:06:47 +02:00
|
|
|
OUStringBuffer aCompleteName;
|
2011-12-19 18:10:37 -02:00
|
|
|
if ( !m_pImpl->sRelativeRoot.isEmpty() )
|
2006-07-10 14:38:03 +00:00
|
|
|
{
|
|
|
|
aCompleteName.append( m_pImpl->sRelativeRoot );
|
2015-08-31 08:03:51 +02:00
|
|
|
aCompleteName.append( "/" );
|
2006-07-10 14:38:03 +00:00
|
|
|
}
|
|
|
|
aCompleteName.append( _rObjectName );
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString sCompleteName( aCompleteName.makeStringAndClear() );
|
2006-07-10 14:38:03 +00:00
|
|
|
if ( !m_pImpl->xHierarchicalNames->hasByHierarchicalName( sCompleteName ) )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
catch( const Exception& )
|
|
|
|
{
|
2018-04-02 08:58:19 +02:00
|
|
|
DBG_UNHANDLED_EXCEPTION("dbaccess");
|
2006-07-10 14:38:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
lcl_fillNameExistsError( _rObjectName, _out_rErrorToDisplay );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-08-17 23:43:14 +02:00
|
|
|
// DynamicTableOrQueryNameCheck_Impl
|
2006-07-10 14:38:03 +00:00
|
|
|
struct DynamicTableOrQueryNameCheck_Impl
|
|
|
|
{
|
|
|
|
sal_Int32 nCommandType;
|
|
|
|
Reference< XObjectNames > xObjectNames;
|
|
|
|
};
|
|
|
|
|
2013-08-17 23:43:14 +02:00
|
|
|
// DynamicTableOrQueryNameCheck
|
2006-07-10 14:38:03 +00:00
|
|
|
DynamicTableOrQueryNameCheck::DynamicTableOrQueryNameCheck( const Reference< XConnection >& _rxSdbLevelConnection, sal_Int32 _nCommandType )
|
|
|
|
:m_pImpl( new DynamicTableOrQueryNameCheck_Impl )
|
|
|
|
{
|
|
|
|
Reference< XConnectionTools > xConnTools( _rxSdbLevelConnection, UNO_QUERY );
|
|
|
|
if ( xConnTools.is() )
|
|
|
|
m_pImpl->xObjectNames.set( xConnTools->getObjectNames() );
|
|
|
|
if ( !m_pImpl->xObjectNames.is() )
|
|
|
|
throw IllegalArgumentException();
|
|
|
|
|
|
|
|
if ( ( _nCommandType != CommandType::QUERY ) && ( _nCommandType != CommandType::TABLE ) )
|
|
|
|
throw IllegalArgumentException();
|
|
|
|
m_pImpl->nCommandType = _nCommandType;
|
|
|
|
}
|
|
|
|
|
|
|
|
DynamicTableOrQueryNameCheck::~DynamicTableOrQueryNameCheck()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
bool DynamicTableOrQueryNameCheck::isNameValid( const OUString& _rObjectName, ::dbtools::SQLExceptionInfo& _out_rErrorToDisplay ) const
|
2006-07-10 14:38:03 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
m_pImpl->xObjectNames->checkNameForCreate( m_pImpl->nCommandType, _rObjectName );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
catch( const SQLException& )
|
|
|
|
{
|
|
|
|
_out_rErrorToDisplay = ::dbtools::SQLExceptionInfo( ::cppu::getCaughtException() );
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace dbaui
|
|
|
|
|
2010-10-12 15:59:03 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|