xref: /trunk/main/connectivity/source/inc/java/sql/Connection.hxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
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_JAVA_SQL_CONNECTION_HXX_
28 #define _CONNECTIVITY_JAVA_SQL_CONNECTION_HXX_
29 
30 #include "java/lang/Object.hxx"
31 #include "TConnection.hxx"
32 #include "connectivity/CommonTools.hxx"
33 #include "OSubComponent.hxx"
34 #include <cppuhelper/weakref.hxx>
35 #include "AutoRetrievingBase.hxx"
36 #include "java/sql/ConnectionLog.hxx"
37 #include "java/LocalRef.hxx"
38 #include "java/GlobalRef.hxx"
39 
40 #include <com/sun/star/beans/NamedValue.hpp>
41 
42 namespace connectivity
43 {
44     class java_sql_Driver;
45 
46     typedef OMetaConnection     java_sql_Connection_BASE;
47 
48     class java_sql_Connection : public java_sql_Connection_BASE,
49                                 public java_lang_Object,
50                                 public OSubComponent<java_sql_Connection, java_sql_Connection_BASE>,
51                                 public OAutoRetrievingBase
52     {
53         friend class OSubComponent<java_sql_Connection, java_sql_Connection_BASE>;
54         const java_sql_Driver*  m_pDriver;
55         jobject                 m_pDriverobject;
56         jdbc::GlobalRef< jobject >
57                                 m_pDriverClassLoader;
58 
59         jclass                  m_Driver_theClass;
60         java::sql::ConnectionLog
61                                 m_aLogger;
62         sal_Bool                m_bParameterSubstitution;
63         sal_Bool                m_bIgnoreDriverPrivileges;
64         sal_Bool                m_bIgnoreCurrency;
65         ::com::sun::star::uno::Any  m_aCatalogRestriction;
66         ::com::sun::star::uno::Any  m_aSchemaRestriction;
67 
68         /** transform named parameter into unnamed one.
69             @param  _sSQL
70                 The SQL statement to transform.
71             @return
72                 The new statement witgh unnamed parameters.
73         */
74         ::rtl::OUString transFormPreparedStatement(const ::rtl::OUString& _sSQL);
75         void loadDriverFromProperties(
76                 const ::rtl::OUString& _sDriverClass,
77                 const ::rtl::OUString& _sDriverClassPath,
78                 const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& _rSystemProperties
79             );
80         /** load driver class path from system configuration.
81             @param  _sDriverClass
82                 The driver class name to look for in the configuration.
83         */
84         ::rtl::OUString impl_getJavaDriverClassPath_nothrow(const ::rtl::OUString& _sDriverClass);
85 
86     protected:
87     // statische Daten fuer die Klasse
88         static jclass theClass;
89 
90         virtual ~java_sql_Connection();
91 
92     public:
93         virtual jclass getMyClass() const;
94 
95         DECLARE_SERVICE_INFO();
96         // ein Konstruktor, der fuer das Returnen des Objektes benoetigt wird:
97         java_sql_Connection( const java_sql_Driver& _rDriver );
98         sal_Bool construct( const ::rtl::OUString& url,
99                         const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& info);
100 
101         const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >&
102             getConnectionInfo() const { return m_aConnectionInfo; }
103 
104         inline  sal_Bool isIgnoreDriverPrivilegesEnabled() const { return   m_bIgnoreDriverPrivileges;}
105         inline  sal_Bool isIgnoreCurrencyEnabled() const { return   m_bIgnoreCurrency; }
106         inline const ::com::sun::star::uno::Any& getCatalogRestriction() const { return m_aCatalogRestriction; }
107         inline const ::com::sun::star::uno::Any& getSchemaRestriction() const { return m_aSchemaRestriction; }
108 
109         /** returns the instance used for logging events related to this connection
110         */
111         const java::sql::ConnectionLog& getLogger() const { return m_aLogger; }
112 
113         /** returns the class loader which was used to load the driver class
114 
115             Usually used in conjunction with a ContextClassLoaderScope instance.
116         */
117         const jdbc::GlobalRef< jobject >& getDriverClassLoader() const { return m_pDriverClassLoader; }
118 
119         // OComponentHelper
120         virtual void SAL_CALL disposing(void);
121         // XInterface
122         virtual void SAL_CALL release() throw();
123 
124         // XConnection
125         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);
126         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);
127         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);
128         virtual ::rtl::OUString SAL_CALL nativeSQL( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
129         virtual void SAL_CALL setAutoCommit( sal_Bool autoCommit ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
130         virtual sal_Bool SAL_CALL getAutoCommit(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
131         virtual void SAL_CALL commit(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
132         virtual void SAL_CALL rollback(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
133         virtual sal_Bool SAL_CALL isClosed(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
134         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);
135         virtual void SAL_CALL setReadOnly( sal_Bool readOnly ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
136         virtual sal_Bool SAL_CALL isReadOnly(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
137         virtual void SAL_CALL setCatalog( const ::rtl::OUString& catalog ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
138         virtual ::rtl::OUString SAL_CALL getCatalog(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
139         virtual void SAL_CALL setTransactionIsolation( sal_Int32 level ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
140         virtual sal_Int32 SAL_CALL getTransactionIsolation(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
141         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);
142         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);
143         // XCloseable
144         virtual void SAL_CALL close(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
145         // XWarningsSupplier
146         virtual ::com::sun::star::uno::Any SAL_CALL getWarnings(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
147         virtual void SAL_CALL clearWarnings(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
148     };
149 }
150 #endif // _CONNECTIVITY_JAVA_SQL_CONNECTION_HXX_
151 
152