1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 /* 3 * This file is part of the LibreOffice project. 4 * 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/. 8 * 9 * This file incorporates work covered by the following license notice: 10 * 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 . 18 */ 19 20 #pragma once 21 22 #include <com/sun/star/sdbc/XDatabaseMetaData2.hpp> 23 #include <cppuhelper/implbase.hxx> 24 #include <cppuhelper/basemutex.hxx> 25 #include <com/sun/star/lang/XEventListener.hpp> 26 #include "FDatabaseMetaDataResultSet.hxx" 27 #include <functional> 28 #include <connectivity/dbtoolsdllapi.hxx> 29 30 namespace connectivity 31 { 32 class OOO_DLLPUBLIC_DBTOOLS ODatabaseMetaDataBase : 33 public cppu::BaseMutex, 34 public ::cppu::WeakImplHelper< css::sdbc::XDatabaseMetaData2, 35 css::lang::XEventListener> 36 { 37 private: 38 css::uno::Sequence< css::beans::PropertyValue > m_aConnectionInfo; 39 ::connectivity::ODatabaseMetaDataResultSet::ORows m_aTypeInfoRows; 40 41 // cached database information 42 std::pair<bool,bool> m_isCatalogAtStart; 43 std::pair<bool,OUString> m_sCatalogSeparator; 44 std::pair<bool,OUString> m_sIdentifierQuoteString; 45 std::pair<bool,bool> m_supportsCatalogsInTableDefinitions; 46 std::pair<bool,bool> m_supportsSchemasInTableDefinitions; 47 std::pair<bool,bool> m_supportsCatalogsInDataManipulation; 48 std::pair<bool,bool> m_supportsSchemasInDataManipulation; 49 std::pair<bool,bool> m_supportsMixedCaseQuotedIdentifiers; 50 std::pair<bool,bool> m_supportsAlterTableWithAddColumn; 51 std::pair<bool,bool> m_supportsAlterTableWithDropColumn; 52 std::pair<bool,sal_Int32> m_MaxStatements; 53 std::pair<bool,sal_Int32> m_MaxTablesInSelect; 54 std::pair<bool,bool> m_storesMixedCaseQuotedIdentifiers; 55 callImplMethod(std::pair<bool,T> & _rCache,const std::function<T (ODatabaseMetaDataBase *)> & _pImplMethod)56 template <typename T> T callImplMethod(std::pair<bool,T>& _rCache,const std::function<T(ODatabaseMetaDataBase *)>& _pImplMethod) 57 { 58 ::osl::MutexGuard aGuard( m_aMutex ); 59 if ( !_rCache.first ) 60 { 61 _rCache.second = _pImplMethod(this); 62 _rCache.first = true; 63 } 64 return _rCache.second; 65 } 66 protected: 67 css::uno::Reference< css::sdbc::XConnection > m_xConnection; 68 css::uno::Reference< css::lang::XEventListener> m_xListenerHelper; // forward the calls from the connection to me 69 70 virtual ~ODatabaseMetaDataBase() override; 71 72 protected: 73 virtual css::uno::Reference< css::sdbc::XResultSet > impl_getTypeInfo_throw() = 0; 74 // cached database information 75 virtual OUString impl_getIdentifierQuoteString_throw( ) = 0; 76 virtual bool impl_isCatalogAtStart_throw( ) = 0; 77 virtual OUString impl_getCatalogSeparator_throw( ) = 0; 78 virtual bool impl_supportsCatalogsInTableDefinitions_throw( ) = 0; 79 virtual bool impl_supportsSchemasInTableDefinitions_throw( ) = 0; 80 virtual bool impl_supportsCatalogsInDataManipulation_throw( ) = 0; 81 virtual bool impl_supportsSchemasInDataManipulation_throw( ) = 0; 82 virtual bool impl_supportsMixedCaseQuotedIdentifiers_throw( ) = 0; 83 virtual bool impl_supportsAlterTableWithAddColumn_throw( ) = 0; 84 virtual bool impl_supportsAlterTableWithDropColumn_throw( ) = 0; 85 virtual sal_Int32 impl_getMaxStatements_throw( ) = 0; 86 virtual sal_Int32 impl_getMaxTablesInSelect_throw( ) = 0; 87 virtual bool impl_storesMixedCaseQuotedIdentifiers_throw( ) = 0; 88 89 90 public: 91 92 ODatabaseMetaDataBase(const css::uno::Reference< css::sdbc::XConnection >& _rxConnection,const css::uno::Sequence< css::beans::PropertyValue >& _rInfo); 93 94 // XDatabaseMetaData2 95 virtual css::uno::Sequence< css::beans::PropertyValue > SAL_CALL getConnectionInfo( ) override; 96 97 // XEventListener 98 virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override; 99 100 virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getTypeInfo( ) override; 101 virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getProcedures( const css::uno::Any& catalog, const OUString& schemaPattern, const OUString& procedureNamePattern ) override; 102 virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getProcedureColumns( const css::uno::Any& catalog, const OUString& schemaPattern, const OUString& procedureNamePattern, const OUString& columnNamePattern ) override; 103 virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getSchemas( ) override; 104 virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getCatalogs( ) override; 105 virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getColumnPrivileges( const css::uno::Any& catalog, const OUString& schema, const OUString& table, const OUString& columnNamePattern ) override; 106 virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getTablePrivileges( const css::uno::Any& catalog, const OUString& schemaPattern, const OUString& tableNamePattern ) override; 107 virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getBestRowIdentifier( const css::uno::Any& catalog, const OUString& schema, const OUString& table, sal_Int32 scope, sal_Bool nullable ) override; 108 virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getVersionColumns( const css::uno::Any& catalog, const OUString& schema, const OUString& table ) override; 109 virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getPrimaryKeys( const css::uno::Any& catalog, const OUString& schema, const OUString& table ) override; 110 virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getImportedKeys( const css::uno::Any& catalog, const OUString& schema, const OUString& table ) override; 111 virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getExportedKeys( const css::uno::Any& catalog, const OUString& schema, const OUString& table ) override; 112 virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getCrossReference( const css::uno::Any& primaryCatalog, const OUString& primarySchema, const OUString& primaryTable, const css::uno::Any& foreignCatalog, const OUString& foreignSchema, const OUString& foreignTable ) override; 113 virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getIndexInfo( const css::uno::Any& catalog, const OUString& schema, const OUString& table, sal_Bool unique, sal_Bool approximate ) override; 114 115 virtual css::uno::Reference< css::sdbc::XConnection > SAL_CALL getConnection( ) override; 116 // cached database information 117 virtual OUString SAL_CALL getIdentifierQuoteString( ) override; 118 virtual sal_Bool SAL_CALL isCatalogAtStart( ) override; 119 virtual OUString SAL_CALL getCatalogSeparator( ) override; 120 virtual sal_Bool SAL_CALL supportsCatalogsInTableDefinitions( ) override; 121 virtual sal_Bool SAL_CALL supportsSchemasInTableDefinitions( ) override; 122 virtual sal_Bool SAL_CALL supportsCatalogsInDataManipulation( ) override; 123 virtual sal_Bool SAL_CALL supportsSchemasInDataManipulation( ) override; 124 virtual sal_Bool SAL_CALL supportsMixedCaseQuotedIdentifiers( ) override; 125 virtual sal_Bool SAL_CALL supportsAlterTableWithAddColumn( ) override; 126 virtual sal_Bool SAL_CALL supportsAlterTableWithDropColumn( ) override; 127 virtual sal_Int32 SAL_CALL getMaxStatements( ) override; 128 virtual sal_Int32 SAL_CALL getMaxTablesInSelect( ) override; 129 virtual sal_Bool SAL_CALL storesMixedCaseQuotedIdentifiers( ) override; 130 }; 131 } 132 133 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 134