1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_dbaccess.hxx"
26
27 #ifndef _DBACORE_DATACOLUMN_HXX_
28 #include "CRowSetDataColumn.hxx"
29 #endif
30 #ifndef DBACCESS_SHARED_DBASTRINGS_HRC
31 #include "dbastrings.hrc"
32 #endif
33 #ifndef _DBASHARED_APITOOLS_HXX_
34 #include "apitools.hxx"
35 #endif
36 #ifndef _COMPHELPER_TYPES_HXX_
37 #include <comphelper/types.hxx>
38 #endif
39 #ifndef _CPPUHELPER_TYPEPROVIDER_HXX_
40 #include <cppuhelper/typeprovider.hxx>
41 #endif
42 #ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBUTE_HPP_
43 #include <com/sun/star/beans/PropertyAttribute.hpp>
44 #endif
45 #ifndef _TOOLS_DEBUG_HXX
46 #include <tools/debug.hxx>
47 #endif
48
49 using namespace dbaccess;
50 using namespace comphelper;
51 using namespace connectivity;
52 using namespace ::com::sun::star::uno;
53 using namespace ::com::sun::star::beans;
54 // using namespace ::com::sun::star::sdbcx;
55 using namespace ::com::sun::star::sdbc;
56 using namespace ::com::sun::star::container;
57 using namespace ::com::sun::star::lang;
58 using namespace ::com::sun::star::util;
59 using namespace cppu;
60 using namespace osl;
61
DBG_NAME(ORowSetDataColumn)62 DBG_NAME(ORowSetDataColumn)
63 // -------------------------------------------------------------------------
64 ORowSetDataColumn::ORowSetDataColumn( const Reference < XResultSetMetaData >& _xMetaData,
65 const Reference < XRow >& _xRow,
66 const Reference < XRowUpdate >& _xRowUpdate,
67 sal_Int32 _nPos,
68 const Reference< XDatabaseMetaData >& _rxDBMeta,
69 const ::rtl::OUString& _rDescription,
70 const ::rtl::OUString& i_sLabel,
71 const ORowSetCacheIterator& _rColumnValue)
72 :ODataColumn(_xMetaData,_xRow,_xRowUpdate,_nPos,_rxDBMeta)
73 ,m_aColumnValue(_rColumnValue)
74 ,m_sLabel(i_sLabel)
75 ,m_aDescription(_rDescription)
76 {
77 DBG_CTOR(ORowSetDataColumn,NULL);
78 OColumnSettings::registerProperties( *this );
79 registerProperty( PROPERTY_DESCRIPTION, PROPERTY_ID_DESCRIPTION, PropertyAttribute::READONLY, &m_aDescription, ::getCppuType( &m_aDescription ) );
80 }
81 // -------------------------------------------------------------------------
~ORowSetDataColumn()82 ORowSetDataColumn::~ORowSetDataColumn()
83 {
84 DBG_DTOR(ORowSetDataColumn,NULL);
85 }
86 // -------------------------------------------------------------------------
87 // comphelper::OPropertyArrayUsageHelper
88 //------------------------------------------------------------------------------
createArrayHelper() const89 ::cppu::IPropertyArrayHelper* ORowSetDataColumn::createArrayHelper( ) const
90 {
91 const sal_Int32 nDerivedProperties = 21;
92 Sequence< Property> aDerivedProperties( nDerivedProperties );
93 Property* pDesc = aDerivedProperties.getArray();
94 sal_Int32 nPos = 0;
95
96 DECL_PROP1( CATALOGNAME, ::rtl::OUString, READONLY );
97 DECL_PROP1( DISPLAYSIZE, sal_Int32, READONLY );
98 DECL_PROP1_BOOL( ISAUTOINCREMENT, READONLY );
99 DECL_PROP1_BOOL( ISCASESENSITIVE, READONLY );
100 DECL_PROP1_BOOL( ISCURRENCY, READONLY );
101 DECL_PROP1_BOOL( ISDEFINITELYWRITABLE, READONLY );
102 DECL_PROP1( ISNULLABLE, sal_Int32, READONLY );
103 DECL_PROP1_BOOL( ISREADONLY, BOUND );
104 DECL_PROP1_BOOL( ISROWVERSION, READONLY );
105 DECL_PROP1_BOOL( ISSEARCHABLE, READONLY );
106 DECL_PROP1_BOOL( ISSIGNED, READONLY );
107 DECL_PROP1_BOOL( ISWRITABLE, READONLY );
108 DECL_PROP1( LABEL, ::rtl::OUString, READONLY );
109 DECL_PROP1( PRECISION, sal_Int32, READONLY );
110 DECL_PROP1( SCALE, sal_Int32, READONLY );
111 DECL_PROP1( SCHEMANAME, ::rtl::OUString, READONLY );
112 DECL_PROP1( SERVICENAME, ::rtl::OUString, READONLY );
113 DECL_PROP1( TABLENAME, ::rtl::OUString, READONLY );
114 DECL_PROP1( TYPE, sal_Int32, READONLY );
115 DECL_PROP1( TYPENAME, ::rtl::OUString, READONLY );
116 DECL_PROP1( VALUE, Any, BOUND );
117 OSL_ENSURE( nPos == nDerivedProperties, "ORowSetDataColumn::createArrayHelper: inconsistency!" );
118
119 Sequence< Property > aRegisteredProperties;
120 describeProperties( aRegisteredProperties );
121
122 return new ::cppu::OPropertyArrayHelper( ::comphelper::concatSequences( aDerivedProperties, aRegisteredProperties ), sal_False );
123 }
124
125 // cppu::OPropertySetHelper
126 //------------------------------------------------------------------------------
getInfoHelper()127 ::cppu::IPropertyArrayHelper& ORowSetDataColumn::getInfoHelper()
128 {
129 return *static_cast< ::comphelper::OPropertyArrayUsageHelper< ORowSetDataColumn >* >(this)->getArrayHelper();
130 }
131 // -------------------------------------------------------------------------
getFastPropertyValue(Any & rValue,sal_Int32 nHandle) const132 void SAL_CALL ORowSetDataColumn::getFastPropertyValue( Any& rValue, sal_Int32 nHandle ) const
133 {
134 if ( PROPERTY_ID_VALUE == nHandle )
135 {
136 if ( !m_aColumnValue.isNull() && m_aColumnValue->isValid() )
137 {
138 ::osl::Mutex* pMutex = m_aColumnValue.getMutex();
139 ::osl::MutexGuard aGuard( *pMutex );
140 #if OSL_DEBUG_LEVEL > 0
141 ORowSetRow aRow = *m_aColumnValue;
142 #endif
143 OSL_ENSURE((sal_Int32)aRow->get().size() > m_nPos,"Pos is greater than size of vector");
144 rValue = ((*m_aColumnValue)->get())[m_nPos].makeAny();
145 }
146 }
147 else if ( PROPERTY_ID_LABEL == nHandle && m_sLabel.getLength() )
148 rValue <<= m_sLabel;
149 else
150 ODataColumn::getFastPropertyValue( rValue, nHandle );
151 }
152
153 // -------------------------------------------------------------------------
setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any & rValue)154 void SAL_CALL ORowSetDataColumn::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rValue )throw (Exception)
155 {
156 switch( nHandle )
157 {
158 case PROPERTY_ID_VALUE:
159 updateObject(rValue);
160 break;
161 case PROPERTY_ID_ISREADONLY:
162 {
163 sal_Bool bVal = sal_False;
164 rValue >>= bVal;
165 m_isReadOnly.reset(bVal);
166 }
167 break;
168 default:
169 ODataColumn::setFastPropertyValue_NoBroadcast( nHandle,rValue );
170 break;
171 }
172 }
173 // -------------------------------------------------------------------------
convertFastPropertyValue(Any & rConvertedValue,Any & rOldValue,sal_Int32 nHandle,const Any & rValue)174 sal_Bool SAL_CALL ORowSetDataColumn::convertFastPropertyValue( Any & rConvertedValue,
175 Any & rOldValue,
176 sal_Int32 nHandle,
177 const Any& rValue ) throw (IllegalArgumentException)
178 {
179 sal_Bool bModified = sal_False;
180 switch( nHandle )
181 {
182 case PROPERTY_ID_VALUE:
183 {
184 rConvertedValue = rValue;
185 getFastPropertyValue(rOldValue, PROPERTY_ID_VALUE);
186 bModified = rConvertedValue != rOldValue;
187 }
188 break;
189 case PROPERTY_ID_ISREADONLY:
190 {
191 rConvertedValue = rValue;
192 getFastPropertyValue(rOldValue, PROPERTY_ID_ISREADONLY);
193 bModified = rConvertedValue != rOldValue;
194 }
195 break;
196 default:
197 bModified = ODataColumn::convertFastPropertyValue(rConvertedValue, rOldValue, nHandle, rValue);
198 break;
199 }
200
201 return bModified;
202 }
203 //--------------------------------------------------------------------------
getImplementationId()204 Sequence< sal_Int8 > ORowSetDataColumn::getImplementationId() throw (RuntimeException)
205 {
206 static OImplementationId * pId = 0;
207 if (! pId)
208 {
209 MutexGuard aGuard( Mutex::getGlobalMutex() );
210 if (! pId)
211 {
212 static OImplementationId aId;
213 pId = &aId;
214 }
215 }
216 return pId->getImplementationId();
217 }
218 // -------------------------------------------------------------------------
fireValueChange(const ORowSetValue & _rOldValue)219 void ORowSetDataColumn::fireValueChange(const ORowSetValue& _rOldValue)
220 {
221 if ( !m_aColumnValue.isNull() && m_aColumnValue->isValid() && (!(((*m_aColumnValue)->get())[m_nPos] == _rOldValue)) )
222 {
223 sal_Int32 nHandle = PROPERTY_ID_VALUE;
224 m_aOldValue = _rOldValue.makeAny();
225 Any aNew = ((*m_aColumnValue)->get())[m_nPos].makeAny();
226
227 fire(&nHandle, &aNew, &m_aOldValue, 1, sal_False );
228 }
229 else if ( !m_aColumnValue.isNull() && !_rOldValue.isNull() )
230 {
231 sal_Int32 nHandle = PROPERTY_ID_VALUE;
232 m_aOldValue = _rOldValue.makeAny();
233 Any aNew;
234
235 fire(&nHandle, &aNew, &m_aOldValue, 1, sal_False );
236 }
237 }
238 // -----------------------------------------------------------------------------
DBG_NAME(ORowSetDataColumns)239 DBG_NAME(ORowSetDataColumns )
240 ORowSetDataColumns::ORowSetDataColumns(
241 sal_Bool _bCase,
242 const ::vos::ORef< ::connectivity::OSQLColumns>& _rColumns,
243 ::cppu::OWeakObject& _rParent,
244 ::osl::Mutex& _rMutex,
245 const ::std::vector< ::rtl::OUString> &_rVector
246 ) : connectivity::sdbcx::OCollection(_rParent,_bCase,_rMutex,_rVector)
247 ,m_aColumns(_rColumns)
248 {
249 DBG_CTOR(ORowSetDataColumns ,NULL);
250 }
251 // -----------------------------------------------------------------------------
~ORowSetDataColumns()252 ORowSetDataColumns::~ORowSetDataColumns()
253 {
254 DBG_DTOR(ORowSetDataColumns ,NULL);
255 }
256 // -----------------------------------------------------------------------------
createObject(const::rtl::OUString & _rName)257 sdbcx::ObjectType ORowSetDataColumns::createObject(const ::rtl::OUString& _rName)
258 {
259 connectivity::sdbcx::ObjectType xNamed;
260
261 ::comphelper::UStringMixEqual aCase(isCaseSensitive());
262 ::connectivity::OSQLColumns::Vector::const_iterator first = ::connectivity::find(m_aColumns->get().begin(),m_aColumns->get().end(),_rName,aCase);
263 if(first != m_aColumns->get().end())
264 xNamed.set(*first,UNO_QUERY);
265
266 return xNamed;
267 }
268 // -----------------------------------------------------------------------------
disposing(void)269 void SAL_CALL ORowSetDataColumns::disposing(void)
270 {
271 // clear_NoDispose();
272 ORowSetDataColumns_BASE::disposing();
273 m_aColumns = NULL;
274 // m_aColumns.clear();
275 }
276 // -----------------------------------------------------------------------------
assign(const::vos::ORef<::connectivity::OSQLColumns> & _rColumns,const::std::vector<::rtl::OUString> & _rVector)277 void ORowSetDataColumns::assign(const ::vos::ORef< ::connectivity::OSQLColumns>& _rColumns,const ::std::vector< ::rtl::OUString> &_rVector)
278 {
279 m_aColumns = _rColumns;
280 reFill(_rVector);
281 }
282 // -----------------------------------------------------------------------------
impl_refresh()283 void ORowSetDataColumns::impl_refresh() throw(::com::sun::star::uno::RuntimeException)
284 {
285 }
286 // -----------------------------------------------------------------------------
287
288
289