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_java.h>
26 #include <string_view>
28 #include <rtl/ref.hxx>
29 #include <rtl/ustring.hxx>
31 #include <cppuhelper/weakref.hxx>
32 #include <comphelper/stl_types.hxx>
33 #include <com/sun/star/beans/XPropertySet.hpp>
34 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
35 #include <connectivity/dbtoolsdllapi.hxx>
36 #include <cppuhelper/supportsservice.hxx>
37 #include <salhelper/simplereferenceobject.hxx>
39 namespace com::sun::star::uno
{ class XComponentContext
; }
42 namespace jvmaccess
{ class VirtualMachine
; }
45 namespace connectivity
47 OOO_DLLPUBLIC_DBTOOLS
bool match(const sal_Unicode
* pWild
, const sal_Unicode
* pStr
, const sal_Unicode cEscape
);
48 inline bool match(const OUString
&rWild
, const OUString
&rStr
, const sal_Unicode cEscape
)
50 return match(rWild
.getStr(), rStr
.getStr(), cEscape
);
53 typedef std::vector
< css::uno::WeakReferenceHelper
> OWeakRefArray
;
54 typedef css::uno::Reference
< css::sdbcx::XColumnsSupplier
> OSQLTable
;
56 typedef std::map
<OUString
,OSQLTable
,comphelper::UStringMixLess
> OSQLTables
;
58 // class ORefVector allows reference counting on a std::vector
59 template< class VectorVal
> class ORefVector
: public salhelper::SimpleReferenceObject
,
60 public std::vector
< VectorVal
>
63 virtual ~ORefVector() override
{}
65 typedef std::vector
< VectorVal
> Vector
;
68 ORefVector(size_t _st
) : std::vector
< VectorVal
>(_st
) {}
69 ORefVector(const ORefVector
& rOther
)
70 : salhelper::SimpleReferenceObject()
71 , std::vector
< VectorVal
>(rOther
)
74 ORefVector
& operator=(const ORefVector
& _rRH
)
78 std::vector
< VectorVal
>::operator=(_rRH
);
84 // class ORowVector includes refcounting and initialize himself
85 // with at least one element. This first element is reserved for
87 template< class VectorVal
> class ORowVector
: public ORefVector
< VectorVal
>
90 ORowVector() : ORefVector
< VectorVal
>(1){}
91 ORowVector(size_t _st
) : ORefVector
< VectorVal
>(_st
+1)
95 typedef ORefVector
< css::uno::Reference
< css::beans::XPropertySet
> > OSQLColumns
;
97 // search from first to last the column with the name _rVal
98 // when no such column exist last is returned
100 OSQLColumns::const_iterator
find( const OSQLColumns::const_iterator
& first
,
101 const OSQLColumns::const_iterator
& last
,
102 std::u16string_view _rVal
,
103 const ::comphelper::UStringMixEqual
& _rCase
);
105 // search from first to last the column with the realname _rVal
106 // when no such column exist last is returned
107 OOO_DLLPUBLIC_DBTOOLS
108 OSQLColumns::const_iterator
findRealName( const OSQLColumns::const_iterator
& first
,
109 const OSQLColumns::const_iterator
& last
,
110 std::u16string_view _rVal
,
111 const ::comphelper::UStringMixEqual
& _rCase
);
113 // the first two find methods are much faster than the one below
114 // search from first to last the column with the property _rProp equals the value _rVal
115 // when no such column exist last is returned
116 OOO_DLLPUBLIC_DBTOOLS
117 OSQLColumns::const_iterator
find( OSQLColumns::const_iterator first
,
118 const OSQLColumns::const_iterator
& last
,
119 const OUString
& _rProp
,
120 std::u16string_view _rVal
,
121 const ::comphelper::UStringMixEqual
& _rCase
);
123 /// @throws css::lang::DisposedException
124 OOO_DLLPUBLIC_DBTOOLS
void checkDisposed(bool _bThrow
);
126 #if HAVE_FEATURE_JAVA
127 /** creates a java virtual machine
133 OOO_DLLPUBLIC_DBTOOLS ::rtl::Reference
< jvmaccess::VirtualMachine
> getJavaVM(const css::uno::Reference
< css::uno::XComponentContext
>& _rxContext
);
135 /** return <TRUE/> if the java class exists, otherwise <FALSE/>.
139 The class name to look for.
141 OOO_DLLPUBLIC_DBTOOLS
bool existsJavaClassByName( const ::rtl::Reference
< jvmaccess::VirtualMachine
>& _pJVM
,std::u16string_view _sClassName
);
145 #define DECLARE_SERVICE_INFO() \
146 virtual OUString SAL_CALL getImplementationName( ) override; \
147 virtual sal_Bool SAL_CALL supportsService( const OUString& rServiceName ) override; \
148 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override \
150 #define IMPLEMENT_SERVICE_INFO(classname, implasciiname, serviceasciiname) \
151 OUString SAL_CALL classname::getImplementationName( ) \
153 return implasciiname; \
155 css::uno::Sequence< OUString > SAL_CALL classname::getSupportedServiceNames( ) \
157 css::uno::Sequence< OUString > aSupported { serviceasciiname }; \
160 sal_Bool SAL_CALL classname::supportsService( const OUString& rServiceName ) \
162 return cppu::supportsService(this, rServiceName); \
165 #endif // INCLUDED_CONNECTIVITY_COMMONTOOLS_HXX
167 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */