1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #ifndef INCLUDED_CONNECTIVITY_COMMONTOOLS_HXX
20 #define INCLUDED_CONNECTIVITY_COMMONTOOLS_HXX
22 #include <config_features.h>
24 #include <rtl/ref.hxx>
25 #include <rtl/ustring.hxx>
26 #include <com/sun/star/lang/DisposedException.hpp>
27 #include <com/sun/star/uno/Any.hxx>
29 #include <cppuhelper/weakref.hxx>
30 #include <comphelper/stl_types.hxx>
31 #include <com/sun/star/beans/XPropertySet.hpp>
32 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
33 #include <osl/interlck.h>
34 #include <com/sun/star/uno/XComponentContext.hpp>
35 #include <connectivity/dbtoolsdllapi.hxx>
37 namespace com
{ namespace sun
{ namespace star
{ namespace util
{
45 namespace jvmaccess
{ class VirtualMachine
; }
48 namespace connectivity
50 //------------------------------------------------------------------------------
51 OOO_DLLPUBLIC_DBTOOLS sal_Bool
match(const sal_Unicode
* pWild
, const sal_Unicode
* pStr
, const sal_Unicode cEscape
);
52 inline sal_Bool
match(const OUString
&rWild
, const OUString
&rStr
, const sal_Unicode cEscape
)
54 return match(rWild
.getStr(), rStr
.getStr(), cEscape
);
57 typedef std::vector
< ::com::sun::star::uno::WeakReferenceHelper
> OWeakRefArray
;
58 typedef ::com::sun::star::uno::Reference
< ::com::sun::star::sdbcx::XColumnsSupplier
> OSQLTable
;
60 DECLARE_STL_MAP(OUString
,OSQLTable
,comphelper::UStringMixLess
, OSQLTables
);
62 // -------------------------------------------------------------------------
63 // class ORefVector allows reference counting on a std::vector
64 // -------------------------------------------------------------------------
65 template< class VectorVal
> class ORefVector
67 std::vector
< VectorVal
> m_vector
;
68 oslInterlockedCount m_refCount
;
71 virtual ~ORefVector(){}
73 typedef std::vector
< VectorVal
> Vector
;
75 ORefVector() : m_refCount(0) {}
76 ORefVector(size_t _st
) : m_vector(_st
) , m_refCount(0) {}
77 ORefVector(const ORefVector
& _rRH
) : m_vector(_rRH
.m_vector
),m_refCount(0)
80 ORefVector
& operator=(const ORefVector
& _rRH
)
84 m_vector
= _rRH
.m_vector
;
89 std::vector
< VectorVal
> & get() { return m_vector
; }
90 std::vector
< VectorVal
> const & get() const { return m_vector
; }
92 inline static void * SAL_CALL
operator new( size_t nSize
) SAL_THROW(())
93 { return ::rtl_allocateMemory( nSize
); }
94 inline static void SAL_CALL
operator delete( void * pMem
) SAL_THROW(())
95 { ::rtl_freeMemory( pMem
); }
96 inline static void * SAL_CALL
operator new( size_t, void * pMem
) SAL_THROW(())
98 inline static void SAL_CALL
operator delete( void *, void * ) SAL_THROW(())
103 osl_atomic_increment( &m_refCount
);
107 if (! osl_atomic_decrement( &m_refCount
))
112 // -------------------------------------------------------------------------
113 // class ORowVector incudes refcounting and initialze himself
114 // with at least one element. This first element is reserved for
116 // -------------------------------------------------------------------------
117 template< class VectorVal
> class ORowVector
: public ORefVector
< VectorVal
>
120 ORowVector() : ORefVector
< VectorVal
>(1){}
121 ORowVector(size_t _st
) : ORefVector
< VectorVal
>(_st
+1)
125 typedef ORefVector
< ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
> > OSQLColumns
;
127 // =======================================================================================
128 // search from __first to __last the column with the name _rVal
129 // when no such column exist __last is returned
130 OOO_DLLPUBLIC_DBTOOLS
131 OSQLColumns::Vector::const_iterator
find( OSQLColumns::Vector::const_iterator __first
,
132 OSQLColumns::Vector::const_iterator __last
,
133 const OUString
& _rVal
,
134 const ::comphelper::UStringMixEqual
& _rCase
);
135 // =======================================================================================
136 // search from __first to __last the column with the realname _rVal
137 // when no such column exist __last is returned
138 OOO_DLLPUBLIC_DBTOOLS
139 OSQLColumns::Vector::const_iterator
findRealName( OSQLColumns::Vector::const_iterator __first
,
140 OSQLColumns::Vector::const_iterator __last
,
141 const OUString
& _rVal
,
142 const ::comphelper::UStringMixEqual
& _rCase
);
144 // =======================================================================================
145 // the first two find methods are much faster than the one below
146 // =======================================================================================
147 // search from __first to __last the column with the property _rProp equals the value _rVal
148 // when no such column exist __last is returned
149 OOO_DLLPUBLIC_DBTOOLS
150 OSQLColumns::Vector::const_iterator
find( OSQLColumns::Vector::const_iterator __first
,
151 OSQLColumns::Vector::const_iterator __last
,
152 const OUString
& _rProp
,
153 const OUString
& _rVal
,
154 const ::comphelper::UStringMixEqual
& _rCase
);
156 OOO_DLLPUBLIC_DBTOOLS
void checkDisposed(sal_Bool _bThrow
) throw ( ::com::sun::star::lang::DisposedException
);
158 #if HAVE_FEATURE_JAVA
159 /** creates a java virtual machine
165 OOO_DLLPUBLIC_DBTOOLS ::rtl::Reference
< jvmaccess::VirtualMachine
> getJavaVM(const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& _rxContext
);
167 /** return <TRUE/> if the java class exists, otherwise <FALSE/>.
171 The class name to look for.
173 OOO_DLLPUBLIC_DBTOOLS sal_Bool
existsJavaClassByName( const ::rtl::Reference
< jvmaccess::VirtualMachine
>& _pJVM
,const OUString
& _sClassName
);
177 //==================================================================================
179 #define DECLARE_SERVICE_INFO() \
180 virtual OUString SAL_CALL getImplementationName( ) throw (::com::sun::star::uno::RuntimeException); \
181 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException); \
182 virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException) \
184 #define IMPLEMENT_SERVICE_INFO(classname, implasciiname, serviceasciiname) \
185 OUString SAL_CALL classname::getImplementationName( ) throw (::com::sun::star::uno::RuntimeException) \
187 return OUString::createFromAscii(implasciiname); \
189 ::com::sun::star::uno::Sequence< OUString > SAL_CALL classname::getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException) \
191 ::com::sun::star::uno::Sequence< OUString > aSupported(1); \
192 aSupported[0] = OUString::createFromAscii(serviceasciiname); \
195 sal_Bool SAL_CALL classname::supportsService( const OUString& _rServiceName ) throw(::com::sun::star::uno::RuntimeException) \
197 Sequence< OUString > aSupported(getSupportedServiceNames()); \
198 const OUString* pSupported = aSupported.getConstArray(); \
199 const OUString* pEnd = pSupported + aSupported.getLength(); \
200 for (;pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported) \
203 return pSupported != pEnd; \
206 //==================================================================================
208 #endif // INCLUDED_CONNECTIVITY_COMMONTOOLS_HXX
210 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */