1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #ifndef _CONNECTIVITY_FILE_OCONNECTION_HXX_
28 #define _CONNECTIVITY_FILE_OCONNECTION_HXX_
29 
30 #include <com/sun/star/ucb/XContent.hpp>
31 #include <com/sun/star/sdbc/SQLWarning.hpp>
32 #include <com/sun/star/beans/PropertyValue.hpp>
33 #include "OSubComponent.hxx"
34 #ifndef _MAP_
35 #include <map>
36 #endif
37 #include "connectivity/CommonTools.hxx"
38 #include "OTypeInfo.hxx"
39 #include <tools/string.hxx>
40 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
41 #include <com/sun/star/ucb/XDynamicResultSet.hpp>
42 #include "connectivity/sqlparse.hxx"
43 #include "connectivity/sqliterator.hxx"
44 #include "TConnection.hxx"
45 #include "file/filedllapi.hxx"
46 
47 namespace connectivity
48 {
49 	namespace file
50 	{
51 
52 		class OStatement_Base;
53 		class ODatabaseMetaData;
54 		class OFileDriver;
55 
56 		class OOO_DLLPUBLIC_FILE OConnection :
57                             public connectivity::OMetaConnection,
58 							public connectivity::OSubComponent<OConnection, connectivity::OMetaConnection>
59 		{
60 			friend class connectivity::OSubComponent<OConnection, connectivity::OMetaConnection>;
61 
62 		protected:
63 			//====================================================================
64 			// Data attributes
65 			//====================================================================
66             ::com::sun::star::uno::WeakReference< ::com::sun::star::sdbcx::XTablesSupplier>			m_xCatalog;
67 
68 			::com::sun::star::sdbc::SQLWarning            m_aLastWarning; //      Last SQLWarning generated by
69 
70 			String						m_aFilenameExtension;
71 			OFileDriver*				m_pDriver;		//	Pointer to the owning
72 														//  driver object
73 			::com::sun::star::uno::Reference< ::com::sun::star::ucb::XDynamicResultSet >	m_xDir; // directory
74 			::com::sun::star::uno::Reference< ::com::sun::star::ucb::XContent>				m_xContent;
75 
76 			sal_Bool					m_bClosed;
77 			sal_Bool					m_bAutoCommit;
78 			sal_Bool					m_bReadOnly;
79 			sal_Bool					m_bShowDeleted;
80 			sal_Bool					m_bCaseSensitiveExtension;
81 			sal_Bool					m_bCheckSQL92;
82             bool                        m_bDefaultTextEncoding;
83 
84 
85 			void throwUrlNotValid(const ::rtl::OUString & _rsUrl,const ::rtl::OUString & _rsMessage);
86 
87 			virtual ~OConnection();
88 		public:
89 
90 			OConnection(OFileDriver*	_pDriver);
91 
92             virtual void construct(const ::rtl::OUString& _rUrl,const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _rInfo ) throw( ::com::sun::star::sdbc::SQLException);
93 
94             void closeAllStatements () throw( ::com::sun::star::sdbc::SQLException);
95 
96 			// OComponentHelper
97 			virtual void SAL_CALL disposing(void);
98 			// XInterface
99 			virtual void SAL_CALL release() throw();
100 
101 			// XServiceInfo
102 			DECLARE_SERVICE_INFO();
103 
104 			// XConnection
105             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);
106             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);
107             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);
108             virtual ::rtl::OUString SAL_CALL nativeSQL( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
109             virtual void SAL_CALL setAutoCommit( sal_Bool autoCommit ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
110             virtual sal_Bool SAL_CALL getAutoCommit(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
111             virtual void SAL_CALL commit(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
112             virtual void SAL_CALL rollback(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
113             virtual sal_Bool SAL_CALL isClosed(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
114             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);
115             virtual void SAL_CALL setReadOnly( sal_Bool readOnly ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
116             virtual sal_Bool SAL_CALL isReadOnly(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
117             virtual void SAL_CALL setCatalog( const ::rtl::OUString& catalog ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
118             virtual ::rtl::OUString SAL_CALL getCatalog(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
119             virtual void SAL_CALL setTransactionIsolation( sal_Int32 level ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
120             virtual sal_Int32 SAL_CALL getTransactionIsolation(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
121             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);
122             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);
123 			// XCloseable
124 			virtual void SAL_CALL close(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
125 			// XWarningsSupplier
126 			virtual ::com::sun::star::uno::Any SAL_CALL getWarnings(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
127 			virtual void SAL_CALL clearWarnings(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
128 			//XUnoTunnel
129 			virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier ) throw (::com::sun::star::uno::RuntimeException);
130 			static ::com::sun::star::uno::Sequence< sal_Int8 > getUnoTunnelImplementationId();
131 
132 			// no interface methods
133 			::com::sun::star::uno::Reference< ::com::sun::star::ucb::XDynamicResultSet > getDir() const;
134 			::com::sun::star::uno::Reference< ::com::sun::star::ucb::XContent>	getContent() const { return m_xContent; }
135 			// create a catalog or return the catalog already created
136             virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XTablesSupplier > createCatalog();
137 
138 			sal_Bool				matchesExtension( const String& _rExt ) const;
139 
140 			inline const String&	getExtension()				const { return m_aFilenameExtension; }
141 			inline sal_Bool			isCaseSensitveExtension()	const { return m_bCaseSensitiveExtension; }
142 			inline OFileDriver*		getDriver()					const { return m_pDriver; }
143 			inline sal_Bool			showDeleted()				const { return m_bShowDeleted; }
144 			inline sal_Bool			isCheckEnabled()			const { return m_bCheckSQL92; }
145             inline bool             isTextEncodingDefaulted()   const { return m_bDefaultTextEncoding; }
146 
147 		public:
148 			struct GrantAccess
149 			{
150 				friend class ODatabaseMetaData;
151 			private:
152 				GrantAccess() { }
153 			};
154 
155 			void	setCaseSensitiveExtension( sal_Bool _bIsCS, GrantAccess ) { m_bCaseSensitiveExtension = _bIsCS; }
156 		};
157 	}
158 }
159 #endif // _CONNECTIVITY_FILE_OCONNECTION_HXX_
160 
161