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