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 #ifndef _CONNECTIVITY_JAVA_SQL_CONNECTION_HXX_
24 #define _CONNECTIVITY_JAVA_SQL_CONNECTION_HXX_
25 
26 #include "java/lang/Object.hxx"
27 #include "TConnection.hxx"
28 #include "connectivity/CommonTools.hxx"
29 #include "OSubComponent.hxx"
30 #include <cppuhelper/weakref.hxx>
31 #include "AutoRetrievingBase.hxx"
32 #include "java/sql/ConnectionLog.hxx"
33 #include "java/LocalRef.hxx"
34 #include "java/GlobalRef.hxx"
35 
36 #include <com/sun/star/beans/NamedValue.hpp>
37 
38 namespace connectivity
39 {
40 	class java_sql_Driver;
41 
42 	typedef OMetaConnection     java_sql_Connection_BASE;
43 
44 	class java_sql_Connection : public java_sql_Connection_BASE,
45 								public java_lang_Object,
46 								public OSubComponent<java_sql_Connection, java_sql_Connection_BASE>,
47 								public OAutoRetrievingBase
48 	{
49 		friend class OSubComponent<java_sql_Connection, java_sql_Connection_BASE>;
50 		const java_sql_Driver*	m_pDriver;
51 		jobject				    m_pDriverobject;
52         jdbc::GlobalRef< jobject >
53                                 m_pDriverClassLoader;
54 
55 		jclass				    m_Driver_theClass;
56         java::sql::ConnectionLog
57                                 m_aLogger;
58 		sal_Bool			    m_bParameterSubstitution;
59 		sal_Bool		        m_bIgnoreDriverPrivileges;
60         sal_Bool		        m_bIgnoreCurrency;
61         ::com::sun::star::uno::Any  m_aCatalogRestriction;
62         ::com::sun::star::uno::Any  m_aSchemaRestriction;
63 
64 		/** transform named parameter into unnamed one.
65 			@param	_sSQL
66 				The SQL statement to transform.
67 			@return
68 				The new statement witgh unnamed parameters.
69 		*/
70 		::rtl::OUString transFormPreparedStatement(const ::rtl::OUString& _sSQL);
71 		void loadDriverFromProperties(
72                 const ::rtl::OUString& _sDriverClass,
73                 const ::rtl::OUString& _sDriverClassPath,
74                 const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& _rSystemProperties
75             );
76         /** load driver class path from system configuration.
77             @param  _sDriverClass
78                 The driver class name to look for in the configuration.
79         */
80         ::rtl::OUString impl_getJavaDriverClassPath_nothrow(const ::rtl::OUString& _sDriverClass);
81 
82 	protected:
83 	// statische Daten fuer die Klasse
84 		static jclass theClass;
85 
86 		virtual ~java_sql_Connection();
87 
88 	public:
89 		virtual jclass getMyClass() const;
90 
91 		DECLARE_SERVICE_INFO();
92 		// ein Konstruktor, der fuer das Returnen des Objektes benoetigt wird:
93 		java_sql_Connection( const java_sql_Driver& _rDriver );
94 		sal_Bool construct(	const ::rtl::OUString& url,
95 						const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& info);
96 
97         const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >&
getConnectionInfo() const98             getConnectionInfo() const { return m_aConnectionInfo; }
99 
isIgnoreDriverPrivilegesEnabled() const100 		inline 	sal_Bool isIgnoreDriverPrivilegesEnabled() const { return	m_bIgnoreDriverPrivileges;}
isIgnoreCurrencyEnabled() const101         inline 	sal_Bool isIgnoreCurrencyEnabled() const { return	m_bIgnoreCurrency; }
getCatalogRestriction() const102         inline const ::com::sun::star::uno::Any& getCatalogRestriction() const { return m_aCatalogRestriction; }
getSchemaRestriction() const103         inline const ::com::sun::star::uno::Any& getSchemaRestriction() const { return m_aSchemaRestriction; }
104 
105         /** returns the instance used for logging events related to this connection
106         */
getLogger() const107         const java::sql::ConnectionLog& getLogger() const { return m_aLogger; }
108 
109         /** returns the class loader which was used to load the driver class
110 
111             Usually used in conjunction with a ContextClassLoaderScope instance.
112         */
getDriverClassLoader() const113         const jdbc::GlobalRef< jobject >& getDriverClassLoader() const { return m_pDriverClassLoader; }
114 
115         // OComponentHelper
116 		virtual void SAL_CALL disposing(void);
117 		// XInterface
118 		virtual void SAL_CALL release() throw();
119 
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 #endif // _CONNECTIVITY_JAVA_SQL_CONNECTION_HXX_
147 
148