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); 52 //------------------------------------------------------------------------------ 53 OOO_DLLPUBLIC_DBTOOLS rtl::OUString toString(const ::com::sun::star::uno::Any& rValue); 54 OOO_DLLPUBLIC_DBTOOLS rtl::OUString toDateString(const ::com::sun::star::util::Date& rDate); 55 OOO_DLLPUBLIC_DBTOOLS rtl::OUString toTimeString(const ::com::sun::star::util::Time& rTime); 56 OOO_DLLPUBLIC_DBTOOLS rtl::OUString toDateTimeString(const ::com::sun::star::util::DateTime& rDateTime); 57 58 // typedefs 59 typedef std::vector< ::com::sun::star::uno::WeakReferenceHelper > OWeakRefArray; 60 typedef ::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XColumnsSupplier> OSQLTable; 61 62 DECLARE_STL_MAP(::rtl::OUString,OSQLTable,comphelper::UStringMixLess, OSQLTables); 63 64 // ------------------------------------------------------------------------- 65 // class ORefVector allows reference counting on a std::vector 66 // ------------------------------------------------------------------------- 67 template< class VectorVal > class ORefVector 68 { 69 std::vector< VectorVal > m_vector; 70 oslInterlockedCount m_refCount; 71 // ORefVector(const ORefVector&); 72 // ORefVector& operator=(const ORefVector&); 73 74 protected: 75 virtual ~ORefVector(){} 76 public: 77 typedef std::vector< VectorVal > Vector; 78 79 ORefVector() : m_refCount(0) {} 80 ORefVector(size_t _st) : m_vector(_st) , m_refCount(0) {} 81 ORefVector(const ORefVector& _rRH) : m_vector(_rRH.m_vector),m_refCount(0) 82 { 83 } 84 ORefVector& operator=(const ORefVector& _rRH) 85 { 86 if ( &_rRH != this ) 87 { 88 m_vector = _rRH.m_vector; 89 } 90 return *this; 91 } 92 93 std::vector< VectorVal > & get() { return m_vector; } 94 std::vector< VectorVal > const & get() const { return m_vector; } 95 96 inline static void * SAL_CALL operator new( size_t nSize ) SAL_THROW( () ) 97 { return ::rtl_allocateMemory( nSize ); } 98 inline static void SAL_CALL operator delete( void * pMem ) SAL_THROW( () ) 99 { ::rtl_freeMemory( pMem ); } 100 inline static void * SAL_CALL operator new( size_t, void * pMem ) SAL_THROW( () ) 101 { return pMem; } 102 inline static void SAL_CALL operator delete( void *, void * ) SAL_THROW( () ) 103 {} 104 105 void acquire() 106 { 107 osl_incrementInterlockedCount( &m_refCount ); 108 } 109 void release() 110 { 111 if (! osl_decrementInterlockedCount( &m_refCount )) 112 delete this; 113 } 114 115 }; 116 // ------------------------------------------------------------------------- 117 // class ORowVector incudes refcounting and initialze himself 118 // with at least one element. This first element is reserved for 119 // the bookmark 120 // ------------------------------------------------------------------------- 121 template< class VectorVal > class ORowVector : public ORefVector< VectorVal > 122 { 123 public: 124 ORowVector() : ORefVector< VectorVal >(1){} 125 ORowVector(size_t _st) : ORefVector< VectorVal >(_st+1) 126 {} 127 }; 128 129 typedef ORefVector< ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet> > OSQLColumns; 130 131 // ======================================================================================= 132 // search from __first to __last the column with the name _rVal 133 // when no such column exist __last is returned 134 OOO_DLLPUBLIC_DBTOOLS 135 OSQLColumns::Vector::const_iterator find( OSQLColumns::Vector::const_iterator __first, 136 OSQLColumns::Vector::const_iterator __last, 137 const ::rtl::OUString& _rVal, 138 const ::comphelper::UStringMixEqual& _rCase); 139 // ======================================================================================= 140 // search from __first to __last the column with the realname _rVal 141 // when no such column exist __last is returned 142 OOO_DLLPUBLIC_DBTOOLS 143 OSQLColumns::Vector::const_iterator findRealName( OSQLColumns::Vector::const_iterator __first, 144 OSQLColumns::Vector::const_iterator __last, 145 const ::rtl::OUString& _rVal, 146 const ::comphelper::UStringMixEqual& _rCase); 147 148 // ======================================================================================= 149 // the first two find methods are much faster than the one below 150 // ======================================================================================= 151 // search from __first to __last the column with the property _rProp equals the value _rVal 152 // when no such column exist __last is returned 153 OOO_DLLPUBLIC_DBTOOLS 154 OSQLColumns::Vector::const_iterator find( OSQLColumns::Vector::const_iterator __first, 155 OSQLColumns::Vector::const_iterator __last, 156 const ::rtl::OUString& _rProp, 157 const ::rtl::OUString& _rVal, 158 const ::comphelper::UStringMixEqual& _rCase); 159 160 OOO_DLLPUBLIC_DBTOOLS void checkDisposed(sal_Bool _bThrow) throw ( ::com::sun::star::lang::DisposedException ); 161 162 163 /** creates a java virtual machine 164 @param _rxFactory 165 The ORB. 166 @return 167 The JavaVM. 168 */ 169 OOO_DLLPUBLIC_DBTOOLS ::rtl::Reference< jvmaccess::VirtualMachine > getJavaVM(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory); 170 171 /** return <TRUE/> if the java class exists, otherwise <FALSE/>. 172 @param _pJVM 173 The JavaVM. 174 @param _sClassName 175 The class name to look for. 176 */ 177 OOO_DLLPUBLIC_DBTOOLS sal_Bool existsJavaClassByName( const ::rtl::Reference< jvmaccess::VirtualMachine >& _pJVM,const ::rtl::OUString& _sClassName ); 178 } 179 180 //================================================================================== 181 182 #define DECLARE_SERVICE_INFO() \ 183 virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw (::com::sun::star::uno::RuntimeException); \ 184 virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException); \ 185 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException) \ 186 187 #define IMPLEMENT_SERVICE_INFO(classname, implasciiname, serviceasciiname) \ 188 ::rtl::OUString SAL_CALL classname::getImplementationName( ) throw (::com::sun::star::uno::RuntimeException) \ 189 { \ 190 return ::rtl::OUString::createFromAscii(implasciiname); \ 191 } \ 192 ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL classname::getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException) \ 193 { \ 194 ::com::sun::star::uno::Sequence< ::rtl::OUString > aSupported(1); \ 195 aSupported[0] = ::rtl::OUString::createFromAscii(serviceasciiname); \ 196 return aSupported; \ 197 } \ 198 sal_Bool SAL_CALL classname::supportsService( const ::rtl::OUString& _rServiceName ) throw(::com::sun::star::uno::RuntimeException) \ 199 { \ 200 Sequence< ::rtl::OUString > aSupported(getSupportedServiceNames()); \ 201 const ::rtl::OUString* pSupported = aSupported.getConstArray(); \ 202 const ::rtl::OUString* pEnd = pSupported + aSupported.getLength(); \ 203 for (;pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported) \ 204 ; \ 205 \ 206 return pSupported != pEnd; \ 207 } \ 208 209 //================================================================================== 210 211 #endif // _CONNECTIVITY_COMMONTOOLS_HXX_ 212 213