28#include <core_resource.hxx>
35#include <com/sun/star/lang/NoSupportException.hpp>
36#include <com/sun/star/sdb/CommandType.hpp>
37#include <com/sun/star/sdb/tools/ConnectionTools.hpp>
38#include <com/sun/star/reflection/ProxyFactory.hpp>
39#include <com/sun/star/beans/NamedValue.hpp>
43#include <osl/diagnose.h>
61using namespace ::
cppu;
64using ::com::sun::star::sdb::tools::XTableName;
65using ::com::sun::star::sdb::tools::XObjectNames;
66using ::com::sun::star::sdb::tools::XDataSourceMetaData;
74 return "com.sun.star.comp.dbaccess.Connection";
84 Sequence< OUString > aSupported = OConnectionWrapper::getSupportedServiceNames();
88 sal_Int32 nLen = aSupported.getLength();
89 aSupported.realloc( nLen + 1 );
115 Reference< XStatement > xStatement;
117 if ( xMasterStatement.is() )
119 xStatement =
new OStatement(
this, xMasterStatement);
131 Reference< XPreparedStatement > xStatement;
133 if ( xMasterStatement.is() )
146 Reference< XPreparedStatement > xStatement;
148 if ( xMasterStatement.is() )
257 , Reference< XConnection >
const & _rxMaster
258 ,
const Reference< XComponentContext >& _rxORB)
263 ,m_aTableFilter(_rDB.
m_pImpl->m_aTableFilter)
264 ,m_aTableTypeFilter(_rDB.
m_pImpl->m_aTableTypeFilter)
266 ,m_xMasterConnection(_rxMaster)
267 ,m_aWarnings(
Reference< XWarningsSupplier >( _rxMaster, UNO_QUERY ) )
269 ,m_bSupportsViews(false)
270 ,m_bSupportsUsers(false)
271 ,m_bSupportsGroups(false)
273 osl_atomic_increment(&m_refCount);
277 Reference< XProxyFactory > xProxyFactory = ProxyFactory::create(
m_aContext );
278 Reference<XAggregation> xAgg = xProxyFactory->createProxy(_rxMaster);
280 OSL_ENSURE(
m_xConnection.is(),
"OConnection::OConnection : invalid master connection !");
282 catch(
const Exception&)
294 Reference<XDatabaseMetaData> xMeta;
298 bCase = xMeta.is() && xMeta->supportsMixedCaseQuotedIdentifiers();
300 catch(
const SQLException&)
303 Reference< XNameContainer > xTableDefinitions(_rDB.getTables(),UNO_QUERY);
309 Reference<XResultSet> xRes = xMeta->getTableTypes();
312 Reference<XRow> xRow(xRes,UNO_QUERY);
315 OUString sValue = xRow->getString(1);
316 if( !xRow->wasNull() && sValue ==
"VIEW")
328 if (xMaster.is() && xMaster->getViews().is())
343 catch(
const Exception& )
347 osl_atomic_decrement( &m_refCount );
371 struct CompareTypeByName
373 bool operator() (
const Type& _rLHS,
const Type& _rRHS )
const
375 return _rLHS.getTypeName() < _rRHS.getTypeName();
378 typedef std::set< Type, CompareTypeByName >
TypeBag;
380 void lcl_copyTypes(
TypeBag& _out_rTypes,
const Sequence< Type >& _rTypes )
382 std::copy( _rTypes.begin(), _rTypes.end(),
383 std::insert_iterator< TypeBag >( _out_rTypes, _out_rTypes.begin() ) );
392 lcl_copyTypes( aNormalizedTypes, OSubComponent::getTypes() );
408 return css::uno::Sequence<sal_Int8>();
420 Any aReturn = OSubComponent::queryInterface( rType );
421 if (!aReturn.hasValue())
424 if (!aReturn.hasValue())
433 OSubComponent::acquire();
447 OSubComponent::disposing();
452 Reference<XComponent> xComp(statement.get(),UNO_QUERY);
453 ::comphelper::disposeComponent(xComp);
467 Reference<XComponent> xComp(composer.get(),UNO_QUERY);
468 ::comphelper::disposeComponent(xComp);
494 throw NoSupportException();
504 Reference< XSQLQueryComposer > xComposer(
new OQueryComposer(
this ) );
511 Reference<XPropertySet> xProp(
getParent(),UNO_QUERY);
521 if ( _rToBeRefreshed == Reference< XNameAccess >(
m_pTables.get()) )
539 else if ( _rToBeRefreshed == Reference< XNameAccess >(
m_pViews.get()) )
547 if (xMaster.is() && xMaster->getViews().is())
596 aStatement =
"SELECT * FROM ";
599 ::dbtools::qualifiedNameComponents(
getMetaData(), command,
sCatalog,
sSchema, sTable, ::dbtools::EComposeRule::InDataManipulation );
600 aStatement += ::dbtools::composeTableNameForSelect(
this,
sCatalog,
sSchema, sTable );
606 Reference< XPropertySet > xQuery(
m_xQueries->getByName(command),UNO_QUERY);
611 aStatement = command;
619 Reference< XServiceInfo > xRet;
627 if ( !_sServiceSpecifier.isEmpty() )
632 Reference<XConnection> xMy(
this);
633 Sequence<Any> aArgs{
Any(NamedValue(
"ActiveConnection",
Any(xMy))) };
636 m_aContext->getServiceManager()->createInstanceWithArgumentsAndContext(_sServiceSpecifier, aArgs,
m_aContext)
639 return aFind->second;
642 return Reference<XInterface>(xRet, UNO_QUERY);
663 Reference<XDatabaseMetaData> xMeta =
getMetaData();
667 catch(
const SQLException&)
681 return xUsr.is() ? xUsr->getUsers() : Reference< XNameAccess >();
690 return xGrp.is() ? xGrp->getGroups() : Reference< XNameAccess >();
731 return m_xConnectionTools->getFieldsByCommandDescriptor(commandType,command,keepFieldsAlive);
752 Reference< XNameAccess > xTables(
getTables() );
753 const Sequence< OUString > aTableNames( xTables->getElementNames() );
754 std::set< OUString > aSortedTableNames( aTableNames.begin(), aTableNames.end() );
756 Reference< XNameAccess > xQueries(
getQueries() );
757 const Sequence< OUString > aQueryNames( xQueries->getElementNames() );
759 for (
auto const & queryName : aQueryNames )
761 if ( aSortedTableNames.find( queryName ) != aSortedTableNames.end() )
763 OUString sConflictWarning(
DBA_RES( RID_STR_CONFLICTING_NAMES ) );
776 Reference< XGraphic > xReturn;
792 Reference< XInterface > xReturn;
css::uno::Reference< css::uno::XInterface > m_xParent
virtual void SAL_CALL release() noexcept override
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &_rType) override
void setDelegation(css::uno::Reference< css::uno::XAggregation > &_rxProxyConnection, oslInterlockedCount &_rRefCount)
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
css::uno::Reference< css::sdbc::XConnection > m_xConnection
mutable::osl::Mutex m_aMutex
virtual css::uno::Any SAL_CALL queryInterface(css::uno::Type const &rType) SAL_OVERRIDE
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() SAL_OVERRIDE
virtual css::uno::Reference< css::sdb::tools::XDataSourceMetaData > SAL_CALL getDataSourceMetaData() override
virtual void SAL_CALL setParent(const css::uno::Reference< css::uno::XInterface > &Parent) override
virtual void SAL_CALL close() override
virtual void SAL_CALL release() noexcept override
virtual void SAL_CALL disposing() override
virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstance(const OUString &aServiceSpecifier) override
virtual void SAL_CALL setReadOnly(sal_Bool readOnly) override
virtual css::uno::Reference< css::container::XNameAccess > SAL_CALL getUsers() override
css::uno::Reference< css::sdbcx::XTablesSupplier > const & getMasterTables()
virtual css::uno::Reference< css::sdbc::XPreparedStatement > SAL_CALL prepareCall(const OUString &sql) override
void impl_loadConnectionTools_throw()
loads the XConnectionTools implementation which we forward the respective functionality to
virtual css::uno::Reference< css::sdb::tools::XTableName > SAL_CALL createTableName() override
OConnection(ODatabaseSource &_rDB, css::uno::Reference< css::sdbc::XConnection > const &_rxMaster, const css::uno::Reference< css::uno::XComponentContext > &_rxORB)
virtual void SAL_CALL setAutoCommit(sal_Bool autoCommit) override
virtual css::uno::Reference< css::sdb::XSingleSelectQueryComposer > SAL_CALL getComposer(::sal_Int32 commandType, const OUString &command) override
virtual css::uno::Reference< css::container::XNameAccess > SAL_CALL getFieldsByCommandDescriptor(::sal_Int32 commandType, const OUString &command, css::uno::Reference< css::lang::XComponent > &keepFieldsAlive) override
::dbtools::WarningsContainer m_aWarnings
virtual void SAL_CALL setCatalog(const OUString &catalog) override
void impl_checkTableQueryNames_nothrow()
checks whether or not there are naming conflicts between tables and queries
virtual sal_Int32 SAL_CALL getTransactionIsolation() override
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) override
virtual css::uno::Reference< css::container::XNameAccess > SAL_CALL getTypeMap() override
virtual css::uno::Reference< css::sdb::XSQLQueryComposer > SAL_CALL createQueryComposer() override
virtual css::uno::Reference< css::sdbc::XDatabaseMetaData > SAL_CALL getMetaData() override
css::uno::Reference< css::container::XNameAccess > m_xQueries
virtual void SAL_CALL commit() override
css::uno::Reference< css::sdbc::XConnection > m_xMasterConnection
virtual css::uno::Reference< css::container::XNameAccess > SAL_CALL getViews() override
css::uno::Sequence< OUString > m_aTableTypeFilter
connectivity::OWeakRefArray m_aComposers
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual void SAL_CALL rollback() override
virtual ~OConnection() override
virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getParent() override
virtual void refresh(const css::uno::Reference< css::container::XNameAccess > &_rToBeRefreshed) override
css::uno::Reference< css::sdb::tools::XConnectionTools > m_xConnectionTools
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual void SAL_CALL setTypeMap(const css::uno::Reference< css::container::XNameAccess > &typeMap) override
virtual void SAL_CALL clearWarnings() override
css::uno::Reference< css::sdb::application::XTableUIProvider > m_xTableUIProvider
std::unique_ptr< OTableContainer > m_pTables
virtual css::uno::Reference< css::graphic::XGraphic > SAL_CALL getTableIcon(const OUString &TableName, ::sal_Int32 ColorMode) override
virtual css::uno::Reference< css::sdb::tools::XObjectNames > SAL_CALL getObjectNames() override
virtual css::uno::Reference< css::sdbc::XPreparedStatement > SAL_CALL prepareCommand(const OUString &command, sal_Int32 commandType) override
virtual OUString SAL_CALL getCatalog() override
virtual sal_Bool SAL_CALL getAutoCommit() override
virtual css::uno::Reference< css::container::XNameAccess > SAL_CALL getGroups() override
TSupportServices m_aSupportServices
void impl_fillTableFilter()
reads the table filter and table type filter from the datasource
css::uno::Reference< css::uno::XComponentContext > m_aContext
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override
virtual sal_Bool SAL_CALL isReadOnly() override
virtual css::uno::Reference< css::sdbc::XStatement > SAL_CALL createStatement() override
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
virtual css::uno::Reference< css::sdbc::XPreparedStatement > SAL_CALL prepareStatement(const OUString &sql) override
virtual void SAL_CALL acquire() noexcept override
connectivity::OWeakRefArray m_aStatements
virtual css::uno::Reference< css::container::XNameAccess > SAL_CALL getTables() override
std::atomic< std::size_t > m_nInAppend
virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getTableEditor(const css::uno::Reference< css::sdb::application::XDatabaseDocumentUI > &DocumentUI, const OUString &TableName) override
virtual OUString SAL_CALL getImplementationName() override
virtual OUString SAL_CALL nativeSQL(const OUString &sql) override
virtual sal_Bool SAL_CALL isClosed() override
virtual css::uno::Sequence< OUString > SAL_CALL getAvailableServiceNames() override
std::unique_ptr< OViewContainer > m_pViews
virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstanceWithArguments(const OUString &ServiceSpecifier, const css::uno::Sequence< css::uno::Any > &Arguments) override
virtual css::uno::Any SAL_CALL getWarnings() override
virtual css::uno::Reference< css::container::XNameAccess > SAL_CALL getQueries() override
css::uno::Reference< css::sdbcx::XTablesSupplier > m_xMasterTables
virtual void SAL_CALL setTransactionIsolation(sal_Int32 level) override
css::uno::Sequence< OUString > m_aTableFilter
static rtl::Reference< OQueryContainer > create(const css::uno::Reference< css::container::XNameContainer > &_rxCommandDefinitions, const css::uno::Reference< css::sdbc::XConnection > &_rxConn, const css::uno::Reference< css::uno::XComponentContext > &_rxORB, ::dbtools::WarningsContainer *_pWarnings)
Reference< XComponentContext > m_aContext
#define DBG_UNHANDLED_EXCEPTION(...)
sal_Int32 findValue(const css::uno::Sequence< T1 > &_rList, const T2 &_rValue)
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
std::set< css::uno::Type, UnoTypeLess > TypeBag
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
constexpr OUStringLiteral PROPERTY_COMMAND(u"Command")
constexpr OUStringLiteral PROPERTY_TABLEFILTER(u"TableFilter")
constexpr OUStringLiteral SERVICE_SDB_CONNECTION
constexpr OUStringLiteral SERVICE_NAME_SINGLESELECTQUERYCOMPOSER
constexpr OUStringLiteral PROPERTY_TABLETYPEFILTER(u"TableTypeFilter")