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_KAB_CONNECTION_HXX_
25 #define _CONNECTIVITY_KAB_CONNECTION_HXX_
26 
27 #include <map>
28 #include "OSubComponent.hxx"
29 #include "connectivity/CommonTools.hxx"
30 #include <com/sun/star/lang/XServiceInfo.hpp>
31 #include <com/sun/star/sdbc/SQLWarning.hpp>
32 #include <com/sun/star/sdbc/XWarningsSupplier.hpp>
33 #include <com/sun/star/sdbc/XConnection.hpp>
34 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
35 #include <comphelper/broadcasthelper.hxx>
36 #include <cppuhelper/compbase3.hxx>
37 
38 namespace KABC
39 {
40     class StdAddressBook;
41     class AddressBook;
42 }
43 
44 namespace connectivity
45 {
46 	namespace kab
47 	{
48 
49 		typedef ::cppu::WeakComponentImplHelper3<   ::com::sun::star::sdbc::XConnection,
50 												::com::sun::star::sdbc::XWarningsSupplier,
51                                                 ::com::sun::star::lang::XServiceInfo
52 											> OMetaConnection_BASE;
53 
54 		class KabStatement_Base;
55 		class KabDriver;
56 		class KabDatabaseMetaData;
57 
58 		typedef OMetaConnection_BASE				KabConnection_BASE; // implements basics and text encoding
59 		typedef std::vector< ::com::sun::star::uno::WeakReferenceHelper > OWeakRefArray;
60 
61 		class KabConnection : public comphelper::OBaseMutex,
62 							public KabConnection_BASE,
63 							public OSubComponent<KabConnection, KabConnection_BASE>
64 		{
65 			friend class OSubComponent<KabConnection, KabConnection_BASE>;
66 
67 		protected:
68 			//====================================================================
69 			// Data attributes
70 			//====================================================================
71 			::com::sun::star::uno::WeakReference< ::com::sun::star::sdbc::XDatabaseMetaData > m_xMetaData;
72 
73 			OWeakRefArray							m_aStatements;	// vector containing a list of all the Statement objects
74 																	// for this Connection
75 
76 			::KABC::StdAddressBook*					m_pAddressBook;	// the address book
77 			KabDriver*								m_pDriver;		// pointer to the owning driver object
78 			::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XTablesSupplier>
79 													m_xCatalog;		// needed for the SQL interpreter
80 
81 		public:
82 			virtual void construct( const ::rtl::OUString& url,const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& info) throw(::com::sun::star::sdbc::SQLException);
83 
84 			KabConnection(KabDriver* _pDriver);
85 			virtual ~KabConnection();
86 
87 			void closeAllStatements () throw( ::com::sun::star::sdbc::SQLException);
88 
89 			// OComponentHelper
90 			virtual void SAL_CALL disposing(void);
91 
92 			// XInterface
93 			virtual void SAL_CALL release() throw();
94 
95 			// XServiceInfo
96 			DECLARE_SERVICE_INFO();
97 
98 			// XConnection
99             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);
100             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);
101             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);
102             virtual ::rtl::OUString SAL_CALL nativeSQL( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
103             virtual void SAL_CALL setAutoCommit( sal_Bool autoCommit ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
104             virtual sal_Bool SAL_CALL getAutoCommit(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
105             virtual void SAL_CALL commit(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
106             virtual void SAL_CALL rollback(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
107             virtual sal_Bool SAL_CALL isClosed(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
108             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);
109             virtual void SAL_CALL setReadOnly( sal_Bool readOnly ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
110             virtual sal_Bool SAL_CALL isReadOnly(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
111             virtual void SAL_CALL setCatalog( const ::rtl::OUString& catalog ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
112             virtual ::rtl::OUString SAL_CALL getCatalog(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
113             virtual void SAL_CALL setTransactionIsolation( sal_Int32 level ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
114             virtual sal_Int32 SAL_CALL getTransactionIsolation(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
115             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);
116             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);
117 
118 			// XCloseable
119 			virtual void SAL_CALL close(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
120 
121 			// XWarningsSupplier
122 			virtual ::com::sun::star::uno::Any SAL_CALL getWarnings(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
123 			virtual void SAL_CALL clearWarnings(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
124 
125 			// needed for the SQL interpreter
126 			::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XTablesSupplier > SAL_CALL createCatalog();
127 
128 			// accessors
getDriver() const129 			inline KabDriver*			getDriver()			const { return m_pDriver;}
130 			       ::KABC::AddressBook* getAddressBook()	const;
131 		};
132 	}
133 }
134 
135 #endif // _CONNECTIVITY_KAB_CONNECTION_HXX_
136