1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #ifndef _CONNECTIVITY_ODATABASEMETADATABASE_HXX_
29*cdf0e10cSrcweir #define _CONNECTIVITY_ODATABASEMETADATABASE_HXX_
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <com/sun/star/sdbc/XDatabaseMetaData2.hpp>
32*cdf0e10cSrcweir #include <cppuhelper/implbase2.hxx>
33*cdf0e10cSrcweir #include <comphelper/broadcasthelper.hxx>
34*cdf0e10cSrcweir #include <com/sun/star/lang/XEventListener.hpp>
35*cdf0e10cSrcweir #include "FDatabaseMetaDataResultSet.hxx"
36*cdf0e10cSrcweir #include <functional>
37*cdf0e10cSrcweir #include "connectivity/dbtoolsdllapi.hxx"
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir namespace connectivity
40*cdf0e10cSrcweir {
41*cdf0e10cSrcweir         typedef ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >  TConditions;
42*cdf0e10cSrcweir 		class OOO_DLLPUBLIC_DBTOOLS ODatabaseMetaDataBase :
43*cdf0e10cSrcweir                                         public	comphelper::OBaseMutex,
44*cdf0e10cSrcweir 										public ::cppu::WeakImplHelper2< ::com::sun::star::sdbc::XDatabaseMetaData2,
45*cdf0e10cSrcweir 																		::com::sun::star::lang::XEventListener>
46*cdf0e10cSrcweir 		{
47*cdf0e10cSrcweir         private:
48*cdf0e10cSrcweir             ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >   m_aConnectionInfo;
49*cdf0e10cSrcweir             ::connectivity::ODatabaseMetaDataResultSet::ORows                           m_aTypeInfoRows;
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir             // cached database information
52*cdf0e10cSrcweir             ::std::pair<bool,sal_Bool>          m_isCatalogAtStart;
53*cdf0e10cSrcweir             ::std::pair<bool,::rtl::OUString>   m_sCatalogSeparator;
54*cdf0e10cSrcweir             ::std::pair<bool,::rtl::OUString>   m_sIdentifierQuoteString;
55*cdf0e10cSrcweir             ::std::pair<bool,sal_Bool>          m_supportsCatalogsInTableDefinitions;
56*cdf0e10cSrcweir             ::std::pair<bool,sal_Bool>          m_supportsSchemasInTableDefinitions;
57*cdf0e10cSrcweir             ::std::pair<bool,sal_Bool>          m_supportsCatalogsInDataManipulation;
58*cdf0e10cSrcweir             ::std::pair<bool,sal_Bool>          m_supportsSchemasInDataManipulation;
59*cdf0e10cSrcweir             ::std::pair<bool,sal_Bool>          m_supportsMixedCaseQuotedIdentifiers;
60*cdf0e10cSrcweir             ::std::pair<bool,sal_Bool>          m_supportsAlterTableWithAddColumn;
61*cdf0e10cSrcweir             ::std::pair<bool,sal_Bool>          m_supportsAlterTableWithDropColumn;
62*cdf0e10cSrcweir             ::std::pair<bool,sal_Int32>         m_MaxStatements;
63*cdf0e10cSrcweir             ::std::pair<bool,sal_Int32>         m_MaxTablesInSelect;
64*cdf0e10cSrcweir             ::std::pair<bool,sal_Bool>          m_storesMixedCaseQuotedIdentifiers;
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir             template <typename T> T callImplMethod(::std::pair<bool,T>& _rCache,const ::std::mem_fun_t<T,ODatabaseMetaDataBase>& _pImplMethod)
67*cdf0e10cSrcweir             {
68*cdf0e10cSrcweir                 ::osl::MutexGuard aGuard( m_aMutex );
69*cdf0e10cSrcweir                 if ( !_rCache.first )
70*cdf0e10cSrcweir                 {
71*cdf0e10cSrcweir                     _rCache.second = _pImplMethod(this);
72*cdf0e10cSrcweir                     _rCache.first = true;
73*cdf0e10cSrcweir                 }
74*cdf0e10cSrcweir                 return _rCache.second;
75*cdf0e10cSrcweir             }
76*cdf0e10cSrcweir 		protected:
77*cdf0e10cSrcweir 			::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >		m_xConnection;
78*cdf0e10cSrcweir 			::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener>	m_xListenerHelper; // forward the calls from the connection to me
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir 			virtual ~ODatabaseMetaDataBase();
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir         protected:
83*cdf0e10cSrcweir             virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > impl_getTypeInfo_throw() = 0;
84*cdf0e10cSrcweir             // cached database information
85*cdf0e10cSrcweir             virtual ::rtl::OUString impl_getIdentifierQuoteString_throw(  )             = 0;
86*cdf0e10cSrcweir             virtual sal_Bool        impl_isCatalogAtStart_throw(  )                     = 0;
87*cdf0e10cSrcweir             virtual ::rtl::OUString impl_getCatalogSeparator_throw(  )                  = 0;
88*cdf0e10cSrcweir             virtual sal_Bool        impl_supportsCatalogsInTableDefinitions_throw(  )   = 0;
89*cdf0e10cSrcweir             virtual sal_Bool        impl_supportsSchemasInTableDefinitions_throw(  )    = 0;
90*cdf0e10cSrcweir             virtual sal_Bool        impl_supportsCatalogsInDataManipulation_throw(  )   = 0;
91*cdf0e10cSrcweir             virtual sal_Bool        impl_supportsSchemasInDataManipulation_throw(  )    = 0;
92*cdf0e10cSrcweir             virtual sal_Bool        impl_supportsMixedCaseQuotedIdentifiers_throw(  )   = 0;
93*cdf0e10cSrcweir             virtual sal_Bool        impl_supportsAlterTableWithAddColumn_throw(  )      = 0;
94*cdf0e10cSrcweir             virtual sal_Bool        impl_supportsAlterTableWithDropColumn_throw(  )     = 0;
95*cdf0e10cSrcweir             virtual sal_Int32       impl_getMaxStatements_throw(  )                     = 0;
96*cdf0e10cSrcweir             virtual sal_Int32       impl_getMaxTablesInSelect_throw(  )                 = 0;
97*cdf0e10cSrcweir             virtual sal_Bool        impl_storesMixedCaseQuotedIdentifiers_throw(  )     = 0;
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir 		public:
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir 			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);
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir             // XDatabaseMetaData2
105*cdf0e10cSrcweir             virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > SAL_CALL getConnectionInfo(  ) throw (::com::sun::star::uno::RuntimeException);
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir 			// XEventListener
108*cdf0e10cSrcweir 			virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw(::com::sun::star::uno::RuntimeException);
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir             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);
111*cdf0e10cSrcweir             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);
112*cdf0e10cSrcweir             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);
113*cdf0e10cSrcweir             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);
114*cdf0e10cSrcweir             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);
115*cdf0e10cSrcweir             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);
116*cdf0e10cSrcweir             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);
117*cdf0e10cSrcweir             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);
118*cdf0e10cSrcweir             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);
119*cdf0e10cSrcweir             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);
120*cdf0e10cSrcweir             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);
121*cdf0e10cSrcweir             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);
122*cdf0e10cSrcweir             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);
123*cdf0e10cSrcweir             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);
124*cdf0e10cSrcweir 
125*cdf0e10cSrcweir             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);
126*cdf0e10cSrcweir             // cached database information
127*cdf0e10cSrcweir             virtual ::rtl::OUString SAL_CALL getIdentifierQuoteString(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
128*cdf0e10cSrcweir             virtual sal_Bool SAL_CALL isCatalogAtStart(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
129*cdf0e10cSrcweir             virtual ::rtl::OUString SAL_CALL getCatalogSeparator(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
130*cdf0e10cSrcweir             virtual sal_Bool SAL_CALL supportsCatalogsInTableDefinitions(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
131*cdf0e10cSrcweir             virtual sal_Bool SAL_CALL supportsSchemasInTableDefinitions(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
132*cdf0e10cSrcweir             virtual sal_Bool SAL_CALL supportsCatalogsInDataManipulation(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
133*cdf0e10cSrcweir             virtual sal_Bool SAL_CALL supportsSchemasInDataManipulation(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
134*cdf0e10cSrcweir             virtual sal_Bool SAL_CALL supportsMixedCaseQuotedIdentifiers(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
135*cdf0e10cSrcweir             virtual sal_Bool SAL_CALL supportsAlterTableWithAddColumn(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
136*cdf0e10cSrcweir             virtual sal_Bool SAL_CALL supportsAlterTableWithDropColumn(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
137*cdf0e10cSrcweir             virtual sal_Int32 SAL_CALL getMaxStatements(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
138*cdf0e10cSrcweir             virtual sal_Int32 SAL_CALL getMaxTablesInSelect(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
139*cdf0e10cSrcweir             virtual sal_Bool SAL_CALL storesMixedCaseQuotedIdentifiers(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
140*cdf0e10cSrcweir 		};
141*cdf0e10cSrcweir }
142*cdf0e10cSrcweir #endif // _CONNECTIVITY_ODATABASEMETADATABASE_HXX_
143