1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _CONNECTIVITY_ODATABASEMETADATABASE_HXX_
25 #define _CONNECTIVITY_ODATABASEMETADATABASE_HXX_
26 
27 #include <com/sun/star/sdbc/XDatabaseMetaData2.hpp>
28 #include <cppuhelper/implbase2.hxx>
29 #include <comphelper/broadcasthelper.hxx>
30 #include <com/sun/star/lang/XEventListener.hpp>
31 #include "FDatabaseMetaDataResultSet.hxx"
32 #include <functional>
33 #include "connectivity/dbtoolsdllapi.hxx"
34 
35 namespace connectivity
36 {
37         typedef ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >  TConditions;
38 		class OOO_DLLPUBLIC_DBTOOLS ODatabaseMetaDataBase :
39                                         public	comphelper::OBaseMutex,
40 										public ::cppu::WeakImplHelper2< ::com::sun::star::sdbc::XDatabaseMetaData2,
41 																		::com::sun::star::lang::XEventListener>
42 		{
43         private:
44             ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >   m_aConnectionInfo;
45             ::connectivity::ODatabaseMetaDataResultSet::ORows                           m_aTypeInfoRows;
46 
47             // cached database information
48             ::std::pair<bool,sal_Bool>          m_isCatalogAtStart;
49             ::std::pair<bool,::rtl::OUString>   m_sCatalogSeparator;
50             ::std::pair<bool,::rtl::OUString>   m_sIdentifierQuoteString;
51             ::std::pair<bool,sal_Bool>          m_supportsCatalogsInTableDefinitions;
52             ::std::pair<bool,sal_Bool>          m_supportsSchemasInTableDefinitions;
53             ::std::pair<bool,sal_Bool>          m_supportsCatalogsInDataManipulation;
54             ::std::pair<bool,sal_Bool>          m_supportsSchemasInDataManipulation;
55             ::std::pair<bool,sal_Bool>          m_supportsMixedCaseQuotedIdentifiers;
56             ::std::pair<bool,sal_Bool>          m_supportsAlterTableWithAddColumn;
57             ::std::pair<bool,sal_Bool>          m_supportsAlterTableWithDropColumn;
58             ::std::pair<bool,sal_Int32>         m_MaxStatements;
59             ::std::pair<bool,sal_Int32>         m_MaxTablesInSelect;
60             ::std::pair<bool,sal_Bool>          m_storesMixedCaseQuotedIdentifiers;
61 
callImplMethod(::std::pair<bool,T> & _rCache,const::std::mem_fun_t<T,ODatabaseMetaDataBase> & _pImplMethod)62             template <typename T> T callImplMethod(::std::pair<bool,T>& _rCache,const ::std::mem_fun_t<T,ODatabaseMetaDataBase>& _pImplMethod)
63             {
64                 ::osl::MutexGuard aGuard( m_aMutex );
65                 if ( !_rCache.first )
66                 {
67                     _rCache.second = _pImplMethod(this);
68                     _rCache.first = true;
69                 }
70                 return _rCache.second;
71             }
72 		protected:
73 			::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >		m_xConnection;
74 			::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener>	m_xListenerHelper; // forward the calls from the connection to me
75 
76 			virtual ~ODatabaseMetaDataBase();
77 
78         protected:
79             virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > impl_getTypeInfo_throw() = 0;
80             // cached database information
81             virtual ::rtl::OUString impl_getIdentifierQuoteString_throw(  )             = 0;
82             virtual sal_Bool        impl_isCatalogAtStart_throw(  )                     = 0;
83             virtual ::rtl::OUString impl_getCatalogSeparator_throw(  )                  = 0;
84             virtual sal_Bool        impl_supportsCatalogsInTableDefinitions_throw(  )   = 0;
85             virtual sal_Bool        impl_supportsSchemasInTableDefinitions_throw(  )    = 0;
86             virtual sal_Bool        impl_supportsCatalogsInDataManipulation_throw(  )   = 0;
87             virtual sal_Bool        impl_supportsSchemasInDataManipulation_throw(  )    = 0;
88             virtual sal_Bool        impl_supportsMixedCaseQuotedIdentifiers_throw(  )   = 0;
89             virtual sal_Bool        impl_supportsAlterTableWithAddColumn_throw(  )      = 0;
90             virtual sal_Bool        impl_supportsAlterTableWithDropColumn_throw(  )     = 0;
91             virtual sal_Int32       impl_getMaxStatements_throw(  )                     = 0;
92             virtual sal_Int32       impl_getMaxTablesInSelect_throw(  )                 = 0;
93             virtual sal_Bool        impl_storesMixedCaseQuotedIdentifiers_throw(  )     = 0;
94 
95 
96 		public:
97 
98 			ODatabaseMetaDataBase(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxConnection,const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _rInfo);
99 
100             // XDatabaseMetaData2
101             virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > SAL_CALL getConnectionInfo(  ) throw (::com::sun::star::uno::RuntimeException);
102 
103 			// XEventListener
104 			virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw(::com::sun::star::uno::RuntimeException);
105 
106             virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL getTypeInfo(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
107             virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL getProcedures( const ::com::sun::star::uno::Any& catalog, const ::rtl::OUString& schemaPattern, const ::rtl::OUString& procedureNamePattern ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
108             virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL getProcedureColumns( const ::com::sun::star::uno::Any& catalog, const ::rtl::OUString& schemaPattern, const ::rtl::OUString& procedureNamePattern, const ::rtl::OUString& columnNamePattern ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
109             virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL getSchemas(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
110             virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL getCatalogs(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
111             virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL getColumnPrivileges( const ::com::sun::star::uno::Any& catalog, const ::rtl::OUString& schema, const ::rtl::OUString& table, const ::rtl::OUString& columnNamePattern ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
112             virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL getTablePrivileges( const ::com::sun::star::uno::Any& catalog, const ::rtl::OUString& schemaPattern, const ::rtl::OUString& tableNamePattern ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
113             virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL getBestRowIdentifier( const ::com::sun::star::uno::Any& catalog, const ::rtl::OUString& schema, const ::rtl::OUString& table, sal_Int32 scope, sal_Bool nullable ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
114             virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL getVersionColumns( const ::com::sun::star::uno::Any& catalog, const ::rtl::OUString& schema, const ::rtl::OUString& table ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
115             virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL getPrimaryKeys( const ::com::sun::star::uno::Any& catalog, const ::rtl::OUString& schema, const ::rtl::OUString& table ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
116             virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL getImportedKeys( const ::com::sun::star::uno::Any& catalog, const ::rtl::OUString& schema, const ::rtl::OUString& table ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
117             virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL getExportedKeys( const ::com::sun::star::uno::Any& catalog, const ::rtl::OUString& schema, const ::rtl::OUString& table ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
118             virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL getCrossReference( const ::com::sun::star::uno::Any& primaryCatalog, const ::rtl::OUString& primarySchema, const ::rtl::OUString& primaryTable, const ::com::sun::star::uno::Any& foreignCatalog, const ::rtl::OUString& foreignSchema, const ::rtl::OUString& foreignTable ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
119             virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL getIndexInfo( const ::com::sun::star::uno::Any& catalog, const ::rtl::OUString& schema, const ::rtl::OUString& table, sal_Bool unique, sal_Bool approximate ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
120 
121             virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection > SAL_CALL getConnection(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
122             // cached database information
123             virtual ::rtl::OUString SAL_CALL getIdentifierQuoteString(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
124             virtual sal_Bool SAL_CALL isCatalogAtStart(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
125             virtual ::rtl::OUString SAL_CALL getCatalogSeparator(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
126             virtual sal_Bool SAL_CALL supportsCatalogsInTableDefinitions(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
127             virtual sal_Bool SAL_CALL supportsSchemasInTableDefinitions(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
128             virtual sal_Bool SAL_CALL supportsCatalogsInDataManipulation(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
129             virtual sal_Bool SAL_CALL supportsSchemasInDataManipulation(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
130             virtual sal_Bool SAL_CALL supportsMixedCaseQuotedIdentifiers(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
131             virtual sal_Bool SAL_CALL supportsAlterTableWithAddColumn(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
132             virtual sal_Bool SAL_CALL supportsAlterTableWithDropColumn(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
133             virtual sal_Int32 SAL_CALL getMaxStatements(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
134             virtual sal_Int32 SAL_CALL getMaxTablesInSelect(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
135             virtual sal_Bool SAL_CALL storesMixedCaseQuotedIdentifiers(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
136 		};
137 }
138 #endif // _CONNECTIVITY_ODATABASEMETADATABASE_HXX_
139