update dev300-m58
[ooovba.git] / dbaccess / source / core / api / CRowSetDataColumn.cxx
blobd3591da069db9af2d27c9abf8ff184cd23413af1
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: CRowSetDataColumn.cxx,v $
10 * $Revision: 1.35 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
34 #ifndef _DBACORE_DATACOLUMN_HXX_
35 #include "CRowSetDataColumn.hxx"
36 #endif
37 #ifndef DBACCESS_SHARED_DBASTRINGS_HRC
38 #include "dbastrings.hrc"
39 #endif
40 #ifndef _DBASHARED_APITOOLS_HXX_
41 #include "apitools.hxx"
42 #endif
43 #ifndef _COMPHELPER_TYPES_HXX_
44 #include <comphelper/types.hxx>
45 #endif
46 #ifndef _CPPUHELPER_TYPEPROVIDER_HXX_
47 #include <cppuhelper/typeprovider.hxx>
48 #endif
49 #ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBUTE_HPP_
50 #include <com/sun/star/beans/PropertyAttribute.hpp>
51 #endif
52 #ifndef _TOOLS_DEBUG_HXX
53 #include <tools/debug.hxx>
54 #endif
56 using namespace dbaccess;
57 using namespace comphelper;
58 using namespace connectivity;
59 using namespace ::com::sun::star::uno;
60 using namespace ::com::sun::star::beans;
61 // using namespace ::com::sun::star::sdbcx;
62 using namespace ::com::sun::star::sdbc;
63 using namespace ::com::sun::star::container;
64 using namespace ::com::sun::star::lang;
65 using namespace ::com::sun::star::util;
66 using namespace cppu;
67 using namespace osl;
69 DBG_NAME(ORowSetDataColumn)
70 // -------------------------------------------------------------------------
71 ORowSetDataColumn::ORowSetDataColumn( const Reference < XResultSetMetaData >& _xMetaData,
72 const Reference < XRow >& _xRow,
73 const Reference < XRowUpdate >& _xRowUpdate,
74 sal_Int32 _nPos,
75 const Reference< XDatabaseMetaData >& _rxDBMeta,
76 const ::rtl::OUString& _rDescription,
77 const ORowSetCacheIterator& _rColumnValue)
78 : ODataColumn(_xMetaData,_xRow,_xRowUpdate,_nPos,_rxDBMeta)
79 ,m_aColumnValue(_rColumnValue)
80 ,m_aDescription(_rDescription)
82 DBG_CTOR(ORowSetDataColumn,NULL);
84 // -------------------------------------------------------------------------
85 ORowSetDataColumn::~ORowSetDataColumn()
87 DBG_DTOR(ORowSetDataColumn,NULL);
89 // -------------------------------------------------------------------------
90 // comphelper::OPropertyArrayUsageHelper
91 //------------------------------------------------------------------------------
92 ::cppu::IPropertyArrayHelper* ORowSetDataColumn::createArrayHelper( ) const
94 BEGIN_PROPERTY_HELPER(31)
95 DECL_PROP2(ALIGN, sal_Int32, BOUND,MAYBEVOID);
96 DECL_PROP1(CATALOGNAME, ::rtl::OUString, READONLY);
97 DECL_PROP2(CONTROLDEFAULT, ::rtl::OUString, BOUND,MAYBEVOID);
98 DECL_PROP1_IFACE(CONTROLMODEL, XPropertySet, BOUND );
99 DECL_PROP1(DESCRIPTION, ::rtl::OUString, READONLY);
100 DECL_PROP1(DISPLAYSIZE, sal_Int32, READONLY);
101 DECL_PROP2(NUMBERFORMAT, sal_Int32, BOUND,MAYBEVOID);
102 DECL_PROP2(HELPTEXT, ::rtl::OUString, BOUND,MAYBEVOID);
103 DECL_PROP1_BOOL(HIDDEN, BOUND);
104 DECL_PROP1_BOOL(ISAUTOINCREMENT, READONLY);
105 DECL_PROP1_BOOL(ISCASESENSITIVE, READONLY);
106 DECL_PROP1_BOOL(ISCURRENCY, READONLY);
107 DECL_PROP1_BOOL(ISDEFINITELYWRITABLE, READONLY);
108 DECL_PROP1(ISNULLABLE, sal_Int32, READONLY);
109 DECL_PROP1_BOOL(ISREADONLY, READONLY);
110 DECL_PROP1_BOOL(ISROWVERSION, READONLY);
111 DECL_PROP1_BOOL(ISSEARCHABLE, READONLY);
112 DECL_PROP1_BOOL(ISSIGNED, READONLY);
113 DECL_PROP1_BOOL(ISWRITABLE, READONLY);
114 DECL_PROP1(LABEL, ::rtl::OUString, READONLY);
115 DECL_PROP1(NAME, ::rtl::OUString, READONLY);
116 DECL_PROP1(PRECISION, sal_Int32, READONLY);
117 DECL_PROP2(RELATIVEPOSITION, sal_Int32, BOUND, MAYBEVOID);
118 DECL_PROP1(SCALE, sal_Int32, READONLY);
119 DECL_PROP1(SCHEMANAME, ::rtl::OUString, READONLY);
120 DECL_PROP1(SERVICENAME, ::rtl::OUString, READONLY);
121 DECL_PROP1(TABLENAME, ::rtl::OUString, READONLY);
122 DECL_PROP1(TYPE, sal_Int32, READONLY);
123 DECL_PROP1(TYPENAME, ::rtl::OUString, READONLY);
124 DECL_PROP1(VALUE, Any, BOUND);
125 DECL_PROP1(WIDTH, sal_Int32, MAYBEVOID);
126 END_PROPERTY_HELPER();
129 // cppu::OPropertySetHelper
130 //------------------------------------------------------------------------------
131 ::cppu::IPropertyArrayHelper& ORowSetDataColumn::getInfoHelper()
133 return *static_cast< ::comphelper::OPropertyArrayUsageHelper< ORowSetDataColumn >* >(this)->getArrayHelper();
135 // -------------------------------------------------------------------------
136 void SAL_CALL ORowSetDataColumn::getFastPropertyValue( Any& rValue, sal_Int32 nHandle ) const
138 switch(nHandle)
140 case PROPERTY_ID_DESCRIPTION:
141 rValue <<= m_aDescription;
142 break;
143 case PROPERTY_ID_ALIGN:
144 case PROPERTY_ID_NUMBERFORMAT:
145 case PROPERTY_ID_RELATIVEPOSITION:
146 case PROPERTY_ID_WIDTH:
147 case PROPERTY_ID_HIDDEN:
148 case PROPERTY_ID_CONTROLMODEL:
149 case PROPERTY_ID_HELPTEXT:
150 case PROPERTY_ID_CONTROLDEFAULT:
151 OColumnSettings::getFastPropertyValue( rValue, nHandle );
152 break;
153 case PROPERTY_ID_VALUE:
154 if ( !m_aColumnValue.isNull() && m_aColumnValue->isValid() )
156 ::osl::Mutex* pMutex = m_aColumnValue.getMutex();
157 ::osl::MutexGuard aGuard( *pMutex );
158 #if OSL_DEBUG_LEVEL > 0
159 ORowSetRow aRow = *m_aColumnValue;
160 #endif
161 OSL_ENSURE((sal_Int32)aRow->get().size() > m_nPos,"Pos is greater than size of vector");
162 rValue = ((*m_aColumnValue)->get())[m_nPos].makeAny();
164 break;
165 default:
166 ODataColumn::getFastPropertyValue(rValue,nHandle);
169 // -------------------------------------------------------------------------
170 void SAL_CALL ORowSetDataColumn::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rValue )throw (Exception)
172 switch(nHandle)
174 case PROPERTY_ID_ALIGN:
175 case PROPERTY_ID_NUMBERFORMAT:
176 case PROPERTY_ID_RELATIVEPOSITION:
177 case PROPERTY_ID_WIDTH:
178 case PROPERTY_ID_HIDDEN:
179 case PROPERTY_ID_CONTROLMODEL:
180 case PROPERTY_ID_HELPTEXT:
181 case PROPERTY_ID_CONTROLDEFAULT:
182 OColumnSettings::setFastPropertyValue_NoBroadcast( nHandle, rValue );
183 break;
184 case PROPERTY_ID_VALUE:
185 updateObject(rValue);
186 break;
187 default:
188 ODataColumn::setFastPropertyValue_NoBroadcast(nHandle,rValue );
191 // -------------------------------------------------------------------------
192 sal_Bool SAL_CALL ORowSetDataColumn::convertFastPropertyValue( Any & rConvertedValue,
193 Any & rOldValue,
194 sal_Int32 nHandle,
195 const Any& rValue ) throw (IllegalArgumentException)
197 sal_Bool bModified = sal_False;
198 switch(nHandle)
200 case PROPERTY_ID_ALIGN:
201 case PROPERTY_ID_NUMBERFORMAT:
202 case PROPERTY_ID_RELATIVEPOSITION:
203 case PROPERTY_ID_WIDTH:
204 case PROPERTY_ID_HIDDEN:
205 case PROPERTY_ID_CONTROLMODEL:
206 case PROPERTY_ID_HELPTEXT:
207 case PROPERTY_ID_CONTROLDEFAULT:
208 bModified = OColumnSettings::convertFastPropertyValue( rConvertedValue, rOldValue, nHandle, rValue );
209 break;
210 case PROPERTY_ID_VALUE:
211 rConvertedValue = rValue;
212 getFastPropertyValue(rOldValue, PROPERTY_ID_VALUE);
213 bModified = !::comphelper::compare(rConvertedValue, rOldValue);
214 break;
215 default:
216 bModified = ODataColumn::convertFastPropertyValue(rConvertedValue, rOldValue, nHandle, rValue);
220 return bModified;
222 //--------------------------------------------------------------------------
223 Sequence< sal_Int8 > ORowSetDataColumn::getImplementationId() throw (RuntimeException)
225 static OImplementationId * pId = 0;
226 if (! pId)
228 MutexGuard aGuard( Mutex::getGlobalMutex() );
229 if (! pId)
231 static OImplementationId aId;
232 pId = &aId;
235 return pId->getImplementationId();
237 // -------------------------------------------------------------------------
238 void ORowSetDataColumn::fireValueChange(const ORowSetValue& _rOldValue)
240 if ( !m_aColumnValue.isNull() && m_aColumnValue->isValid() && (!(((*m_aColumnValue)->get())[m_nPos] == _rOldValue)) )
242 sal_Int32 nHandle = PROPERTY_ID_VALUE;
243 m_aOldValue = _rOldValue.makeAny();
244 Any aNew = ((*m_aColumnValue)->get())[m_nPos].makeAny();
246 fire(&nHandle, &aNew, &m_aOldValue, 1, sal_False );
248 else if ( !m_aColumnValue.isNull() && !_rOldValue.isNull() )
250 sal_Int32 nHandle = PROPERTY_ID_VALUE;
251 m_aOldValue = _rOldValue.makeAny();
252 Any aNew;
254 fire(&nHandle, &aNew, &m_aOldValue, 1, sal_False );
257 // -----------------------------------------------------------------------------
258 DBG_NAME(ORowSetDataColumns )
259 ORowSetDataColumns::ORowSetDataColumns(
260 sal_Bool _bCase,
261 const ::vos::ORef< ::connectivity::OSQLColumns>& _rColumns,
262 ::cppu::OWeakObject& _rParent,
263 ::osl::Mutex& _rMutex,
264 const ::std::vector< ::rtl::OUString> &_rVector
265 ) : connectivity::sdbcx::OCollection(_rParent,_bCase,_rMutex,_rVector)
266 ,m_aColumns(_rColumns)
268 DBG_CTOR(ORowSetDataColumns ,NULL);
270 // -----------------------------------------------------------------------------
271 ORowSetDataColumns::~ORowSetDataColumns()
273 DBG_DTOR(ORowSetDataColumns ,NULL);
275 // -----------------------------------------------------------------------------
276 sdbcx::ObjectType ORowSetDataColumns::createObject(const ::rtl::OUString& _rName)
278 connectivity::sdbcx::ObjectType xNamed;
280 ::comphelper::UStringMixEqual aCase(isCaseSensitive());
281 ::connectivity::OSQLColumns::Vector::const_iterator first = ::connectivity::find(m_aColumns->get().begin(),m_aColumns->get().end(),_rName,aCase);
282 if(first != m_aColumns->get().end())
283 xNamed.set(*first,UNO_QUERY);
285 return xNamed;
287 // -----------------------------------------------------------------------------
288 void SAL_CALL ORowSetDataColumns::disposing(void)
290 // clear_NoDispose();
291 ORowSetDataColumns_BASE::disposing();
292 m_aColumns = NULL;
293 // m_aColumns.clear();
295 // -----------------------------------------------------------------------------
296 void ORowSetDataColumns::assign(const ::vos::ORef< ::connectivity::OSQLColumns>& _rColumns,const ::std::vector< ::rtl::OUString> &_rVector)
298 m_aColumns = _rColumns;
299 reFill(_rVector);
301 // -----------------------------------------------------------------------------
302 void ORowSetDataColumns::impl_refresh() throw(::com::sun::star::uno::RuntimeException)
305 // -----------------------------------------------------------------------------