summaryrefslogtreecommitdiffstats
path: root/connectivity/source/drivers/postgresql/pq_xcontainer.hxx
blob: fd9d432bfad353b2a73a540cbdc15cbb0cb2fb30 (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
181
182
183
184
185
186
187
188
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
 *
 *  Effective License of whole file:
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 *  Parts "Copyright by Sun Microsystems, Inc" prior to August 2011:
 *
 *    The Contents of this file are made available subject to the terms of
 *    the GNU Lesser General Public License Version 2.1
 *
 *    Copyright: 2000 by Sun Microsystems, Inc.
 *
 *    Contributor(s): Joerg Budischewski
 *
 *  All parts contributed on or after August 2011:
 *
 *    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/.
 *
 ************************************************************************/

#pragma once
#include <com/sun/star/container/XNameAccess.hpp>
#include <com/sun/star/container/XIndexAccess.hpp>
#include <com/sun/star/container/XEnumerationAccess.hpp>
#include <com/sun/star/container/XContainer.hpp>

#include <com/sun/star/sdbc/XConnection.hpp>
#include <com/sun/star/sdbcx/XAppend.hpp>
#include <com/sun/star/sdbcx/XDrop.hpp>
#include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp>

#include <com/sun/star/util/XRefreshable.hpp>

#include <comphelper/refcountedmutex.hxx>
#include <cppuhelper/compbase.hxx>
#include <rtl/ref.hxx>

#include <unordered_map>

namespace pq_sdbc_driver
{

struct ConnectionSettings;

class EventBroadcastHelper
{
public:
    virtual void fire(css::lang::XEventListener * listener) const = 0;
    virtual css::uno::Type getType() const = 0;
    virtual ~EventBroadcastHelper(){};
};

class RefreshedBroadcaster : public EventBroadcastHelper
{
    css::lang::EventObject m_event;
public:
    explicit RefreshedBroadcaster(const css::uno::Reference< css::uno::XInterface > & source ) :
        m_event( source )
    {}

    virtual void fire( css::lang::XEventListener * listener ) const override
    {
        static_cast<css::util::XRefreshListener*>(listener)->refreshed( m_event );
    }

    virtual css::uno::Type getType() const override
    {
        return cppu::UnoType<
            css::util::XRefreshListener>::get();
    }
};

typedef std::unordered_map
<
   OUString,
   sal_Int32
> String2IntMap;

typedef ::cppu::WeakComponentImplHelper
<
    css::container::XNameAccess,
    css::container::XIndexAccess,
    css::container::XEnumerationAccess,
    css::sdbcx::XAppend,
    css::sdbcx::XDrop,
    css::util::XRefreshable,
    css::sdbcx::XDataDescriptorFactory,
    css::container::XContainer
> ContainerBase;

class /* abstract */ Container : public ContainerBase
{
protected:
    ::rtl::Reference< comphelper::RefCountedMutex > m_xMutex;
    ConnectionSettings *m_pSettings;
    css::uno::Reference< css::sdbc::XConnection > m_origin;
    String2IntMap m_name2index;  // maps the element name to an index
    std::vector< css::uno::Any > m_values; // contains the real values
    OUString m_type;

public:
    Container(
        const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex,
        const css::uno::Reference< css::sdbc::XConnection >  & origin,
        ConnectionSettings *pSettings,
        const OUString & type  // for exception messages
        );

public: // XIndexAccess
    virtual sal_Int32 SAL_CALL getCount(  ) override;
    virtual css::uno::Any SAL_CALL getByIndex( sal_Int32 Index ) override;

public: // XEnumerationAccess
    virtual css::uno::Reference< css::container::XEnumeration >
    SAL_CALL createEnumeration(  ) override;

public: // XNameAccess
    virtual css::uno::Any SAL_CALL getByName( const OUString& aName ) override;
    virtual css::uno::Sequence< OUString > SAL_CALL getElementNames(  ) override;
    virtual sal_Bool SAL_CALL hasByName( const OUString& aName ) override;
    // Methods
    virtual css::uno::Type SAL_CALL getElementType(  ) override;
    virtual sal_Bool SAL_CALL hasElements(  ) override;


public: // XAppend
    // Must be overridden in Non-Descriptors. May be overridden in descriptors, when
    // PropertySet.NAME != container name
    virtual void SAL_CALL appendByDescriptor(
        const css::uno::Reference< css::beans::XPropertySet >& descriptor ) override;

    // helper method !
    /// @throws css::container::ElementExistException
    void append(
        const OUString & str,
        const css::uno::Reference< css::beans::XPropertySet >& descriptor );


public: // XDrop
    virtual void SAL_CALL dropByName( const OUString& elementName ) override;
    virtual void SAL_CALL dropByIndex( sal_Int32 index ) override;

public: // XDataDescriptorFactory
    virtual css::uno::Reference< css::beans::XPropertySet > SAL_CALL createDataDescriptor(  ) override = 0;

public: // XRefreshable
    virtual void SAL_CALL refresh(  ) override {}
    virtual void SAL_CALL addRefreshListener(
        const css::uno::Reference< css::util::XRefreshListener >& l ) override;
    virtual void SAL_CALL removeRefreshListener(
        const css::uno::Reference< css::util::XRefreshListener >& l ) override;

public:
    // Methods
    virtual void SAL_CALL addContainerListener(
        const css::uno::Reference< css::container::XContainerListener >& xListener ) override;
    virtual void SAL_CALL removeContainerListener(
        const css::uno::Reference< css::container::XContainerListener >& xListener ) override;

public:
    virtual void SAL_CALL disposing() override;

public:
    void rename( const OUString & oldName, const OUString &newName );

protected:
    void fire( const EventBroadcastHelper & helper );
};

}

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