1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 #ifndef _CONNECTIVITY_COMMONTOOLS_HXX_ 24 #define _CONNECTIVITY_COMMONTOOLS_HXX_ 25 26 #include <rtl/ustring.hxx> 27 #include <com/sun/star/lang/DisposedException.hpp> 28 #include <com/sun/star/uno/Any.hxx> 29 #ifndef _VECTOR_ 30 #include <vector> 31 #endif 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 <jvmaccess/virtualmachine.hxx> 38 #include <com/sun/star/lang/XMultiServiceFactory.hpp> 39 #include "connectivity/dbtoolsdllapi.hxx" 40 41 namespace com { namespace sun { namespace star { namespace util { 42 struct Date; 43 struct DateTime; 44 struct Time; 45 } 46 }}} 47 48 namespace connectivity 49 { 50 //------------------------------------------------------------------------------ 51 OOO_DLLPUBLIC_DBTOOLS sal_Bool match(const sal_Unicode* pWild, const sal_Unicode* pStr, const sal_Unicode cEscape); match(const rtl::OUString & rWild,const sal_Unicode * pStr,sal_Unicode cEscape)52 inline sal_Bool match( const rtl::OUString& rWild, const sal_Unicode* pStr, sal_Unicode cEscape) 53 { return match( rWild.getStr(), pStr, cEscape); } match(const rtl::OUString & rWild,const rtl::OUString & rStr,sal_Unicode cEscape)54 inline sal_Bool match( const rtl::OUString& rWild, const rtl::OUString& rStr, sal_Unicode cEscape) 55 { return match( rWild, rStr.getStr(), cEscape); } 56 //------------------------------------------------------------------------------ 57 OOO_DLLPUBLIC_DBTOOLS rtl::OUString toString(const ::com::sun::star::uno::Any& rValue); 58 OOO_DLLPUBLIC_DBTOOLS rtl::OUString toDateString(const ::com::sun::star::util::Date& rDate); 59 OOO_DLLPUBLIC_DBTOOLS rtl::OUString toTimeString(const ::com::sun::star::util::Time& rTime); 60 OOO_DLLPUBLIC_DBTOOLS rtl::OUString toDateTimeString(const ::com::sun::star::util::DateTime& rDateTime); 61 62 // typedefs 63 typedef std::vector< ::com::sun::star::uno::WeakReferenceHelper > OWeakRefArray; 64 typedef ::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XColumnsSupplier> OSQLTable; 65 66 DECLARE_STL_MAP(::rtl::OUString,OSQLTable,comphelper::UStringMixLess, OSQLTables); 67 68 // ------------------------------------------------------------------------- 69 // class ORefVector allows reference counting on a std::vector 70 // ------------------------------------------------------------------------- 71 template< class VectorVal > class ORefVector 72 { 73 std::vector< VectorVal > m_vector; 74 oslInterlockedCount m_refCount; 75 // ORefVector(const ORefVector&); 76 // ORefVector& operator=(const ORefVector&); 77 78 protected: ~ORefVector()79 virtual ~ORefVector(){} 80 public: 81 typedef std::vector< VectorVal > Vector; 82 ORefVector()83 ORefVector() : m_refCount(0) {} ORefVector(size_t _st)84 ORefVector(size_t _st) : m_vector(_st) , m_refCount(0) {} ORefVector(const ORefVector & _rRH)85 ORefVector(const ORefVector& _rRH) : m_vector(_rRH.m_vector),m_refCount(0) 86 { 87 } operator =(const ORefVector & _rRH)88 ORefVector& operator=(const ORefVector& _rRH) 89 { 90 if ( &_rRH != this ) 91 { 92 m_vector = _rRH.m_vector; 93 } 94 return *this; 95 } 96 get()97 std::vector< VectorVal > & get() { return m_vector; } get() const98 std::vector< VectorVal > const & get() const { return m_vector; } 99 operator new(size_t nSize)100 inline static void * SAL_CALL operator new( size_t nSize ) SAL_THROW( () ) 101 { return ::rtl_allocateMemory( nSize ); } operator delete(void * pMem)102 inline static void SAL_CALL operator delete( void * pMem ) SAL_THROW( () ) 103 { ::rtl_freeMemory( pMem ); } operator new(size_t,void * pMem)104 inline static void * SAL_CALL operator new( size_t, void * pMem ) SAL_THROW( () ) 105 { return pMem; } operator delete(void *,void *)106 inline static void SAL_CALL operator delete( void *, void * ) SAL_THROW( () ) 107 {} 108 acquire()109 void acquire() 110 { 111 osl_incrementInterlockedCount( &m_refCount ); 112 } release()113 void release() 114 { 115 if (! osl_decrementInterlockedCount( &m_refCount )) 116 delete this; 117 } 118 119 }; 120 // ------------------------------------------------------------------------- 121 // class ORowVector incudes refcounting and initialze himself 122 // with at least one element. This first element is reserved for 123 // the bookmark 124 // ------------------------------------------------------------------------- 125 template< class VectorVal > class ORowVector : public ORefVector< VectorVal > 126 { 127 public: ORowVector()128 ORowVector() : ORefVector< VectorVal >(1){} ORowVector(size_t _st)129 ORowVector(size_t _st) : ORefVector< VectorVal >(_st+1) 130 {} 131 }; 132 133 typedef ORefVector< ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet> > OSQLColumns; 134 135 // ======================================================================================= 136 // search from __first to __last the column with the name _rVal 137 // when no such column exist __last is returned 138 OOO_DLLPUBLIC_DBTOOLS 139 OSQLColumns::Vector::const_iterator find( OSQLColumns::Vector::const_iterator __first, 140 OSQLColumns::Vector::const_iterator __last, 141 const ::rtl::OUString& _rVal, 142 const ::comphelper::UStringMixEqual& _rCase); 143 // ======================================================================================= 144 // search from __first to __last the column with the realname _rVal 145 // when no such column exist __last is returned 146 OOO_DLLPUBLIC_DBTOOLS 147 OSQLColumns::Vector::const_iterator findRealName( OSQLColumns::Vector::const_iterator __first, 148 OSQLColumns::Vector::const_iterator __last, 149 const ::rtl::OUString& _rVal, 150 const ::comphelper::UStringMixEqual& _rCase); 151 152 // ======================================================================================= 153 // the first two find methods are much faster than the one below 154 // ======================================================================================= 155 // search from __first to __last the column with the property _rProp equals the value _rVal 156 // when no such column exist __last is returned 157 OOO_DLLPUBLIC_DBTOOLS 158 OSQLColumns::Vector::const_iterator find( OSQLColumns::Vector::const_iterator __first, 159 OSQLColumns::Vector::const_iterator __last, 160 const ::rtl::OUString& _rProp, 161 const ::rtl::OUString& _rVal, 162 const ::comphelper::UStringMixEqual& _rCase); 163 164 OOO_DLLPUBLIC_DBTOOLS void checkDisposed(sal_Bool _bThrow) throw ( ::com::sun::star::lang::DisposedException ); 165 166 167 /** creates a java virtual machine 168 @param _rxFactory 169 The ORB. 170 @return 171 The JavaVM. 172 */ 173 OOO_DLLPUBLIC_DBTOOLS ::rtl::Reference< jvmaccess::VirtualMachine > getJavaVM(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory); 174 175 /** return <TRUE/> if the java class exists, otherwise <FALSE/>. 176 @param _pJVM 177 The JavaVM. 178 @param _sClassName 179 The class name to look for. 180 */ 181 OOO_DLLPUBLIC_DBTOOLS sal_Bool existsJavaClassByName( const ::rtl::Reference< jvmaccess::VirtualMachine >& _pJVM,const ::rtl::OUString& _sClassName ); 182 } 183 184 //================================================================================== 185 186 #define DECLARE_SERVICE_INFO() \ 187 virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw (::com::sun::star::uno::RuntimeException); \ 188 virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException); \ 189 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException) \ 190 191 #define IMPLEMENT_SERVICE_INFO(classname, implasciiname, serviceasciiname) \ 192 ::rtl::OUString SAL_CALL classname::getImplementationName( ) throw (::com::sun::star::uno::RuntimeException) \ 193 { \ 194 return ::rtl::OUString::createFromAscii(implasciiname); \ 195 } \ 196 ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL classname::getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException) \ 197 { \ 198 ::com::sun::star::uno::Sequence< ::rtl::OUString > aSupported(1); \ 199 aSupported[0] = ::rtl::OUString::createFromAscii(serviceasciiname); \ 200 return aSupported; \ 201 } \ 202 sal_Bool SAL_CALL classname::supportsService( const ::rtl::OUString& _rServiceName ) throw(::com::sun::star::uno::RuntimeException) \ 203 { \ 204 Sequence< ::rtl::OUString > aSupported(getSupportedServiceNames()); \ 205 const ::rtl::OUString* pSupported = aSupported.getConstArray(); \ 206 const ::rtl::OUString* pEnd = pSupported + aSupported.getLength(); \ 207 for (;pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported) \ 208 ; \ 209 \ 210 return pSupported != pEnd; \ 211 } \ 212 213 //================================================================================== 214 215 #endif // _CONNECTIVITY_COMMONTOOLS_HXX_ 216 217