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>
28 #include "ftpresultsetbase.hxx"
31 using namespace com::sun::star
;
33 ResultSetBase::ResultSetBase(
34 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(
89 (static_cast< lang::XComponent
* >(this)),
90 (static_cast< sdbc::XRow
* >(this)),
91 (static_cast< sdbc::XResultSet
* >(this)),
92 (static_cast< sdbc::XResultSetMetaDataSupplier
* >(this)),
93 (static_cast< beans::XPropertySet
* >(this)),
94 (static_cast< ucb::XContentAccess
* >(this)) );
95 return aRet
.hasValue() ? aRet
: OWeakObject::queryInterface( rType
);
104 ResultSetBase::addEventListener(
105 const uno::Reference
< lang::XEventListener
>& Listener
)
106 throw( uno::RuntimeException
)
108 osl::MutexGuard
aGuard( m_aMutex
);
110 if ( ! m_pDisposeEventListeners
)
111 m_pDisposeEventListeners
=
112 new cppu::OInterfaceContainerHelper( m_aMutex
);
114 m_pDisposeEventListeners
->addInterface( Listener
);
119 ResultSetBase::removeEventListener(
120 const uno::Reference
< lang::XEventListener
>& Listener
)
121 throw( uno::RuntimeException
)
123 osl::MutexGuard
aGuard( m_aMutex
);
125 if ( m_pDisposeEventListeners
)
126 m_pDisposeEventListeners
->removeInterface( Listener
);
132 ResultSetBase::dispose()
133 throw( uno::RuntimeException
)
135 osl::MutexGuard
aGuard( m_aMutex
);
137 lang::EventObject aEvt
;
138 aEvt
.Source
= static_cast< lang::XComponent
* >( this );
140 if ( m_pDisposeEventListeners
&& m_pDisposeEventListeners
->getLength() )
142 m_pDisposeEventListeners
->disposeAndClear( aEvt
);
144 if( m_pRowCountListeners
&& m_pRowCountListeners
->getLength() )
146 m_pRowCountListeners
->disposeAndClear( aEvt
);
148 if( m_pIsFinalListeners
&& m_pIsFinalListeners
->getLength() )
150 m_pIsFinalListeners
->disposeAndClear( aEvt
);
161 throw( sdbc::SQLException
,
162 uno::RuntimeException
)
165 if( ++m_nRow
< sal::static_int_cast
<sal_Int32
>(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 m_nRow
>= sal::static_int_cast
<sal_Int32
>(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( m_nRow
== sal::static_int_cast
<sal_Int32
>(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
|| m_nRow
>= sal::static_int_cast
<sal_Int32
>(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
&& m_nRow
< sal::static_int_cast
<sal_Int32
>(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
&& m_nRow
< sal::static_int_cast
<sal_Int32
>(m_aItems
.size());
313 ResultSetBase::previous(
315 throw( sdbc::SQLException
,
316 uno::RuntimeException
)
318 if( m_nRow
> sal::static_int_cast
<sal_Int32
>(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
&& m_nRow
< sal::static_int_cast
<sal_Int32
>(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
)
385 rtl::OUString SAL_CALL
386 ResultSetBase::queryContentIdentifierString(
388 throw( uno::RuntimeException
)
390 if( 0 <= m_nRow
&& m_nRow
< sal::static_int_cast
<sal_Int32
>(m_aItems
.size()) )
391 return m_aPath
[m_nRow
];
393 return rtl::OUString();
397 uno::Reference
< ucb::XContentIdentifier
> SAL_CALL
398 ResultSetBase::queryContentIdentifier(
402 uno::RuntimeException
405 if( 0 <= m_nRow
&& m_nRow
< sal::static_int_cast
<sal_Int32
>(m_aItems
.size()) )
407 if(!m_aIdents
[m_nRow
].is()) {
408 rtl::OUString url
= queryContentIdentifierString();
411 uno::Reference
< ucb::XContentIdentifier
>(
412 new ::ucbhelper::ContentIdentifier(url
) );
414 return m_aIdents
[m_nRow
];
417 return uno::Reference
<ucb::XContentIdentifier
>();
421 uno::Reference
< ucb::XContent
> SAL_CALL
422 ResultSetBase::queryContent(
424 throw( uno::RuntimeException
)
426 if( 0 <= m_nRow
&& m_nRow
< sal::static_int_cast
<sal_Int32
>(m_aItems
.size()) )
427 return m_xProvider
->queryContent(queryContentIdentifier());
429 return uno::Reference
< ucb::XContent
>();
434 class XPropertySetInfoImpl
435 : public cppu::OWeakObject
,
436 public beans::XPropertySetInfo
440 XPropertySetInfoImpl( const uno::Sequence
< beans::Property
>& aSeq
)
445 void SAL_CALL
acquire( void )
448 OWeakObject::acquire();
452 void SAL_CALL
release( void )
455 OWeakObject::release();
458 uno::Any SAL_CALL
queryInterface( const uno::Type
& rType
)
459 throw( uno::RuntimeException
)
461 uno::Any aRet
= cppu::queryInterface(
463 (static_cast< beans::XPropertySetInfo
* >(this)) );
464 return aRet
.hasValue() ? aRet
: OWeakObject::queryInterface( rType
);
467 uno::Sequence
< beans::Property
> SAL_CALL
getProperties()
468 throw( uno::RuntimeException
)
473 beans::Property SAL_CALL
getPropertyByName( const ::rtl::OUString
& aName
)
474 throw( beans::UnknownPropertyException
,
475 uno::RuntimeException
)
477 for( int i
= 0; i
< m_aSeq
.getLength(); ++i
)
478 if( aName
== m_aSeq
[i
].Name
)
480 throw beans::UnknownPropertyException();
483 sal_Bool SAL_CALL
hasPropertyByName( const ::rtl::OUString
& Name
)
484 throw( uno::RuntimeException
)
486 for( int i
= 0; i
< m_aSeq
.getLength(); ++i
)
487 if( Name
== m_aSeq
[i
].Name
)
494 uno::Sequence
< beans::Property
> m_aSeq
;
500 uno::Reference
< beans::XPropertySetInfo
> SAL_CALL
501 ResultSetBase::getPropertySetInfo()
502 throw( uno::RuntimeException
)
504 uno::Sequence
< beans::Property
> seq(2);
505 seq
[0].Name
= rtl::OUString("RowCount");
507 seq
[0].Type
= getCppuType( static_cast< sal_Int32
* >(0) );
508 seq
[0].Attributes
= beans::PropertyAttribute::READONLY
;
510 seq
[1].Name
= rtl::OUString("IsRowCountFinal");
512 seq
[1].Type
= getCppuType( static_cast< sal_Bool
* >(0) );
513 seq
[1].Attributes
= beans::PropertyAttribute::READONLY
;
516 return uno::Reference
< beans::XPropertySetInfo
> (
517 new XPropertySetInfoImpl( seq
) );
522 void SAL_CALL
ResultSetBase::setPropertyValue(
523 const rtl::OUString
& aPropertyName
, const uno::Any
& /*aValue*/ )
524 throw( beans::UnknownPropertyException
,
525 beans::PropertyVetoException
,
526 lang::IllegalArgumentException
,
527 lang::WrappedTargetException
,
528 uno::RuntimeException
)
530 if( aPropertyName
== rtl::OUString("IsRowCountFinal") ||
531 aPropertyName
== rtl::OUString("RowCount") )
534 throw beans::UnknownPropertyException();
538 uno::Any SAL_CALL
ResultSetBase::getPropertyValue(
539 const rtl::OUString
& PropertyName
)
540 throw( beans::UnknownPropertyException
,
541 lang::WrappedTargetException
,
542 uno::RuntimeException
)
544 if( PropertyName
== rtl::OUString("IsRowCountFinal") )
547 aAny
<<= m_bRowCountFinal
;
550 else if ( PropertyName
== rtl::OUString("RowCount") )
553 sal_Int32 count
= m_aItems
.size();
558 throw beans::UnknownPropertyException();
562 void SAL_CALL
ResultSetBase::addPropertyChangeListener(
563 const rtl::OUString
& aPropertyName
,
564 const uno::Reference
< beans::XPropertyChangeListener
>& xListener
)
565 throw( beans::UnknownPropertyException
,
566 lang::WrappedTargetException
,
567 uno::RuntimeException
)
569 if( aPropertyName
== rtl::OUString("IsRowCountFinal") )
571 osl::MutexGuard
aGuard( m_aMutex
);
572 if ( ! m_pIsFinalListeners
)
573 m_pIsFinalListeners
=
574 new cppu::OInterfaceContainerHelper( m_aMutex
);
576 m_pIsFinalListeners
->addInterface( xListener
);
578 else if ( aPropertyName
== rtl::OUString("RowCount") )
580 osl::MutexGuard
aGuard( m_aMutex
);
581 if ( ! m_pRowCountListeners
)
582 m_pRowCountListeners
=
583 new cppu::OInterfaceContainerHelper( m_aMutex
);
584 m_pRowCountListeners
->addInterface( xListener
);
587 throw beans::UnknownPropertyException();
591 void SAL_CALL
ResultSetBase::removePropertyChangeListener(
592 const rtl::OUString
& aPropertyName
,
593 const uno::Reference
< beans::XPropertyChangeListener
>& aListener
)
594 throw( beans::UnknownPropertyException
,
595 lang::WrappedTargetException
,
596 uno::RuntimeException
)
598 if( aPropertyName
== rtl::OUString("IsRowCountFinal") &&
599 m_pIsFinalListeners
)
601 osl::MutexGuard
aGuard( m_aMutex
);
602 m_pIsFinalListeners
->removeInterface( aListener
);
604 else if ( aPropertyName
== rtl::OUString("RowCount") &&
605 m_pRowCountListeners
)
607 osl::MutexGuard
aGuard( m_aMutex
);
608 m_pRowCountListeners
->removeInterface( aListener
);
611 throw beans::UnknownPropertyException();
615 void SAL_CALL
ResultSetBase::addVetoableChangeListener(
616 const rtl::OUString
& /*PropertyName*/,
617 const uno::Reference
< beans::XVetoableChangeListener
>& /*aListener*/ )
618 throw( beans::UnknownPropertyException
,
619 lang::WrappedTargetException
,
620 uno::RuntimeException
)
625 void SAL_CALL
ResultSetBase::removeVetoableChangeListener(
626 const rtl::OUString
& /*PropertyName*/,
627 const uno::Reference
< beans::XVetoableChangeListener
>& /*aListener*/ )
628 throw( beans::UnknownPropertyException
,
629 lang::WrappedTargetException
,
630 uno::RuntimeException
)
636 // XResultSetMetaDataSupplier
637 uno::Reference
< sdbc::XResultSetMetaData
> SAL_CALL
638 ResultSetBase::getMetaData(
640 throw( sdbc::SQLException
,
641 uno::RuntimeException
)
643 ::ucbhelper::ResultSetMetaData
* p
=
644 new ::ucbhelper::ResultSetMetaData( m_xContext
, m_sProperty
);
645 return uno::Reference
< sdbc::XResultSetMetaData
>( p
);
651 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */