Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / dbaccess / source / core / api / CRowSetDataColumn.cxx
blobd16c211e13b84cb79a36695c77d37033a0b9191c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/typeprovider.hxx>
26 #include <com/sun/star/beans/PropertyAttribute.hpp>
27 #include <tools/debug.hxx>
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;
41 DBG_NAME(ORowSetDataColumn)
43 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 ,m_aDescription(_rDescription)
56 DBG_CTOR(ORowSetDataColumn,NULL);
57 OColumnSettings::registerProperties( *this );
58 registerProperty( PROPERTY_DESCRIPTION, PROPERTY_ID_DESCRIPTION, PropertyAttribute::READONLY, &m_aDescription, ::getCppuType( &m_aDescription ) );
61 ORowSetDataColumn::~ORowSetDataColumn()
63 DBG_DTOR(ORowSetDataColumn,NULL);
66 // comphelper::OPropertyArrayUsageHelper
67 ::cppu::IPropertyArrayHelper* ORowSetDataColumn::createArrayHelper( ) const
69 BEGIN_PROPERTY_SEQUENCE(21)
71 DECL_PROP1( CATALOGNAME, ::rtl::OUString, READONLY );
72 DECL_PROP1( DISPLAYSIZE, sal_Int32, READONLY );
73 DECL_PROP1_BOOL( ISAUTOINCREMENT, READONLY );
74 DECL_PROP1_BOOL( ISCASESENSITIVE, READONLY );
75 DECL_PROP1_BOOL( ISCURRENCY, READONLY );
76 DECL_PROP1_BOOL( ISDEFINITELYWRITABLE, READONLY );
77 DECL_PROP1( ISNULLABLE, sal_Int32, READONLY );
78 DECL_PROP1_BOOL( ISREADONLY, BOUND );
79 DECL_PROP1_BOOL( ISROWVERSION, READONLY );
80 DECL_PROP1_BOOL( ISSEARCHABLE, READONLY );
81 DECL_PROP1_BOOL( ISSIGNED, READONLY );
82 DECL_PROP1_BOOL( ISWRITABLE, READONLY );
83 DECL_PROP1( LABEL, ::rtl::OUString, READONLY );
84 DECL_PROP1( PRECISION, sal_Int32, READONLY );
85 DECL_PROP1( SCALE, sal_Int32, READONLY );
86 DECL_PROP1( SCHEMANAME, ::rtl::OUString, READONLY );
87 DECL_PROP1( SERVICENAME, ::rtl::OUString, READONLY );
88 DECL_PROP1( TABLENAME, ::rtl::OUString, READONLY );
89 DECL_PROP1( TYPE, sal_Int32, READONLY );
90 DECL_PROP1( TYPENAME, ::rtl::OUString, READONLY );
91 DECL_PROP1( VALUE, Any, BOUND );
93 END_PROPERTY_SEQUENCE()
95 Sequence< Property > aRegisteredProperties;
96 describeProperties( aRegisteredProperties );
98 return new ::cppu::OPropertyArrayHelper( ::comphelper::concatSequences( aDescriptor, aRegisteredProperties ), sal_False );
101 // cppu::OPropertySetHelper
102 ::cppu::IPropertyArrayHelper& ORowSetDataColumn::getInfoHelper()
104 return *static_cast< ::comphelper::OPropertyArrayUsageHelper< ORowSetDataColumn >* >(this)->getArrayHelper();
107 void SAL_CALL ORowSetDataColumn::getFastPropertyValue( Any& rValue, sal_Int32 nHandle ) const
109 if ( PROPERTY_ID_VALUE == nHandle )
111 if ( !m_aColumnValue.isNull() && m_aColumnValue->is() )
113 ::osl::Mutex* pMutex = m_aColumnValue.getMutex();
114 ::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 rValue = ((*m_aColumnValue)->get())[m_nPos].makeAny();
122 else if ( PROPERTY_ID_LABEL == nHandle && !m_sLabel.isEmpty() )
123 rValue <<= m_sLabel;
124 else
125 ODataColumn::getFastPropertyValue( rValue, nHandle );
128 void SAL_CALL ORowSetDataColumn::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rValue )throw (Exception)
130 switch( nHandle )
132 case PROPERTY_ID_VALUE:
133 updateObject(rValue);
134 break;
135 case PROPERTY_ID_ISREADONLY:
137 sal_Bool bVal = sal_False;
138 rValue >>= bVal;
139 m_isReadOnly.reset(bVal);
141 break;
142 default:
143 ODataColumn::setFastPropertyValue_NoBroadcast( nHandle,rValue );
144 break;
148 sal_Bool SAL_CALL ORowSetDataColumn::convertFastPropertyValue( Any & rConvertedValue,
149 Any & rOldValue,
150 sal_Int32 nHandle,
151 const Any& rValue ) throw (IllegalArgumentException)
153 sal_Bool bModified = sal_False;
154 switch( nHandle )
156 case PROPERTY_ID_VALUE:
158 rConvertedValue = rValue;
159 getFastPropertyValue(rOldValue, PROPERTY_ID_VALUE);
160 bModified = rConvertedValue != rOldValue;
162 break;
163 case PROPERTY_ID_ISREADONLY:
165 rConvertedValue = rValue;
166 getFastPropertyValue(rOldValue, PROPERTY_ID_ISREADONLY);
167 bModified = rConvertedValue != rOldValue;
169 break;
170 default:
171 bModified = ODataColumn::convertFastPropertyValue(rConvertedValue, rOldValue, nHandle, rValue);
172 break;
175 return bModified;
178 Sequence< sal_Int8 > ORowSetDataColumn::getImplementationId() throw (RuntimeException)
180 static OImplementationId * pId = 0;
181 if (! pId)
183 MutexGuard aGuard( Mutex::getGlobalMutex() );
184 if (! pId)
186 static OImplementationId aId;
187 pId = &aId;
190 return pId->getImplementationId();
193 void ORowSetDataColumn::fireValueChange(const ORowSetValue& _rOldValue)
195 if ( !m_aColumnValue.isNull() && m_aColumnValue->is() && (((*m_aColumnValue)->get())[m_nPos] != _rOldValue) )
197 sal_Int32 nHandle = PROPERTY_ID_VALUE;
198 m_aOldValue = _rOldValue.makeAny();
199 Any aNew = ((*m_aColumnValue)->get())[m_nPos].makeAny();
201 fire(&nHandle, &aNew, &m_aOldValue, 1, sal_False );
203 else if ( !m_aColumnValue.isNull() && !_rOldValue.isNull() )
205 sal_Int32 nHandle = PROPERTY_ID_VALUE;
206 m_aOldValue = _rOldValue.makeAny();
207 Any aNew;
209 fire(&nHandle, &aNew, &m_aOldValue, 1, sal_False );
213 DBG_NAME(ORowSetDataColumns )
214 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 ,m_aColumns(_rColumns)
223 DBG_CTOR(ORowSetDataColumns ,NULL);
226 ORowSetDataColumns::~ORowSetDataColumns()
228 DBG_DTOR(ORowSetDataColumns ,NULL);
231 sdbcx::ObjectType ORowSetDataColumns::createObject(const ::rtl::OUString& _rName)
233 connectivity::sdbcx::ObjectType xNamed;
235 ::comphelper::UStringMixEqual aCase(isCaseSensitive());
236 ::connectivity::OSQLColumns::Vector::const_iterator first = ::connectivity::find(m_aColumns->get().begin(),m_aColumns->get().end(),_rName,aCase);
237 if(first != m_aColumns->get().end())
238 xNamed.set(*first,UNO_QUERY);
240 return xNamed;
243 void SAL_CALL ORowSetDataColumns::disposing(void)
245 ORowSetDataColumns_BASE::disposing();
246 m_aColumns = NULL;
249 void ORowSetDataColumns::assign(const ::rtl::Reference< ::connectivity::OSQLColumns>& _rColumns,const ::std::vector< ::rtl::OUString> &_rVector)
251 m_aColumns = _rColumns;
252 reFill(_rVector);
255 void ORowSetDataColumns::impl_refresh() throw(::com::sun::star::uno::RuntimeException)
258 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */