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
, std::exception
)
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
, std::exception
)
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
, std::exception
)
123 osl::MutexGuard
aGuard( m_aMutex
);
125 if ( m_pDisposeEventListeners
)
126 m_pDisposeEventListeners
->removeInterface( Listener
);
132 ResultSetBase::dispose()
133 throw( uno::RuntimeException
, std::exception
)
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
, std::exception
)
165 if( ++m_nRow
< sal::static_int_cast
<sal_Int32
>(m_aItems
.size()) )
174 ResultSetBase::isBeforeFirst(
176 throw( sdbc::SQLException
,
177 uno::RuntimeException
, std::exception
)
184 ResultSetBase::isAfterLast(
186 throw( sdbc::SQLException
,
187 uno::RuntimeException
, std::exception
)
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
, std::exception
)
204 ResultSetBase::isLast(
206 throw( sdbc::SQLException
,
207 uno::RuntimeException
, std::exception
)
209 if( m_nRow
== sal::static_int_cast
<sal_Int32
>(m_aItems
.size()) - 1 )
217 ResultSetBase::beforeFirst(
219 throw( sdbc::SQLException
,
220 uno::RuntimeException
, std::exception
)
227 ResultSetBase::afterLast(
229 throw( sdbc::SQLException
,
230 uno::RuntimeException
, std::exception
)
232 m_nRow
= m_aItems
.size();
237 ResultSetBase::first(
239 throw( sdbc::SQLException
,
240 uno::RuntimeException
, std::exception
)
250 throw( sdbc::SQLException
,
251 uno::RuntimeException
, std::exception
)
253 m_nRow
= m_aItems
.size() - 1;
259 ResultSetBase::getRow(
261 throw( sdbc::SQLException
,
262 uno::RuntimeException
, std::exception
)
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
, std::exception
)
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
, std::exception
)
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
, std::exception
)
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
, std::exception
)
336 ResultSetBase::rowUpdated(
338 throw( sdbc::SQLException
,
339 uno::RuntimeException
, std::exception
)
345 ResultSetBase::rowInserted(
347 throw( sdbc::SQLException
,
348 uno::RuntimeException
, std::exception
)
354 ResultSetBase::rowDeleted(
356 throw( sdbc::SQLException
,
357 uno::RuntimeException
, std::exception
)
363 uno::Reference
< uno::XInterface
> SAL_CALL
364 ResultSetBase::getStatement(
366 throw( sdbc::SQLException
,
367 uno::RuntimeException
, std::exception
)
369 uno::Reference
< uno::XInterface
> test( 0 );
377 ResultSetBase::close(
379 throw( sdbc::SQLException
,
380 uno::RuntimeException
, std::exception
)
386 ResultSetBase::queryContentIdentifierString(
388 throw( uno::RuntimeException
, std::exception
)
390 if( 0 <= m_nRow
&& m_nRow
< sal::static_int_cast
<sal_Int32
>(m_aItems
.size()) )
391 return m_aPath
[m_nRow
];
397 uno::Reference
< ucb::XContentIdentifier
> SAL_CALL
398 ResultSetBase::queryContentIdentifier(
402 uno::RuntimeException
, std::exception
405 if( 0 <= m_nRow
&& m_nRow
< sal::static_int_cast
<sal_Int32
>(m_aItems
.size()) )
407 if(!m_aIdents
[m_nRow
].is()) {
408 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
, std::exception
)
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()
448 OWeakObject::acquire();
452 void SAL_CALL
release()
455 OWeakObject::release();
458 uno::Any SAL_CALL
queryInterface( const uno::Type
& rType
)
459 throw( uno::RuntimeException
, std::exception
) SAL_OVERRIDE
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
, std::exception
) SAL_OVERRIDE
473 beans::Property SAL_CALL
getPropertyByName( const OUString
& aName
)
474 throw( beans::UnknownPropertyException
,
475 uno::RuntimeException
, std::exception
) SAL_OVERRIDE
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 OUString
& Name
)
484 throw( uno::RuntimeException
, std::exception
) SAL_OVERRIDE
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
, std::exception
)
504 uno::Sequence
< beans::Property
> seq(2);
505 seq
[0].Name
= "RowCount";
507 seq
[0].Type
= cppu::UnoType
<sal_Int32
>::get();
508 seq
[0].Attributes
= beans::PropertyAttribute::READONLY
;
510 seq
[1].Name
= "IsRowCountFinal";
512 seq
[1].Type
= cppu::UnoType
<sal_Bool
>::get();
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 OUString
& aPropertyName
, const uno::Any
& /*aValue*/ )
524 throw( beans::UnknownPropertyException
,
525 beans::PropertyVetoException
,
526 lang::IllegalArgumentException
,
527 lang::WrappedTargetException
,
528 uno::RuntimeException
, std::exception
)
530 if( aPropertyName
== "IsRowCountFinal" ||
531 aPropertyName
== "RowCount" )
534 throw beans::UnknownPropertyException();
538 uno::Any SAL_CALL
ResultSetBase::getPropertyValue(
539 const OUString
& PropertyName
)
540 throw( beans::UnknownPropertyException
,
541 lang::WrappedTargetException
,
542 uno::RuntimeException
, std::exception
)
544 if( PropertyName
== "IsRowCountFinal" )
547 aAny
<<= m_bRowCountFinal
;
550 else if ( PropertyName
== "RowCount" )
553 sal_Int32 count
= m_aItems
.size();
558 throw beans::UnknownPropertyException();
562 void SAL_CALL
ResultSetBase::addPropertyChangeListener(
563 const OUString
& aPropertyName
,
564 const uno::Reference
< beans::XPropertyChangeListener
>& xListener
)
565 throw( beans::UnknownPropertyException
,
566 lang::WrappedTargetException
,
567 uno::RuntimeException
, std::exception
)
569 if( aPropertyName
== "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
== "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 OUString
& aPropertyName
,
593 const uno::Reference
< beans::XPropertyChangeListener
>& aListener
)
594 throw( beans::UnknownPropertyException
,
595 lang::WrappedTargetException
,
596 uno::RuntimeException
, std::exception
)
598 if( aPropertyName
== "IsRowCountFinal" &&
599 m_pIsFinalListeners
)
601 osl::MutexGuard
aGuard( m_aMutex
);
602 m_pIsFinalListeners
->removeInterface( aListener
);
604 else if ( aPropertyName
== "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 OUString
& /*PropertyName*/,
617 const uno::Reference
< beans::XVetoableChangeListener
>& /*aListener*/ )
618 throw( beans::UnknownPropertyException
,
619 lang::WrappedTargetException
,
620 uno::RuntimeException
, std::exception
)
625 void SAL_CALL
ResultSetBase::removeVetoableChangeListener(
626 const OUString
& /*PropertyName*/,
627 const uno::Reference
< beans::XVetoableChangeListener
>& /*aListener*/ )
628 throw( beans::UnknownPropertyException
,
629 lang::WrappedTargetException
,
630 uno::RuntimeException
, std::exception
)
636 // XResultSetMetaDataSupplier
637 uno::Reference
< sdbc::XResultSetMetaData
> SAL_CALL
638 ResultSetBase::getMetaData(
640 throw( sdbc::SQLException
,
641 uno::RuntimeException
, std::exception
)
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: */