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 "dbastrings.hrc"
23 #include "apitools.hxx"
24 #include <comphelper/types.hxx>
25 #include <cppuhelper/exc_hlp.hxx>
26 #include <cppuhelper/typeprovider.hxx>
27 #include <com/sun/star/beans/PropertyAttribute.hpp>
28 #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
29 #include <tools/debug.hxx>
31 using namespace dbaccess
;
32 using namespace comphelper
;
33 using namespace connectivity
;
34 using namespace ::com::sun::star::uno
;
35 using namespace ::com::sun::star::beans
;
36 using namespace ::com::sun::star::sdbc
;
37 using namespace ::com::sun::star::container
;
38 using namespace ::com::sun::star::lang
;
39 using namespace ::com::sun::star::util
;
44 ORowSetDataColumn::ORowSetDataColumn( const Reference
< XResultSetMetaData
>& _xMetaData
,
45 const Reference
< XRow
>& _xRow
,
46 const Reference
< XRowUpdate
>& _xRowUpdate
,
48 const Reference
< XDatabaseMetaData
>& _rxDBMeta
,
49 const OUString
& _rDescription
,
50 const OUString
& i_sLabel
,
51 const boost::function
< const ORowSetValue
& (sal_Int32
)> &_getValue
)
52 :ODataColumn(_xMetaData
,_xRow
,_xRowUpdate
,_nPos
,_rxDBMeta
)
53 ,m_pGetValue(_getValue
)
55 ,m_aDescription(_rDescription
)
57 OColumnSettings::registerProperties( *this );
58 registerProperty( PROPERTY_DESCRIPTION
, PROPERTY_ID_DESCRIPTION
, PropertyAttribute::READONLY
, &m_aDescription
, cppu::UnoType
<decltype(m_aDescription
)>::get() );
61 ORowSetDataColumn::~ORowSetDataColumn()
65 // comphelper::OPropertyArrayUsageHelper
66 ::cppu::IPropertyArrayHelper
* ORowSetDataColumn::createArrayHelper( ) const
68 BEGIN_PROPERTY_SEQUENCE(21)
70 DECL_PROP1( CATALOGNAME
, OUString
, READONLY
);
71 DECL_PROP1( DISPLAYSIZE
, sal_Int32
, READONLY
);
72 DECL_PROP1_BOOL( ISAUTOINCREMENT
, READONLY
);
73 DECL_PROP1_BOOL( ISCASESENSITIVE
, READONLY
);
74 DECL_PROP1_BOOL( ISCURRENCY
, READONLY
);
75 DECL_PROP1_BOOL( ISDEFINITELYWRITABLE
, READONLY
);
76 DECL_PROP1( ISNULLABLE
, sal_Int32
, READONLY
);
77 DECL_PROP1_BOOL( ISREADONLY
, BOUND
);
78 DECL_PROP1_BOOL( ISROWVERSION
, READONLY
);
79 DECL_PROP1_BOOL( ISSEARCHABLE
, READONLY
);
80 DECL_PROP1_BOOL( ISSIGNED
, READONLY
);
81 DECL_PROP1_BOOL( ISWRITABLE
, READONLY
);
82 DECL_PROP1( LABEL
, OUString
, READONLY
);
83 DECL_PROP1( PRECISION
, sal_Int32
, READONLY
);
84 DECL_PROP1( SCALE
, sal_Int32
, READONLY
);
85 DECL_PROP1( SCHEMANAME
, OUString
, READONLY
);
86 DECL_PROP1( SERVICENAME
, OUString
, READONLY
);
87 DECL_PROP1( TABLENAME
, OUString
, READONLY
);
88 DECL_PROP1( TYPE
, sal_Int32
, READONLY
);
89 DECL_PROP1( TYPENAME
, OUString
, READONLY
);
90 DECL_PROP1( VALUE
, Any
, BOUND
);
92 END_PROPERTY_SEQUENCE()
94 Sequence
< Property
> aRegisteredProperties
;
95 describeProperties( aRegisteredProperties
);
97 return new ::cppu::OPropertyArrayHelper( ::comphelper::concatSequences( aDescriptor
, aRegisteredProperties
), sal_False
);
100 // cppu::OPropertySetHelper
101 ::cppu::IPropertyArrayHelper
& ORowSetDataColumn::getInfoHelper()
103 return *static_cast< ::comphelper::OPropertyArrayUsageHelper
< ORowSetDataColumn
>* >(this)->getArrayHelper();
106 void SAL_CALL
ORowSetDataColumn::getFastPropertyValue( Any
& rValue
, sal_Int32 nHandle
) const
108 if ( PROPERTY_ID_VALUE
== nHandle
)
112 rValue
= m_pGetValue(m_nPos
).makeAny();
114 catch(const SQLException
&e
)
116 throw WrappedTargetRuntimeException("Could not retrieve column value: " + e
.Message
,
117 *const_cast<ORowSetDataColumn
*>(this),
121 else if ( PROPERTY_ID_LABEL
== nHandle
&& !m_sLabel
.isEmpty() )
124 ODataColumn::getFastPropertyValue( rValue
, nHandle
);
127 void SAL_CALL
ORowSetDataColumn::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle
,const Any
& rValue
)throw (Exception
, std::exception
)
131 case PROPERTY_ID_VALUE
:
132 updateObject(rValue
);
134 case PROPERTY_ID_ISREADONLY
:
138 m_isReadOnly
.reset(bVal
);
142 ODataColumn::setFastPropertyValue_NoBroadcast( nHandle
,rValue
);
147 sal_Bool SAL_CALL
ORowSetDataColumn::convertFastPropertyValue( Any
& rConvertedValue
,
150 const Any
& rValue
) throw (IllegalArgumentException
)
152 bool bModified
= false;
155 case PROPERTY_ID_VALUE
:
157 rConvertedValue
= rValue
;
158 getFastPropertyValue(rOldValue
, PROPERTY_ID_VALUE
);
159 bModified
= rConvertedValue
!= rOldValue
;
162 case PROPERTY_ID_ISREADONLY
:
164 rConvertedValue
= rValue
;
165 getFastPropertyValue(rOldValue
, PROPERTY_ID_ISREADONLY
);
166 bModified
= rConvertedValue
!= rOldValue
;
170 bModified
= ODataColumn::convertFastPropertyValue(rConvertedValue
, rOldValue
, nHandle
, rValue
);
177 Sequence
< sal_Int8
> ORowSetDataColumn::getImplementationId() throw (RuntimeException
, std::exception
)
179 return css::uno::Sequence
<sal_Int8
>();
182 void ORowSetDataColumn::fireValueChange(const ORowSetValue
& _rOldValue
)
184 const ORowSetValue
&value(m_pGetValue(m_nPos
));
185 if ( value
!= _rOldValue
)
187 sal_Int32
nHandle(PROPERTY_ID_VALUE
);
188 m_aOldValue
= _rOldValue
.makeAny();
189 Any aNew
= value
.makeAny();
191 fire(&nHandle
, &aNew
, &m_aOldValue
, 1, sal_False
);
195 ORowSetDataColumns::ORowSetDataColumns(
197 const ::rtl::Reference
< ::connectivity::OSQLColumns
>& _rColumns
,
198 ::cppu::OWeakObject
& _rParent
,
199 ::osl::Mutex
& _rMutex
,
200 const ::std::vector
< OUString
> &_rVector
201 ) : connectivity::sdbcx::OCollection(_rParent
,_bCase
,_rMutex
,_rVector
)
202 ,m_aColumns(_rColumns
)
206 ORowSetDataColumns::~ORowSetDataColumns()
210 sdbcx::ObjectType
ORowSetDataColumns::createObject(const OUString
& _rName
)
212 connectivity::sdbcx::ObjectType xNamed
;
214 ::comphelper::UStringMixEqual
aCase(isCaseSensitive());
215 ::connectivity::OSQLColumns::Vector::const_iterator first
= ::connectivity::find(m_aColumns
->get().begin(),m_aColumns
->get().end(),_rName
,aCase
);
216 if(first
!= m_aColumns
->get().end())
217 xNamed
.set(*first
,UNO_QUERY
);
222 void SAL_CALL
ORowSetDataColumns::disposing()
224 ORowSetDataColumns_BASE::disposing();
228 void ORowSetDataColumns::assign(const ::rtl::Reference
< ::connectivity::OSQLColumns
>& _rColumns
,const ::std::vector
< OUString
> &_rVector
)
230 m_aColumns
= _rColumns
;
234 void ORowSetDataColumns::impl_refresh() throw(::com::sun::star::uno::RuntimeException
)
238 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */