1 /*************************************************************************
3 * $RCSfile: pq_connection.hxx,v $
7 * last change: $Author: jbu $ $Date: 2004/06/10 15:26:55 $
9 * The Contents of this file are made available subject to the terms of
10 * either of the following licenses
12 * - GNU Lesser General Public License Version 2.1
13 * - Sun Industry Standards Source License Version 1.1
15 * Sun Microsystems Inc., October, 2000
17 * GNU Lesser General Public License Version 2.1
18 * =============================================
19 * Copyright 2000 by Sun Microsystems, Inc.
20 * 901 San Antonio Road, Palo Alto, CA 94303, USA
22 * This library is free software; you can redistribute it and/or
23 * modify it under the terms of the GNU Lesser General Public
24 * License version 2.1, as published by the Free Software Foundation.
26 * This library is distributed in the hope that it will be useful,
27 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
29 * Lesser General Public License for more details.
31 * You should have received a copy of the GNU Lesser General Public
32 * License along with this library; if not, write to the Free Software
33 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
37 * Sun Industry Standards Source License Version 1.1
38 * =================================================
39 * The contents of this file are subject to the Sun Industry Standards
40 * Source License Version 1.1 (the "License"); You may not use this file
41 * except in compliance with the License. You may obtain a copy of the
42 * License at http://www.openoffice.org/license.html.
44 * Software provided under this License is provided on an "AS IS" basis,
45 * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
46 * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
47 * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
48 * See the License for the specific provisions governing your rights and
49 * obligations concerning the Software.
51 * The Initial Developer of the Original Code is: Joerg Budischewski
53 * Copyright: 2000 by Sun Microsystems, Inc.
55 * All Rights Reserved.
57 * Contributor(s): Joerg Budischewski
60 ************************************************************************/
62 #ifndef _PQ_CONNECTION_HXX_
63 #define _PQ_CONNECTION_HXX_
65 #include <com/sun/star/uno/XComponentContext.hpp>
67 #include <com/sun/star/lang/XInitialization.hpp>
69 #include <com/sun/star/script/XTypeConverter.hpp>
71 #include <com/sun/star/sdbc/XWarningsSupplier.hpp>
72 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
73 #include <com/sun/star/sdbcx/XUsersSupplier.hpp>
74 #include <com/sun/star/sdbcx/XViewsSupplier.hpp>
75 #include <com/sun/star/sdbc/XConnection.hpp>
77 #include <com/sun/star/container/XNameAccess.hpp>
79 #include <rtl/ref.hxx>
80 #include <rtl/byteseq.hxx>
82 #include <salhelper/simplereferenceobject.hxx>
84 #include <cppuhelper/weakref.hxx>
85 #include <cppuhelper/compbase6.hxx>
88 #include "pq_allocator.hxx"
90 namespace pq_sdbc_driver
93 #define POSTGRE_TRACE( x ) printf( "%s\n" , x )
94 #define POSTGRE_TRACE_1( x ,y) printf( "%s %s\n" , x ,y )
96 #define POSTGRE_TRACE(x) ((void)0)
97 #define POSTGRE_TRACE_1(x,y) ((void)0)
100 class RefCountedMutex
: public salhelper::SimpleReferenceObject
106 struct ConnectionSettings
;
110 //--------------------------------------------------
112 //--------------------------------------------------
115 // when you add a loglevel, extend the log function !
116 static const sal_Int32 NONE
= 0;
117 static const sal_Int32 ERROR
= 1;
118 static const sal_Int32 SQL
= 2;
119 static const sal_Int32 INFO
= 3;
120 static const sal_Int32 DATA
= 4;
122 bool isLog( ConnectionSettings
*settings
, int loglevel
);
123 void log( ConnectionSettings
*settings
, sal_Int32 level
, const rtl::OUString
&logString
);
124 void log( ConnectionSettings
*settings
, sal_Int32 level
, const char *str
);
125 //--------------------------------------------------
129 struct ConnectionSettings
131 ConnectionSettings() :
132 showSystemColumns( sal_False
),
134 encoding( RTL_TEXTENCODING_UTF8
),
136 loglevel( LogLevel::INFO
)
138 rtl_TextEncoding encoding
;
140 ::com::sun::star::uno::Reference
< com::sun::star::script::XTypeConverter
> tc
;
141 ::com::sun::star::uno::Reference
< com::sun::star::container::XNameAccess
> tables
;
142 ::com::sun::star::uno::Reference
< com::sun::star::container::XNameAccess
> users
;
143 ::com::sun::star::uno::Reference
< com::sun::star::container::XNameAccess
> views
;
144 Tables
*pTablesImpl
; // needed to implement renaming of tables / views
145 Views
*pViewsImpl
; // needed to implement renaming of tables / views
146 ::rtl::OUString user
;
147 ::rtl::OUString catalog
;
148 sal_Bool showSystemColumns
;
153 //--------------------------------------------------
154 typedef cppu::WeakComponentImplHelper6
<
155 com::sun::star::sdbc::XConnection
,
156 com::sun::star::sdbc::XWarningsSupplier
,
157 com::sun::star::lang::XInitialization
,
158 com::sun::star::sdbcx::XTablesSupplier
,
159 com::sun::star::sdbcx::XViewsSupplier
,
160 com::sun::star::sdbcx::XUsersSupplier
> ConnectionBase
;
163 struct HashByteSequence
165 sal_Int32
operator () ( const ::rtl::ByteSequence
& seq
) const
167 return *(sal_Int32
*) seq
.getConstArray();
171 typedef ::std::hash_map
<
173 ::com::sun::star::uno::WeakReference
< com::sun::star::sdbc::XCloseable
>,
175 ::std::equal_to
< ::rtl::ByteSequence
>,
176 Allocator
< std::pair
< const ::rtl::ByteSequence
,::com::sun::star::uno::WeakReference
< com::sun::star::sdbc::XCloseable
> > >
178 typedef ::std::vector
< rtl::OString
, Allocator
< ::rtl::OString
> > OStringVector
;
182 typedef std::hash_map
186 ::std::hash
< sal_Int32
>,
187 ::std::equal_to
< sal_Int32
>,
188 Allocator
< ::std::pair
< sal_Int32
, ::rtl::OUString
> >
191 class Connection
: public ConnectionBase
193 ::com::sun::star::uno::Reference
< com::sun::star::uno::XComponentContext
> m_ctx
;
194 ::com::sun::star::uno::Reference
< com::sun::star::container::XNameAccess
> m_typeMap
;
195 ConnectionSettings m_settings
;
196 ::rtl::Reference
< RefCountedMutex
> m_refMutex
;
197 ::com::sun::star::uno::Reference
< com::sun::star::sdbc::XDatabaseMetaData
> m_meta
;
198 WeakHashMap m_myStatements
;
202 throw ( com::sun::star::sdbc::SQLException
, com::sun::star::uno::RuntimeException
);
206 const rtl::Reference
< RefCountedMutex
> &refMutex
,
207 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
> & ctx
);
211 public: // XCloseable
212 virtual void SAL_CALL
close()
213 throw ( ::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
215 public: // XConnection
217 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XStatement
> SAL_CALL
createStatement( )
218 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
) ;
219 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XPreparedStatement
> SAL_CALL
prepareStatement(
220 const ::rtl::OUString
& sql
)
221 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
222 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XPreparedStatement
> SAL_CALL
prepareCall(
223 const ::rtl::OUString
& sql
)
224 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
225 virtual ::rtl::OUString SAL_CALL
nativeSQL( const ::rtl::OUString
& sql
)
226 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
227 virtual void SAL_CALL
setAutoCommit( sal_Bool autoCommit
)
228 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
229 virtual sal_Bool SAL_CALL
getAutoCommit( )
230 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
231 virtual void SAL_CALL
commit( )
232 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
233 virtual void SAL_CALL
rollback( )
234 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
235 virtual sal_Bool SAL_CALL
isClosed( )
236 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
237 virtual ::com::sun::star::uno::Reference
< com::sun::star::sdbc::XDatabaseMetaData
> SAL_CALL
getMetaData( )
238 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
239 virtual void SAL_CALL
setReadOnly( sal_Bool readOnly
)
240 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
241 virtual sal_Bool SAL_CALL
isReadOnly( )
242 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
243 virtual void SAL_CALL
setCatalog( const ::rtl::OUString
& catalog
)
244 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
245 virtual ::rtl::OUString SAL_CALL
getCatalog( )
246 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
247 virtual void SAL_CALL
setTransactionIsolation( sal_Int32 level
)
248 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
249 virtual sal_Int32 SAL_CALL
getTransactionIsolation( )
250 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
251 virtual ::com::sun::star::uno::Reference
< com::sun::star::container::XNameAccess
> SAL_CALL
getTypeMap( )
252 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
253 virtual void SAL_CALL
setTypeMap(
254 const ::com::sun::star::uno::Reference
< com::sun::star::container::XNameAccess
>& typeMap
)
255 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
257 public: // XWarningsSupplier
258 virtual ::com::sun::star::uno::Any SAL_CALL
getWarnings( )
259 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
260 virtual void SAL_CALL
clearWarnings( )
261 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
263 public: // XInitialization
264 virtual void SAL_CALL
initialize(
265 const ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Any
>& aArguments
)
266 throw (com::sun::star::uno::Exception
, ::com::sun::star::uno::RuntimeException
);
268 public: // XTablesSupplier
269 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameAccess
> SAL_CALL
getTables( ) throw (::com::sun::star::uno::RuntimeException
);
271 public: // XUsersSupplier
272 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameAccess
> SAL_CALL
getUsers( ) throw (::com::sun::star::uno::RuntimeException
);
274 public: // XViewsSupplier
275 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameAccess
> SAL_CALL
getViews( ) throw (::com::sun::star::uno::RuntimeException
);
278 virtual void SAL_CALL
disposing();
280 public: // helper function
281 void removeFromWeakMap( const ::rtl::ByteSequence
& seq
);