2000-09-18 15:18:56 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2005-09-08 06:42:34 +00:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
2005-09-08 06:42:34 +00:00
|
|
|
* $RCSfile: VCollection.cxx,v $
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
2006-06-20 01:09:50 +00:00
|
|
|
* $Revision: 1.39 $
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
2006-06-20 01:09:50 +00:00
|
|
|
* last change: $Author: hr $ $Date: 2006-06-20 02:09:50 $
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
2005-09-08 06:42:34 +00:00
|
|
|
* The Contents of this file are made available subject to
|
|
|
|
* the terms of GNU Lesser General Public License Version 2.1.
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
|
|
|
*
|
2005-09-08 06:42:34 +00:00
|
|
|
* GNU Lesser General Public License Version 2.1
|
|
|
|
* =============================================
|
|
|
|
* Copyright 2005 by Sun Microsystems, Inc.
|
|
|
|
* 901 San Antonio Road, Palo Alto, CA 94303, USA
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
2005-09-08 06:42:34 +00:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License version 2.1, as published by the Free Software Foundation.
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
2005-09-08 06:42:34 +00:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
2005-09-08 06:42:34 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
|
|
* MA 02111-1307 USA
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
|
|
|
************************************************************************/
|
2000-11-29 11:28:04 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2000-09-18 15:18:56 +00:00
|
|
|
#ifndef _CONNECTIVITY_SDBCX_COLLECTION_HXX_
|
|
|
|
#include "connectivity/sdbcx/VCollection.hxx"
|
|
|
|
#endif
|
2000-11-03 12:36:27 +00:00
|
|
|
#ifndef _CONNECTIVITY_SDBCX_DESCRIPTOR_HXX_
|
|
|
|
#include "connectivity/sdbcx/VDescriptor.hxx"
|
|
|
|
#endif
|
2000-10-19 10:47:14 +00:00
|
|
|
#ifndef _COMPHELPER_ENUMHELPER_HXX_
|
|
|
|
#include <comphelper/enumhelper.hxx>
|
2000-09-18 15:18:56 +00:00
|
|
|
#endif
|
2000-10-09 11:09:06 +00:00
|
|
|
#ifndef _COMPHELPER_CONTAINER_HXX_
|
|
|
|
#include <comphelper/container.hxx>
|
|
|
|
#endif
|
2001-03-12 12:51:27 +00:00
|
|
|
#ifndef _COMPHELPER_TYPES_HXX_
|
|
|
|
#include <comphelper/types.hxx>
|
|
|
|
#endif
|
2001-05-14 10:42:44 +00:00
|
|
|
#ifndef CONNECTIVITY_CONNECTION_HXX
|
|
|
|
#include "TConnection.hxx"
|
2001-03-30 13:01:50 +00:00
|
|
|
#endif
|
2000-09-18 15:18:56 +00:00
|
|
|
|
|
|
|
using namespace connectivity::sdbcx;
|
|
|
|
using namespace connectivity;
|
2000-10-19 10:47:14 +00:00
|
|
|
using namespace comphelper;
|
2001-02-23 13:55:44 +00:00
|
|
|
using namespace ::cppu;
|
2000-09-18 15:18:56 +00:00
|
|
|
using namespace ::com::sun::star::beans;
|
|
|
|
using namespace ::com::sun::star::uno;
|
|
|
|
using namespace ::com::sun::star::lang;
|
|
|
|
using namespace ::com::sun::star::sdbc;
|
|
|
|
using namespace ::com::sun::star::container;
|
|
|
|
using namespace ::com::sun::star::util;
|
|
|
|
|
2004-08-02 16:17:12 +00:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
template < typename T> class OHardRefMap : public connectivity::sdbcx::IObjectCollection
|
|
|
|
{
|
|
|
|
typedef ::std::multimap< ::rtl::OUString, T , ::comphelper::UStringMixLess> ObjectMap;
|
2004-08-23 07:08:50 +00:00
|
|
|
typedef typename ObjectMap::iterator ObjectIter;
|
|
|
|
typedef typename ObjectMap::value_type ObjectEntry;
|
2004-08-02 16:17:12 +00:00
|
|
|
|
|
|
|
// private:
|
|
|
|
// this combination of map and vector is used to have a fast name and index access
|
|
|
|
::std::vector< ObjectIter > m_aElements; // hold the iterators which point to map
|
|
|
|
ObjectMap m_aNameMap; // hold the elements and a name
|
|
|
|
public:
|
|
|
|
OHardRefMap(sal_Bool _bCase)
|
|
|
|
: m_aNameMap(_bCase ? true : false)
|
|
|
|
{
|
|
|
|
}
|
2006-06-20 01:09:50 +00:00
|
|
|
virtual ~OHardRefMap()
|
|
|
|
{
|
|
|
|
}
|
2004-08-02 16:17:12 +00:00
|
|
|
|
|
|
|
virtual void reserve(size_t nLength)
|
|
|
|
{
|
|
|
|
m_aElements.reserve(nLength);
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
virtual bool exists(const ::rtl::OUString& _sName )
|
|
|
|
{
|
|
|
|
return m_aNameMap.find(_sName) != m_aNameMap.end();
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
virtual bool empty()
|
|
|
|
{
|
|
|
|
return m_aNameMap.empty();
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
virtual void swapAll()
|
|
|
|
{
|
|
|
|
::std::vector< ObjectIter >(m_aElements).swap(m_aElements);
|
|
|
|
ObjectMap(m_aNameMap).swap(m_aNameMap);
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
virtual void swap()
|
|
|
|
{
|
|
|
|
::std::vector< ObjectIter >().swap(m_aElements);
|
|
|
|
|
|
|
|
OSL_ENSURE( m_aNameMap.empty(), "swap: what did disposeElements do?" );
|
|
|
|
ObjectMap( m_aNameMap ).swap( m_aNameMap );
|
|
|
|
// Note that it's /important/ to construct the new ObjectMap from m_aNameMap before
|
|
|
|
// swapping. This way, it's ensured that the compare object held by these maps is preserved
|
|
|
|
// during the swap. If we would not do this, the UStringMixLess instance which is used would be
|
|
|
|
// default constructed (instead of being constructed from the same instance in m_aNameMap), and
|
|
|
|
// it's case-sensitive flag would have an unpredictable value.
|
|
|
|
// 2002-01-09 - #106589# - fs@openoffice.org
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
virtual void clear()
|
|
|
|
{
|
|
|
|
m_aElements.clear();
|
|
|
|
m_aNameMap.clear();
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
2005-03-10 14:41:57 +00:00
|
|
|
virtual void insert(const ::rtl::OUString& _sName,const ObjectType& _xObject)
|
2004-08-02 16:17:12 +00:00
|
|
|
{
|
2004-08-23 07:08:50 +00:00
|
|
|
m_aElements.push_back(m_aNameMap.insert(m_aNameMap.begin(), ObjectEntry(_sName,_xObject)));
|
2004-08-02 16:17:12 +00:00
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
virtual void reFill(const TStringVector &_rVector)
|
|
|
|
{
|
|
|
|
OSL_ENSURE(!m_aNameMap.size(),"OCollection::reFill: collection isn't empty");
|
|
|
|
m_aElements.reserve(_rVector.size());
|
|
|
|
|
|
|
|
for(TStringVector::const_iterator i=_rVector.begin(); i != _rVector.end();++i)
|
2005-03-10 14:41:57 +00:00
|
|
|
m_aElements.push_back(m_aNameMap.insert(m_aNameMap.begin(), ObjectEntry(*i,ObjectType())));
|
2004-08-02 16:17:12 +00:00
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
virtual bool rename(const ::rtl::OUString _sOldName,const ::rtl::OUString _sNewName)
|
|
|
|
{
|
|
|
|
bool bRet = false;
|
2004-08-23 07:08:50 +00:00
|
|
|
ObjectIter aIter = m_aNameMap.find(_sOldName);
|
2004-08-02 16:17:12 +00:00
|
|
|
if ( aIter != m_aNameMap.end() )
|
|
|
|
{
|
2004-08-23 07:08:50 +00:00
|
|
|
typename ::std::vector< ObjectIter >::iterator aFind = ::std::find(m_aElements.begin(),m_aElements.end(),aIter);
|
2004-08-02 16:17:12 +00:00
|
|
|
if(m_aElements.end() != aFind)
|
|
|
|
{
|
2004-08-23 07:08:50 +00:00
|
|
|
(*aFind) = m_aNameMap.insert(m_aNameMap.begin(), ObjectEntry(_sNewName,(*aFind)->second));
|
2004-08-02 16:17:12 +00:00
|
|
|
m_aNameMap.erase(aIter);
|
|
|
|
|
|
|
|
bRet = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return bRet;
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
virtual sal_Int32 size()
|
|
|
|
{
|
|
|
|
return static_cast<sal_Int32>(m_aNameMap.size());
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
virtual Sequence< ::rtl::OUString > getElementNames()
|
|
|
|
{
|
2006-04-19 12:17:12 +00:00
|
|
|
Sequence< ::rtl::OUString > aNameList(m_aElements.size());
|
2004-08-02 16:17:12 +00:00
|
|
|
|
|
|
|
::rtl::OUString* pStringArray = aNameList.getArray();
|
2006-04-19 12:17:12 +00:00
|
|
|
typename ::std::vector< ObjectIter >::const_iterator aEnd = m_aElements.end();
|
|
|
|
for(typename ::std::vector< ObjectIter >::const_iterator aIter = m_aElements.begin(); aIter != aEnd;++aIter,++pStringArray)
|
2004-08-02 16:17:12 +00:00
|
|
|
*pStringArray = (*aIter)->first;
|
|
|
|
|
|
|
|
return aNameList;
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
virtual ::rtl::OUString getName(sal_Int32 _nIndex)
|
|
|
|
{
|
|
|
|
return m_aElements[_nIndex]->first;
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
virtual void disposeAndErase(sal_Int32 _nIndex)
|
|
|
|
{
|
|
|
|
OSL_ENSURE(_nIndex >= 0 && _nIndex < static_cast<sal_Int32>(m_aElements.size()),"Illegal argument!");
|
|
|
|
Reference<XComponent> xComp(m_aElements[_nIndex]->second.get(),UNO_QUERY);
|
|
|
|
::comphelper::disposeComponent(xComp);
|
|
|
|
m_aElements[_nIndex]->second = T();
|
|
|
|
|
|
|
|
::rtl::OUString sName = m_aElements[_nIndex]->first;
|
|
|
|
m_aElements.erase(m_aElements.begin()+_nIndex);
|
|
|
|
m_aNameMap.erase(sName);
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
virtual void disposeElements()
|
|
|
|
{
|
|
|
|
for( ObjectIter aIter = m_aNameMap.begin(); aIter != m_aNameMap.end(); ++aIter)
|
|
|
|
{
|
|
|
|
Reference<XComponent> xComp(aIter->second.get(),UNO_QUERY);
|
|
|
|
if ( xComp.is() )
|
|
|
|
{
|
|
|
|
::comphelper::disposeComponent(xComp);
|
|
|
|
(*aIter).second = T();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m_aElements.clear();
|
|
|
|
m_aNameMap.clear();
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
virtual sal_Int32 findColumn( const ::rtl::OUString& columnName )
|
|
|
|
{
|
|
|
|
ObjectIter aIter = m_aNameMap.find(columnName);
|
|
|
|
OSL_ENSURE(aIter != m_aNameMap.end(),"findColumn:: Illegal name!");
|
|
|
|
return m_aElements.size() - (m_aElements.end() - ::std::find(m_aElements.begin(),m_aElements.end(),aIter));
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
virtual ::rtl::OUString findColumnAtIndex( sal_Int32 _nIndex)
|
|
|
|
{
|
|
|
|
OSL_ENSURE(_nIndex >= 0 && _nIndex < static_cast<sal_Int32>(m_aElements.size()),"Illegal argument!");
|
|
|
|
return m_aElements[_nIndex]->first;
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
2005-03-10 14:41:57 +00:00
|
|
|
virtual ObjectType getObject(sal_Int32 _nIndex)
|
2004-08-02 16:17:12 +00:00
|
|
|
{
|
|
|
|
OSL_ENSURE(_nIndex >= 0 && _nIndex < static_cast<sal_Int32>(m_aElements.size()),"Illegal argument!");
|
|
|
|
return m_aElements[_nIndex]->second;
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
2005-03-10 14:41:57 +00:00
|
|
|
virtual ObjectType getObject(const ::rtl::OUString& columnName)
|
2004-08-02 16:17:12 +00:00
|
|
|
{
|
|
|
|
return m_aNameMap.find(columnName)->second;
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
2005-03-10 14:41:57 +00:00
|
|
|
virtual void setObject(sal_Int32 _nIndex,const ObjectType& _xObject)
|
2004-08-02 16:17:12 +00:00
|
|
|
{
|
|
|
|
OSL_ENSURE(_nIndex >= 0 && _nIndex < static_cast<sal_Int32>(m_aElements.size()),"Illegal argument!");
|
|
|
|
m_aElements[_nIndex]->second = _xObject;
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
sal_Bool isCaseSensitive() const
|
|
|
|
{
|
|
|
|
return m_aNameMap.key_comp().isCaseSensitive();
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
};
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
2000-09-18 15:18:56 +00:00
|
|
|
IMPLEMENT_SERVICE_INFO(OCollection,"com.sun.star.sdbcx.VContainer" , "com.sun.star.sdbcx.Container")
|
|
|
|
|
2004-08-02 16:17:12 +00:00
|
|
|
OCollection::OCollection(::cppu::OWeakObject& _rParent
|
|
|
|
, sal_Bool _bCase
|
|
|
|
, ::osl::Mutex& _rMutex
|
|
|
|
, const TStringVector &_rVector
|
|
|
|
, sal_Bool _bUseIndexOnly
|
|
|
|
, sal_Bool _bUseHardRef)
|
2006-06-20 01:09:50 +00:00
|
|
|
:m_aContainerListeners(_rMutex)
|
2000-10-17 07:36:20 +00:00
|
|
|
,m_aRefreshListeners(_rMutex)
|
2006-06-20 01:09:50 +00:00
|
|
|
,m_rParent(_rParent)
|
|
|
|
,m_rMutex(_rMutex)
|
2002-05-10 06:38:26 +00:00
|
|
|
,m_bUseIndexOnly(_bUseIndexOnly)
|
2000-10-17 07:36:20 +00:00
|
|
|
{
|
2004-08-02 16:17:12 +00:00
|
|
|
if ( _bUseHardRef )
|
|
|
|
{
|
2005-03-10 14:41:57 +00:00
|
|
|
m_pElements.reset(new OHardRefMap< ObjectType >(_bCase));
|
2004-08-02 16:17:12 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-03-10 14:41:57 +00:00
|
|
|
m_pElements.reset(new OHardRefMap< WeakReference< XPropertySet> >(_bCase));
|
2004-08-02 16:17:12 +00:00
|
|
|
}
|
|
|
|
m_pElements->reFill(_rVector);
|
2000-10-17 07:36:20 +00:00
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
OCollection::~OCollection()
|
|
|
|
{
|
|
|
|
}
|
2002-05-10 06:38:26 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
Any SAL_CALL OCollection::queryInterface( const Type & rType ) throw (RuntimeException)
|
|
|
|
{
|
|
|
|
if ( m_bUseIndexOnly && rType == ::getCppuType(static_cast< Reference< XNameAccess > *> (NULL)) )
|
|
|
|
{
|
|
|
|
return Any();
|
|
|
|
}
|
|
|
|
return OCollectionBase::queryInterface( rType );
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
Sequence< Type > SAL_CALL OCollection::getTypes() throw (RuntimeException)
|
|
|
|
{
|
|
|
|
if ( m_bUseIndexOnly )
|
|
|
|
{
|
|
|
|
Sequence< Type > aTypes(OCollectionBase::getTypes());
|
|
|
|
Type* pBegin = aTypes.getArray();
|
|
|
|
Type* pEnd = pBegin + aTypes.getLength();
|
2000-11-07 16:15:48 +00:00
|
|
|
|
2002-05-10 06:51:26 +00:00
|
|
|
::std::vector<Type> aOwnTypes;
|
|
|
|
aOwnTypes.reserve(aTypes.getLength());
|
2002-05-10 06:38:26 +00:00
|
|
|
Type aType = ::getCppuType(static_cast< Reference<XNameAccess> *>(NULL));
|
|
|
|
for(;pBegin != pEnd; ++pBegin)
|
|
|
|
{
|
|
|
|
if ( *pBegin != aType )
|
2002-05-10 06:51:26 +00:00
|
|
|
aOwnTypes.push_back(*pBegin);
|
2002-05-10 06:38:26 +00:00
|
|
|
}
|
2004-09-08 15:22:59 +00:00
|
|
|
Type* pTypes = aOwnTypes.empty() ? 0 : &aOwnTypes[0];
|
|
|
|
return Sequence< Type >(pTypes,aOwnTypes.size());
|
2002-05-10 06:38:26 +00:00
|
|
|
}
|
|
|
|
return OCollectionBase::getTypes( );
|
|
|
|
}
|
2000-11-07 16:15:48 +00:00
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
void OCollection::clear_NoDispose()
|
|
|
|
{
|
|
|
|
::osl::MutexGuard aGuard(m_rMutex);
|
2001-08-02 06:58:25 +00:00
|
|
|
|
2004-08-02 16:17:12 +00:00
|
|
|
m_pElements->clear();
|
|
|
|
m_pElements->swapAll();
|
2000-11-07 16:15:48 +00:00
|
|
|
}
|
|
|
|
|
2000-09-18 15:18:56 +00:00
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
void OCollection::disposing(void)
|
|
|
|
{
|
2004-10-22 07:46:17 +00:00
|
|
|
m_aContainerListeners.disposeAndClear(EventObject(static_cast<XTypeProvider*>(this)));
|
|
|
|
m_aRefreshListeners.disposeAndClear(EventObject(static_cast<XTypeProvider*>(this)));
|
2000-09-18 15:18:56 +00:00
|
|
|
|
|
|
|
::osl::MutexGuard aGuard(m_rMutex);
|
2001-10-12 11:02:56 +00:00
|
|
|
|
|
|
|
disposeElements();
|
|
|
|
|
2004-08-02 16:17:12 +00:00
|
|
|
m_pElements->swap();
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
Any SAL_CALL OCollection::getByIndex( sal_Int32 Index ) throw(IndexOutOfBoundsException, WrappedTargetException, RuntimeException)
|
|
|
|
{
|
|
|
|
::osl::MutexGuard aGuard(m_rMutex);
|
2004-08-02 16:17:12 +00:00
|
|
|
if (Index < 0 || Index >= m_pElements->size() )
|
2004-10-22 07:46:17 +00:00
|
|
|
throw IndexOutOfBoundsException(::rtl::OUString::valueOf(Index),static_cast<XTypeProvider*>(this));
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2004-08-02 16:17:12 +00:00
|
|
|
return makeAny(getObject(Index));
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
Any SAL_CALL OCollection::getByName( const ::rtl::OUString& aName ) throw(NoSuchElementException, WrappedTargetException, RuntimeException)
|
|
|
|
{
|
|
|
|
::osl::MutexGuard aGuard(m_rMutex);
|
|
|
|
|
2004-08-02 16:17:12 +00:00
|
|
|
if ( !m_pElements->exists(aName) )
|
2004-10-22 07:46:17 +00:00
|
|
|
throw NoSuchElementException(aName,static_cast<XTypeProvider*>(this));
|
2004-08-02 16:17:12 +00:00
|
|
|
|
|
|
|
return makeAny(getObject(m_pElements->findColumn(aName)));
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
Sequence< ::rtl::OUString > SAL_CALL OCollection::getElementNames( ) throw(RuntimeException)
|
|
|
|
{
|
|
|
|
::osl::MutexGuard aGuard(m_rMutex);
|
2004-08-02 16:17:12 +00:00
|
|
|
return m_pElements->getElementNames();
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
void SAL_CALL OCollection::refresh( ) throw(RuntimeException)
|
|
|
|
{
|
|
|
|
::osl::MutexGuard aGuard(m_rMutex);
|
2001-10-12 11:02:56 +00:00
|
|
|
|
|
|
|
disposeElements();
|
2000-09-18 15:18:56 +00:00
|
|
|
|
|
|
|
impl_refresh();
|
2004-10-22 07:46:17 +00:00
|
|
|
EventObject aEvt(static_cast<XTypeProvider*>(this));
|
2006-06-20 01:09:50 +00:00
|
|
|
m_aRefreshListeners.notifyEach( &XRefreshListener::refreshed, aEvt );
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
2001-04-23 09:07:41 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
2001-05-02 11:57:37 +00:00
|
|
|
void OCollection::reFill(const TStringVector &_rVector)
|
2001-04-23 09:07:41 +00:00
|
|
|
{
|
2004-08-02 16:17:12 +00:00
|
|
|
m_pElements->reFill(_rVector);
|
2001-04-23 09:07:41 +00:00
|
|
|
}
|
2000-09-18 15:18:56 +00:00
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
// XDataDescriptorFactory
|
|
|
|
Reference< XPropertySet > SAL_CALL OCollection::createDataDescriptor( ) throw(RuntimeException)
|
|
|
|
{
|
|
|
|
::osl::MutexGuard aGuard(m_rMutex);
|
|
|
|
|
|
|
|
return createEmptyObject();
|
|
|
|
}
|
2005-03-10 14:41:57 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
::rtl::OUString OCollection::getNameForObject(const ObjectType& _xObject)
|
|
|
|
{
|
|
|
|
OSL_ENSURE(_xObject.is(),"OCollection::getNameForObject: Object is NULL!");
|
|
|
|
::rtl::OUString sName;
|
|
|
|
_xObject->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME)) >>= sName;
|
|
|
|
return sName;
|
|
|
|
}
|
2000-09-18 15:18:56 +00:00
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
// XAppend
|
|
|
|
void SAL_CALL OCollection::appendByDescriptor( const Reference< XPropertySet >& descriptor ) throw(SQLException, ElementExistException, RuntimeException)
|
|
|
|
{
|
|
|
|
::osl::MutexGuard aGuard(m_rMutex);
|
|
|
|
|
2005-03-10 14:41:57 +00:00
|
|
|
ObjectType xName(descriptor,UNO_QUERY);
|
2000-09-18 15:18:56 +00:00
|
|
|
if(xName.is())
|
|
|
|
{
|
2005-03-10 14:41:57 +00:00
|
|
|
|
|
|
|
::rtl::OUString sName = getNameForObject(xName);
|
|
|
|
|
2004-08-02 16:17:12 +00:00
|
|
|
if ( m_pElements->exists(sName) )
|
2004-10-22 07:46:17 +00:00
|
|
|
throw ElementExistException(sName,static_cast<XTypeProvider*>(this));
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2001-10-12 11:02:56 +00:00
|
|
|
appendObject(descriptor);
|
2005-03-10 14:41:57 +00:00
|
|
|
ObjectType xNewName = cloneObject(descriptor);
|
2006-06-20 01:09:50 +00:00
|
|
|
|
|
|
|
ODescriptor* pDescriptor = ODescriptor::getImplementation( xNewName );
|
|
|
|
if ( pDescriptor )
|
|
|
|
pDescriptor->setNew( sal_False );
|
2001-10-12 11:02:56 +00:00
|
|
|
|
2001-11-09 05:13:56 +00:00
|
|
|
if(xNewName.is())
|
2001-10-30 07:32:16 +00:00
|
|
|
{
|
2005-03-10 14:41:57 +00:00
|
|
|
sName = getNameForObject(xNewName);
|
2004-08-02 16:17:12 +00:00
|
|
|
if ( !m_pElements->exists(sName) ) // this may happen when the drived class included it itself
|
|
|
|
m_pElements->insert(sName,xNewName);
|
2001-11-09 05:13:56 +00:00
|
|
|
// notify our container listeners
|
|
|
|
ContainerEvent aEvent(static_cast<XContainer*>(this), makeAny(sName), makeAny(xNewName), Any());
|
|
|
|
OInterfaceIteratorHelper aListenerLoop(m_aContainerListeners);
|
|
|
|
while (aListenerLoop.hasMoreElements())
|
|
|
|
static_cast<XContainerListener*>(aListenerLoop.next())->elementInserted(aEvent);
|
2001-10-30 07:32:16 +00:00
|
|
|
}
|
2001-11-09 05:13:56 +00:00
|
|
|
else
|
|
|
|
throw SQLException();
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
// XDrop
|
|
|
|
void SAL_CALL OCollection::dropByName( const ::rtl::OUString& elementName ) throw(SQLException, NoSuchElementException, RuntimeException)
|
|
|
|
{
|
|
|
|
::osl::MutexGuard aGuard(m_rMutex);
|
|
|
|
|
2004-08-02 16:17:12 +00:00
|
|
|
if ( !m_pElements->exists(elementName) )
|
2004-10-22 07:46:17 +00:00
|
|
|
throw NoSuchElementException(elementName,static_cast<XTypeProvider*>(this));
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2004-08-02 16:17:12 +00:00
|
|
|
dropImpl(m_pElements->findColumn(elementName));
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
void SAL_CALL OCollection::dropByIndex( sal_Int32 index ) throw(SQLException, IndexOutOfBoundsException, RuntimeException)
|
|
|
|
{
|
|
|
|
::osl::MutexGuard aGuard(m_rMutex);
|
2001-03-30 13:01:50 +00:00
|
|
|
if(index <0 || index >= getCount())
|
2004-10-22 07:46:17 +00:00
|
|
|
throw IndexOutOfBoundsException(::rtl::OUString::valueOf(index),static_cast<XTypeProvider*>(this));
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2001-10-12 11:02:56 +00:00
|
|
|
dropImpl(index);
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
2003-08-18 13:47:24 +00:00
|
|
|
void OCollection::dropImpl(sal_Int32 _nIndex,sal_Bool _bReallyDrop)
|
2001-10-12 11:02:56 +00:00
|
|
|
{
|
2004-08-02 16:17:12 +00:00
|
|
|
::rtl::OUString elementName = m_pElements->getName(_nIndex);
|
2001-10-12 11:02:56 +00:00
|
|
|
|
2003-08-18 13:47:24 +00:00
|
|
|
if ( _bReallyDrop )
|
|
|
|
dropObject(_nIndex,elementName);
|
2001-10-12 11:02:56 +00:00
|
|
|
|
2004-08-02 16:17:12 +00:00
|
|
|
m_pElements->disposeAndErase(_nIndex);
|
2001-08-02 06:58:25 +00:00
|
|
|
|
2001-02-23 13:55:44 +00:00
|
|
|
// notify our container listeners
|
2001-10-12 11:02:56 +00:00
|
|
|
notifyElementRemoved(elementName);
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
void OCollection::notifyElementRemoved(const ::rtl::OUString& _sName)
|
|
|
|
{
|
|
|
|
ContainerEvent aEvent(static_cast<XContainer*>(this), makeAny(_sName), Any(), Any());
|
2001-09-25 12:12:51 +00:00
|
|
|
// note that xExistent may be empty, in case somebody removed the data source while it is not alive at this moment
|
2001-02-23 13:55:44 +00:00
|
|
|
OInterfaceIteratorHelper aListenerLoop(m_aContainerListeners);
|
|
|
|
while (aListenerLoop.hasMoreElements())
|
|
|
|
static_cast<XContainerListener*>(aListenerLoop.next())->elementRemoved(aEvent);
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
2001-08-02 06:58:25 +00:00
|
|
|
sal_Int32 SAL_CALL OCollection::findColumn( const ::rtl::OUString& columnName ) throw(SQLException, RuntimeException)
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2004-08-02 16:17:12 +00:00
|
|
|
if ( !m_pElements->exists(columnName) )
|
2004-10-22 07:46:17 +00:00
|
|
|
throw SQLException(::rtl::OUString::createFromAscii("Unknown column name!"),static_cast<XTypeProvider*>(this),OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_HY0000),1000,makeAny(NoSuchElementException(columnName,static_cast<XTypeProvider*>(this))) );
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2004-08-02 16:17:12 +00:00
|
|
|
return m_pElements->findColumn(columnName) + 1; // because columns start at one
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
Reference< XEnumeration > SAL_CALL OCollection::createEnumeration( ) throw(RuntimeException)
|
|
|
|
{
|
|
|
|
::osl::MutexGuard aGuard(m_rMutex);
|
2000-10-19 10:47:14 +00:00
|
|
|
return new OEnumerationByIndex( static_cast< XIndexAccess*>(this));
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
2001-02-23 13:55:44 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
void SAL_CALL OCollection::addContainerListener( const Reference< XContainerListener >& _rxListener ) throw(RuntimeException)
|
|
|
|
{
|
|
|
|
m_aContainerListeners.addInterface(_rxListener);
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void SAL_CALL OCollection::removeContainerListener( const Reference< XContainerListener >& _rxListener ) throw(RuntimeException)
|
|
|
|
{
|
|
|
|
m_aContainerListeners.removeInterface(_rxListener);
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
2001-10-16 17:14:25 +00:00
|
|
|
void SAL_CALL OCollection::acquire() throw()
|
2001-04-30 08:59:56 +00:00
|
|
|
{
|
|
|
|
m_rParent.acquire();
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
2001-10-16 17:14:25 +00:00
|
|
|
void SAL_CALL OCollection::release() throw()
|
2001-04-30 08:59:56 +00:00
|
|
|
{
|
|
|
|
m_rParent.release();
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
2001-08-02 06:58:25 +00:00
|
|
|
Type SAL_CALL OCollection::getElementType( ) throw(RuntimeException)
|
2001-04-30 08:59:56 +00:00
|
|
|
{
|
2001-08-02 06:58:25 +00:00
|
|
|
return::getCppuType(static_cast< Reference< XPropertySet>*>(NULL));
|
2001-04-30 08:59:56 +00:00
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
2001-08-02 06:58:25 +00:00
|
|
|
sal_Bool SAL_CALL OCollection::hasElements( ) throw(RuntimeException)
|
2001-04-30 08:59:56 +00:00
|
|
|
{
|
|
|
|
::osl::MutexGuard aGuard(m_rMutex);
|
2004-08-02 16:17:12 +00:00
|
|
|
return !m_pElements->empty();
|
2001-04-30 08:59:56 +00:00
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
2001-08-02 06:58:25 +00:00
|
|
|
sal_Int32 SAL_CALL OCollection::getCount( ) throw(RuntimeException)
|
2001-04-30 08:59:56 +00:00
|
|
|
{
|
|
|
|
::osl::MutexGuard aGuard(m_rMutex);
|
2004-08-02 16:17:12 +00:00
|
|
|
return m_pElements->size();
|
2001-04-30 08:59:56 +00:00
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
2001-08-02 06:58:25 +00:00
|
|
|
sal_Bool SAL_CALL OCollection::hasByName( const ::rtl::OUString& aName ) throw(RuntimeException)
|
2001-04-30 08:59:56 +00:00
|
|
|
{
|
|
|
|
::osl::MutexGuard aGuard(m_rMutex);
|
2004-08-02 16:17:12 +00:00
|
|
|
return m_pElements->exists(aName);
|
2001-04-30 08:59:56 +00:00
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
2001-08-02 06:58:25 +00:00
|
|
|
void SAL_CALL OCollection::addRefreshListener( const Reference< XRefreshListener >& l ) throw(RuntimeException)
|
2001-04-30 08:59:56 +00:00
|
|
|
{
|
|
|
|
m_aRefreshListeners.addInterface(l);
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
2001-08-02 06:58:25 +00:00
|
|
|
void SAL_CALL OCollection::removeRefreshListener( const Reference< XRefreshListener >& l ) throw(RuntimeException)
|
2001-04-30 08:59:56 +00:00
|
|
|
{
|
|
|
|
m_aRefreshListeners.removeInterface(l);
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
2005-03-10 14:41:57 +00:00
|
|
|
void OCollection::insertElement(const ::rtl::OUString& _sElementName,const ObjectType& _xElement)
|
2001-08-13 13:03:54 +00:00
|
|
|
{
|
2004-08-02 16:17:12 +00:00
|
|
|
OSL_ENSURE(!m_pElements->exists(_sElementName),"Element already exists");
|
|
|
|
if ( !m_pElements->exists(_sElementName) )
|
|
|
|
m_pElements->insert(_sElementName,_xElement);
|
2001-08-13 13:03:54 +00:00
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
2001-09-25 12:12:51 +00:00
|
|
|
void OCollection::renameObject(const ::rtl::OUString _sOldName,const ::rtl::OUString _sNewName)
|
|
|
|
{
|
2004-08-02 16:17:12 +00:00
|
|
|
OSL_ENSURE(m_pElements->exists(_sOldName),"Element doesn't exist");
|
|
|
|
OSL_ENSURE(!m_pElements->exists(_sNewName),"Element already exists");
|
2001-09-25 12:12:51 +00:00
|
|
|
OSL_ENSURE(_sNewName.getLength(),"New name must not be empty!");
|
|
|
|
OSL_ENSURE(_sOldName.getLength(),"New name must not be empty!");
|
|
|
|
|
2004-08-02 16:17:12 +00:00
|
|
|
if ( m_pElements->rename(_sOldName,_sNewName) )
|
2001-09-25 12:12:51 +00:00
|
|
|
{
|
2004-08-02 16:17:12 +00:00
|
|
|
ContainerEvent aEvent(static_cast<XContainer*>(this), makeAny(_sNewName), makeAny(m_pElements->getObject(_sNewName)),makeAny(_sOldName));
|
|
|
|
// note that xExistent may be empty, in case somebody removed the data source while it is not alive at this moment
|
|
|
|
OInterfaceIteratorHelper aListenerLoop(m_aContainerListeners);
|
|
|
|
while (aListenerLoop.hasMoreElements())
|
|
|
|
static_cast<XContainerListener*>(aListenerLoop.next())->elementReplaced(aEvent);
|
2001-09-25 12:12:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
2005-03-10 14:41:57 +00:00
|
|
|
ObjectType OCollection::getObject(sal_Int32 _nIndex)
|
2001-10-12 11:02:56 +00:00
|
|
|
{
|
2005-03-10 14:41:57 +00:00
|
|
|
ObjectType xName = m_pElements->getObject(_nIndex);
|
2004-08-02 16:17:12 +00:00
|
|
|
if ( !xName.is() )
|
2001-10-12 11:02:56 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2004-08-02 16:17:12 +00:00
|
|
|
xName = createObject(m_pElements->getName(_nIndex));
|
2001-10-12 11:02:56 +00:00
|
|
|
}
|
|
|
|
catch(const SQLException& e)
|
|
|
|
{
|
2003-08-18 13:47:24 +00:00
|
|
|
try
|
|
|
|
{
|
2004-08-02 16:17:12 +00:00
|
|
|
dropImpl(_nIndex,sal_False);
|
2003-08-18 13:47:24 +00:00
|
|
|
}
|
|
|
|
catch(const Exception& )
|
|
|
|
{
|
|
|
|
}
|
2004-10-22 07:46:17 +00:00
|
|
|
throw WrappedTargetException(e.Message,static_cast<XTypeProvider*>(this),makeAny(e));
|
2001-10-12 11:02:56 +00:00
|
|
|
}
|
2004-08-02 16:17:12 +00:00
|
|
|
m_pElements->setObject(_nIndex,xName);
|
2001-10-12 11:02:56 +00:00
|
|
|
}
|
|
|
|
return xName;
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
void OCollection::disposeElements()
|
|
|
|
{
|
2004-08-02 16:17:12 +00:00
|
|
|
m_pElements->disposeElements();
|
2001-10-12 11:02:56 +00:00
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
Reference< XPropertySet > OCollection::createEmptyObject()
|
|
|
|
{
|
|
|
|
OSL_ASSERT(!"Need to be overloaded when used!");
|
|
|
|
throw SQLException();
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
2006-06-20 01:09:50 +00:00
|
|
|
void OCollection::appendObject( const Reference< XPropertySet >& /*descriptor*/ )
|
2001-10-12 11:02:56 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
2005-03-10 14:41:57 +00:00
|
|
|
ObjectType OCollection::cloneObject(const Reference< XPropertySet >& _xDescriptor)
|
2001-10-12 11:02:56 +00:00
|
|
|
{
|
2005-03-10 14:41:57 +00:00
|
|
|
return _xDescriptor.is() ? createObject(getNameForObject(_xDescriptor)) : sdbcx::ObjectType();
|
2001-10-12 11:02:56 +00:00
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
2006-06-20 01:09:50 +00:00
|
|
|
void OCollection::dropObject(sal_Int32 /*_nPos*/,const ::rtl::OUString /*_sElementName*/)
|
2001-10-12 11:02:56 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|