1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include "CRowSetDataColumn.hxx"
22 #include <stringconstants.hxx>
23 #include <strings.hxx>
24 #include <cppuhelper/exc_hlp.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>
30 using namespace dbaccess
;
31 using namespace comphelper
;
32 using namespace connectivity
;
33 using namespace ::com::sun::star::uno
;
34 using namespace ::com::sun::star::beans
;
35 using namespace ::com::sun::star::sdbc
;
36 using namespace ::com::sun::star::container
;
37 using namespace ::com::sun::star::lang
;
38 using namespace ::com::sun::star::util
;
43 ORowSetDataColumn::ORowSetDataColumn( const Reference
< XResultSetMetaData
>& _xMetaData
,
44 const Reference
< XRow
>& _xRow
,
45 const Reference
< XRowUpdate
>& _xRowUpdate
,
47 const Reference
< XDatabaseMetaData
>& _rxDBMeta
,
48 OUString i_sDescription
,
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
))
56 OColumnSettings::registerProperties( *this );
57 registerProperty( PROPERTY_DESCRIPTION
, PROPERTY_ID_DESCRIPTION
, PropertyAttribute::READONLY
, &m_aDescription
, cppu::UnoType
<decltype(m_aDescription
)>::get() );
60 ORowSetDataColumn::~ORowSetDataColumn()
64 // comphelper::OPropertyArrayUsageHelper
65 ::cppu::IPropertyArrayHelper
* ORowSetDataColumn::createArrayHelper( ) const
67 css::uno::Sequence
< css::beans::Property
> aDescriptor
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
},
74 { PROPERTY_ISDEFINITELYWRITABLE
, PROPERTY_ID_ISDEFINITELYWRITABLE
, 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
}
92 Sequence
< Property
> aRegisteredProperties
;
93 describeProperties( aRegisteredProperties
);
95 return new ::cppu::OPropertyArrayHelper( ::comphelper::concatSequences( aDescriptor
, aRegisteredProperties
), false );
98 // cppu::OPropertySetHelper
99 ::cppu::IPropertyArrayHelper
& ORowSetDataColumn::getInfoHelper()
101 return *static_cast< ::comphelper::OPropertyArrayUsageHelper
< ORowSetDataColumn
>* >(this)->getArrayHelper();
104 void SAL_CALL
ORowSetDataColumn::getFastPropertyValue( Any
& rValue
, sal_Int32 nHandle
) const
106 if ( PROPERTY_ID_VALUE
== nHandle
)
110 rValue
= m_pGetValue(m_nPos
).makeAny();
112 catch(const SQLException
&e
)
114 css::uno::Any anyEx
= cppu::getCaughtException();
115 throw WrappedTargetRuntimeException("Could not retrieve column value: " + e
.Message
,
116 *const_cast<ORowSetDataColumn
*>(this),
120 else if ( PROPERTY_ID_LABEL
== nHandle
&& !m_sLabel
.isEmpty() )
123 ODataColumn::getFastPropertyValue( rValue
, nHandle
);
126 void SAL_CALL
ORowSetDataColumn::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle
,const Any
& rValue
)
130 case PROPERTY_ID_VALUE
:
131 updateObject(rValue
);
133 case PROPERTY_ID_ISREADONLY
:
141 ODataColumn::setFastPropertyValue_NoBroadcast( nHandle
,rValue
);
146 sal_Bool SAL_CALL
ORowSetDataColumn::convertFastPropertyValue( Any
& rConvertedValue
,
151 bool bModified
= false;
154 case PROPERTY_ID_VALUE
:
156 rConvertedValue
= rValue
;
157 getFastPropertyValue(rOldValue
, PROPERTY_ID_VALUE
);
158 bModified
= rConvertedValue
!= rOldValue
;
161 case PROPERTY_ID_ISREADONLY
:
163 rConvertedValue
= rValue
;
164 getFastPropertyValue(rOldValue
, PROPERTY_ID_ISREADONLY
);
165 bModified
= rConvertedValue
!= rOldValue
;
169 bModified
= ODataColumn::convertFastPropertyValue(rConvertedValue
, rOldValue
, nHandle
, rValue
);
176 Sequence
< sal_Int8
> ORowSetDataColumn::getImplementationId()
178 return css::uno::Sequence
<sal_Int8
>();
181 void ORowSetDataColumn::fireValueChange(const ORowSetValue
& _rOldValue
)
183 const ORowSetValue
&value(m_pGetValue(m_nPos
));
184 if ( value
!= _rOldValue
)
186 sal_Int32
nHandle(PROPERTY_ID_VALUE
);
187 m_aOldValue
= _rOldValue
.makeAny();
188 Any aNew
= value
.makeAny();
190 fire(&nHandle
, &aNew
, &m_aOldValue
, 1, false );
194 ORowSetDataColumns::ORowSetDataColumns(
196 ::rtl::Reference
< ::connectivity::OSQLColumns
> _xColumns
,
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
))
205 ORowSetDataColumns::~ORowSetDataColumns()
209 sdbcx::ObjectType
ORowSetDataColumns::createObject(const OUString
& _rName
)
211 connectivity::sdbcx::ObjectType xNamed
;
213 ::comphelper::UStringMixEqual
aCase(isCaseSensitive());
214 ::connectivity::OSQLColumns::Vector::const_iterator first
= ::connectivity::find(m_aColumns
->begin(),m_aColumns
->end(),_rName
,aCase
);
215 if(first
!= m_aColumns
->end())
221 void ORowSetDataColumns::disposing()
223 ORowSetDataColumns_BASE::disposing();
224 m_aColumns
= nullptr;
227 void ORowSetDataColumns::assign(const ::rtl::Reference
< ::connectivity::OSQLColumns
>& _rColumns
,const std::vector
< OUString
> &_rVector
)
229 m_aColumns
= _rColumns
;
233 void ORowSetDataColumns::impl_refresh()
237 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */