summaryrefslogtreecommitdiff
path: root/include/connectivity/CommonTools.hxx
blob: 7a798c6e469636e2158fa1a2c3fe99acccb64609 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */
#ifndef INCLUDED_CONNECTIVITY_COMMONTOOLS_HXX
#define INCLUDED_CONNECTIVITY_COMMONTOOLS_HXX

#include <sal/config.h>
#include <config_features.h>

#include <map>

#include <rtl/ref.hxx>
#include <rtl/ustring.hxx>
#include <com/sun/star/lang/DisposedException.hpp>
#include <com/sun/star/uno/Any.hxx>
#include <vector>
#include <cppuhelper/weakref.hxx>
#include <comphelper/stl_types.hxx>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
#include <osl/interlck.h>
#include <com/sun/star/uno/XComponentContext.hpp>
#include <connectivity/dbtoolsdllapi.hxx>
#include <cppuhelper/supportsservice.hxx>
#include <salhelper/simplereferenceobject.hxx>

namespace com { namespace sun { namespace star { namespace util {
    struct Date;
    struct DateTime;
    struct Time;
}
}}}

#if HAVE_FEATURE_JAVA
namespace jvmaccess { class VirtualMachine; }
#endif

namespace connectivity
{
    OOO_DLLPUBLIC_DBTOOLS bool match(const sal_Unicode* pWild, const sal_Unicode* pStr, const sal_Unicode cEscape);
    inline bool match(const OUString &rWild, const OUString &rStr, const sal_Unicode cEscape)
    {
        return match(rWild.getStr(), rStr.getStr(), cEscape);
    }
    // typedefs
    typedef std::vector< css::uno::WeakReferenceHelper >           OWeakRefArray;
    typedef css::uno::Reference< css::sdbcx::XColumnsSupplier>     OSQLTable;

    typedef std::map<OUString,OSQLTable,comphelper::UStringMixLess> OSQLTables;

    // class ORefVector allows reference counting on a std::vector
    template< class VectorVal > class ORefVector : public salhelper::SimpleReferenceObject
    {
        std::vector< VectorVal > m_vector;

    protected:
        virtual ~ORefVector(){}
    public:
        typedef std::vector< VectorVal > Vector;

        ORefVector() {}
        ORefVector(size_t _st) : m_vector(_st) {}
        ORefVector(const ORefVector& rOther)
            : salhelper::SimpleReferenceObject()
            , m_vector(rOther.m_vector)
        {}

        ORefVector& operator=(const ORefVector& _rRH)
        {
            if ( &_rRH != this )
            {
                m_vector = _rRH.m_vector;
            }
            return *this;
        }

        std::vector< VectorVal > & get() { return m_vector; }
        std::vector< VectorVal > const & get() const { return m_vector; }

    };

    // class ORowVector incudes refcounting and initialze himself
    // with at least one element. This first element is reserved for
    // the bookmark
    template< class VectorVal > class ORowVector : public  ORefVector< VectorVal >
    {
    public:
        ORowVector() : ORefVector< VectorVal >(1){}
        ORowVector(size_t _st) : ORefVector< VectorVal >(_st+1)
            {}
    };

    typedef ORefVector< css::uno::Reference< css::beans::XPropertySet> > OSQLColumns;

    // search from __first to __last the column with the name _rVal
    // when no such column exist __last is returned
    OOO_DLLPUBLIC_DBTOOLS
    OSQLColumns::Vector::const_iterator find(   OSQLColumns::Vector::const_iterator __first,
                                        OSQLColumns::Vector::const_iterator __last,
                                        const OUString& _rVal,
                                        const ::comphelper::UStringMixEqual& _rCase);

    // search from __first to __last the column with the realname _rVal
    // when no such column exist __last is returned
    OOO_DLLPUBLIC_DBTOOLS
    OSQLColumns::Vector::const_iterator findRealName(   OSQLColumns::Vector::const_iterator __first,
                                                OSQLColumns::Vector::const_iterator __last,
                                                const OUString& _rVal,
                                                const ::comphelper::UStringMixEqual& _rCase);

    // the first two find methods are much faster than the one below
    // search from __first to __last the column with the property _rProp equals the value _rVal
    // when no such column exist __last is returned
    OOO_DLLPUBLIC_DBTOOLS
    OSQLColumns::Vector::const_iterator find(   OSQLColumns::Vector::const_iterator __first,
                                        OSQLColumns::Vector::const_iterator __last,
                                        const OUString& _rProp,
                                        const OUString& _rVal,
                                        const ::comphelper::UStringMixEqual& _rCase);

    OOO_DLLPUBLIC_DBTOOLS void checkDisposed(bool _bThrow) throw ( css::lang::DisposedException );

#if HAVE_FEATURE_JAVA
    /** creates a java virtual machine
        @param  _rxContext
            The ORB.
        @return
            The JavaVM.
    */
    OOO_DLLPUBLIC_DBTOOLS ::rtl::Reference< jvmaccess::VirtualMachine > getJavaVM(const css::uno::Reference< css::uno::XComponentContext >& _rxContext);

    /** return <TRUE/> if the java class exists, otherwise <FALSE/>.
        @param  _pJVM
            The JavaVM.
        @param  _sClassName
            The class name to look for.
    */
    OOO_DLLPUBLIC_DBTOOLS bool existsJavaClassByName( const ::rtl::Reference< jvmaccess::VirtualMachine >& _pJVM,const OUString& _sClassName );
#endif
}

#define DECLARE_SERVICE_INFO()  \
    virtual OUString SAL_CALL getImplementationName(  ) throw (css::uno::RuntimeException, std::exception) override; \
    virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw(css::uno::RuntimeException, std::exception) override; \
    virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames(  ) throw(css::uno::RuntimeException, std::exception) override \

#define IMPLEMENT_SERVICE_INFO(classname, implasciiname, serviceasciiname)  \
    OUString SAL_CALL classname::getImplementationName(  ) throw (css::uno::RuntimeException, std::exception)   \
    {   \
        return OUString(implasciiname); \
    }   \
    css::uno::Sequence< OUString > SAL_CALL classname::getSupportedServiceNames(  ) throw(css::uno::RuntimeException, std::exception)  \
    {   \
        css::uno::Sequence< OUString > aSupported(1);   \
        aSupported[0] = serviceasciiname; \
        return aSupported;  \
    }   \
    sal_Bool SAL_CALL classname::supportsService( const OUString& _rServiceName ) throw(css::uno::RuntimeException, std::exception) \
    {   \
        return cppu::supportsService(this, _rServiceName); \
    }   \

#endif // INCLUDED_CONNECTIVITY_COMMONTOOLS_HXX

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */