1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
20 #include <comphelper/processfactory.hxx>
21 #include <ucbhelper/contentidentifier.hxx>
22 #include <com/sun/star/ucb/OpenMode.hpp>
23 #include <com/sun/star/uno/Reference.h>
24 #include <com/sun/star/beans/PropertyAttribute.hpp>
25 #include <com/sun/star/ucb/ListActionType.hpp>
26 #include <com/sun/star/ucb/XSourceInitialization.hpp>
27 #include <ucbhelper/resultsetmetadata.hxx>
29 #include "resultsetbase.hxx"
31 using namespace chelp
;
32 using namespace com::sun::star
;
34 ResultSetBase::ResultSetBase( const uno::Reference
< uno::XComponentContext
>& rxContext
,
35 const uno::Reference
< ucb::XContentProvider
>& xProvider
,
37 const uno::Sequence
< beans::Property
>& seq
,
38 const uno::Sequence
< ucb::NumberedSortingInfo
>& seqSort
)
39 : m_xContext( rxContext
),
40 m_xProvider( xProvider
),
43 m_nOpenMode( nOpenMode
),
44 m_bRowCountFinal( true ),
46 m_sSortingInfo( seqSort
),
47 m_pDisposeEventListeners( 0 ),
48 m_pRowCountListeners( 0 ),
49 m_pIsFinalListeners( 0 )
53 ResultSetBase::~ResultSetBase()
55 delete m_pIsFinalListeners
;
56 delete m_pRowCountListeners
;
57 delete m_pDisposeEventListeners
;
64 ResultSetBase::acquire(
68 OWeakObject::acquire();
73 ResultSetBase::release(
77 OWeakObject::release();
83 ResultSetBase::queryInterface(
84 const uno::Type
& rType
)
85 throw( uno::RuntimeException
)
87 uno::Any aRet
= cppu::queryInterface( rType
,
88 (static_cast< lang::XComponent
* >(this)),
89 (static_cast< sdbc::XRow
* >(this)),
90 (static_cast< sdbc::XResultSet
* >(this)),
91 (static_cast< sdbc::XResultSetMetaDataSupplier
* >(this)),
92 (static_cast< beans::XPropertySet
* >(this)),
93 (static_cast< ucb::XContentAccess
* >(this)) );
94 return aRet
.hasValue() ? aRet
: OWeakObject::queryInterface( rType
);
103 ResultSetBase::addEventListener(
104 const uno::Reference
< lang::XEventListener
>& Listener
)
105 throw( uno::RuntimeException
)
107 osl::MutexGuard
aGuard( m_aMutex
);
109 if ( ! m_pDisposeEventListeners
)
110 m_pDisposeEventListeners
=
111 new cppu::OInterfaceContainerHelper( m_aMutex
);
113 m_pDisposeEventListeners
->addInterface( Listener
);
118 ResultSetBase::removeEventListener(
119 const uno::Reference
< lang::XEventListener
>& Listener
)
120 throw( uno::RuntimeException
)
122 osl::MutexGuard
aGuard( m_aMutex
);
124 if ( m_pDisposeEventListeners
)
125 m_pDisposeEventListeners
->removeInterface( Listener
);
131 ResultSetBase::dispose()
132 throw( uno::RuntimeException
)
134 osl::MutexGuard
aGuard( m_aMutex
);
136 lang::EventObject aEvt
;
137 aEvt
.Source
= static_cast< lang::XComponent
* >( this );
139 if ( m_pDisposeEventListeners
&& m_pDisposeEventListeners
->getLength() )
141 m_pDisposeEventListeners
->disposeAndClear( aEvt
);
143 if( m_pRowCountListeners
&& m_pRowCountListeners
->getLength() )
145 m_pRowCountListeners
->disposeAndClear( aEvt
);
147 if( m_pIsFinalListeners
&& m_pIsFinalListeners
->getLength() )
149 m_pIsFinalListeners
->disposeAndClear( aEvt
);
160 throw( sdbc::SQLException
,
161 uno::RuntimeException
)
165 if( sal::static_int_cast
<sal_uInt32
>( m_nRow
) < m_aItems
.size() )
174 ResultSetBase::isBeforeFirst(
176 throw( sdbc::SQLException
,
177 uno::RuntimeException
)
184 ResultSetBase::isAfterLast(
186 throw( sdbc::SQLException
,
187 uno::RuntimeException
)
189 return sal::static_int_cast
<sal_uInt32
>( m_nRow
) >= m_aItems
.size(); // Cannot happen, if m_aFolder.isOpen()
194 ResultSetBase::isFirst(
196 throw( sdbc::SQLException
,
197 uno::RuntimeException
)
204 ResultSetBase::isLast(
206 throw( sdbc::SQLException
,
207 uno::RuntimeException
)
209 if( sal::static_int_cast
<sal_uInt32
>( m_nRow
) == m_aItems
.size() - 1 )
217 ResultSetBase::beforeFirst(
219 throw( sdbc::SQLException
,
220 uno::RuntimeException
)
227 ResultSetBase::afterLast(
229 throw( sdbc::SQLException
,
230 uno::RuntimeException
)
232 m_nRow
= m_aItems
.size();
237 ResultSetBase::first(
239 throw( sdbc::SQLException
,
240 uno::RuntimeException
)
250 throw( sdbc::SQLException
,
251 uno::RuntimeException
)
253 m_nRow
= m_aItems
.size() - 1;
259 ResultSetBase::getRow(
261 throw( sdbc::SQLException
,
262 uno::RuntimeException
)
264 // Test, whether behind last row
265 if( -1 == m_nRow
|| sal::static_int_cast
<sal_uInt32
>( m_nRow
) >= m_aItems
.size() )
272 sal_Bool SAL_CALL
ResultSetBase::absolute( sal_Int32 row
)
273 throw( sdbc::SQLException
, uno::RuntimeException
)
280 m_nRow
+= ( row
+ 1 );
285 return 0<= m_nRow
&& sal::static_int_cast
<sal_uInt32
>( m_nRow
) < m_aItems
.size();
292 ResultSetBase::relative(
294 throw( sdbc::SQLException
,
295 uno::RuntimeException
)
297 if( isAfterLast() || isBeforeFirst() )
298 throw sdbc::SQLException();
304 while( row
++ && m_nRow
> -1 )
307 return 0 <= m_nRow
&& sal::static_int_cast
<sal_uInt32
>( m_nRow
) < m_aItems
.size();
313 ResultSetBase::previous(
315 throw( sdbc::SQLException
,
316 uno::RuntimeException
)
318 if( sal::static_int_cast
<sal_uInt32
>( m_nRow
) > m_aItems
.size() )
319 m_nRow
= m_aItems
.size(); // Correct Handling of afterLast
320 if( 0 <= m_nRow
) -- m_nRow
;
322 return 0 <= m_nRow
&& sal::static_int_cast
<sal_uInt32
>( m_nRow
) < m_aItems
.size();
327 ResultSetBase::refreshRow(
329 throw( sdbc::SQLException
,
330 uno::RuntimeException
)
336 ResultSetBase::rowUpdated(
338 throw( sdbc::SQLException
,
339 uno::RuntimeException
)
345 ResultSetBase::rowInserted(
347 throw( sdbc::SQLException
,
348 uno::RuntimeException
)
354 ResultSetBase::rowDeleted(
356 throw( sdbc::SQLException
,
357 uno::RuntimeException
)
363 uno::Reference
< uno::XInterface
> SAL_CALL
364 ResultSetBase::getStatement(
366 throw( sdbc::SQLException
,
367 uno::RuntimeException
)
369 uno::Reference
< uno::XInterface
> test( 0 );
377 ResultSetBase::close(
379 throw( sdbc::SQLException
,
380 uno::RuntimeException
)
386 ResultSetBase::queryContentIdentifierString(
388 throw( uno::RuntimeException
)
390 if( 0 <= m_nRow
&& sal::static_int_cast
<sal_uInt32
>( m_nRow
) < m_aItems
.size() )
391 return m_aPath
[m_nRow
];
397 uno::Reference
< ucb::XContentIdentifier
> SAL_CALL
398 ResultSetBase::queryContentIdentifier(
400 throw( uno::RuntimeException
)
402 if( 0 <= m_nRow
&& sal::static_int_cast
<sal_uInt32
>( m_nRow
) < m_aItems
.size() )
404 OUString url
= queryContentIdentifierString();
405 if( ! m_aIdents
[m_nRow
].is() && !url
.isEmpty() )
406 m_aIdents
[m_nRow
] = uno::Reference
< ucb::XContentIdentifier
>(
407 new ::ucbhelper::ContentIdentifier( url
) );
408 return m_aIdents
[m_nRow
];
411 return uno::Reference
< ucb::XContentIdentifier
>();
415 uno::Reference
< ucb::XContent
> SAL_CALL
416 ResultSetBase::queryContent(
418 throw( uno::RuntimeException
)
420 if( 0 <= m_nRow
&& sal::static_int_cast
<sal_uInt32
>( m_nRow
) < m_aItems
.size() )
421 return m_xProvider
->queryContent( queryContentIdentifier() );
423 return uno::Reference
< ucb::XContent
>();
428 class XPropertySetInfoImpl
429 : public cppu::OWeakObject
,
430 public beans::XPropertySetInfo
434 XPropertySetInfoImpl( const uno::Sequence
< beans::Property
>& aSeq
)
439 void SAL_CALL
acquire( void )
442 OWeakObject::acquire();
446 void SAL_CALL
release( void )
449 OWeakObject::release();
452 uno::Any SAL_CALL
queryInterface( const uno::Type
& rType
)
453 throw( uno::RuntimeException
)
455 uno::Any aRet
= cppu::queryInterface( rType
,
456 (static_cast< beans::XPropertySetInfo
* >(this)) );
457 return aRet
.hasValue() ? aRet
: OWeakObject::queryInterface( rType
);
460 uno::Sequence
< beans::Property
> SAL_CALL
getProperties()
461 throw( uno::RuntimeException
)
466 beans::Property SAL_CALL
getPropertyByName( const OUString
& aName
)
467 throw( beans::UnknownPropertyException
,
468 uno::RuntimeException
)
470 for( int i
= 0; i
< m_aSeq
.getLength(); ++i
)
471 if( aName
== m_aSeq
[i
].Name
)
473 throw beans::UnknownPropertyException();
476 sal_Bool SAL_CALL
hasPropertyByName( const OUString
& Name
)
477 throw( uno::RuntimeException
)
479 for( int i
= 0; i
< m_aSeq
.getLength(); ++i
)
480 if( Name
== m_aSeq
[i
].Name
)
487 uno::Sequence
< beans::Property
> m_aSeq
;
493 uno::Reference
< beans::XPropertySetInfo
> SAL_CALL
494 ResultSetBase::getPropertySetInfo()
495 throw( uno::RuntimeException
)
497 uno::Sequence
< beans::Property
> seq(2);
498 seq
[0].Name
= OUString( "RowCount" );
500 seq
[0].Type
= getCppuType( static_cast< sal_Int32
* >(0) );
501 seq
[0].Attributes
= beans::PropertyAttribute::READONLY
;
503 seq
[1].Name
= OUString( "IsRowCountFinal" );
505 seq
[1].Type
= getCppuType( static_cast< sal_Bool
* >(0) );
506 seq
[1].Attributes
= beans::PropertyAttribute::READONLY
;
509 return uno::Reference
< beans::XPropertySetInfo
> ( new XPropertySetInfoImpl( seq
) );
514 void SAL_CALL
ResultSetBase::setPropertyValue(
515 const OUString
& aPropertyName
, const uno::Any
& aValue
)
516 throw( beans::UnknownPropertyException
,
517 beans::PropertyVetoException
,
518 lang::IllegalArgumentException
,
519 lang::WrappedTargetException
,
520 uno::RuntimeException
)
524 if( aPropertyName
== OUString( "IsRowCountFinal" ) ||
525 aPropertyName
== OUString( "RowCount" ) )
528 throw beans::UnknownPropertyException();
532 uno::Any SAL_CALL
ResultSetBase::getPropertyValue(
533 const OUString
& PropertyName
)
534 throw( beans::UnknownPropertyException
,
535 lang::WrappedTargetException
,
536 uno::RuntimeException
)
538 if( PropertyName
== OUString( "IsRowCountFinal" ) )
541 aAny
<<= m_bRowCountFinal
;
544 else if ( PropertyName
== OUString( "RowCount" ) )
547 sal_Int32 count
= m_aItems
.size();
552 throw beans::UnknownPropertyException();
556 void SAL_CALL
ResultSetBase::addPropertyChangeListener(
557 const OUString
& aPropertyName
,
558 const uno::Reference
< beans::XPropertyChangeListener
>& xListener
)
559 throw( beans::UnknownPropertyException
,
560 lang::WrappedTargetException
,
561 uno::RuntimeException
)
563 if( aPropertyName
== OUString( "IsRowCountFinal" ) )
565 osl::MutexGuard
aGuard( m_aMutex
);
566 if ( ! m_pIsFinalListeners
)
567 m_pIsFinalListeners
=
568 new cppu::OInterfaceContainerHelper( m_aMutex
);
570 m_pIsFinalListeners
->addInterface( xListener
);
572 else if ( aPropertyName
== OUString( "RowCount" ) )
574 osl::MutexGuard
aGuard( m_aMutex
);
575 if ( ! m_pRowCountListeners
)
576 m_pRowCountListeners
=
577 new cppu::OInterfaceContainerHelper( m_aMutex
);
578 m_pRowCountListeners
->addInterface( xListener
);
581 throw beans::UnknownPropertyException();
585 void SAL_CALL
ResultSetBase::removePropertyChangeListener(
586 const OUString
& aPropertyName
,
587 const uno::Reference
< beans::XPropertyChangeListener
>& aListener
)
588 throw( beans::UnknownPropertyException
,
589 lang::WrappedTargetException
,
590 uno::RuntimeException
)
592 if( aPropertyName
== OUString( "IsRowCountFinal" ) &&
593 m_pIsFinalListeners
)
595 osl::MutexGuard
aGuard( m_aMutex
);
596 m_pIsFinalListeners
->removeInterface( aListener
);
598 else if ( aPropertyName
== OUString( "RowCount" ) &&
599 m_pRowCountListeners
)
601 osl::MutexGuard
aGuard( m_aMutex
);
602 m_pRowCountListeners
->removeInterface( aListener
);
605 throw beans::UnknownPropertyException();
609 void SAL_CALL
ResultSetBase::addVetoableChangeListener(
610 const OUString
& PropertyName
,
611 const uno::Reference
< beans::XVetoableChangeListener
>& aListener
)
612 throw( beans::UnknownPropertyException
,
613 lang::WrappedTargetException
,
614 uno::RuntimeException
)
621 void SAL_CALL
ResultSetBase::removeVetoableChangeListener(
622 const OUString
& PropertyName
,
623 const uno::Reference
< beans::XVetoableChangeListener
>& aListener
)
624 throw( beans::UnknownPropertyException
,
625 lang::WrappedTargetException
,
626 uno::RuntimeException
)
634 // XResultSetMetaDataSupplier
635 uno::Reference
< sdbc::XResultSetMetaData
> SAL_CALL
636 ResultSetBase::getMetaData(
638 throw( sdbc::SQLException
,
639 uno::RuntimeException
)
641 ::ucbhelper::ResultSetMetaData
* p
=
642 new ::ucbhelper::ResultSetMetaData( m_xContext
, m_sProperty
);
643 return uno::Reference
< sdbc::XResultSetMetaData
>( p
);
646 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */