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 <sal/config.h>
23 #include <config_features.h>
27 #include <rtl/ref.hxx>
28 #include <rtl/ustring.hxx>
29 #include <com/sun/star/lang/DisposedException.hpp>
30 #include <com/sun/star/uno/Any.hxx>
32 #include <cppuhelper/weakref.hxx>
33 #include <comphelper/stl_types.hxx>
34 #include <com/sun/star/beans/XPropertySet.hpp>
35 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
36 #include <osl/interlck.h>
37 #include <com/sun/star/uno/XComponentContext.hpp>
38 #include <connectivity/dbtoolsdllapi.hxx>
39 #include <cppuhelper/supportsservice.hxx>
40 #include <salhelper/simplereferenceobject.hxx>
42 namespace com
{ namespace sun
{ namespace star
{ namespace util
{
50 namespace jvmaccess
{ class VirtualMachine
; }
53 namespace connectivity
55 OOO_DLLPUBLIC_DBTOOLS
bool match(const sal_Unicode
* pWild
, const sal_Unicode
* pStr
, const sal_Unicode cEscape
);
56 inline bool match(const OUString
&rWild
, const OUString
&rStr
, const sal_Unicode cEscape
)
58 return match(rWild
.getStr(), rStr
.getStr(), cEscape
);
61 typedef std::vector
< ::com::sun::star::uno::WeakReferenceHelper
> OWeakRefArray
;
62 typedef ::com::sun::star::uno::Reference
< ::com::sun::star::sdbcx::XColumnsSupplier
> OSQLTable
;
64 typedef std::map
<OUString
,OSQLTable
,comphelper::UStringMixLess
> OSQLTables
;
66 // class ORefVector allows reference counting on a std::vector
67 template< class VectorVal
> class ORefVector
: public salhelper::SimpleReferenceObject
69 std::vector
< VectorVal
> m_vector
;
72 virtual ~ORefVector(){}
74 typedef std::vector
< VectorVal
> Vector
;
77 ORefVector(size_t _st
) : m_vector(_st
) {}
78 ORefVector(const ORefVector
& rOther
)
79 : salhelper::SimpleReferenceObject()
80 , m_vector(rOther
.m_vector
)
83 ORefVector
& operator=(const ORefVector
& _rRH
)
87 m_vector
= _rRH
.m_vector
;
92 std::vector
< VectorVal
> & get() { return m_vector
; }
93 std::vector
< VectorVal
> const & get() const { return m_vector
; }
97 // class ORowVector incudes refcounting and initialze himself
98 // with at least one element. This first element is reserved for
100 template< class VectorVal
> class ORowVector
: public ORefVector
< VectorVal
>
103 ORowVector() : ORefVector
< VectorVal
>(1){}
104 ORowVector(size_t _st
) : ORefVector
< VectorVal
>(_st
+1)
108 typedef ORefVector
< ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
> > OSQLColumns
;
110 // search from __first to __last the column with the name _rVal
111 // when no such column exist __last is returned
112 OOO_DLLPUBLIC_DBTOOLS
113 OSQLColumns::Vector::const_iterator
find( OSQLColumns::Vector::const_iterator __first
,
114 OSQLColumns::Vector::const_iterator __last
,
115 const OUString
& _rVal
,
116 const ::comphelper::UStringMixEqual
& _rCase
);
118 // search from __first to __last the column with the realname _rVal
119 // when no such column exist __last is returned
120 OOO_DLLPUBLIC_DBTOOLS
121 OSQLColumns::Vector::const_iterator
findRealName( OSQLColumns::Vector::const_iterator __first
,
122 OSQLColumns::Vector::const_iterator __last
,
123 const OUString
& _rVal
,
124 const ::comphelper::UStringMixEqual
& _rCase
);
126 // the first two find methods are much faster than the one below
127 // search from __first to __last the column with the property _rProp equals the value _rVal
128 // when no such column exist __last is returned
129 OOO_DLLPUBLIC_DBTOOLS
130 OSQLColumns::Vector::const_iterator
find( OSQLColumns::Vector::const_iterator __first
,
131 OSQLColumns::Vector::const_iterator __last
,
132 const OUString
& _rProp
,
133 const OUString
& _rVal
,
134 const ::comphelper::UStringMixEqual
& _rCase
);
136 OOO_DLLPUBLIC_DBTOOLS
void checkDisposed(bool _bThrow
) throw ( ::com::sun::star::lang::DisposedException
);
138 #if HAVE_FEATURE_JAVA
139 /** creates a java virtual machine
145 OOO_DLLPUBLIC_DBTOOLS ::rtl::Reference
< jvmaccess::VirtualMachine
> getJavaVM(const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& _rxContext
);
147 /** return <TRUE/> if the java class exists, otherwise <FALSE/>.
151 The class name to look for.
153 OOO_DLLPUBLIC_DBTOOLS
bool existsJavaClassByName( const ::rtl::Reference
< jvmaccess::VirtualMachine
>& _pJVM
,const OUString
& _sClassName
);
157 #define DECLARE_SERVICE_INFO() \
158 virtual OUString SAL_CALL getImplementationName( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; \
159 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; \
160 virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE \
162 #define IMPLEMENT_SERVICE_INFO(classname, implasciiname, serviceasciiname) \
163 OUString SAL_CALL classname::getImplementationName( ) throw (::com::sun::star::uno::RuntimeException, std::exception) \
165 return OUString(implasciiname); \
167 ::com::sun::star::uno::Sequence< OUString > SAL_CALL classname::getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException, std::exception) \
169 ::com::sun::star::uno::Sequence< OUString > aSupported(1); \
170 aSupported[0] = serviceasciiname; \
173 sal_Bool SAL_CALL classname::supportsService( const OUString& _rServiceName ) throw(::com::sun::star::uno::RuntimeException, std::exception) \
175 return cppu::supportsService(this, _rServiceName); \
178 #endif // INCLUDED_CONNECTIVITY_COMMONTOOLS_HXX
180 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */