Branch data Line data Source code
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 "dbastrings.hrc"
23 : : #include "apitools.hxx"
24 : : #include <comphelper/types.hxx>
25 : : #include <cppuhelper/typeprovider.hxx>
26 : : #include <com/sun/star/beans/PropertyAttribute.hpp>
27 : : #include <tools/debug.hxx>
28 : :
29 : : using namespace dbaccess;
30 : : using namespace comphelper;
31 : : using namespace connectivity;
32 : : using namespace ::com::sun::star::uno;
33 : : using namespace ::com::sun::star::beans;
34 : : using namespace ::com::sun::star::sdbc;
35 : : using namespace ::com::sun::star::container;
36 : : using namespace ::com::sun::star::lang;
37 : : using namespace ::com::sun::star::util;
38 : : using namespace cppu;
39 : : using namespace osl;
40 : :
41 : : DBG_NAME(ORowSetDataColumn)
42 : :
43 : 524 : ORowSetDataColumn::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 : : const ::rtl::OUString& _rDescription,
49 : : const ::rtl::OUString& i_sLabel,
50 : : const ORowSetCacheIterator& _rColumnValue)
51 : : :ODataColumn(_xMetaData,_xRow,_xRowUpdate,_nPos,_rxDBMeta)
52 : : ,m_aColumnValue(_rColumnValue)
53 : : ,m_sLabel(i_sLabel)
54 [ + - ][ + - ]: 524 : ,m_aDescription(_rDescription)
[ + - ]
55 : : {
56 : : DBG_CTOR(ORowSetDataColumn,NULL);
57 [ + - ]: 524 : OColumnSettings::registerProperties( *this );
58 [ + - ][ + - ]: 524 : registerProperty( PROPERTY_DESCRIPTION, PROPERTY_ID_DESCRIPTION, PropertyAttribute::READONLY, &m_aDescription, ::getCppuType( &m_aDescription ) );
[ + - ]
59 : 524 : }
60 : :
61 [ + - ][ + - ]: 524 : ORowSetDataColumn::~ORowSetDataColumn()
62 : : {
63 : : DBG_DTOR(ORowSetDataColumn,NULL);
64 [ - + ]: 964 : }
65 : :
66 : : // comphelper::OPropertyArrayUsageHelper
67 : 40 : ::cppu::IPropertyArrayHelper* ORowSetDataColumn::createArrayHelper( ) const
68 : : {
69 [ + - ][ + - ]: 40 : BEGIN_PROPERTY_SEQUENCE(21)
70 : :
71 [ + - ][ + - ]: 40 : DECL_PROP1( CATALOGNAME, ::rtl::OUString, READONLY );
72 [ + - ][ + - ]: 40 : DECL_PROP1( DISPLAYSIZE, sal_Int32, READONLY );
73 [ + - ][ + - ]: 40 : DECL_PROP1_BOOL( ISAUTOINCREMENT, READONLY );
74 [ + - ][ + - ]: 40 : DECL_PROP1_BOOL( ISCASESENSITIVE, READONLY );
75 [ + - ][ + - ]: 40 : DECL_PROP1_BOOL( ISCURRENCY, READONLY );
76 [ + - ][ + - ]: 40 : DECL_PROP1_BOOL( ISDEFINITELYWRITABLE, READONLY );
77 [ + - ][ + - ]: 40 : DECL_PROP1( ISNULLABLE, sal_Int32, READONLY );
78 [ + - ][ + - ]: 40 : DECL_PROP1_BOOL( ISREADONLY, BOUND );
79 [ + - ][ + - ]: 40 : DECL_PROP1_BOOL( ISROWVERSION, READONLY );
80 [ + - ][ + - ]: 40 : DECL_PROP1_BOOL( ISSEARCHABLE, READONLY );
81 [ + - ][ + - ]: 40 : DECL_PROP1_BOOL( ISSIGNED, READONLY );
82 [ + - ][ + - ]: 40 : DECL_PROP1_BOOL( ISWRITABLE, READONLY );
83 [ + - ][ + - ]: 40 : DECL_PROP1( LABEL, ::rtl::OUString, READONLY );
84 [ + - ][ + - ]: 40 : DECL_PROP1( PRECISION, sal_Int32, READONLY );
85 [ + - ][ + - ]: 40 : DECL_PROP1( SCALE, sal_Int32, READONLY );
86 [ + - ][ + - ]: 40 : DECL_PROP1( SCHEMANAME, ::rtl::OUString, READONLY );
87 [ + - ][ + - ]: 40 : DECL_PROP1( SERVICENAME, ::rtl::OUString, READONLY );
88 [ + - ][ + - ]: 40 : DECL_PROP1( TABLENAME, ::rtl::OUString, READONLY );
89 [ + - ][ + - ]: 40 : DECL_PROP1( TYPE, sal_Int32, READONLY );
90 [ + - ][ + - ]: 40 : DECL_PROP1( TYPENAME, ::rtl::OUString, READONLY );
91 [ + - ][ + - ]: 40 : DECL_PROP1( VALUE, Any, BOUND );
92 : :
93 : : END_PROPERTY_SEQUENCE()
94 : :
95 [ + - ]: 40 : Sequence< Property > aRegisteredProperties;
96 [ + - ]: 40 : describeProperties( aRegisteredProperties );
97 : :
98 [ + - ][ + - ]: 40 : return new ::cppu::OPropertyArrayHelper( ::comphelper::concatSequences( aDescriptor, aRegisteredProperties ), sal_False );
[ + - ][ + - ]
[ + - ]
99 : : }
100 : :
101 : : // cppu::OPropertySetHelper
102 : 17124 : ::cppu::IPropertyArrayHelper& ORowSetDataColumn::getInfoHelper()
103 : : {
104 : 17124 : return *static_cast< ::comphelper::OPropertyArrayUsageHelper< ORowSetDataColumn >* >(this)->getArrayHelper();
105 : : }
106 : :
107 : 4517 : void SAL_CALL ORowSetDataColumn::getFastPropertyValue( Any& rValue, sal_Int32 nHandle ) const
108 : : {
109 [ + + ]: 4517 : if ( PROPERTY_ID_VALUE == nHandle )
110 : : {
111 [ - + ][ # # ]: 6 : if ( !m_aColumnValue.isNull() && m_aColumnValue->is() )
[ - + ]
112 : : {
113 [ # # ]: 0 : ::osl::Mutex* pMutex = m_aColumnValue.getMutex();
114 [ # # ]: 0 : ::osl::MutexGuard aGuard( *pMutex );
115 : : #if OSL_DEBUG_LEVEL > 0
116 : : ORowSetRow aRow = *m_aColumnValue;
117 : : #endif
118 : : OSL_ENSURE((sal_Int32)aRow->get().size() > m_nPos,"Pos is greater than size of vector");
119 [ # # ][ # # ]: 0 : rValue = ((*m_aColumnValue)->get())[m_nPos].makeAny();
[ # # ][ # # ]
120 : : }
121 : : }
122 [ + + ][ - + ]: 4511 : else if ( PROPERTY_ID_LABEL == nHandle && !m_sLabel.isEmpty() )
[ - + ]
123 : 0 : rValue <<= m_sLabel;
124 : : else
125 : 4511 : ODataColumn::getFastPropertyValue( rValue, nHandle );
126 : 4517 : }
127 : :
128 : 1880 : void SAL_CALL ORowSetDataColumn::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rValue )throw (Exception)
129 : : {
130 [ - + + ]: 1880 : switch( nHandle )
131 : : {
132 : : case PROPERTY_ID_VALUE:
133 : 0 : updateObject(rValue);
134 : 0 : break;
135 : : case PROPERTY_ID_ISREADONLY:
136 : : {
137 : 440 : sal_Bool bVal = sal_False;
138 : 440 : rValue >>= bVal;
139 [ + - ]: 440 : m_isReadOnly.reset(bVal);
140 : : }
141 : 440 : break;
142 : : default:
143 : 1440 : ODataColumn::setFastPropertyValue_NoBroadcast( nHandle,rValue );
144 : 1440 : break;
145 : : }
146 : 1880 : }
147 : :
148 : 4084 : sal_Bool SAL_CALL ORowSetDataColumn::convertFastPropertyValue( Any & rConvertedValue,
149 : : Any & rOldValue,
150 : : sal_Int32 nHandle,
151 : : const Any& rValue ) throw (IllegalArgumentException)
152 : : {
153 : 4084 : sal_Bool bModified = sal_False;
154 [ - + + ]: 4084 : switch( nHandle )
155 : : {
156 : : case PROPERTY_ID_VALUE:
157 : : {
158 : 0 : rConvertedValue = rValue;
159 : 0 : getFastPropertyValue(rOldValue, PROPERTY_ID_VALUE);
160 : 0 : bModified = rConvertedValue != rOldValue;
161 : : }
162 : 0 : break;
163 : : case PROPERTY_ID_ISREADONLY:
164 : : {
165 : 124 : rConvertedValue = rValue;
166 : 124 : getFastPropertyValue(rOldValue, PROPERTY_ID_ISREADONLY);
167 : 124 : bModified = rConvertedValue != rOldValue;
168 : : }
169 : 124 : break;
170 : : default:
171 : 3960 : bModified = ODataColumn::convertFastPropertyValue(rConvertedValue, rOldValue, nHandle, rValue);
172 : 3960 : break;
173 : : }
174 : :
175 : 4084 : return bModified;
176 : : }
177 : :
178 : 0 : Sequence< sal_Int8 > ORowSetDataColumn::getImplementationId() throw (RuntimeException)
179 : : {
180 : : static OImplementationId * pId = 0;
181 [ # # ]: 0 : if (! pId)
182 : : {
183 [ # # ][ # # ]: 0 : MutexGuard aGuard( Mutex::getGlobalMutex() );
184 [ # # ]: 0 : if (! pId)
185 : : {
186 [ # # ][ # # ]: 0 : static OImplementationId aId;
187 : 0 : pId = &aId;
188 [ # # ]: 0 : }
189 : : }
190 : 0 : return pId->getImplementationId();
191 : : }
192 : :
193 : 3014 : void ORowSetDataColumn::fireValueChange(const ORowSetValue& _rOldValue)
194 : : {
195 [ + + ][ + - ]: 3014 : if ( !m_aColumnValue.isNull() && m_aColumnValue->is() && (((*m_aColumnValue)->get())[m_nPos] != _rOldValue) )
[ + + ][ + + ]
196 : : {
197 : 764 : sal_Int32 nHandle = PROPERTY_ID_VALUE;
198 [ + - ]: 764 : m_aOldValue = _rOldValue.makeAny();
199 [ + - ][ + - ]: 764 : Any aNew = ((*m_aColumnValue)->get())[m_nPos].makeAny();
[ + - ]
200 : :
201 [ + - ]: 764 : fire(&nHandle, &aNew, &m_aOldValue, 1, sal_False );
202 : : }
203 [ + + ][ + + ]: 2250 : else if ( !m_aColumnValue.isNull() && !_rOldValue.isNull() )
[ + + ]
204 : : {
205 : 300 : sal_Int32 nHandle = PROPERTY_ID_VALUE;
206 [ + - ]: 300 : m_aOldValue = _rOldValue.makeAny();
207 : 300 : Any aNew;
208 : :
209 [ + - ]: 300 : fire(&nHandle, &aNew, &m_aOldValue, 1, sal_False );
210 : : }
211 : 3014 : }
212 : :
213 : : DBG_NAME(ORowSetDataColumns )
214 : 32 : ORowSetDataColumns::ORowSetDataColumns(
215 : : sal_Bool _bCase,
216 : : const ::rtl::Reference< ::connectivity::OSQLColumns>& _rColumns,
217 : : ::cppu::OWeakObject& _rParent,
218 : : ::osl::Mutex& _rMutex,
219 : : const ::std::vector< ::rtl::OUString> &_rVector
220 : : ) : connectivity::sdbcx::OCollection(_rParent,_bCase,_rMutex,_rVector)
221 [ + - ]: 32 : ,m_aColumns(_rColumns)
222 : : {
223 : : DBG_CTOR(ORowSetDataColumns ,NULL);
224 : 32 : }
225 : :
226 [ + - ]: 32 : ORowSetDataColumns::~ORowSetDataColumns()
227 : : {
228 : : DBG_DTOR(ORowSetDataColumns ,NULL);
229 [ - + ]: 64 : }
230 : :
231 : 148 : sdbcx::ObjectType ORowSetDataColumns::createObject(const ::rtl::OUString& _rName)
232 : : {
233 : 148 : connectivity::sdbcx::ObjectType xNamed;
234 : :
235 [ + - ]: 148 : ::comphelper::UStringMixEqual aCase(isCaseSensitive());
236 [ + - ][ + - ]: 148 : ::connectivity::OSQLColumns::Vector::const_iterator first = ::connectivity::find(m_aColumns->get().begin(),m_aColumns->get().end(),_rName,aCase);
[ + - ]
237 [ + - ][ + - ]: 148 : if(first != m_aColumns->get().end())
238 [ + - ]: 148 : xNamed.set(*first,UNO_QUERY);
239 : :
240 : 148 : return xNamed;
241 : : }
242 : :
243 : 116 : void SAL_CALL ORowSetDataColumns::disposing(void)
244 : : {
245 : 116 : ORowSetDataColumns_BASE::disposing();
246 : 116 : m_aColumns = NULL;
247 : 116 : }
248 : :
249 : 12 : void ORowSetDataColumns::assign(const ::rtl::Reference< ::connectivity::OSQLColumns>& _rColumns,const ::std::vector< ::rtl::OUString> &_rVector)
250 : : {
251 : 12 : m_aColumns = _rColumns;
252 : 12 : reFill(_rVector);
253 : 12 : }
254 : :
255 : 0 : void ORowSetDataColumns::impl_refresh() throw(::com::sun::star::uno::RuntimeException)
256 : : {
257 : 0 : }
258 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|