1 /*************************************************************************
2  *
3  *  The Contents of this file are made available subject to the terms of
4  *  the BSD license.
5  *
6  *  Copyright 2000, 2010 Oracle and/or its affiliates.
7  *  All rights reserved.
8  *
9  *  Redistribution and use in source and binary forms, with or without
10  *  modification, are permitted provided that the following conditions
11  *  are met:
12  *  1. Redistributions of source code must retain the above copyright
13  *     notice, this list of conditions and the following disclaimer.
14  *  2. Redistributions in binary form must reproduce the above copyright
15  *     notice, this list of conditions and the following disclaimer in the
16  *     documentation and/or other materials provided with the distribution.
17  *  3. Neither the name of Sun Microsystems, Inc. nor the names of its
18  *     contributors may be used to endorse or promote products derived
19  *     from this software without specific prior written permission.
20  *
21  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
28  *  OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
29  *  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
30  *  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
31  *  USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  *
33  *************************************************************************/
34 
35 #ifndef CONNECTIVITY_SCONNECTION_HXX
36 #define CONNECTIVITY_SCONNECTION_HXX
37 
38 #include <com/sun/star/sdbc/SQLWarning.hpp>
39 #include <com/sun/star/beans/PropertyValue.hpp>
40 #include "OSubComponent.hxx"
41 #include "OTypeInfo.hxx"
42 #include <com/sun/star/lang/DisposedException.hpp>
43 #include <com/sun/star/lang/XServiceInfo.hpp>
44 #include <com/sun/star/lang/XUnoTunnel.hpp>
45 #include <com/sun/star/sdbc/XWarningsSupplier.hpp>
46 #include <com/sun/star/sdbc/XConnection.hpp>
47 #include <cppuhelper/compbase3.hxx>
48 #include <cppuhelper/weakref.hxx>
49 
50 #include <map>
51 
52 namespace connectivity
53 {
54 	namespace skeleton
55 	{
56 
57 		typedef ::cppu::WeakComponentImplHelper3<   ::com::sun::star::sdbc::XConnection,
58 												::com::sun::star::sdbc::XWarningsSupplier,
59                                                 ::com::sun::star::lang::XServiceInfo
60 											> OMetaConnection_BASE;
61 
62 		class OStatement_Base;
63 		class SkeletonDriver;
64 		class ODatabaseMetaData;
65 
66 		typedef OMetaConnection_BASE				OConnection_BASE; // implements basics and text encoding
67 		typedef ::std::vector< ::connectivity::OTypeInfo>	TTypeInfoVector;
68 		typedef std::vector< ::com::sun::star::uno::WeakReferenceHelper > OWeakRefArray;
69 
70 		class OConnection : public OBase_Mutex,
71 							public OConnection_BASE,
72 							public connectivity::skeleton::OSubComponent<OConnection, OConnection_BASE>
73 		{
74 			friend class connectivity::skeleton::OSubComponent<OConnection, OConnection_BASE>;
75 
76 		protected:
77 
78 			rtl_TextEncoding						m_nTextEncoding; // the encoding which is used for all text conversions
79 			//====================================================================
80 			// Data attributes
81 			//====================================================================
82 			TTypeInfoVector							m_aTypeInfo;	//	vector containing an entry
83 																	//  for each row returned by
84 																	//  DatabaseMetaData.getTypeInfo.
85             ::com::sun::star::uno::WeakReference< ::com::sun::star::sdbc::XDatabaseMetaData > m_xMetaData;
86 
87 			OWeakRefArray							m_aStatements;	//	vector containing a list
88 														//  of all the Statement objects
89 														//  for this Connection
90 
91             ::com::sun::star::sdbc::SQLWarning      m_aLastWarning; //      Last SQLWarning generated by
92 														//  an operation
93 			::rtl::OUString							m_aURL;			//	URL of connection
94 			::rtl::OUString							m_sUser;		// the user name
95 			SkeletonDriver*							m_pDriver;		//	Pointer to the owning
96 																	//  driver object
97 
98 			sal_Bool								m_bClosed;
99 			sal_Bool								m_bUseCatalog;	// should we use the catalog on filebased databases
100 			sal_Bool								m_bUseOldDateFormat;
101 
102 
103             void                    buildTypeInfo() throw( ::com::sun::star::sdbc::SQLException);
104 
105 		public:
106             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);
107 
108 			OConnection(SkeletonDriver*	_pDriver);
109 			virtual ~OConnection();
110 
111             void closeAllStatements () throw( ::com::sun::star::sdbc::SQLException);
112 
113 			// OComponentHelper
114 			virtual void SAL_CALL disposing(void);
115 			// XInterface
116 			virtual void SAL_CALL release() throw();
117 
118 			// XServiceInfo
119 			DECLARE_SERVICE_INFO();
120 			// XConnection
121             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);
122             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);
123             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);
124             virtual ::rtl::OUString SAL_CALL nativeSQL( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
125             virtual void SAL_CALL setAutoCommit( sal_Bool autoCommit ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
126             virtual sal_Bool SAL_CALL getAutoCommit(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
127             virtual void SAL_CALL commit(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
128             virtual void SAL_CALL rollback(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
129             virtual sal_Bool SAL_CALL isClosed(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
130             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);
131             virtual void SAL_CALL setReadOnly( sal_Bool readOnly ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
132             virtual sal_Bool SAL_CALL isReadOnly(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
133             virtual void SAL_CALL setCatalog( const ::rtl::OUString& catalog ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
134             virtual ::rtl::OUString SAL_CALL getCatalog(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
135             virtual void SAL_CALL setTransactionIsolation( sal_Int32 level ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
136             virtual sal_Int32 SAL_CALL getTransactionIsolation(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
137             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);
138             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);
139 			// XCloseable
140 			virtual void SAL_CALL close(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
141 			// XWarningsSupplier
142 			virtual ::com::sun::star::uno::Any SAL_CALL getWarnings(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
143 			virtual void SAL_CALL clearWarnings(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
144 			//
145 
146 			// should we use the catalog on filebased databases
147 			inline sal_Bool			isCatalogUsed()		const { return m_bUseCatalog; }
148 			inline ::rtl::OUString	getUserName()		const { return m_sUser; }
149 			inline SkeletonDriver*	getDriver()			const { return m_pDriver;}
150 			inline rtl_TextEncoding getTextEncoding()	const { return m_nTextEncoding; }
151 		};
152 	}
153 }
154 #endif // CONNECTIVITY_SCONNECTION_HXX
155 
156