Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 : #ifndef INCLUDED_CONNECTIVITY_COMMONTOOLS_HXX
20 : #define INCLUDED_CONNECTIVITY_COMMONTOOLS_HXX
21 :
22 : #include <sal/config.h>
23 : #include <config_features.h>
24 :
25 : #include <map>
26 :
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>
31 : #include <vector>
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 :
41 : namespace com { namespace sun { namespace star { namespace util {
42 : struct Date;
43 : struct DateTime;
44 : struct Time;
45 : }
46 : }}}
47 :
48 : #if HAVE_FEATURE_JAVA
49 : namespace jvmaccess { class VirtualMachine; }
50 : #endif
51 :
52 : namespace connectivity
53 : {
54 : OOO_DLLPUBLIC_DBTOOLS bool match(const sal_Unicode* pWild, const sal_Unicode* pStr, const sal_Unicode cEscape);
55 0 : inline bool match(const OUString &rWild, const OUString &rStr, const sal_Unicode cEscape)
56 : {
57 0 : return match(rWild.getStr(), rStr.getStr(), cEscape);
58 : }
59 : // typedefs
60 : typedef std::vector< ::com::sun::star::uno::WeakReferenceHelper > OWeakRefArray;
61 : typedef ::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XColumnsSupplier> OSQLTable;
62 :
63 : typedef std::map<OUString,OSQLTable,comphelper::UStringMixLess> OSQLTables;
64 :
65 : // class ORefVector allows reference counting on a std::vector
66 : template< class VectorVal > class ORefVector
67 : {
68 : std::vector< VectorVal > m_vector;
69 : oslInterlockedCount m_refCount;
70 :
71 : protected:
72 0 : virtual ~ORefVector(){}
73 : public:
74 : typedef std::vector< VectorVal > Vector;
75 :
76 0 : ORefVector() : m_refCount(0) {}
77 0 : ORefVector(size_t _st) : m_vector(_st) , m_refCount(0) {}
78 0 : ORefVector(const ORefVector& _rRH) : m_vector(_rRH.m_vector),m_refCount(0)
79 : {
80 0 : }
81 0 : ORefVector& operator=(const ORefVector& _rRH)
82 : {
83 0 : if ( &_rRH != this )
84 : {
85 0 : m_vector = _rRH.m_vector;
86 : }
87 0 : return *this;
88 : }
89 :
90 0 : std::vector< VectorVal > & get() { return m_vector; }
91 0 : std::vector< VectorVal > const & get() const { return m_vector; }
92 :
93 0 : inline static void * SAL_CALL operator new( size_t nSize ) SAL_THROW(())
94 0 : { return ::rtl_allocateMemory( nSize ); }
95 0 : inline static void SAL_CALL operator delete( void * pMem ) SAL_THROW(())
96 0 : { ::rtl_freeMemory( pMem ); }
97 : inline static void * SAL_CALL operator new( size_t, void * pMem ) SAL_THROW(())
98 : { return pMem; }
99 : inline static void SAL_CALL operator delete( void *, void * ) SAL_THROW(())
100 : {}
101 :
102 0 : void acquire()
103 : {
104 0 : osl_atomic_increment( &m_refCount );
105 0 : }
106 0 : void release()
107 : {
108 0 : if (! osl_atomic_decrement( &m_refCount ))
109 0 : delete this;
110 0 : }
111 :
112 : };
113 :
114 : // class ORowVector incudes refcounting and initialze himself
115 : // with at least one element. This first element is reserved for
116 : // the bookmark
117 0 : template< class VectorVal > class ORowVector : public ORefVector< VectorVal >
118 : {
119 : public:
120 0 : ORowVector() : ORefVector< VectorVal >(1){}
121 0 : ORowVector(size_t _st) : ORefVector< VectorVal >(_st+1)
122 0 : {}
123 : };
124 :
125 : typedef ORefVector< ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet> > OSQLColumns;
126 :
127 : // search from __first to __last the column with the name _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& _rVal,
133 : const ::comphelper::UStringMixEqual& _rCase);
134 :
135 : // search from __first to __last the column with the realname _rVal
136 : // when no such column exist __last is returned
137 : OOO_DLLPUBLIC_DBTOOLS
138 : OSQLColumns::Vector::const_iterator findRealName( OSQLColumns::Vector::const_iterator __first,
139 : OSQLColumns::Vector::const_iterator __last,
140 : const OUString& _rVal,
141 : const ::comphelper::UStringMixEqual& _rCase);
142 :
143 : // the first two find methods are much faster than the one below
144 : // search from __first to __last the column with the property _rProp equals the value _rVal
145 : // when no such column exist __last is returned
146 : OOO_DLLPUBLIC_DBTOOLS
147 : OSQLColumns::Vector::const_iterator find( OSQLColumns::Vector::const_iterator __first,
148 : OSQLColumns::Vector::const_iterator __last,
149 : const OUString& _rProp,
150 : const OUString& _rVal,
151 : const ::comphelper::UStringMixEqual& _rCase);
152 :
153 : OOO_DLLPUBLIC_DBTOOLS void checkDisposed(bool _bThrow) throw ( ::com::sun::star::lang::DisposedException );
154 :
155 : #if HAVE_FEATURE_JAVA
156 : /** creates a java virtual machine
157 : @param _rxContext
158 : The ORB.
159 : @return
160 : The JavaVM.
161 : */
162 : OOO_DLLPUBLIC_DBTOOLS ::rtl::Reference< jvmaccess::VirtualMachine > getJavaVM(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext);
163 :
164 : /** return <TRUE/> if the java class exists, otherwise <FALSE/>.
165 : @param _pJVM
166 : The JavaVM.
167 : @param _sClassName
168 : The class name to look for.
169 : */
170 : OOO_DLLPUBLIC_DBTOOLS bool existsJavaClassByName( const ::rtl::Reference< jvmaccess::VirtualMachine >& _pJVM,const OUString& _sClassName );
171 : #endif
172 : }
173 :
174 : #define DECLARE_SERVICE_INFO() \
175 : virtual OUString SAL_CALL getImplementationName( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; \
176 : virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; \
177 : virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE \
178 :
179 : #define IMPLEMENT_SERVICE_INFO(classname, implasciiname, serviceasciiname) \
180 : OUString SAL_CALL classname::getImplementationName( ) throw (::com::sun::star::uno::RuntimeException, std::exception) \
181 : { \
182 : return OUString::createFromAscii(implasciiname); \
183 : } \
184 : ::com::sun::star::uno::Sequence< OUString > SAL_CALL classname::getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException, std::exception) \
185 : { \
186 : ::com::sun::star::uno::Sequence< OUString > aSupported(1); \
187 : aSupported[0] = OUString::createFromAscii(serviceasciiname); \
188 : return aSupported; \
189 : } \
190 : sal_Bool SAL_CALL classname::supportsService( const OUString& _rServiceName ) throw(::com::sun::star::uno::RuntimeException, std::exception) \
191 : { \
192 : return cppu::supportsService(this, _rServiceName); \
193 : } \
194 :
195 : #endif // INCLUDED_CONNECTIVITY_COMMONTOOLS_HXX
196 :
197 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|