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