LibreOffice Module dbaccess (master) 1
CRowSetDataColumn.cxx
Go to the documentation of this file.
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
20
21#include "CRowSetDataColumn.hxx"
22#include <stringconstants.hxx>
23#include <strings.hxx>
25#include <com/sun/star/beans/PropertyAttribute.hpp>
26#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
27#include <com/sun/star/sdbc/SQLException.hpp>
28#include <utility>
29
30using namespace dbaccess;
31using namespace comphelper;
32using namespace connectivity;
33using namespace ::com::sun::star::uno;
34using namespace ::com::sun::star::beans;
35using namespace ::com::sun::star::sdbc;
36using namespace ::com::sun::star::container;
37using namespace ::com::sun::star::lang;
38using namespace ::com::sun::star::util;
39using namespace cppu;
40using namespace osl;
41
42
43ORowSetDataColumn::ORowSetDataColumn( const Reference < XResultSetMetaData >& _xMetaData,
44 const Reference < XRow >& _xRow,
45 const Reference < XRowUpdate >& _xRowUpdate,
46 sal_Int32 _nPos,
47 const Reference< XDatabaseMetaData >& _rxDBMeta,
48 OUString i_sDescription,
49 OUString i_sLabel,
50 std::function<const ORowSetValue& (sal_Int32)> _getValue)
51 :ODataColumn(_xMetaData,_xRow,_xRowUpdate,_nPos,_rxDBMeta)
52 ,m_pGetValue(std::move(_getValue))
53 ,m_sLabel(std::move(i_sLabel))
54 ,m_aDescription(std::move(i_sDescription))
55{
57 registerProperty( PROPERTY_DESCRIPTION, PROPERTY_ID_DESCRIPTION, PropertyAttribute::READONLY, &m_aDescription, cppu::UnoType<decltype(m_aDescription)>::get() );
58}
59
61{
62}
63
64// comphelper::OPropertyArrayUsageHelper
66{
67 css::uno::Sequence< css::beans::Property> aDescriptor
68 {
69 { PROPERTY_CATALOGNAME, PROPERTY_ID_CATALOGNAME, cppu::UnoType<OUString>::get(), css::beans::PropertyAttribute::READONLY },
70 { PROPERTY_DISPLAYSIZE, PROPERTY_ID_DISPLAYSIZE, cppu::UnoType<sal_Int32>::get(), css::beans::PropertyAttribute::READONLY },
71 { PROPERTY_ISAUTOINCREMENT, PROPERTY_ID_ISAUTOINCREMENT, cppu::UnoType<bool>::get(), css::beans::PropertyAttribute::READONLY },
72 { PROPERTY_ISCASESENSITIVE, PROPERTY_ID_ISCASESENSITIVE, cppu::UnoType<bool>::get(), css::beans::PropertyAttribute::READONLY },
73 { PROPERTY_ISCURRENCY, PROPERTY_ID_ISCURRENCY, cppu::UnoType<bool>::get(), css::beans::PropertyAttribute::READONLY },
75 { PROPERTY_ISNULLABLE, PROPERTY_ID_ISNULLABLE, cppu::UnoType<sal_Int32>::get(), css::beans::PropertyAttribute::READONLY },
76 { PROPERTY_ISREADONLY, PROPERTY_ID_ISREADONLY, cppu::UnoType<bool>::get(), css::beans::PropertyAttribute::BOUND },
77 { PROPERTY_ISROWVERSION, PROPERTY_ID_ISROWVERSION, cppu::UnoType<bool>::get(), css::beans::PropertyAttribute::READONLY },
78 { PROPERTY_ISSEARCHABLE, PROPERTY_ID_ISSEARCHABLE, cppu::UnoType<bool>::get(), css::beans::PropertyAttribute::READONLY },
79 { PROPERTY_ISSIGNED, PROPERTY_ID_ISSIGNED, cppu::UnoType<bool>::get(), css::beans::PropertyAttribute::READONLY },
80 { PROPERTY_ISWRITABLE, PROPERTY_ID_ISWRITABLE, cppu::UnoType<bool>::get(), css::beans::PropertyAttribute::READONLY },
81 { PROPERTY_LABEL, PROPERTY_ID_LABEL, cppu::UnoType<OUString>::get(), css::beans::PropertyAttribute::READONLY },
82 { PROPERTY_PRECISION, PROPERTY_ID_PRECISION, cppu::UnoType<sal_Int32>::get(), css::beans::PropertyAttribute::READONLY },
83 { PROPERTY_SCALE, PROPERTY_ID_SCALE, cppu::UnoType<sal_Int32>::get(), css::beans::PropertyAttribute::READONLY },
84 { PROPERTY_SCHEMANAME, PROPERTY_ID_SCHEMANAME, cppu::UnoType<OUString>::get(), css::beans::PropertyAttribute::READONLY },
85 { PROPERTY_SERVICENAME, PROPERTY_ID_SERVICENAME, cppu::UnoType<OUString>::get(), css::beans::PropertyAttribute::READONLY },
86 { PROPERTY_TABLENAME, PROPERTY_ID_TABLENAME, cppu::UnoType<OUString>::get(), css::beans::PropertyAttribute::READONLY },
87 { PROPERTY_TYPE, PROPERTY_ID_TYPE, cppu::UnoType<sal_Int32>::get(), css::beans::PropertyAttribute::READONLY },
88 { PROPERTY_TYPENAME, PROPERTY_ID_TYPENAME, cppu::UnoType<OUString>::get(), css::beans::PropertyAttribute::READONLY },
89 { PROPERTY_VALUE, PROPERTY_ID_VALUE, cppu::UnoType<Any>::get(), css::beans::PropertyAttribute::BOUND }
90 };
91
92 Sequence< Property > aRegisteredProperties;
93 describeProperties( aRegisteredProperties );
94
95 return new ::cppu::OPropertyArrayHelper( ::comphelper::concatSequences( aDescriptor, aRegisteredProperties ), false );
96}
97
98// cppu::OPropertySetHelper
100{
102}
103
104void SAL_CALL ORowSetDataColumn::getFastPropertyValue( Any& rValue, sal_Int32 nHandle ) const
105{
106 if ( PROPERTY_ID_VALUE == nHandle )
107 {
108 try
109 {
110 rValue = m_pGetValue(m_nPos).makeAny();
111 }
112 catch(const SQLException &e)
113 {
114 css::uno::Any anyEx = cppu::getCaughtException();
115 throw WrappedTargetRuntimeException("Could not retrieve column value: " + e.Message,
116 *const_cast<ORowSetDataColumn*>(this),
117 anyEx);
118 }
119 }
120 else if ( PROPERTY_ID_LABEL == nHandle && !m_sLabel.isEmpty() )
121 rValue <<= m_sLabel;
122 else
124}
125
126void SAL_CALL ORowSetDataColumn::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rValue )
127{
128 switch( nHandle )
129 {
131 updateObject(rValue);
132 break;
134 {
135 bool bVal = false;
136 rValue >>= bVal;
137 m_isReadOnly = bVal;
138 }
139 break;
140 default:
141 ODataColumn::setFastPropertyValue_NoBroadcast( nHandle,rValue );
142 break;
143 }
144}
145
147 Any & rOldValue,
148 sal_Int32 nHandle,
149 const Any& rValue )
150{
151 bool bModified = false;
152 switch( nHandle )
153 {
155 {
156 rConvertedValue = rValue;
158 bModified = rConvertedValue != rOldValue;
159 }
160 break;
162 {
163 rConvertedValue = rValue;
165 bModified = rConvertedValue != rOldValue;
166 }
167 break;
168 default:
169 bModified = ODataColumn::convertFastPropertyValue(rConvertedValue, rOldValue, nHandle, rValue);
170 break;
171 }
172
173 return bModified;
174}
175
177{
178 return css::uno::Sequence<sal_Int8>();
179}
180
182{
184 if ( value != _rOldValue)
185 {
186 sal_Int32 nHandle(PROPERTY_ID_VALUE);
187 m_aOldValue = _rOldValue.makeAny();
188 Any aNew = value.makeAny();
189
190 fire(&nHandle, &aNew, &m_aOldValue, 1, false );
191 }
192}
193
195 bool _bCase,
197 ::cppu::OWeakObject& _rParent,
198 ::osl::Mutex& _rMutex,
199 const std::vector< OUString> &_rVector
200 ) : connectivity::sdbcx::OCollection(_rParent,_bCase,_rMutex,_rVector)
201 ,m_aColumns(std::move(_xColumns))
202{
203}
204
206{
207}
208
210{
212
214 ::connectivity::OSQLColumns::Vector::const_iterator first = ::connectivity::find(m_aColumns->begin(),m_aColumns->end(),_rName,aCase);
215 if(first != m_aColumns->end())
216 xNamed = *first;
217
218 return xNamed;
219}
220
222{
224 m_aColumns = nullptr;
225}
226
227void ORowSetDataColumns::assign(const ::rtl::Reference< ::connectivity::OSQLColumns>& _rColumns,const std::vector< OUString> &_rVector)
228{
229 m_aColumns = _rColumns;
230 reFill(_rVector);
231}
232
234{
235}
236
237/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
::cppu::IPropertyArrayHelper * getArrayHelper()
css::uno::Any makeAny() const
void reFill(const ::std::vector< OUString > &_rVector)
css::uno::Type const & get()
void registerProperties(IPropertyContainer &_rPropertyContainer)
virtual void SAL_CALL updateObject(const css::uno::Any &x) override
Definition: datacolumn.cxx:388
virtual void SAL_CALL getFastPropertyValue(css::uno::Any &rValue, sal_Int32 nHandle) const override
mutable ::std::optional< sal_Bool > m_isReadOnly
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override
const std::function< const ::connectivity::ORowSetValue &(sal_Int32)> m_pGetValue
virtual void SAL_CALL setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const css::uno::Any &rValue) override
void fireValueChange(const ::connectivity::ORowSetValue &_rOldValue)
virtual ::cppu::IPropertyArrayHelper &SAL_CALL getInfoHelper() override
virtual void SAL_CALL getFastPropertyValue(css::uno::Any &rValue, sal_Int32 nHandle) const override
virtual ::cppu::IPropertyArrayHelper * createArrayHelper() const override
virtual sal_Bool SAL_CALL convertFastPropertyValue(css::uno::Any &rConvertedValue, css::uno::Any &rOldValue, sal_Int32 nHandle, const css::uno::Any &rValue) override
virtual ~ORowSetDataColumn() override
virtual connectivity::sdbcx::ObjectType createObject(const OUString &_rName) override
virtual void disposing() override
virtual ~ORowSetDataColumns() override
virtual void impl_refresh() override
ORowSetDataColumns(bool _bCase, ::rtl::Reference< ::connectivity::OSQLColumns > _xColumns, ::cppu::OWeakObject &_rParent, ::osl::Mutex &_rMutex, const std::vector< OUString > &_rVector)
::rtl::Reference< ::connectivity::OSQLColumns > m_aColumns
void assign(const ::rtl::Reference< ::connectivity::OSQLColumns > &_rColumns, const std::vector< OUString > &_rVector)
Any value
css::uno::Reference< css::beans::XPropertySet > ObjectType
Any SAL_CALL getCaughtException()
constexpr OUStringLiteral first
sal_Int32 nHandle
#define PROPERTY_ID_ISSIGNED
#define PROPERTY_ID_DISPLAYSIZE
#define PROPERTY_ID_ISCASESENSITIVE
#define PROPERTY_ID_TYPE
#define PROPERTY_ID_ISREADONLY
#define PROPERTY_ID_TABLENAME
#define PROPERTY_ID_DESCRIPTION
#define PROPERTY_ID_SERVICENAME
#define PROPERTY_ID_CATALOGNAME
#define PROPERTY_ID_ISWRITABLE
#define PROPERTY_ID_ISROWVERSION
#define PROPERTY_ID_ISSEARCHABLE
#define PROPERTY_ID_ISNULLABLE
#define PROPERTY_ID_PRECISION
#define PROPERTY_ID_LABEL
#define PROPERTY_ID_SCHEMANAME
#define PROPERTY_ID_ISAUTOINCREMENT
#define PROPERTY_ID_ISCURRENCY
#define PROPERTY_ID_TYPENAME
#define PROPERTY_ID_VALUE
#define PROPERTY_ID_ISDEFINITELYWRITABLE
#define PROPERTY_ID_SCALE
constexpr OUStringLiteral PROPERTY_ISAUTOINCREMENT(u"IsAutoIncrement")
constexpr OUStringLiteral PROPERTY_ISCURRENCY(u"IsCurrency")
constexpr OUStringLiteral PROPERTY_ISWRITABLE(u"IsWritable")
constexpr OUStringLiteral PROPERTY_PRECISION(u"Precision")
constexpr OUStringLiteral PROPERTY_SERVICENAME(u"ServiceName")
constexpr OUStringLiteral PROPERTY_ISREADONLY(u"IsReadOnly")
constexpr OUStringLiteral PROPERTY_TYPENAME(u"TypeName")
constexpr OUStringLiteral PROPERTY_LABEL(u"Label")
constexpr OUStringLiteral PROPERTY_ISROWVERSION(u"IsRowVersion")
constexpr OUStringLiteral PROPERTY_ISNULLABLE(u"IsNullable")
constexpr OUStringLiteral PROPERTY_SCHEMANAME(u"SchemaName")
constexpr OUStringLiteral PROPERTY_ISDEFINITELYWRITABLE(u"IsDefinitelyWritable")
constexpr OUStringLiteral PROPERTY_DESCRIPTION(u"Description")
constexpr OUStringLiteral PROPERTY_SCALE(u"Scale")
constexpr OUStringLiteral PROPERTY_ISSEARCHABLE(u"IsSearchable")
constexpr OUStringLiteral PROPERTY_TABLENAME(u"TableName")
constexpr OUStringLiteral PROPERTY_DISPLAYSIZE(u"DisplaySize")
constexpr OUStringLiteral PROPERTY_CATALOGNAME(u"CatalogName")
constexpr OUStringLiteral PROPERTY_TYPE(u"Type")
constexpr OUStringLiteral PROPERTY_ISSIGNED(u"IsSigned")
constexpr OUStringLiteral PROPERTY_ISCASESENSITIVE(u"IsCaseSensitive")
constexpr OUStringLiteral PROPERTY_VALUE(u"Value")
unsigned char sal_Bool
sal_Int32 _nPos