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 : #include <salhelper/simplereferenceobject.hxx>
41 :
42 : namespace com { namespace sun { namespace star { namespace util {
43 : struct Date;
44 : struct DateTime;
45 : struct Time;
46 : }
47 : }}}
48 :
49 : #if HAVE_FEATURE_JAVA
50 : namespace jvmaccess { class VirtualMachine; }
51 : #endif
52 :
53 : namespace connectivity
54 : {
55 : OOO_DLLPUBLIC_DBTOOLS bool match(const sal_Unicode* pWild, const sal_Unicode* pStr, const sal_Unicode cEscape);
56 6472 : inline bool match(const OUString &rWild, const OUString &rStr, const sal_Unicode cEscape)
57 : {
58 6472 : return match(rWild.getStr(), rStr.getStr(), cEscape);
59 : }
60 : // typedefs
61 : typedef std::vector< ::com::sun::star::uno::WeakReferenceHelper > OWeakRefArray;
62 : typedef ::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XColumnsSupplier> OSQLTable;
63 :
64 : typedef std::map<OUString,OSQLTable,comphelper::UStringMixLess> OSQLTables;
65 :
66 : // class ORefVector allows reference counting on a std::vector
67 : template< class VectorVal > class ORefVector : public salhelper::SimpleReferenceObject
68 : {
69 : std::vector< VectorVal > m_vector;
70 :
71 : protected:
72 11276 : virtual ~ORefVector(){}
73 : public:
74 : typedef std::vector< VectorVal > Vector;
75 :
76 4672 : ORefVector() {}
77 1482 : ORefVector(size_t _st) : m_vector(_st) {}
78 508 : ORefVector(const ORefVector& rOther)
79 : : salhelper::SimpleReferenceObject()
80 508 : , m_vector(rOther.m_vector)
81 508 : {}
82 :
83 10 : ORefVector& operator=(const ORefVector& _rRH)
84 : {
85 10 : if ( &_rRH != this )
86 : {
87 10 : m_vector = _rRH.m_vector;
88 : }
89 10 : return *this;
90 : }
91 :
92 369814 : std::vector< VectorVal > & get() { return m_vector; }
93 15258 : std::vector< VectorVal > const & get() const { return m_vector; }
94 :
95 : };
96 :
97 : // class ORowVector incudes refcounting and initialze himself
98 : // with at least one element. This first element is reserved for
99 : // the bookmark
100 3370 : template< class VectorVal > class ORowVector : public ORefVector< VectorVal >
101 : {
102 : public:
103 804 : ORowVector() : ORefVector< VectorVal >(1){}
104 678 : ORowVector(size_t _st) : ORefVector< VectorVal >(_st+1)
105 678 : {}
106 : };
107 :
108 : typedef ORefVector< ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet> > OSQLColumns;
109 :
110 : // search from __first to __last the column with the name _rVal
111 : // when no such column exist __last is returned
112 : OOO_DLLPUBLIC_DBTOOLS
113 : OSQLColumns::Vector::const_iterator find( OSQLColumns::Vector::const_iterator __first,
114 : OSQLColumns::Vector::const_iterator __last,
115 : const OUString& _rVal,
116 : const ::comphelper::UStringMixEqual& _rCase);
117 :
118 : // search from __first to __last the column with the realname _rVal
119 : // when no such column exist __last is returned
120 : OOO_DLLPUBLIC_DBTOOLS
121 : OSQLColumns::Vector::const_iterator findRealName( OSQLColumns::Vector::const_iterator __first,
122 : OSQLColumns::Vector::const_iterator __last,
123 : const OUString& _rVal,
124 : const ::comphelper::UStringMixEqual& _rCase);
125 :
126 : // the first two find methods are much faster than the one below
127 : // search from __first to __last the column with the property _rProp equals the value _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& _rProp,
133 : const OUString& _rVal,
134 : const ::comphelper::UStringMixEqual& _rCase);
135 :
136 : OOO_DLLPUBLIC_DBTOOLS void checkDisposed(bool _bThrow) throw ( ::com::sun::star::lang::DisposedException );
137 :
138 : #if HAVE_FEATURE_JAVA
139 : /** creates a java virtual machine
140 : @param _rxContext
141 : The ORB.
142 : @return
143 : The JavaVM.
144 : */
145 : OOO_DLLPUBLIC_DBTOOLS ::rtl::Reference< jvmaccess::VirtualMachine > getJavaVM(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext);
146 :
147 : /** return <TRUE/> if the java class exists, otherwise <FALSE/>.
148 : @param _pJVM
149 : The JavaVM.
150 : @param _sClassName
151 : The class name to look for.
152 : */
153 : OOO_DLLPUBLIC_DBTOOLS bool existsJavaClassByName( const ::rtl::Reference< jvmaccess::VirtualMachine >& _pJVM,const OUString& _sClassName );
154 : #endif
155 : }
156 :
157 : #define DECLARE_SERVICE_INFO() \
158 : virtual OUString SAL_CALL getImplementationName( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; \
159 : virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; \
160 : virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE \
161 :
162 : #define IMPLEMENT_SERVICE_INFO(classname, implasciiname, serviceasciiname) \
163 : OUString SAL_CALL classname::getImplementationName( ) throw (::com::sun::star::uno::RuntimeException, std::exception) \
164 : { \
165 : return OUString::createFromAscii(implasciiname); \
166 : } \
167 : ::com::sun::star::uno::Sequence< OUString > SAL_CALL classname::getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException, std::exception) \
168 : { \
169 : ::com::sun::star::uno::Sequence< OUString > aSupported(1); \
170 : aSupported[0] = OUString::createFromAscii(serviceasciiname); \
171 : return aSupported; \
172 : } \
173 : sal_Bool SAL_CALL classname::supportsService( const OUString& _rServiceName ) throw(::com::sun::star::uno::RuntimeException, std::exception) \
174 : { \
175 : return cppu::supportsService(this, _rServiceName); \
176 : } \
177 :
178 : #endif // INCLUDED_CONNECTIVITY_COMMONTOOLS_HXX
179 :
180 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|