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 #ifndef _CONNECTIVITY_ADO_ACONNECTION_HXX_
24cdf0e10cSrcweir #define _CONNECTIVITY_ADO_ACONNECTION_HXX_
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include <com/sun/star/sdbc/SQLWarning.hpp>
27cdf0e10cSrcweir #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
28cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
29cdf0e10cSrcweir #include "OSubComponent.hxx"
30cdf0e10cSrcweir #include <map>
31cdf0e10cSrcweir #include "connectivity/CommonTools.hxx"
32cdf0e10cSrcweir #include "OTypeInfo.hxx"
33cdf0e10cSrcweir #include "TConnection.hxx"
34cdf0e10cSrcweir #include "ado/Awrapado.hxx"
35cdf0e10cSrcweir 
36cdf0e10cSrcweir namespace connectivity
37cdf0e10cSrcweir {
38cdf0e10cSrcweir 	namespace ado
39cdf0e10cSrcweir 	{
40cdf0e10cSrcweir 		struct OExtendedTypeInfo
41cdf0e10cSrcweir 		{
42cdf0e10cSrcweir 			::connectivity::OTypeInfo		aSimpleType;	// the general type info
43cdf0e10cSrcweir 			DataTypeEnum					eType;
44cdf0e10cSrcweir 
getDBNameconnectivity::ado::OExtendedTypeInfo45cdf0e10cSrcweir 			inline ::rtl::OUString getDBName() const { return aSimpleType.aTypeName; }
46cdf0e10cSrcweir 		};
47cdf0e10cSrcweir 
48cdf0e10cSrcweir 		class WpADOConnection;
49cdf0e10cSrcweir 		class ODriver;
50cdf0e10cSrcweir 		class OCatalog;
51cdf0e10cSrcweir 		typedef ::std::multimap<DataTypeEnum, OExtendedTypeInfo*>		OTypeInfoMap;
52cdf0e10cSrcweir 		typedef connectivity::OMetaConnection							OConnection_BASE;
53cdf0e10cSrcweir 
54cdf0e10cSrcweir 
55cdf0e10cSrcweir 		class OConnection : public OConnection_BASE,
56cdf0e10cSrcweir 							public connectivity::OSubComponent<OConnection, OConnection_BASE>
57cdf0e10cSrcweir 		{
58cdf0e10cSrcweir 			friend class connectivity::OSubComponent<OConnection, OConnection_BASE>;
59cdf0e10cSrcweir 
60cdf0e10cSrcweir 		protected:
61cdf0e10cSrcweir 			//====================================================================
62cdf0e10cSrcweir 			// Data attributes
63cdf0e10cSrcweir 			//====================================================================
64cdf0e10cSrcweir 			OTypeInfoMap				m_aTypeInfo;	//	vector containing an entry
65cdf0e10cSrcweir 																				//  for each row returned by
66cdf0e10cSrcweir 																				//  DatabaseMetaData.getTypeInfo.
67cdf0e10cSrcweir             ::com::sun::star::uno::WeakReference< ::com::sun::star::sdbcx::XTablesSupplier>      m_xCatalog;
68cdf0e10cSrcweir 			ODriver*					m_pDriver;
69cdf0e10cSrcweir 		private:
70cdf0e10cSrcweir 			WpADOConnection*			m_pAdoConnection;
71cdf0e10cSrcweir 			OCatalog*					m_pCatalog;
72cdf0e10cSrcweir 			sal_Int32					m_nEngineType;
73cdf0e10cSrcweir 			sal_Bool					m_bClosed;
74cdf0e10cSrcweir 			sal_Bool					m_bAutocommit;
75cdf0e10cSrcweir 
76cdf0e10cSrcweir 		protected:
77cdf0e10cSrcweir             void buildTypeInfo() throw( ::com::sun::star::sdbc::SQLException);
78cdf0e10cSrcweir 		public:
79cdf0e10cSrcweir 
80cdf0e10cSrcweir             OConnection(ODriver*        _pDriver) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
81cdf0e10cSrcweir 			//	OConnection(const SQLHANDLE _pConnectionHandle);
82cdf0e10cSrcweir 			~OConnection();
83cdf0e10cSrcweir             void construct(const ::rtl::OUString& url,const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& info);
84cdf0e10cSrcweir 
85cdf0e10cSrcweir             void closeAllStatements () throw( ::com::sun::star::sdbc::SQLException);
86cdf0e10cSrcweir 
87cdf0e10cSrcweir 			//XUnoTunnel
88cdf0e10cSrcweir 			virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier ) throw (::com::sun::star::uno::RuntimeException);
89cdf0e10cSrcweir 			static ::com::sun::star::uno::Sequence< sal_Int8 > getUnoTunnelImplementationId();
90cdf0e10cSrcweir 			// XServiceInfo
91cdf0e10cSrcweir 			DECLARE_SERVICE_INFO();
92cdf0e10cSrcweir 			// OComponentHelper
93cdf0e10cSrcweir 			virtual void SAL_CALL disposing(void);
94cdf0e10cSrcweir 			// XInterface
95cdf0e10cSrcweir 			virtual void SAL_CALL release() throw();
96cdf0e10cSrcweir 
97cdf0e10cSrcweir 			// XConnection
98cdf0e10cSrcweir             virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XStatement > SAL_CALL createStatement(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
99cdf0e10cSrcweir             virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XPreparedStatement > SAL_CALL prepareStatement( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
100cdf0e10cSrcweir             virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XPreparedStatement > SAL_CALL prepareCall( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
101cdf0e10cSrcweir             virtual ::rtl::OUString SAL_CALL nativeSQL( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
102cdf0e10cSrcweir             virtual void SAL_CALL setAutoCommit( sal_Bool autoCommit ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
103cdf0e10cSrcweir             virtual sal_Bool SAL_CALL getAutoCommit(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
104cdf0e10cSrcweir             virtual void SAL_CALL commit(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
105cdf0e10cSrcweir             virtual void SAL_CALL rollback(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
106cdf0e10cSrcweir             virtual sal_Bool SAL_CALL isClosed(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
107cdf0e10cSrcweir             virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDatabaseMetaData > SAL_CALL getMetaData(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
108cdf0e10cSrcweir             virtual void SAL_CALL setReadOnly( sal_Bool readOnly ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
109cdf0e10cSrcweir             virtual sal_Bool SAL_CALL isReadOnly(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
110cdf0e10cSrcweir             virtual void SAL_CALL setCatalog( const ::rtl::OUString& catalog ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
111cdf0e10cSrcweir             virtual ::rtl::OUString SAL_CALL getCatalog(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
112cdf0e10cSrcweir             virtual void SAL_CALL setTransactionIsolation( sal_Int32 level ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
113cdf0e10cSrcweir             virtual sal_Int32 SAL_CALL getTransactionIsolation(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
114cdf0e10cSrcweir             virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > SAL_CALL getTypeMap(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
115cdf0e10cSrcweir             virtual void SAL_CALL setTypeMap( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& typeMap ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
116cdf0e10cSrcweir 			// XCloseable
117cdf0e10cSrcweir 			virtual void SAL_CALL close(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
118cdf0e10cSrcweir 			// XWarningsSupplier
119cdf0e10cSrcweir 			virtual ::com::sun::star::uno::Any SAL_CALL getWarnings(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
120cdf0e10cSrcweir 			virtual void SAL_CALL clearWarnings(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
121cdf0e10cSrcweir 			//
getConnection()122cdf0e10cSrcweir 			WpADOConnection* getConnection() { return m_pAdoConnection; }
setCatalog(const::com::sun::star::uno::WeakReference<::com::sun::star::sdbcx::XTablesSupplier> & _xCat)123cdf0e10cSrcweir             void setCatalog(const ::com::sun::star::uno::WeakReference< ::com::sun::star::sdbcx::XTablesSupplier>& _xCat) { m_xCatalog = _xCat; }
setCatalog(OCatalog * _pCatalog)124cdf0e10cSrcweir 			void setCatalog(OCatalog* _pCatalog) { m_pCatalog = _pCatalog; }
125cdf0e10cSrcweir 
getTypeInfo() const126cdf0e10cSrcweir 			const OTypeInfoMap* getTypeInfo() const { return &m_aTypeInfo;}
getAdoCatalog() const127cdf0e10cSrcweir 			OCatalog* getAdoCatalog() const
128cdf0e10cSrcweir 			{
129cdf0e10cSrcweir 				if ( m_xCatalog.get().is() )
130cdf0e10cSrcweir 					return m_pCatalog;
131cdf0e10cSrcweir 				return NULL;
132cdf0e10cSrcweir 			}
133cdf0e10cSrcweir 
getEngineType() const134cdf0e10cSrcweir 			sal_Int32 getEngineType()	const { return m_nEngineType; }
getDriver() const135cdf0e10cSrcweir 			ODriver*  getDriver()		const { return m_pDriver; }
136cdf0e10cSrcweir 
137cdf0e10cSrcweir 			static const OExtendedTypeInfo* getTypeInfoFromType(const OTypeInfoMap& _rTypeInfo,
138cdf0e10cSrcweir 							   DataTypeEnum _nType,
139cdf0e10cSrcweir 							   const ::rtl::OUString& _sTypeName,
140cdf0e10cSrcweir 							   sal_Int32 _nPrecision,
141cdf0e10cSrcweir 							   sal_Int32 _nScale,
142cdf0e10cSrcweir 							   sal_Bool& _brForceToType);
143cdf0e10cSrcweir 		};
144cdf0e10cSrcweir 	}
145cdf0e10cSrcweir }
146cdf0e10cSrcweir #endif // _CONNECTIVITY_ADO_ACONNECTION_HXX_
147cdf0e10cSrcweir 
148