xref: /trunk/main/mysqlc/source/mysqlc_connection.hxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3 *
4 * Copyright 2008 by Sun Microsystems, Inc.
5 *
6 * OpenOffice.org - a multi-platform office productivity suite
7 *
8 * $RCSfile: mysqlc_connection.hxx,v $
9 *
10 * $Revision: 1.1.2.4 $
11 *
12 * This file is part of OpenOffice.org.
13 *
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
17 *
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
23 *
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org.  If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
28 ************************************************************************/
29 
30 #ifndef MYSQLC_CONNECTION_HXX
31 #define MYSQLC_CONNECTION_HXX
32 
33 #include "mysqlc_subcomponent.hxx"
34 #include "mysqlc_types.hxx"
35 
36 #include <boost/shared_ptr.hpp>
37 #include <com/sun/star/beans/PropertyValue.hpp>
38 #include <com/sun/star/lang/DisposedException.hpp>
39 #include <com/sun/star/lang/XServiceInfo.hpp>
40 #include <com/sun/star/lang/XUnoTunnel.hpp>
41 #include <com/sun/star/sdbc/ColumnSearch.hpp>
42 #include <com/sun/star/sdbc/ColumnValue.hpp>
43 #include <com/sun/star/sdbc/DataType.hpp>
44 #include <com/sun/star/sdbc/SQLWarning.hpp>
45 #include <com/sun/star/sdbc/XConnection.hpp>
46 #include <com/sun/star/sdbc/XWarningsSupplier.hpp>
47 #include <com/sun/star/util/XStringSubstitution.hpp>
48 
49 #include <preextstl.h>
50 #include <cppconn/driver.h>
51 #include <postextstl.h>
52 #include <cppuhelper/compbase3.hxx>
53 #include <cppuhelper/weakref.hxx>
54 #include <rtl/string.hxx>
55 
56 #include <map>
57 
58 #define UNUSED_PARAM __attribute__((unused))
59 
60 namespace sql
61 {
62     class SQLException;
63 }
64 
65 namespace connectivity
66 {
67     class OMetaConnection;
68     class ODatabaseMetaData;
69 
70     namespace mysqlc
71     {
72         using ::rtl::OUString;
73         using ::com::sun::star::sdbc::SQLWarning;
74         using ::com::sun::star::sdbc::SQLException;
75         using ::com::sun::star::uno::RuntimeException;
76         typedef ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XStatement > my_XStatementRef;
77         typedef ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XPreparedStatement > my_XPreparedStatementRef;
78         typedef ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > my_XNameAccessRef;
79         typedef ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDatabaseMetaData > my_XDatabaseMetaDataRef;
80 
81         typedef ::cppu::WeakComponentImplHelper3<   ::com::sun::star::sdbc::XConnection,
82                                                     ::com::sun::star::sdbc::XWarningsSupplier,
83                                                     ::com::sun::star::lang::XServiceInfo
84                                                 > OMetaConnection_BASE;
85         struct ConnectionSettings
86         {
87             rtl_TextEncoding encoding;
88             std::auto_ptr<sql::Connection> cppConnection;
89             OUString schema;
90             OUString quoteIdentifier;
91             OUString connectionURL;
92             sal_Bool readOnly;
93         };
94 
95         class MysqlCDriver;
96 
97         typedef OMetaConnection_BASE OConnection_BASE;
98 
99         typedef std::vector< ::com::sun::star::uno::WeakReferenceHelper > OWeakRefArray;
100 
101         class OConnection : public OBase_Mutex,
102                             public OConnection_BASE,
103                             public connectivity::mysqlc::OSubComponent<OConnection, OConnection_BASE>
104         {
105             friend class connectivity::mysqlc::OSubComponent<OConnection, OConnection_BASE>;
106 
107         private:
108             ConnectionSettings  m_settings;
109 
110         private:
111             ::com::sun::star::uno::Reference< com::sun::star::container::XNameAccess > m_typeMap;
112             ::com::sun::star::uno::Reference< com::sun::star::util::XStringSubstitution > m_xParameterSubstitution;
113         protected:
114 
115             //====================================================================
116             // Data attributes
117             //====================================================================
118             ::com::sun::star::uno::WeakReference< ::com::sun::star::sdbc::XDatabaseMetaData > m_xMetaData;
119 
120             OWeakRefArray   m_aStatements;  // vector containing a list
121                                             // of all the Statement objects
122                                             // for this Connection
123 
124             SQLWarning      m_aLastWarning; // Last SQLWarning generated by an operation
125             OUString        m_aURL;         // URL of connection
126             OUString        m_sUser;        // the user name
127             MysqlCDriver&   m_rDriver;      // Pointer to the owning driver object
128             sql::Driver*    cppDriver;
129 
130             sal_Bool    m_bClosed;
131             sal_Bool    m_bUseCatalog;  // should we use the catalog on filebased databases
132             sal_Bool    m_bUseOldDateFormat;
133 
134 
135             void        buildTypeInfo() throw(SQLException);
136         public:
137             OUString getMysqlVariable(const char *varname)
138                                                                 throw(SQLException, RuntimeException);
139 
140             sal_Int32 getMysqlVersion()
141                                                                 throw(SQLException, RuntimeException);
142 
143             virtual void construct(const OUString& url,const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& info)
144                                                                 throw(SQLException);
145 
146             OConnection(MysqlCDriver& _rDriver, sql::Driver * cppDriver);
147             virtual ~OConnection();
148 
149             void closeAllStatements ()                          throw(SQLException);
150 
151 
152             rtl_TextEncoding getConnectionEncoding() { return m_settings.encoding; }
153 
154 
155             // OComponentHelper
156             virtual void SAL_CALL disposing(void);
157 
158             // XInterface
159             virtual void SAL_CALL release()                     throw();
160 
161             // XServiceInfo
162             DECLARE_SERVICE_INFO();
163             // XConnection
164             my_XStatementRef SAL_CALL createStatement()
165                                                                 throw(SQLException, RuntimeException);
166 
167             my_XPreparedStatementRef SAL_CALL prepareStatement(const OUString& sql)
168                                                                 throw(SQLException, RuntimeException);
169 
170             my_XPreparedStatementRef SAL_CALL prepareCall(const OUString& sql)
171                                                                 throw(SQLException, RuntimeException);
172 
173             OUString SAL_CALL nativeSQL(const OUString& sql)
174                                                                 throw(SQLException, RuntimeException);
175 
176             void SAL_CALL setAutoCommit(sal_Bool autoCommit)
177                                                                 throw(SQLException, RuntimeException);
178 
179             sal_Bool SAL_CALL getAutoCommit()
180                                                                 throw(SQLException, RuntimeException);
181 
182             void SAL_CALL commit()
183                                                                 throw(SQLException, RuntimeException);
184 
185             void SAL_CALL rollback()
186                                                                 throw(SQLException, RuntimeException);
187 
188             sal_Bool SAL_CALL isClosed()
189                                                                 throw(SQLException, RuntimeException);
190 
191             my_XDatabaseMetaDataRef SAL_CALL getMetaData()
192                                                                 throw(SQLException, RuntimeException);
193 
194             void SAL_CALL setReadOnly(sal_Bool readOnly)
195                                                                 throw(SQLException, RuntimeException);
196 
197             sal_Bool SAL_CALL isReadOnly()
198                                                                 throw(SQLException, RuntimeException);
199 
200             void SAL_CALL setCatalog(const OUString& catalog)
201                                                                 throw(SQLException, RuntimeException);
202 
203             OUString SAL_CALL getCatalog()
204                                                                 throw(SQLException, RuntimeException);
205 
206             void SAL_CALL setTransactionIsolation(sal_Int32 level)
207                                                                 throw(SQLException, RuntimeException);
208 
209             sal_Int32 SAL_CALL getTransactionIsolation()
210                                                                 throw(SQLException, RuntimeException);
211 
212             my_XNameAccessRef SAL_CALL getTypeMap()
213                                                                 throw(SQLException, RuntimeException);
214 
215             void SAL_CALL setTypeMap(const my_XNameAccessRef& typeMap)
216                                                                 throw(SQLException, RuntimeException);
217             // XCloseable
218             void SAL_CALL close()
219                                                                 throw(SQLException, RuntimeException);
220             // XWarningsSupplier
221             ::com::sun::star::uno::Any SAL_CALL getWarnings()
222                                                                 throw(SQLException, RuntimeException);
223             void SAL_CALL clearWarnings()
224                                                                 throw(SQLException, RuntimeException);
225 
226             // TODO: Not used
227             //sal_Int32 sdbcColumnType(OUString typeName);
228             inline const ConnectionSettings& getConnectionSettings() const { return m_settings; }
229             ::rtl::OUString transFormPreparedStatement(const ::rtl::OUString& _sSQL);
230 
231             // should we use the catalog on filebased databases
232             inline sal_Bool             isCatalogUsed()     const { return m_bUseCatalog; }
233             inline OUString             getUserName()       const { return m_sUser; }
234             inline const MysqlCDriver&  getDriver()         const { return m_rDriver;}
235             inline rtl_TextEncoding     getTextEncoding()   const { return m_settings.encoding; }
236 
237         }; /* OConnection */
238         // TODO: Not used.
239         //inline OUString getPattern(OUString p) { return (p.getLength()) ? p : ASC2OU("%"); }
240     } /* mysqlc */
241 } /* connectivity */
242 #endif // MYSQLC_CONNECTION_HXX
243 
244 /*
245  * Local variables:
246  * tab-width: 4
247  * c-basic-offset: 4
248  * End:
249  * vim600: noet sw=4 ts=4 fdm=marker
250  * vim<600: noet sw=4 ts=4
251  */
252 
253