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