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 : #include "resultcolumn.hxx"
21 : #include <com/sun/star/lang/DisposedException.hpp>
22 : #include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
23 : #include <com/sun/star/sdbc/DataType.hpp>
24 : #include <com/sun/star/sdbc/ColumnValue.hpp>
25 : #include <cppuhelper/typeprovider.hxx>
26 : #include <tools/debug.hxx>
27 : #include <tools/diagnose_ex.h>
28 : #include "dbastrings.hrc"
29 : #include "apitools.hxx"
30 : #include <com/sun/star/beans/PropertyAttribute.hpp>
31 : #include <cppuhelper/exc_hlp.hxx>
32 : #include <osl/thread.h>
33 :
34 : using namespace ::com::sun::star::sdbc;
35 : using namespace ::com::sun::star::beans;
36 : using namespace ::com::sun::star::uno;
37 : using namespace ::com::sun::star::lang;
38 : using namespace ::com::sun::star::container;
39 : using namespace ::osl;
40 : using namespace ::comphelper;
41 : using namespace ::cppu;
42 : using namespace dbaccess;
43 :
44 : DBG_NAME(OResultColumn)
45 :
46 0 : OResultColumn::OResultColumn( const Reference < XResultSetMetaData >& _xMetaData, sal_Int32 _nPos,
47 : const Reference< XDatabaseMetaData >& _rxDBMeta )
48 : :OColumn( true )
49 : ,m_xMetaData( _xMetaData )
50 : ,m_xDBMetaData( _rxDBMeta )
51 0 : ,m_nPos( _nPos )
52 : {
53 : DBG_CTOR(OResultColumn,NULL);
54 0 : }
55 :
56 0 : void OResultColumn::impl_determineIsRowVersion_nothrow()
57 : {
58 0 : if ( m_aIsRowVersion.hasValue() )
59 0 : return;
60 0 : m_aIsRowVersion <<= (sal_Bool)(sal_False);
61 :
62 : OSL_ENSURE( m_xDBMetaData.is(), "OResultColumn::impl_determineIsRowVersion_nothrow: no DBMetaData!" );
63 0 : if ( !m_xDBMetaData.is() )
64 0 : return;
65 :
66 : try
67 : {
68 0 : ::rtl::OUString sCatalog, sSchema, sTable, sColumnName;
69 0 : getPropertyValue( PROPERTY_CATALOGNAME ) >>= sCatalog;
70 0 : getPropertyValue( PROPERTY_SCHEMANAME ) >>= sSchema;
71 0 : getPropertyValue( PROPERTY_TABLENAME ) >>= sTable;
72 0 : getPropertyValue( PROPERTY_NAME ) >>= sColumnName;
73 :
74 : try
75 : {
76 0 : Reference< XResultSet > xVersionColumns = m_xDBMetaData->getVersionColumns(
77 0 : makeAny( sCatalog ), sSchema, sTable );
78 0 : if ( xVersionColumns.is() ) // allowed to be NULL
79 : {
80 0 : Reference< XRow > xResultRow( xVersionColumns, UNO_QUERY_THROW );
81 0 : while ( xVersionColumns->next() )
82 : {
83 0 : if ( xResultRow->getString( 2 ) == sColumnName )
84 : {
85 0 : m_aIsRowVersion <<= (sal_Bool)(sal_True);
86 0 : break;
87 : }
88 0 : }
89 0 : }
90 : }
91 0 : catch(const SQLException&)
92 : {
93 0 : }
94 : }
95 0 : catch( const Exception& )
96 : {
97 : DBG_UNHANDLED_EXCEPTION();
98 : }
99 : }
100 :
101 0 : OResultColumn::~OResultColumn()
102 : {
103 : DBG_DTOR(OResultColumn,NULL);
104 0 : }
105 :
106 : // com::sun::star::lang::XTypeProvider
107 0 : Sequence< sal_Int8 > OResultColumn::getImplementationId() throw (RuntimeException)
108 : {
109 : static OImplementationId * pId = 0;
110 0 : if (! pId)
111 : {
112 0 : MutexGuard aGuard( Mutex::getGlobalMutex() );
113 0 : if (! pId)
114 : {
115 0 : static OImplementationId aId;
116 0 : pId = &aId;
117 0 : }
118 : }
119 0 : return pId->getImplementationId();
120 : }
121 :
122 : // XServiceInfo
123 0 : rtl::OUString OResultColumn::getImplementationName( ) throw(RuntimeException)
124 : {
125 0 : return rtl::OUString("com.sun.star.sdb.OResultColumn");
126 : }
127 :
128 0 : Sequence< ::rtl::OUString > OResultColumn::getSupportedServiceNames( ) throw (RuntimeException)
129 : {
130 0 : Sequence< ::rtl::OUString > aSNS( 2 );
131 0 : aSNS[0] = SERVICE_SDBCX_COLUMN;
132 0 : aSNS[1] = SERVICE_SDB_RESULTCOLUMN;
133 0 : return aSNS;
134 : }
135 :
136 : // OComponentHelper
137 0 : void OResultColumn::disposing()
138 : {
139 0 : OColumn::disposing();
140 :
141 0 : MutexGuard aGuard(m_aMutex);
142 0 : m_xMetaData = NULL;
143 0 : }
144 :
145 : // comphelper::OPropertyArrayUsageHelper
146 0 : ::cppu::IPropertyArrayHelper* OResultColumn::createArrayHelper( ) const
147 : {
148 0 : BEGIN_PROPERTY_HELPER(21)
149 0 : DECL_PROP1(CATALOGNAME, ::rtl::OUString, READONLY);
150 0 : DECL_PROP1(DISPLAYSIZE, sal_Int32, READONLY);
151 0 : DECL_PROP1_BOOL(ISAUTOINCREMENT, READONLY);
152 0 : DECL_PROP1_BOOL(ISCASESENSITIVE, READONLY);
153 0 : DECL_PROP1_BOOL(ISCURRENCY, READONLY);
154 0 : DECL_PROP1_BOOL(ISDEFINITELYWRITABLE, READONLY);
155 0 : DECL_PROP1(ISNULLABLE, sal_Int32, READONLY);
156 0 : DECL_PROP1_BOOL(ISREADONLY, READONLY);
157 0 : DECL_PROP1_BOOL(ISROWVERSION, READONLY);
158 0 : DECL_PROP1_BOOL(ISSEARCHABLE, READONLY);
159 0 : DECL_PROP1_BOOL(ISSIGNED, READONLY);
160 0 : DECL_PROP1_BOOL(ISWRITABLE, READONLY);
161 0 : DECL_PROP1(LABEL, ::rtl::OUString, READONLY);
162 0 : DECL_PROP1(NAME, ::rtl::OUString, READONLY);
163 0 : DECL_PROP1(PRECISION, sal_Int32, READONLY);
164 0 : DECL_PROP1(SCALE, sal_Int32, READONLY);
165 0 : DECL_PROP1(SCHEMANAME, ::rtl::OUString, READONLY);
166 0 : DECL_PROP1(SERVICENAME, ::rtl::OUString, READONLY);
167 0 : DECL_PROP1(TABLENAME, ::rtl::OUString, READONLY);
168 0 : DECL_PROP1(TYPE, sal_Int32, READONLY);
169 0 : DECL_PROP1(TYPENAME, ::rtl::OUString, READONLY);
170 0 : END_PROPERTY_HELPER();
171 : }
172 :
173 : // cppu::OPropertySetHelper
174 0 : ::cppu::IPropertyArrayHelper& OResultColumn::getInfoHelper()
175 : {
176 0 : return *static_cast< ::comphelper::OPropertyArrayUsageHelper< OResultColumn >* >(this)->getArrayHelper();
177 : }
178 :
179 : namespace
180 : {
181 : template< typename TYPE >
182 0 : void obtain( Any& _out_rValue, ::boost::optional< TYPE > _rCache, const sal_Int32 _nPos, const Reference < XResultSetMetaData >& _rxResultMeta, TYPE (SAL_CALL XResultSetMetaData::*Getter)( sal_Int32 ) )
183 : {
184 0 : if ( !_rCache )
185 0 : _rCache.reset( (_rxResultMeta.get()->*Getter)( _nPos ) );
186 0 : _out_rValue <<= *_rCache;
187 0 : }
188 : }
189 :
190 0 : void OResultColumn::getFastPropertyValue( Any& rValue, sal_Int32 nHandle ) const
191 : {
192 : try
193 : {
194 0 : if ( OColumn::isRegisteredProperty( nHandle ) )
195 : {
196 0 : OColumn::getFastPropertyValue( rValue, nHandle );
197 : }
198 : else
199 : {
200 0 : switch (nHandle)
201 : {
202 : case PROPERTY_ID_ISROWVERSION:
203 0 : const_cast< OResultColumn* >( this )->impl_determineIsRowVersion_nothrow();
204 0 : rValue = m_aIsRowVersion;
205 0 : break;
206 : case PROPERTY_ID_TABLENAME:
207 0 : rValue <<= m_xMetaData->getTableName(m_nPos);
208 0 : break;
209 : case PROPERTY_ID_SCHEMANAME:
210 0 : rValue <<= m_xMetaData->getSchemaName(m_nPos);
211 0 : break;
212 : case PROPERTY_ID_CATALOGNAME:
213 0 : rValue <<= m_xMetaData->getCatalogName(m_nPos);
214 0 : break;
215 : case PROPERTY_ID_ISSIGNED:
216 0 : obtain( rValue, m_isSigned, m_nPos, m_xMetaData, &XResultSetMetaData::isSigned );
217 0 : break;
218 : case PROPERTY_ID_ISCURRENCY:
219 0 : obtain( rValue, m_isCurrency, m_nPos, m_xMetaData, &XResultSetMetaData::isCurrency );
220 0 : break;
221 : case PROPERTY_ID_ISSEARCHABLE:
222 0 : obtain( rValue, m_bSearchable, m_nPos, m_xMetaData, &XResultSetMetaData::isSearchable );
223 0 : break;
224 : case PROPERTY_ID_ISCASESENSITIVE:
225 0 : obtain( rValue, m_isCaseSensitive, m_nPos, m_xMetaData, &XResultSetMetaData::isCaseSensitive );
226 0 : break;
227 : case PROPERTY_ID_ISREADONLY:
228 0 : obtain( rValue, m_isReadOnly, m_nPos, m_xMetaData, &XResultSetMetaData::isReadOnly );
229 0 : break;
230 : case PROPERTY_ID_ISWRITABLE:
231 0 : obtain( rValue, m_isWritable, m_nPos, m_xMetaData, &XResultSetMetaData::isWritable );
232 0 : break;
233 : case PROPERTY_ID_ISDEFINITELYWRITABLE:
234 0 : obtain( rValue, m_isDefinitelyWritable, m_nPos, m_xMetaData, &XResultSetMetaData::isDefinitelyWritable );
235 0 : break;
236 : case PROPERTY_ID_ISAUTOINCREMENT:
237 0 : obtain( rValue, m_isAutoIncrement, m_nPos, m_xMetaData, &XResultSetMetaData::isAutoIncrement );
238 0 : break;
239 : case PROPERTY_ID_SERVICENAME:
240 0 : rValue <<= m_xMetaData->getColumnServiceName(m_nPos);
241 0 : break;
242 : case PROPERTY_ID_LABEL:
243 0 : obtain( rValue, m_sColumnLabel, m_nPos, m_xMetaData, &XResultSetMetaData::getColumnLabel );
244 0 : break;
245 : case PROPERTY_ID_DISPLAYSIZE:
246 0 : obtain( rValue, m_nColumnDisplaySize, m_nPos, m_xMetaData, &XResultSetMetaData::getColumnDisplaySize );
247 0 : break;
248 : case PROPERTY_ID_TYPE:
249 0 : obtain( rValue, m_nColumnType, m_nPos, m_xMetaData, &XResultSetMetaData::getColumnType );
250 0 : break;
251 : case PROPERTY_ID_PRECISION:
252 0 : obtain( rValue, m_nPrecision, m_nPos, m_xMetaData, &XResultSetMetaData::getPrecision );
253 0 : break;
254 : case PROPERTY_ID_SCALE:
255 0 : obtain( rValue, m_nScale, m_nPos, m_xMetaData, &XResultSetMetaData::getScale );
256 0 : break;
257 : case PROPERTY_ID_ISNULLABLE:
258 0 : obtain( rValue, m_isNullable, m_nPos, m_xMetaData, &XResultSetMetaData::isNullable );
259 0 : break;
260 : case PROPERTY_ID_TYPENAME:
261 0 : rValue <<= m_xMetaData->getColumnTypeName(m_nPos);
262 0 : break;
263 : default:
264 : OSL_FAIL( "OResultColumn::getFastPropertyValue: unknown property handle!" );
265 0 : break;
266 : }
267 : }
268 : }
269 0 : catch (SQLException& )
270 : {
271 : // default handling if we caught an exception
272 0 : switch (nHandle)
273 : {
274 : case PROPERTY_ID_LABEL:
275 : case PROPERTY_ID_TYPENAME:
276 : case PROPERTY_ID_SERVICENAME:
277 : case PROPERTY_ID_TABLENAME:
278 : case PROPERTY_ID_SCHEMANAME:
279 : case PROPERTY_ID_CATALOGNAME:
280 : // empty string'S
281 0 : rValue <<= rtl::OUString();
282 0 : break;
283 : case PROPERTY_ID_ISROWVERSION:
284 : case PROPERTY_ID_ISAUTOINCREMENT:
285 : case PROPERTY_ID_ISWRITABLE:
286 : case PROPERTY_ID_ISDEFINITELYWRITABLE:
287 : case PROPERTY_ID_ISCASESENSITIVE:
288 : case PROPERTY_ID_ISSEARCHABLE:
289 : case PROPERTY_ID_ISCURRENCY:
290 : case PROPERTY_ID_ISSIGNED:
291 : {
292 0 : sal_Bool bVal = sal_False;
293 0 : rValue.setValue(&bVal, getBooleanCppuType());
294 0 : } break;
295 : case PROPERTY_ID_ISREADONLY:
296 : {
297 0 : sal_Bool bVal = sal_True;
298 0 : rValue.setValue(&bVal, getBooleanCppuType());
299 0 : } break;
300 : case PROPERTY_ID_SCALE:
301 : case PROPERTY_ID_PRECISION:
302 : case PROPERTY_ID_DISPLAYSIZE:
303 0 : rValue <<= sal_Int32(0);
304 0 : break;
305 : case PROPERTY_ID_TYPE:
306 0 : rValue <<= sal_Int32(DataType::SQLNULL);
307 0 : break;
308 : case PROPERTY_ID_ISNULLABLE:
309 0 : rValue <<= ColumnValue::NULLABLE_UNKNOWN;
310 0 : break;
311 : }
312 : }
313 0 : }
314 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|