Branch data 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 _CONNECTIVITY_COMMONTOOLS_HXX_
20 : : #define _CONNECTIVITY_COMMONTOOLS_HXX_
21 : :
22 : : #include <rtl/ustring.hxx>
23 : : #include <com/sun/star/lang/DisposedException.hpp>
24 : : #include <com/sun/star/uno/Any.hxx>
25 : : #ifndef _VECTOR_
26 : : #include <vector>
27 : : #endif
28 : : #include <cppuhelper/weakref.hxx>
29 : : #include <comphelper/stl_types.hxx>
30 : : #include <com/sun/star/beans/XPropertySet.hpp>
31 : : #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
32 : : #include <osl/interlck.h>
33 : : #include <jvmaccess/virtualmachine.hxx>
34 : : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
35 : : #include "connectivity/dbtoolsdllapi.hxx"
36 : :
37 : : namespace com { namespace sun { namespace star { namespace util {
38 : : struct Date;
39 : : struct DateTime;
40 : : struct Time;
41 : : }
42 : : }}}
43 : :
44 : : namespace connectivity
45 : : {
46 : : //------------------------------------------------------------------------------
47 : : OOO_DLLPUBLIC_DBTOOLS sal_Bool match(const sal_Unicode* pWild, const sal_Unicode* pStr, const sal_Unicode cEscape);
48 : 194 : inline sal_Bool match(const ::rtl::OUString &rWild, const ::rtl::OUString &rStr, const sal_Unicode cEscape)
49 : : {
50 : 194 : return match(rWild.getStr(), rStr.getStr(), cEscape);
51 : : }
52 : : //------------------------------------------------------------------------------
53 : : OOO_DLLPUBLIC_DBTOOLS rtl::OUString toDateString(const ::com::sun::star::util::Date& rDate);
54 : : OOO_DLLPUBLIC_DBTOOLS rtl::OUString toTimeString(const ::com::sun::star::util::Time& rTime);
55 : : OOO_DLLPUBLIC_DBTOOLS rtl::OUString toDateTimeString(const ::com::sun::star::util::DateTime& rDateTime);
56 : :
57 : : // typedefs
58 : : typedef std::vector< ::com::sun::star::uno::WeakReferenceHelper > OWeakRefArray;
59 : : typedef ::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XColumnsSupplier> OSQLTable;
60 : :
61 : : DECLARE_STL_MAP(::rtl::OUString,OSQLTable,comphelper::UStringMixLess, OSQLTables);
62 : :
63 : : // -------------------------------------------------------------------------
64 : : // class ORefVector allows reference counting on a std::vector
65 : : // -------------------------------------------------------------------------
66 : : template< class VectorVal > class ORefVector
67 : : {
68 : : std::vector< VectorVal > m_vector;
69 : : oslInterlockedCount m_refCount;
70 : :
71 : : protected:
72 [ - + ][ - + ]: 10488 : virtual ~ORefVector(){}
[ # # ][ # # ]
73 : : public:
74 : : typedef std::vector< VectorVal > Vector;
75 : :
76 : 4412 : ORefVector() : m_refCount(0) {}
77 : 1318 : ORefVector(size_t _st) : m_vector(_st) , m_refCount(0) {}
78 : 400 : ORefVector(const ORefVector& _rRH) : m_vector(_rRH.m_vector),m_refCount(0)
79 : : {
80 : 400 : }
81 : 10 : ORefVector& operator=(const ORefVector& _rRH)
82 : : {
83 [ + - ]: 10 : if ( &_rRH != this )
84 : : {
85 : 10 : m_vector = _rRH.m_vector;
86 : : }
87 : 10 : return *this;
88 : : }
89 : :
90 : 265818 : std::vector< VectorVal > & get() { return m_vector; }
91 : 14344 : std::vector< VectorVal > const & get() const { return m_vector; }
92 : :
93 : 5522 : inline static void * SAL_CALL operator new( size_t nSize ) SAL_THROW(())
94 : 5522 : { return ::rtl_allocateMemory( nSize ); }
95 : 5522 : inline static void SAL_CALL operator delete( void * pMem ) SAL_THROW(())
96 : 5522 : { ::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 : 11388 : void acquire()
103 : : {
104 : 11388 : osl_incrementInterlockedCount( &m_refCount );
105 : 11388 : }
106 : 11388 : void release()
107 : : {
108 [ + + ][ + + ]: 11388 : if (! osl_decrementInterlockedCount( &m_refCount ))
[ # # ][ # # ]
109 [ + - ][ + - ]: 5522 : delete this;
[ # # ][ # # ]
110 : 11388 : }
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 : : // -------------------------------------------------------------------------
118 [ - + ][ # # ]: 2830 : template< class VectorVal > class ORowVector : public ORefVector< VectorVal >
[ # # ][ # # ]
119 : : {
120 : : public:
121 : 696 : ORowVector() : ORefVector< VectorVal >(1){}
122 : 622 : ORowVector(size_t _st) : ORefVector< VectorVal >(_st+1)
123 : 622 : {}
124 : : };
125 : :
126 : : typedef ORefVector< ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet> > OSQLColumns;
127 : :
128 : : // =======================================================================================
129 : : // search from __first to __last the column with the name _rVal
130 : : // when no such column exist __last is returned
131 : : OOO_DLLPUBLIC_DBTOOLS
132 : : OSQLColumns::Vector::const_iterator find( OSQLColumns::Vector::const_iterator __first,
133 : : OSQLColumns::Vector::const_iterator __last,
134 : : const ::rtl::OUString& _rVal,
135 : : const ::comphelper::UStringMixEqual& _rCase);
136 : : // =======================================================================================
137 : : // search from __first to __last the column with the realname _rVal
138 : : // when no such column exist __last is returned
139 : : OOO_DLLPUBLIC_DBTOOLS
140 : : OSQLColumns::Vector::const_iterator findRealName( OSQLColumns::Vector::const_iterator __first,
141 : : OSQLColumns::Vector::const_iterator __last,
142 : : const ::rtl::OUString& _rVal,
143 : : const ::comphelper::UStringMixEqual& _rCase);
144 : :
145 : : // =======================================================================================
146 : : // the first two find methods are much faster than the one below
147 : : // =======================================================================================
148 : : // search from __first to __last the column with the property _rProp equals the value _rVal
149 : : // when no such column exist __last is returned
150 : : OOO_DLLPUBLIC_DBTOOLS
151 : : OSQLColumns::Vector::const_iterator find( OSQLColumns::Vector::const_iterator __first,
152 : : OSQLColumns::Vector::const_iterator __last,
153 : : const ::rtl::OUString& _rProp,
154 : : const ::rtl::OUString& _rVal,
155 : : const ::comphelper::UStringMixEqual& _rCase);
156 : :
157 : : OOO_DLLPUBLIC_DBTOOLS void checkDisposed(sal_Bool _bThrow) throw ( ::com::sun::star::lang::DisposedException );
158 : :
159 : :
160 : : /** creates a java virtual machine
161 : : @param _rxFactory
162 : : The ORB.
163 : : @return
164 : : The JavaVM.
165 : : */
166 : : OOO_DLLPUBLIC_DBTOOLS ::rtl::Reference< jvmaccess::VirtualMachine > getJavaVM(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory);
167 : :
168 : : /** return <TRUE/> if the java class exists, otherwise <FALSE/>.
169 : : @param _pJVM
170 : : The JavaVM.
171 : : @param _sClassName
172 : : The class name to look for.
173 : : */
174 : : OOO_DLLPUBLIC_DBTOOLS sal_Bool existsJavaClassByName( const ::rtl::Reference< jvmaccess::VirtualMachine >& _pJVM,const ::rtl::OUString& _sClassName );
175 : : }
176 : :
177 : : //==================================================================================
178 : :
179 : : #define DECLARE_SERVICE_INFO() \
180 : : virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw (::com::sun::star::uno::RuntimeException); \
181 : : virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException); \
182 : : virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException) \
183 : :
184 : : #define IMPLEMENT_SERVICE_INFO(classname, implasciiname, serviceasciiname) \
185 : : ::rtl::OUString SAL_CALL classname::getImplementationName( ) throw (::com::sun::star::uno::RuntimeException) \
186 : : { \
187 : : return ::rtl::OUString::createFromAscii(implasciiname); \
188 : : } \
189 : : ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL classname::getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException) \
190 : : { \
191 : : ::com::sun::star::uno::Sequence< ::rtl::OUString > aSupported(1); \
192 : : aSupported[0] = ::rtl::OUString::createFromAscii(serviceasciiname); \
193 : : return aSupported; \
194 : : } \
195 : : sal_Bool SAL_CALL classname::supportsService( const ::rtl::OUString& _rServiceName ) throw(::com::sun::star::uno::RuntimeException) \
196 : : { \
197 : : Sequence< ::rtl::OUString > aSupported(getSupportedServiceNames()); \
198 : : const ::rtl::OUString* pSupported = aSupported.getConstArray(); \
199 : : const ::rtl::OUString* pEnd = pSupported + aSupported.getLength(); \
200 : : for (;pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported) \
201 : : ; \
202 : : \
203 : : return pSupported != pEnd; \
204 : : } \
205 : :
206 : : //==================================================================================
207 : :
208 : : #endif // _CONNECTIVITY_COMMONTOOLS_HXX_
209 : :
210 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|