diff options
Diffstat (limited to '')
-rw-r--r-- | connectivity/source/sdbcx/VCatalog.cxx | 211 | ||||
-rw-r--r-- | connectivity/source/sdbcx/VCollection.cxx | 583 | ||||
-rw-r--r-- | connectivity/source/sdbcx/VColumn.cxx | 220 | ||||
-rw-r--r-- | connectivity/source/sdbcx/VDescriptor.cxx | 128 | ||||
-rw-r--r-- | connectivity/source/sdbcx/VGroup.cxx | 166 | ||||
-rw-r--r-- | connectivity/source/sdbcx/VIndex.cxx | 199 | ||||
-rw-r--r-- | connectivity/source/sdbcx/VIndexColumn.cxx | 102 | ||||
-rw-r--r-- | connectivity/source/sdbcx/VKey.cxx | 202 | ||||
-rw-r--r-- | connectivity/source/sdbcx/VKeyColumn.cxx | 106 | ||||
-rw-r--r-- | connectivity/source/sdbcx/VTable.cxx | 304 | ||||
-rw-r--r-- | connectivity/source/sdbcx/VUser.cxx | 180 | ||||
-rw-r--r-- | connectivity/source/sdbcx/VView.cxx | 132 |
12 files changed, 2533 insertions, 0 deletions
diff --git a/connectivity/source/sdbcx/VCatalog.cxx b/connectivity/source/sdbcx/VCatalog.cxx new file mode 100644 index 000000000..b30519fca --- /dev/null +++ b/connectivity/source/sdbcx/VCatalog.cxx @@ -0,0 +1,211 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <comphelper/types.hxx> +#include <sdbcx/VCatalog.hxx> +#include <connectivity/sdbcx/VCollection.hxx> +#include <com/sun/star/sdbc/XRow.hpp> +#include <connectivity/sdbcx/VDescriptor.hxx> +#include <com/sun/star/beans/PropertyAttribute.hpp> +#include <TConnection.hxx> +#include <connectivity/dbtools.hxx> + +using namespace connectivity; +using namespace connectivity::sdbcx; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::sdbc; +using namespace ::com::sun::star::sdbcx; +using namespace ::com::sun::star::container; +using namespace ::com::sun::star::lang; + +IMPLEMENT_SERVICE_INFO(OCatalog,"com.sun.star.comp.connectivity.OCatalog","com.sun.star.sdbcx.DatabaseDefinition") + +OCatalog::OCatalog(const Reference< XConnection> &_xConnection) : OCatalog_BASE(m_aMutex) +{ + try + { + m_xMetaData = _xConnection->getMetaData(); + } + catch(const Exception&) + { + OSL_FAIL("No Metadata available!"); + } +} + +OCatalog::~OCatalog() +{ +} + +void SAL_CALL OCatalog::disposing() +{ + ::osl::MutexGuard aGuard(m_aMutex); + + if(m_pTables) + m_pTables->disposing(); + if(m_pViews) + m_pViews->disposing(); + if(m_pGroups) + m_pGroups->disposing(); + if(m_pUsers) + m_pUsers->disposing(); + + OCatalog_BASE::disposing(); +} + +// XTablesSupplier +Reference< XNameAccess > SAL_CALL OCatalog::getTables( ) +{ + ::osl::MutexGuard aGuard(m_aMutex); + checkDisposed(OCatalog_BASE::rBHelper.bDisposed); + + try + { + if(!m_pTables) + refreshTables(); + } + catch( const RuntimeException& ) + { + // allowed to leave this method + throw; + } + catch( const Exception& ) + { + // allowed + } + + return m_pTables.get(); +} + +// XViewsSupplier +Reference< XNameAccess > SAL_CALL OCatalog::getViews( ) +{ + ::osl::MutexGuard aGuard(m_aMutex); + checkDisposed(OCatalog_BASE::rBHelper.bDisposed); + + try + { + if(!m_pViews) + refreshViews(); + } + catch( const RuntimeException& ) + { + // allowed to leave this method + throw; + } + catch( const Exception& ) + { + // allowed + } + + return m_pViews.get(); +} + +// XUsersSupplier +Reference< XNameAccess > SAL_CALL OCatalog::getUsers( ) +{ + ::osl::MutexGuard aGuard(m_aMutex); + checkDisposed(OCatalog_BASE::rBHelper.bDisposed); + + try + { + if(!m_pUsers) + refreshUsers(); + } + catch( const RuntimeException& ) + { + // allowed to leave this method + throw; + } + catch( const Exception& ) + { + // allowed + } + + return m_pUsers.get(); +} + +// XGroupsSupplier +Reference< XNameAccess > SAL_CALL OCatalog::getGroups( ) +{ + ::osl::MutexGuard aGuard(m_aMutex); + checkDisposed(OCatalog_BASE::rBHelper.bDisposed); + + try + { + if(!m_pGroups) + refreshGroups(); + } + catch( const RuntimeException& ) + { + // allowed to leave this method + throw; + } + catch( const Exception& ) + { + // allowed + } + + return m_pGroups.get(); +} + +OUString OCatalog::buildName(const Reference< XRow >& _xRow) +{ + OUString sCatalog = _xRow->getString(1); + if ( _xRow->wasNull() ) + sCatalog.clear(); + OUString sSchema = _xRow->getString(2); + if ( _xRow->wasNull() ) + sSchema.clear(); + OUString sTable = _xRow->getString(3); + if ( _xRow->wasNull() ) + sTable.clear(); + + OUString sComposedName( + ::dbtools::composeTableName( m_xMetaData, sCatalog, sSchema, sTable, false, ::dbtools::EComposeRule::InDataManipulation ) ); + return sComposedName; +} + +void OCatalog::fillNames(Reference< XResultSet >& _xResult,::std::vector< OUString>& _rNames) +{ + if ( _xResult.is() ) + { + _rNames.reserve(20); + Reference< XRow > xRow(_xResult,UNO_QUERY); + while ( _xResult->next() ) + { + _rNames.push_back( buildName(xRow) ); + } + xRow.clear(); + ::comphelper::disposeComponent(_xResult); + } +} + +void ODescriptor::construct() +{ + sal_Int32 nAttrib = isNew() ? 0 : css::beans::PropertyAttribute::READONLY; + registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME), PROPERTY_ID_NAME ,nAttrib,&m_Name,::cppu::UnoType<OUString>::get()); +} + +ODescriptor::~ODescriptor() +{ +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/sdbcx/VCollection.cxx b/connectivity/source/sdbcx/VCollection.cxx new file mode 100644 index 000000000..d7a716a59 --- /dev/null +++ b/connectivity/source/sdbcx/VCollection.cxx @@ -0,0 +1,583 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + + +#include <algorithm> +#include <com/sun/star/container/ElementExistException.hpp> +#include <com/sun/star/lang/IndexOutOfBoundsException.hpp> +#include <connectivity/sdbcx/VCollection.hxx> +#include <connectivity/sdbcx/VDescriptor.hxx> +#include <com/sun/star/sdbc/SQLException.hpp> +#include <connectivity/dbexception.hxx> +#include <comphelper/enumhelper.hxx> +#include <comphelper/types.hxx> +#include <comphelper/property.hxx> +#include <comphelper/servicehelper.hxx> +#include <cppuhelper/exc_hlp.hxx> +#include <TConnection.hxx> +#include <strings.hrc> +#include <resource/sharedresources.hxx> + +using namespace connectivity::sdbcx; +using namespace connectivity; +using namespace comphelper; +using namespace ::cppu; +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; + +namespace +{ + template < typename T> class OHardRefMap : public connectivity::sdbcx::IObjectCollection + { + typedef std::multimap< OUString, T , ::comphelper::UStringMixLess> ObjectMap; + typedef typename ObjectMap::iterator ObjectIter; + typedef typename ObjectMap::value_type ObjectEntry; + + // 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(bool _bCase) + : m_aNameMap(_bCase) + { + } + + virtual bool exists(const OUString& _sName ) override + { + return m_aNameMap.find(_sName) != m_aNameMap.end(); + } + + virtual bool empty() override + { + return m_aNameMap.empty(); + } + + virtual void swapAll() override + { + std::vector< ObjectIter >(m_aElements).swap(m_aElements); + ObjectMap(m_aNameMap).swap(m_aNameMap); + } + + virtual void swap() override + { + 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. + } + + virtual void clear() override + { + m_aElements.clear(); + m_aNameMap.clear(); + } + + virtual void insert(const OUString& _sName,const ObjectType& _xObject) override + { + m_aElements.push_back(m_aNameMap.insert(m_aNameMap.begin(), ObjectEntry(_sName,_xObject))); + } + + virtual void reFill(const ::std::vector< OUString> &_rVector) override + { + OSL_ENSURE(m_aNameMap.empty(),"OCollection::reFill: collection isn't empty"); + m_aElements.reserve(_rVector.size()); + + for (auto const& elem : _rVector) + m_aElements.push_back(m_aNameMap.insert(m_aNameMap.begin(), ObjectEntry(elem,ObjectType()))); + } + + virtual bool rename(const OUString& _sOldName, const OUString& _sNewName) override + { + bool bRet = false; + ObjectIter aIter = m_aNameMap.find(_sOldName); + if ( aIter != m_aNameMap.end() ) + { + typename std::vector< ObjectIter >::iterator aFind = std::find(m_aElements.begin(),m_aElements.end(),aIter); + if(m_aElements.end() != aFind) + { + (*aFind) = m_aNameMap.insert(m_aNameMap.begin(), ObjectEntry(_sNewName,(*aFind)->second)); + m_aNameMap.erase(aIter); + + bRet = true; + } + } + return bRet; + } + + virtual sal_Int32 size() override + { + return static_cast<sal_Int32>(m_aNameMap.size()); + } + + virtual Sequence< OUString > getElementNames() override + { + Sequence< OUString > aNameList(m_aElements.size()); + + OUString* pStringArray = aNameList.getArray(); + for(const auto& rIter : m_aElements) + { + *pStringArray = rIter->first; + ++pStringArray; + } + + return aNameList; + } + + virtual OUString getName(sal_Int32 _nIndex) override + { + return m_aElements[_nIndex]->first; + } + + virtual void disposeAndErase(sal_Int32 _nIndex) override + { + 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(); + + OUString sName = m_aElements[_nIndex]->first; + m_aElements.erase(m_aElements.begin()+_nIndex); + m_aNameMap.erase(sName); + } + + virtual void disposeElements() override + { + for (auto & name : m_aNameMap) + { + Reference<XComponent> xComp(name.second.get(),UNO_QUERY); + if ( xComp.is() ) + { + ::comphelper::disposeComponent(xComp); + name.second = T(); + } + } + m_aElements.clear(); + m_aNameMap.clear(); + } + + virtual sal_Int32 findColumn( const OUString& columnName ) override + { + 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 ObjectType getObject(sal_Int32 _nIndex) override + { + OSL_ENSURE(_nIndex >= 0 && _nIndex < static_cast<sal_Int32>(m_aElements.size()),"Illegal argument!"); + return m_aElements[_nIndex]->second; + } + + virtual ObjectType getObject(const OUString& columnName) override + { + return m_aNameMap.find(columnName)->second; + } + + virtual void setObject(sal_Int32 _nIndex,const ObjectType& _xObject) override + { + OSL_ENSURE(_nIndex >= 0 && _nIndex < static_cast<sal_Int32>(m_aElements.size()),"Illegal argument!"); + m_aElements[_nIndex]->second = _xObject; + } + + bool isCaseSensitive() const override + { + return m_aNameMap.key_comp().isCaseSensitive(); + } + + }; +} + +IObjectCollection::~IObjectCollection() {} + +IMPLEMENT_SERVICE_INFO(OCollection,"com.sun.star.sdbcx.VContainer" , "com.sun.star.sdbcx.Container") + +OCollection::OCollection(::cppu::OWeakObject& _rParent + , bool _bCase + , ::osl::Mutex& _rMutex + , const ::std::vector< OUString> &_rVector + , bool _bUseIndexOnly + , bool _bUseHardRef) + :m_aContainerListeners(_rMutex) + ,m_aRefreshListeners(_rMutex) + ,m_rParent(_rParent) + ,m_rMutex(_rMutex) + ,m_bUseIndexOnly(_bUseIndexOnly) +{ + if ( _bUseHardRef ) + { + m_pElements.reset(new OHardRefMap< ObjectType >(_bCase)); + } + else + { + m_pElements.reset(new OHardRefMap< WeakReference< XPropertySet> >(_bCase)); + } + m_pElements->reFill(_rVector); +} + +OCollection::~OCollection() +{ +} + +Any SAL_CALL OCollection::queryInterface( const Type & rType ) +{ + if ( m_bUseIndexOnly && rType == cppu::UnoType<XNameAccess>::get() ) + { + return Any(); + } + return OCollectionBase::queryInterface( rType ); +} + +Sequence< Type > SAL_CALL OCollection::getTypes() +{ + if ( m_bUseIndexOnly ) + { + Sequence< Type > aTypes(OCollectionBase::getTypes()); + Type* pBegin = aTypes.getArray(); + Type* pEnd = pBegin + aTypes.getLength(); + + std::vector<Type> aOwnTypes; + aOwnTypes.reserve(aTypes.getLength()); + Type aType = cppu::UnoType<XNameAccess>::get(); + for(;pBegin != pEnd; ++pBegin) + { + if ( *pBegin != aType ) + aOwnTypes.push_back(*pBegin); + } + return Sequence< Type >(aOwnTypes.data(), aOwnTypes.size()); + } + return OCollectionBase::getTypes( ); +} + +void OCollection::clear_NoDispose() +{ + ::osl::MutexGuard aGuard(m_rMutex); + + m_pElements->clear(); + m_pElements->swapAll(); +} + + +void OCollection::disposing() +{ + m_aContainerListeners.disposeAndClear(EventObject(static_cast<XTypeProvider*>(this))); + m_aRefreshListeners.disposeAndClear(EventObject(static_cast<XTypeProvider*>(this))); + + ::osl::MutexGuard aGuard(m_rMutex); + + disposeElements(); + + m_pElements->swap(); +} + +Any SAL_CALL OCollection::getByIndex( sal_Int32 Index ) +{ + ::osl::MutexGuard aGuard(m_rMutex); + if (Index < 0 || Index >= m_pElements->size() ) + throw IndexOutOfBoundsException(OUString::number(Index),static_cast<XTypeProvider*>(this)); + + return makeAny(getObject(Index)); +} + +Any SAL_CALL OCollection::getByName( const OUString& aName ) +{ + ::osl::MutexGuard aGuard(m_rMutex); + + if ( !m_pElements->exists(aName) ) + { + ::connectivity::SharedResources aResources; + const OUString sError( aResources.getResourceStringWithSubstitution( + STR_NO_ELEMENT_NAME, + "$name$", aName + ) ); + throw NoSuchElementException( sError, static_cast< XTypeProvider* >( this ) ); + } + + return makeAny(getObject(m_pElements->findColumn(aName))); +} + +Sequence< OUString > SAL_CALL OCollection::getElementNames( ) +{ + ::osl::MutexGuard aGuard(m_rMutex); + return m_pElements->getElementNames(); +} + +void SAL_CALL OCollection::refresh( ) +{ + ::osl::MutexGuard aGuard(m_rMutex); + + disposeElements(); + + impl_refresh(); + EventObject aEvt(static_cast<XTypeProvider*>(this)); + m_aRefreshListeners.notifyEach( &XRefreshListener::refreshed, aEvt ); +} + +void OCollection::reFill(const ::std::vector< OUString> &_rVector) +{ + m_pElements->reFill(_rVector); +} + +// XDataDescriptorFactory +Reference< XPropertySet > SAL_CALL OCollection::createDataDescriptor( ) +{ + ::osl::MutexGuard aGuard(m_rMutex); + + return createDescriptor(); +} + +OUString OCollection::getNameForObject(const ObjectType& _xObject) +{ + OSL_ENSURE(_xObject.is(),"OCollection::getNameForObject: Object is NULL!"); + OUString sName; + _xObject->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME)) >>= sName; + return sName; +} + +// XAppend +void SAL_CALL OCollection::appendByDescriptor( const Reference< XPropertySet >& descriptor ) +{ + ::osl::ClearableMutexGuard aGuard(m_rMutex); + + OUString sName = getNameForObject( descriptor ); + + if ( m_pElements->exists(sName) ) + throw ElementExistException(sName,static_cast<XTypeProvider*>(this)); + + ObjectType xNewlyCreated = appendObject( sName, descriptor ); + if ( !xNewlyCreated.is() ) + throw RuntimeException(); + + ODescriptor* pDescriptor = comphelper::getUnoTunnelImplementation<ODescriptor>( xNewlyCreated ); + if ( pDescriptor ) + pDescriptor->setNew( false ); + + sName = getNameForObject( xNewlyCreated ); + if ( !m_pElements->exists( sName ) ) // this may happen when the derived class included it itself + m_pElements->insert( sName, xNewlyCreated ); + + // notify our container listeners + ContainerEvent aEvent(static_cast<XContainer*>(this), makeAny(sName), makeAny(xNewlyCreated), Any()); + aGuard.clear(); + m_aContainerListeners.notifyEach( &XContainerListener::elementInserted, aEvent ); +} + +// XDrop +void SAL_CALL OCollection::dropByName( const OUString& elementName ) +{ + ::osl::MutexGuard aGuard(m_rMutex); + + if ( !m_pElements->exists(elementName) ) + throw NoSuchElementException(elementName,static_cast<XTypeProvider*>(this)); + + dropImpl(m_pElements->findColumn(elementName)); +} + +void SAL_CALL OCollection::dropByIndex( sal_Int32 index ) +{ + ::osl::MutexGuard aGuard(m_rMutex); + if(index <0 || index >= getCount()) + throw IndexOutOfBoundsException(OUString::number(index),static_cast<XTypeProvider*>(this)); + + dropImpl(index); +} + +void OCollection::dropImpl(sal_Int32 _nIndex, bool _bReallyDrop) +{ + OUString elementName = m_pElements->getName(_nIndex); + + if ( _bReallyDrop ) + dropObject(_nIndex,elementName); + + m_pElements->disposeAndErase(_nIndex); + + // notify our container listeners + notifyElementRemoved(elementName); +} + +void OCollection::notifyElementRemoved(const OUString& _sName) +{ + ContainerEvent aEvent(static_cast<XContainer*>(this), makeAny(_sName), Any(), Any()); + // note that xExistent may be empty, in case somebody removed the data source while it is not alive at this moment + OInterfaceIteratorHelper2 aListenerLoop(m_aContainerListeners); + while (aListenerLoop.hasMoreElements()) + static_cast<XContainerListener*>(aListenerLoop.next())->elementRemoved(aEvent); +} + +sal_Int32 SAL_CALL OCollection::findColumn( const OUString& columnName ) +{ + if ( !m_pElements->exists(columnName) ) + { + ::dbtools::throwInvalidColumnException( columnName, static_cast< XIndexAccess*>(this) ); +#if !(defined(_MSC_VER) && defined(ENABLE_LTO)) + assert(false); +#endif + } + + return m_pElements->findColumn(columnName) + 1; // because columns start at one +} + +Reference< XEnumeration > SAL_CALL OCollection::createEnumeration( ) +{ + ::osl::MutexGuard aGuard(m_rMutex); + return new OEnumerationByIndex( static_cast< XIndexAccess*>(this)); +} + +void SAL_CALL OCollection::addContainerListener( const Reference< XContainerListener >& _rxListener ) +{ + m_aContainerListeners.addInterface(_rxListener); +} + + +void SAL_CALL OCollection::removeContainerListener( const Reference< XContainerListener >& _rxListener ) +{ + m_aContainerListeners.removeInterface(_rxListener); +} + +void SAL_CALL OCollection::acquire() throw() +{ + m_rParent.acquire(); +} + +void SAL_CALL OCollection::release() throw() +{ + m_rParent.release(); +} + +Type SAL_CALL OCollection::getElementType( ) +{ + return cppu::UnoType<XPropertySet>::get(); +} + +sal_Bool SAL_CALL OCollection::hasElements( ) +{ + ::osl::MutexGuard aGuard(m_rMutex); + return !m_pElements->empty(); +} + +sal_Int32 SAL_CALL OCollection::getCount( ) +{ + ::osl::MutexGuard aGuard(m_rMutex); + return m_pElements->size(); +} + +sal_Bool SAL_CALL OCollection::hasByName( const OUString& aName ) +{ + ::osl::MutexGuard aGuard(m_rMutex); + return m_pElements->exists(aName); +} + +void SAL_CALL OCollection::addRefreshListener( const Reference< XRefreshListener >& l ) +{ + m_aRefreshListeners.addInterface(l); +} + +void SAL_CALL OCollection::removeRefreshListener( const Reference< XRefreshListener >& l ) +{ + m_aRefreshListeners.removeInterface(l); +} + +void OCollection::insertElement(const OUString& _sElementName,const ObjectType& _xElement) +{ + OSL_ENSURE(!m_pElements->exists(_sElementName),"Element already exists"); + if ( !m_pElements->exists(_sElementName) ) + m_pElements->insert(_sElementName,_xElement); +} + +void OCollection::renameObject(const OUString& _sOldName, const OUString& _sNewName) +{ + OSL_ENSURE(m_pElements->exists(_sOldName),"Element doesn't exist"); + OSL_ENSURE(!m_pElements->exists(_sNewName),"Element already exists"); + OSL_ENSURE(!_sNewName.isEmpty(),"New name must not be empty!"); + OSL_ENSURE(!_sOldName.isEmpty(),"Old name must not be empty!"); + + if ( m_pElements->rename(_sOldName,_sNewName) ) + { + 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 + OInterfaceIteratorHelper2 aListenerLoop(m_aContainerListeners); + while (aListenerLoop.hasMoreElements()) + static_cast<XContainerListener*>(aListenerLoop.next())->elementReplaced(aEvent); + } +} + +ObjectType OCollection::getObject(sal_Int32 _nIndex) +{ + ObjectType xName = m_pElements->getObject(_nIndex); + if ( !xName.is() ) + { + try + { + xName = createObject(m_pElements->getName(_nIndex)); + } + catch(const SQLException& e) + { + css::uno::Any anyEx = cppu::getCaughtException(); + try + { + dropImpl(_nIndex,false); + } + catch(const Exception& ) + { + } + throw WrappedTargetException(e.Message,static_cast<XTypeProvider*>(this),anyEx); + } + m_pElements->setObject(_nIndex,xName); + } + return xName; +} + +void OCollection::disposeElements() +{ + m_pElements->disposeElements(); +} + +Reference< XPropertySet > OCollection::createDescriptor() +{ + OSL_FAIL("createDescriptor() needs to be overridden when used!"); + throw SQLException(); +} + +ObjectType OCollection::cloneDescriptor( const ObjectType& _descriptor ) +{ + ObjectType xNewDescriptor( createDescriptor() ); + ::comphelper::copyProperties( _descriptor, xNewDescriptor ); + return xNewDescriptor; +} + +ObjectType OCollection::appendObject( const OUString& /*_rForName*/, const Reference< XPropertySet >& descriptor ) +{ + return cloneDescriptor( descriptor ); +} + +void OCollection::dropObject(sal_Int32 /*_nPos*/, const OUString& /*_sElementName*/) +{ +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/sdbcx/VColumn.cxx b/connectivity/source/sdbcx/VColumn.cxx new file mode 100644 index 000000000..239934531 --- /dev/null +++ b/connectivity/source/sdbcx/VColumn.cxx @@ -0,0 +1,220 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <connectivity/sdbcx/VColumn.hxx> +#include <com/sun/star/beans/PropertyAttribute.hpp> +#include <comphelper/sequence.hxx> +#include <cppuhelper/supportsservice.hxx> +#include <TConnection.hxx> +#include <com/sun/star/sdbc/ColumnValue.hpp> + +using namespace connectivity; +using namespace connectivity::sdbcx; +using namespace cppu; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::sdbc; + + +OUString SAL_CALL OColumn::getImplementationName( ) +{ + if(isNew()) + return "com.sun.star.sdbcx.VColumnDescriptor"; + return "com.sun.star.sdbcx.VColumn"; +} + +css::uno::Sequence< OUString > SAL_CALL OColumn::getSupportedServiceNames( ) +{ + return { isNew()?OUString("com.sun.star.sdbcx.ColumnDescriptor"):OUString("com.sun.star.sdbcx.Column") }; +} + +sal_Bool SAL_CALL OColumn::supportsService( const OUString& _rServiceName ) +{ + return cppu::supportsService(this, _rServiceName); +} + +OColumn::OColumn(bool _bCase) + :OColumnDescriptor_BASE(m_aMutex) + ,ODescriptor(OColumnDescriptor_BASE::rBHelper,_bCase,true) + ,m_IsNullable(ColumnValue::NULLABLE) + ,m_Precision(0) + ,m_Scale(0) + ,m_Type(0) + ,m_IsAutoIncrement(false) + ,m_IsRowVersion(false) + ,m_IsCurrency(false) +{ + construct(); +} + +OColumn::OColumn( const OUString& Name, + const OUString& TypeName, + const OUString& DefaultValue, + const OUString& Description, + sal_Int32 IsNullable, + sal_Int32 Precision, + sal_Int32 Scale, + sal_Int32 Type, + bool IsAutoIncrement, + bool IsRowVersion, + bool IsCurrency, + bool _bCase, + const OUString& CatalogName, + const OUString& SchemaName, + const OUString& TableName) + :OColumnDescriptor_BASE(m_aMutex) + ,ODescriptor(OColumnDescriptor_BASE::rBHelper,_bCase) + ,m_TypeName(TypeName) + ,m_Description(Description) + ,m_DefaultValue(DefaultValue) + ,m_IsNullable(IsNullable) + ,m_Precision(Precision) + ,m_Scale(Scale) + ,m_Type(Type) + ,m_IsAutoIncrement(IsAutoIncrement) + ,m_IsRowVersion(IsRowVersion) + ,m_IsCurrency(IsCurrency) + ,m_CatalogName(CatalogName) + ,m_SchemaName(SchemaName) + ,m_TableName(TableName) +{ + m_Name = Name; + + construct(); +} + +OColumn::~OColumn() +{ +} + +::cppu::IPropertyArrayHelper* OColumn::createArrayHelper( sal_Int32 /*_nId*/ ) const +{ + return doCreateArrayHelper(); +} + +::cppu::IPropertyArrayHelper& SAL_CALL OColumn::getInfoHelper() +{ + return *OColumn_PROP::getArrayHelper(isNew() ? 1 : 0); +} + +void SAL_CALL OColumn::acquire() throw() +{ + OColumnDescriptor_BASE::acquire(); +} + +void SAL_CALL OColumn::release() throw() +{ + OColumnDescriptor_BASE::release(); +} + +Any SAL_CALL OColumn::queryInterface( const Type & rType ) +{ + Any aRet = ODescriptor::queryInterface( rType); + if(!aRet.hasValue()) + { + if(!isNew()) + aRet = OColumn_BASE::queryInterface(rType); + if(!aRet.hasValue()) + aRet = OColumnDescriptor_BASE::queryInterface( rType); + } + return aRet; +} + +Sequence< Type > SAL_CALL OColumn::getTypes( ) +{ + if(isNew()) + return ::comphelper::concatSequences(ODescriptor::getTypes(),OColumnDescriptor_BASE::getTypes()); + + return ::comphelper::concatSequences(ODescriptor::getTypes(),OColumn_BASE::getTypes(),OColumnDescriptor_BASE::getTypes()); +} + +void OColumn::construct() +{ + ODescriptor::construct(); + + sal_Int32 nAttrib = isNew() ? 0 : PropertyAttribute::READONLY; + + registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME), PROPERTY_ID_TYPENAME, nAttrib, &m_TypeName, cppu::UnoType<decltype(m_TypeName)>::get()); + registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DESCRIPTION), PROPERTY_ID_DESCRIPTION, nAttrib, &m_Description, cppu::UnoType<decltype(m_Description)>::get()); + registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DEFAULTVALUE), PROPERTY_ID_DEFAULTVALUE, nAttrib, &m_DefaultValue, cppu::UnoType<decltype(m_DefaultValue)>::get()); + registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PRECISION), PROPERTY_ID_PRECISION, nAttrib, &m_Precision, cppu::UnoType<decltype(m_Precision)>::get()); + registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE), PROPERTY_ID_TYPE, nAttrib, &m_Type, cppu::UnoType<decltype(m_Type)>::get()); + registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE), PROPERTY_ID_SCALE, nAttrib, &m_Scale, cppu::UnoType<decltype(m_Scale)>::get()); + registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISNULLABLE), PROPERTY_ID_ISNULLABLE, nAttrib, &m_IsNullable, cppu::UnoType<decltype(m_IsNullable)>::get()); + registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISAUTOINCREMENT), PROPERTY_ID_ISAUTOINCREMENT, nAttrib, &m_IsAutoIncrement, cppu::UnoType<bool>::get()); + registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISROWVERSION), PROPERTY_ID_ISROWVERSION, nAttrib, &m_IsRowVersion, cppu::UnoType<bool>::get()); + registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISCURRENCY), PROPERTY_ID_ISCURRENCY, nAttrib, &m_IsCurrency, cppu::UnoType<bool>::get()); + registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_CATALOGNAME), PROPERTY_ID_CATALOGNAME, nAttrib, &m_CatalogName, cppu::UnoType<decltype(m_CatalogName)>::get()); + registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCHEMANAME), PROPERTY_ID_SCHEMANAME, nAttrib, &m_SchemaName, cppu::UnoType<decltype(m_SchemaName)>::get()); + registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TABLENAME), PROPERTY_ID_TABLENAME, nAttrib, &m_TableName, cppu::UnoType<decltype(m_TableName)>::get()); +} + +void OColumn::disposing() +{ + OPropertySetHelper::disposing(); + + ::osl::MutexGuard aGuard(m_aMutex); + checkDisposed(OColumnDescriptor_BASE::rBHelper.bDisposed); + +} + +Reference< XPropertySet > SAL_CALL OColumn::createDataDescriptor( ) +{ + ::osl::MutexGuard aGuard(m_aMutex); + checkDisposed(OColumnDescriptor_BASE::rBHelper.bDisposed); + + + OColumn* pNewColumn = new OColumn( m_Name, + m_TypeName, + m_DefaultValue, + m_Description, + m_IsNullable, + m_Precision, + m_Scale, + m_Type, + m_IsAutoIncrement, + m_IsRowVersion, + m_IsCurrency, + isCaseSensitive(), + m_CatalogName, + m_SchemaName, + m_TableName); + pNewColumn->setNew(true); + return pNewColumn; +} + +css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL OColumn::getPropertySetInfo( ) +{ + return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper()); +} + +// XNamed +OUString SAL_CALL OColumn::getName( ) +{ + return m_Name; +} + +void SAL_CALL OColumn::setName( const OUString& aName ) +{ + m_Name = aName; +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/sdbcx/VDescriptor.cxx b/connectivity/source/sdbcx/VDescriptor.cxx new file mode 100644 index 000000000..8a32a1b58 --- /dev/null +++ b/connectivity/source/sdbcx/VDescriptor.cxx @@ -0,0 +1,128 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <connectivity/sdbcx/VDescriptor.hxx> +#include <com/sun/star/beans/PropertyAttribute.hpp> +#include <comphelper/servicehelper.hxx> +#include <cppuhelper/queryinterface.hxx> +#include <cppuhelper/typeprovider.hxx> + +#include <algorithm> + +namespace connectivity::sdbcx +{ + using namespace ::com::sun::star::uno; + using namespace ::com::sun::star::lang; + using namespace ::com::sun::star::beans; + + + // = ODescriptor + + + ODescriptor::ODescriptor(::cppu::OBroadcastHelper& _rBHelper, bool _bCase, bool _bNew) + :ODescriptor_PBASE(_rBHelper) + ,m_aCase(_bCase) + ,m_bNew(_bNew) + { + } + + + // css::lang::XUnoTunnel + sal_Int64 SAL_CALL ODescriptor::getSomething( const Sequence< sal_Int8 >& rId ) + { + return (isUnoTunnelId<ODescriptor>(rId)) + ? reinterpret_cast< sal_Int64 >( this ) + : 0; + } + + + namespace + { + struct ResetROAttribute + { + void operator ()( Property& _rProperty ) const + { + _rProperty.Attributes &= ~PropertyAttribute::READONLY; + } + }; + struct SetROAttribute + { + void operator ()( Property& _rProperty ) const + { + _rProperty.Attributes |= PropertyAttribute::READONLY; + } + }; + } + + + ::cppu::IPropertyArrayHelper* ODescriptor::doCreateArrayHelper() const + { + Sequence< Property > aProperties; + describeProperties( aProperties ); + + if ( isNew() ) + std::for_each( aProperties.begin(), aProperties.end(), ResetROAttribute() ); + else + std::for_each( aProperties.begin(), aProperties.end(), SetROAttribute() ); + + return new ::cppu::OPropertyArrayHelper( aProperties ); + } + + + bool ODescriptor::isNew( const Reference< XInterface >& _rxDescriptor ) + { + ODescriptor* pImplementation = comphelper::getUnoTunnelImplementation<ODescriptor>( _rxDescriptor ); + return pImplementation && pImplementation->isNew(); + } + + + Sequence< sal_Int8 > ODescriptor::getUnoTunnelId() + { + static ::cppu::OImplementationId implId; + + return implId.getImplementationId(); + } + + + Any SAL_CALL ODescriptor::queryInterface( const Type & rType ) + { + Any aRet = ::cppu::queryInterface(rType,static_cast< XUnoTunnel*> (this)); + return aRet.hasValue() ? aRet : ODescriptor_PBASE::queryInterface(rType); + } + + + void ODescriptor::setNew(bool _bNew) + { + m_bNew = _bNew; + } + + + Sequence< Type > SAL_CALL ODescriptor::getTypes( ) + { + ::cppu::OTypeCollection aTypes( cppu::UnoType<XMultiPropertySet>::get(), + cppu::UnoType<XFastPropertySet>::get(), + cppu::UnoType<XPropertySet>::get(), + cppu::UnoType<XUnoTunnel>::get()); + return aTypes.getTypes(); + } + +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/sdbcx/VGroup.cxx b/connectivity/source/sdbcx/VGroup.cxx new file mode 100644 index 000000000..ed11a6175 --- /dev/null +++ b/connectivity/source/sdbcx/VGroup.cxx @@ -0,0 +1,166 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + + +#include <sdbcx/VGroup.hxx> +#include <comphelper/sequence.hxx> +#include <connectivity/dbexception.hxx> + + +using namespace ::connectivity::sdbcx; +using namespace ::connectivity; +using namespace ::dbtools; +using namespace ::com::sun::star::sdbc; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::container; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::beans; + +IMPLEMENT_SERVICE_INFO(OGroup,"com.sun.star.sdbcx.VGroup","com.sun.star.sdbcx.Group"); + +OGroup::OGroup(bool _bCase) : OGroup_BASE(m_aMutex) + , ODescriptor(OGroup_BASE::rBHelper,_bCase) +{ +} + +OGroup::OGroup(const OUString& Name, bool _bCase) : OGroup_BASE(m_aMutex) + ,ODescriptor(OGroup_BASE::rBHelper,_bCase) +{ + m_Name = Name; +} + +OGroup::~OGroup() +{ +} + +Any SAL_CALL OGroup::queryInterface( const Type & rType ) +{ + Any aRet = ODescriptor::queryInterface( rType); + return aRet.hasValue() ? aRet : OGroup_BASE::queryInterface( rType); +} + +Sequence< Type > SAL_CALL OGroup::getTypes( ) +{ + return ::comphelper::concatSequences(ODescriptor::getTypes(),OGroup_BASE::getTypes()); +} + +void OGroup::disposing() +{ + OPropertySetHelper::disposing(); + + ::osl::MutexGuard aGuard(m_aMutex); + + if(m_pUsers) + m_pUsers->disposing(); +} + +::cppu::IPropertyArrayHelper* OGroup::createArrayHelper( ) const +{ + Sequence< Property > aProps; + describeProperties(aProps); + return new ::cppu::OPropertyArrayHelper(aProps); +} + +::cppu::IPropertyArrayHelper & OGroup::getInfoHelper() +{ + return *getArrayHelper(); +} + +Reference< XNameAccess > SAL_CALL OGroup::getUsers( ) +{ + ::osl::MutexGuard aGuard(m_aMutex); + checkDisposed(OGroup_BASE::rBHelper.bDisposed); + + try + { + if ( !m_pUsers ) + refreshUsers(); + } + catch( const RuntimeException& ) + { + // allowed to leave this method + throw; + } + catch( const Exception& ) + { + // allowed + } + + return m_pUsers.get(); +} + + +sal_Int32 SAL_CALL OGroup::getPrivileges( const OUString& /*objName*/, sal_Int32 /*objType*/ ) +{ + ::osl::MutexGuard aGuard(m_aMutex); + checkDisposed(OGroup_BASE::rBHelper.bDisposed); + + return 0; +} + +sal_Int32 SAL_CALL OGroup::getGrantablePrivileges( const OUString& /*objName*/, sal_Int32 /*objType*/ ) +{ + ::osl::MutexGuard aGuard(m_aMutex); + checkDisposed(OGroup_BASE::rBHelper.bDisposed); + + return 0; +} + +void SAL_CALL OGroup::grantPrivileges( const OUString& /*objName*/, sal_Int32 /*objType*/, sal_Int32 /*objPrivileges*/ ) +{ + ::osl::MutexGuard aGuard(m_aMutex); + checkDisposed(OGroup_BASE::rBHelper.bDisposed); + throwFeatureNotImplementedSQLException( "XAuthorizable::grantPrivileges", *this ); +} + +void SAL_CALL OGroup::revokePrivileges( const OUString& /*objName*/, sal_Int32 /*objType*/, sal_Int32 /*objPrivileges*/ ) +{ + ::osl::MutexGuard aGuard(m_aMutex); + checkDisposed(OGroup_BASE::rBHelper.bDisposed); + throwFeatureNotImplementedSQLException( "XAuthorizable::revokePrivileges", *this ); +} + +css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL OGroup::getPropertySetInfo( ) +{ + return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper()); +} + +OUString SAL_CALL OGroup::getName( ) +{ + return m_Name; +} + +void SAL_CALL OGroup::setName( const OUString& /*aName*/ ) +{ + throwFeatureNotImplementedRuntimeException( "XNamed::setName", *this ); +} + +// XInterface +void SAL_CALL OGroup::acquire() throw() +{ + OGroup_BASE::acquire(); +} + +void SAL_CALL OGroup::release() throw() +{ + OGroup_BASE::release(); +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/sdbcx/VIndex.cxx b/connectivity/source/sdbcx/VIndex.cxx new file mode 100644 index 000000000..1649ff83a --- /dev/null +++ b/connectivity/source/sdbcx/VIndex.cxx @@ -0,0 +1,199 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <sdbcx/VIndex.hxx> +#include <com/sun/star/beans/PropertyAttribute.hpp> +#include <connectivity/dbexception.hxx> +#include <comphelper/sequence.hxx> +#include <connectivity/sdbcx/VCollection.hxx> +#include <cppuhelper/supportsservice.hxx> +#include <TConnection.hxx> +#include <tools/diagnose_ex.h> + +using namespace ::connectivity; +using namespace ::dbtools; +using namespace ::connectivity::sdbcx; +using namespace ::cppu; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::sdbc; +using namespace ::com::sun::star::sdbcx; +using namespace ::com::sun::star::container; +using namespace ::com::sun::star::lang; + + +OUString SAL_CALL OIndex::getImplementationName( ) +{ + if(isNew()) + return "com.sun.star.sdbcx.VIndexDescriptor"; + return "com.sun.star.sdbcx.VIndex"; +} + +css::uno::Sequence< OUString > SAL_CALL OIndex::getSupportedServiceNames( ) +{ + return { isNew()?OUString("com.sun.star.sdbcx.IndexDescriptor"):OUString("com.sun.star.sdbcx.Index") }; +} + +sal_Bool SAL_CALL OIndex::supportsService( const OUString& _rServiceName ) +{ + return cppu::supportsService(this, _rServiceName); +} + +OIndex::OIndex(bool _bCase) : ODescriptor_BASE(m_aMutex) + , ODescriptor(ODescriptor_BASE::rBHelper,_bCase,true) + ,m_IsUnique(false) + ,m_IsPrimaryKeyIndex(false) + ,m_IsClustered(false) +{ +} + +OIndex::OIndex( const OUString& Name, + const OUString& Catalog, + bool _isUnique, + bool _isPrimaryKeyIndex, + bool _isClustered, + bool _bCase) : ODescriptor_BASE(m_aMutex) + ,ODescriptor(ODescriptor_BASE::rBHelper, _bCase) + ,m_Catalog(Catalog) + ,m_IsUnique(_isUnique) + ,m_IsPrimaryKeyIndex(_isPrimaryKeyIndex) + ,m_IsClustered(_isClustered) +{ + m_Name = Name; +} + +OIndex::~OIndex( ) +{ +} + +::cppu::IPropertyArrayHelper* OIndex::createArrayHelper( sal_Int32 /*_nId*/ ) const +{ + return doCreateArrayHelper(); +} + +::cppu::IPropertyArrayHelper& SAL_CALL OIndex::getInfoHelper() +{ + return *OIndex_PROP::getArrayHelper(isNew() ? 1 : 0); +} + +Any SAL_CALL OIndex::queryInterface( const Type & rType ) +{ + Any aRet = ODescriptor::queryInterface( rType); + if(!aRet.hasValue()) + { + if(!isNew()) + aRet = OIndex_BASE::queryInterface(rType); + if(!aRet.hasValue()) + aRet = ODescriptor_BASE::queryInterface( rType); + } + return aRet; +} + +Sequence< Type > SAL_CALL OIndex::getTypes( ) +{ + if(isNew()) + return ::comphelper::concatSequences(ODescriptor::getTypes(),ODescriptor_BASE::getTypes()); + return ::comphelper::concatSequences(ODescriptor::getTypes(),ODescriptor_BASE::getTypes(),OIndex_BASE::getTypes()); +} + +void OIndex::construct() +{ + ODescriptor::construct(); + + sal_Int32 nAttrib = isNew() ? 0 : PropertyAttribute::READONLY; + + registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_CATALOG), PROPERTY_ID_CATALOG, nAttrib,&m_Catalog, ::cppu::UnoType<OUString>::get()); + registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISUNIQUE), PROPERTY_ID_ISUNIQUE, nAttrib,&m_IsUnique, cppu::UnoType<bool>::get()); + registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISPRIMARYKEYINDEX),PROPERTY_ID_ISPRIMARYKEYINDEX, nAttrib,&m_IsPrimaryKeyIndex, cppu::UnoType<bool>::get()); + registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISCLUSTERED), PROPERTY_ID_ISCLUSTERED, nAttrib,&m_IsClustered, cppu::UnoType<bool>::get()); +} + +void OIndex::disposing() +{ + OPropertySetHelper::disposing(); + + ::osl::MutexGuard aGuard(m_aMutex); + + if(m_pColumns) + m_pColumns->disposing(); +} + +Reference< css::container::XNameAccess > SAL_CALL OIndex::getColumns( ) +{ + ::osl::MutexGuard aGuard(m_aMutex); + checkDisposed(ODescriptor_BASE::rBHelper.bDisposed); + + try + { + if ( !m_pColumns ) + refreshColumns(); + } + catch( const RuntimeException& ) + { + // allowed to leave this method + throw; + } + catch( const Exception& ) + { + TOOLS_WARN_EXCEPTION( "connectivity.commontools", "OIndex::getColumns" ); + } + + return m_pColumns.get(); +} + +Reference< XPropertySet > SAL_CALL OIndex::createDataDescriptor( ) +{ + ::osl::MutexGuard aGuard(m_aMutex); + checkDisposed(ODescriptor_BASE::rBHelper.bDisposed); + + + return this; +} + +css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL OIndex::getPropertySetInfo( ) +{ + return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper()); +} + +OUString SAL_CALL OIndex::getName( ) +{ + return m_Name; +} + +void SAL_CALL OIndex::setName( const OUString& /*aName*/ ) +{ +} + +// XInterface +void SAL_CALL OIndex::acquire() throw() +{ + ODescriptor_BASE::acquire(); +} + +void SAL_CALL OIndex::release() throw() +{ + ODescriptor_BASE::release(); +} + +void OIndex::refreshColumns() +{ +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/sdbcx/VIndexColumn.cxx b/connectivity/source/sdbcx/VIndexColumn.cxx new file mode 100644 index 000000000..edd1ea93e --- /dev/null +++ b/connectivity/source/sdbcx/VIndexColumn.cxx @@ -0,0 +1,102 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <sdbcx/VIndexColumn.hxx> +#include <com/sun/star/beans/PropertyAttribute.hpp> +#include <cppuhelper/supportsservice.hxx> +#include <TConnection.hxx> + +using namespace connectivity; +using namespace connectivity::sdbcx; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::uno; + +OUString SAL_CALL OIndexColumn::getImplementationName( ) +{ + if(isNew()) + return "com.sun.star.sdbcx.VIndexColumnDescriptor"; + return "com.sun.star.sdbcx.VIndexColumn"; +} + +css::uno::Sequence< OUString > SAL_CALL OIndexColumn::getSupportedServiceNames( ) +{ + return { isNew()?OUString("com.sun.star.sdbcx.IndexColumnDescriptor"):OUString("com.sun.star.sdbcx.IndexColumn") }; +} + +sal_Bool SAL_CALL OIndexColumn::supportsService( const OUString& _rServiceName ) +{ + return cppu::supportsService(this, _rServiceName); +} + +OIndexColumn::OIndexColumn(bool _bCase) : OColumn(_bCase), m_IsAscending(true) +{ + construct(); +} + + +OIndexColumn::OIndexColumn( bool IsAscending, + const OUString& Name, + const OUString& TypeName, + const OUString& DefaultValue, + sal_Int32 IsNullable, + sal_Int32 Precision, + sal_Int32 Scale, + sal_Int32 Type, + bool _bCase, + const OUString& CatalogName, + const OUString& SchemaName, + const OUString& TableName + ) : OColumn(Name, + TypeName, + DefaultValue, + OUString(), + IsNullable, + Precision, + Scale, + Type, + false/*IsAutoIncrement*/, + false/*IsRowVersion*/, + false/*IsCurrency*/, + _bCase, + CatalogName, + SchemaName, + TableName) + , m_IsAscending(IsAscending) +{ + construct(); +} + +::cppu::IPropertyArrayHelper* OIndexColumn::createArrayHelper( sal_Int32 /*_nId*/ ) const +{ + return doCreateArrayHelper(); +} + +::cppu::IPropertyArrayHelper& SAL_CALL OIndexColumn::getInfoHelper() +{ + return *OIndexColumn_PROP::getArrayHelper(isNew() ? 1 : 0); +} + +void OIndexColumn::construct() +{ + sal_Int32 nAttrib = isNew() ? 0 : PropertyAttribute::READONLY; + registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISASCENDING), PROPERTY_ID_ISASCENDING, nAttrib,&m_IsAscending, cppu::UnoType<bool>::get()); +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/sdbcx/VKey.cxx b/connectivity/source/sdbcx/VKey.cxx new file mode 100644 index 000000000..33e9340b5 --- /dev/null +++ b/connectivity/source/sdbcx/VKey.cxx @@ -0,0 +1,202 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <sdbcx/VKey.hxx> +#include <com/sun/star/beans/PropertyAttribute.hpp> +#include <com/sun/star/sdbc/KeyRule.hpp> +#include <comphelper/sequence.hxx> +#include <cppuhelper/supportsservice.hxx> +#include <connectivity/sdbcx/VCollection.hxx> +#include <TConnection.hxx> + +using namespace connectivity; +using namespace connectivity::sdbcx; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::sdbc; +using namespace ::com::sun::star::sdbcx; +using namespace ::com::sun::star::container; +using namespace ::com::sun::star::lang; + + +OUString SAL_CALL OKey::getImplementationName( ) +{ + if(isNew()) + return "com.sun.star.sdbcx.VKeyDescriptor"; + return "com.sun.star.sdbcx.VKey"; +} + +css::uno::Sequence< OUString > SAL_CALL OKey::getSupportedServiceNames( ) +{ + return { isNew()?OUString("com.sun.star.sdbcx.KeyDescriptor"):OUString("com.sun.star.sdbcx.Key") }; +} + +sal_Bool SAL_CALL OKey::supportsService( const OUString& _rServiceName ) +{ + return cppu::supportsService(this, _rServiceName); +} + +OKey::OKey(bool _bCase) : ODescriptor_BASE(m_aMutex) + , ODescriptor(ODescriptor_BASE::rBHelper, _bCase, true) + , m_aProps(std::make_shared<KeyProperties>()) +{ +} + +OKey::OKey(const OUString& Name,const std::shared_ptr<KeyProperties>& _rProps, bool _bCase) +: ODescriptor_BASE(m_aMutex) + ,ODescriptor(ODescriptor_BASE::rBHelper, _bCase) + ,m_aProps(_rProps) +{ + m_Name = Name; +} +//OKey::OKey( const OUString& _Name, +// const OUString& _ReferencedTable, +// sal_Int32 _Type, +// sal_Int32 _UpdateRule, +// sal_Int32 _DeleteRule, +// sal_Bool _bCase) : ODescriptor_BASE(m_aMutex) +// ,ODescriptor(ODescriptor_BASE::rBHelper,_bCase) +// ,m_ReferencedTable(_ReferencedTable) +// ,m_Type(_Type) +// ,m_UpdateRule(_UpdateRule) +// ,m_DeleteRule(_DeleteRule) +// ,m_pColumns(NULL) +//{ +// m_Name = _Name; +//} + +OKey::~OKey( ) +{ +} + +Any SAL_CALL OKey::queryInterface( const Type & rType ) +{ + Any aRet = ODescriptor::queryInterface( rType); + if(!aRet.hasValue()) + { + if(!isNew()) + aRet = OKey_BASE::queryInterface(rType); + if(!aRet.hasValue()) + aRet = ODescriptor_BASE::queryInterface( rType); + } + + return aRet; +} + +Sequence< Type > SAL_CALL OKey::getTypes( ) +{ + if(isNew()) + return ::comphelper::concatSequences(ODescriptor::getTypes(),ODescriptor_BASE::getTypes()); + + return ::comphelper::concatSequences(ODescriptor::getTypes(),ODescriptor_BASE::getTypes(),OKey_BASE::getTypes()); +} + +void OKey::construct() +{ + ODescriptor::construct(); + + sal_Int32 nAttrib = isNew() ? 0 : PropertyAttribute::READONLY; + + registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_REFERENCEDTABLE), PROPERTY_ID_REFERENCEDTABLE, nAttrib,&m_aProps->m_ReferencedTable, ::cppu::UnoType<OUString>::get()); + registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE), PROPERTY_ID_TYPE, nAttrib,&m_aProps->m_Type, ::cppu::UnoType<sal_Int32>::get()); + registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_UPDATERULE), PROPERTY_ID_UPDATERULE, nAttrib,&m_aProps->m_UpdateRule, ::cppu::UnoType<sal_Int32>::get()); + registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DELETERULE), PROPERTY_ID_DELETERULE, nAttrib,&m_aProps->m_DeleteRule, ::cppu::UnoType<sal_Int32>::get()); +} + +void SAL_CALL OKey::disposing() +{ + OPropertySetHelper::disposing(); + + ::osl::MutexGuard aGuard(m_aMutex); + + if(m_pColumns) + m_pColumns->disposing(); + + ODescriptor_BASE::disposing(); +} + +::cppu::IPropertyArrayHelper* OKey::createArrayHelper( sal_Int32 /*_nId*/ ) const +{ + return doCreateArrayHelper(); +} + +::cppu::IPropertyArrayHelper & OKey::getInfoHelper() +{ + return *getArrayHelper(isNew() ? 1 : 0); +} + +Reference< css::container::XNameAccess > SAL_CALL OKey::getColumns( ) +{ + ::osl::MutexGuard aGuard(m_aMutex); + checkDisposed(ODescriptor_BASE::rBHelper.bDisposed); + + try + { + if ( !m_pColumns ) + refreshColumns(); + } + catch( const RuntimeException& ) + { + // allowed to leave this method + throw; + } + catch( const Exception& ) + { + // allowed + } + + return m_pColumns.get(); +} + +Reference< XPropertySet > SAL_CALL OKey::createDataDescriptor( ) +{ + ::osl::MutexGuard aGuard(m_aMutex); + checkDisposed(ODescriptor_BASE::rBHelper.bDisposed); + + + return this; +} + +css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL OKey::getPropertySetInfo( ) +{ + return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper()); +} + +OUString SAL_CALL OKey::getName( ) +{ + return m_Name; +} + +void SAL_CALL OKey::setName( const OUString& /*aName*/ ) +{ +} + +// XInterface +void SAL_CALL OKey::acquire() throw() +{ + ODescriptor_BASE::acquire(); +} + +void SAL_CALL OKey::release() throw() +{ + ODescriptor_BASE::release(); +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/sdbcx/VKeyColumn.cxx b/connectivity/source/sdbcx/VKeyColumn.cxx new file mode 100644 index 000000000..b6f69e65c --- /dev/null +++ b/connectivity/source/sdbcx/VKeyColumn.cxx @@ -0,0 +1,106 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <sdbcx/VKeyColumn.hxx> +#include <com/sun/star/beans/PropertyAttribute.hpp> +#include <cppuhelper/supportsservice.hxx> +#include <TConnection.hxx> + +using namespace connectivity; +using namespace connectivity::sdbcx; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::uno; +using namespace cppu; + +OUString SAL_CALL OKeyColumn::getImplementationName( ) +{ + if(isNew()) + return "com.sun.star.sdbcx.VKeyColumnDescriptor"; + return "com.sun.star.sdbcx.VKeyColumn"; +} + +css::uno::Sequence< OUString > SAL_CALL OKeyColumn::getSupportedServiceNames( ) +{ + return { isNew()?OUString("com.sun.star.sdbcx.KeyColumnDescriptor"):OUString("com.sun.star.sdbcx.KeyColumn") }; +} + +sal_Bool SAL_CALL OKeyColumn::supportsService( const OUString& _rServiceName ) +{ + return cppu::supportsService(this, _rServiceName); +} + +OKeyColumn::OKeyColumn(bool _bCase) : OColumn(_bCase) +{ + construct(); +} + +OKeyColumn::OKeyColumn( const OUString& ReferencedColumn, + const OUString& Name, + const OUString& TypeName, + const OUString& DefaultValue, + sal_Int32 IsNullable, + sal_Int32 Precision, + sal_Int32 Scale, + sal_Int32 Type, + bool _bCase, + const OUString& CatalogName, + const OUString& SchemaName, + const OUString& TableName + ) : OColumn(Name, + TypeName, + DefaultValue, + OUString(), + IsNullable, + Precision, + Scale, + Type, + false/*IsAutoIncrement*/, + false/*IsRowVersion*/, + false/*IsCurrency*/, + _bCase, + CatalogName, + SchemaName, + TableName) + , m_ReferencedColumn(ReferencedColumn) +{ + construct(); +} + +OKeyColumn::~OKeyColumn() +{ +} + +::cppu::IPropertyArrayHelper* OKeyColumn::createArrayHelper( sal_Int32 /*_nId*/ ) const +{ + return doCreateArrayHelper(); +} + +::cppu::IPropertyArrayHelper& SAL_CALL OKeyColumn::getInfoHelper() +{ + return *OKeyColumn_PROP::getArrayHelper(isNew() ? 1 : 0); +} + +void OKeyColumn::construct() +{ + sal_Int32 nAttrib = isNew() ? 0 : PropertyAttribute::READONLY; + registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RELATEDCOLUMN), PROPERTY_ID_RELATEDCOLUMN, nAttrib,&m_ReferencedColumn, ::cppu::UnoType<OUString>::get()); +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/sdbcx/VTable.cxx b/connectivity/source/sdbcx/VTable.cxx new file mode 100644 index 000000000..90c742782 --- /dev/null +++ b/connectivity/source/sdbcx/VTable.cxx @@ -0,0 +1,304 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <connectivity/sdbcx/VTable.hxx> +#include <com/sun/star/beans/PropertyAttribute.hpp> +#include <comphelper/sequence.hxx> +#include <connectivity/sdbcx/VCollection.hxx> +#include <TConnection.hxx> +#include <connectivity/dbtools.hxx> +#include <connectivity/dbexception.hxx> +#include <cppuhelper/supportsservice.hxx> + +using namespace ::connectivity; +using namespace ::connectivity::sdbcx; +using namespace ::dbtools; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::sdbc; +using namespace ::com::sun::star::sdbcx; +using namespace ::com::sun::star::container; +using namespace ::com::sun::star::lang; + + +OUString SAL_CALL OTable::getImplementationName( ) +{ + if(isNew()) + return "com.sun.star.sdbcx.VTableDescriptor"; + return "com.sun.star.sdbcx.Table"; +} + + +css::uno::Sequence< OUString > SAL_CALL OTable::getSupportedServiceNames( ) +{ + return { isNew()?OUString("com.sun.star.sdbcx.TableDescriptor"):OUString("com.sun.star.sdbcx.Table") }; +} + +sal_Bool SAL_CALL OTable::supportsService( const OUString& _rServiceName ) +{ + return cppu::supportsService(this, _rServiceName); +} + +OTable::OTable(OCollection* _pTables, + bool _bCase) + : OTableDescriptor_BASE(m_aMutex) + ,ODescriptor(OTableDescriptor_BASE::rBHelper,_bCase,true) + ,m_pTables(_pTables) +{ +} + +OTable::OTable( OCollection* _pTables, + bool _bCase, + const OUString& Name, const OUString& Type, + const OUString& Description,const OUString& SchemaName, + const OUString& CatalogName) : OTableDescriptor_BASE(m_aMutex) + ,ODescriptor(OTableDescriptor_BASE::rBHelper,_bCase) + ,m_CatalogName(CatalogName) + ,m_SchemaName(SchemaName) + ,m_Description(Description) + ,m_Type(Type) + ,m_pTables(_pTables) +{ + m_Name = Name; +} + +OTable::~OTable() +{ +} + +void OTable::construct() +{ + ODescriptor::construct(); + + sal_Int32 nAttrib = isNew() ? 0 : PropertyAttribute::READONLY; + + registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_CATALOGNAME), PROPERTY_ID_CATALOGNAME,nAttrib,&m_CatalogName, ::cppu::UnoType<OUString>::get()); + registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCHEMANAME), PROPERTY_ID_SCHEMANAME, nAttrib,&m_SchemaName, ::cppu::UnoType<OUString>::get()); + registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DESCRIPTION), PROPERTY_ID_DESCRIPTION,nAttrib,&m_Description, ::cppu::UnoType<OUString>::get()); + registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE), PROPERTY_ID_TYPE, nAttrib,&m_Type, ::cppu::UnoType<OUString>::get()); +} + +void SAL_CALL OTable::acquire() throw() +{ + OTableDescriptor_BASE::acquire(); +} + +void SAL_CALL OTable::release() throw() +{ + OTableDescriptor_BASE::release(); +} + + +Any SAL_CALL OTable::queryInterface( const Type & rType ) +{ + Any aRet = ODescriptor::queryInterface( rType); + if(!aRet.hasValue()) + { + if(!isNew()) + aRet = OTable_BASE::queryInterface( rType); + if(isNew() && (rType == cppu::UnoType<XIndexesSupplier>::get())) + return Any(); + if(!aRet.hasValue()) + aRet = OTableDescriptor_BASE::queryInterface( rType); + } + return aRet; +} + +Sequence< Type > SAL_CALL OTable::getTypes( ) +{ + if(isNew()) + return ::comphelper::concatSequences(ODescriptor::getTypes(),OTableDescriptor_BASE::getTypes()); + return ::comphelper::concatSequences(ODescriptor::getTypes(),OTableDescriptor_BASE::getTypes(),OTable_BASE::getTypes()); +} + +void SAL_CALL OTable::disposing() +{ + ODescriptor::disposing(); + + ::osl::MutexGuard aGuard(m_aMutex); + + if(m_xKeys) + m_xKeys->disposing(); + if(m_xColumns) + m_xColumns->disposing(); + if(m_xIndexes) + m_xIndexes->disposing(); + + m_pTables = nullptr; +} + +// XColumnsSupplier +Reference< XNameAccess > SAL_CALL OTable::getColumns( ) +{ + ::osl::MutexGuard aGuard(m_aMutex); + checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed); + + try + { + if ( !m_xColumns ) + refreshColumns(); + } + catch( const RuntimeException& ) + { + // allowed to leave this method + throw; + } + catch( const Exception& ) + { + // allowed + } + + return m_xColumns.get(); +} + + +// XKeysSupplier +Reference< XIndexAccess > SAL_CALL OTable::getKeys( ) +{ + ::osl::MutexGuard aGuard(m_aMutex); + checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed); + + Reference< XIndexAccess > xKeys; + + try + { + if ( !m_xKeys ) + refreshKeys(); + xKeys = m_xKeys.get(); + } + catch( const RuntimeException& ) + { + // allowed to leave this method + throw; + } + catch( const Exception& ) + { + // allowed + } + + return xKeys; +} + +cppu::IPropertyArrayHelper* OTable::createArrayHelper( sal_Int32 /*_nId*/ ) const +{ + return doCreateArrayHelper(); +} + +cppu::IPropertyArrayHelper & OTable::getInfoHelper() +{ + return *getArrayHelper(isNew() ? 1 : 0); +} + +Reference< XPropertySet > SAL_CALL OTable::createDataDescriptor( ) +{ + ::osl::MutexGuard aGuard(m_aMutex); + checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed); + + OTable* pTable = new OTable(m_pTables,isCaseSensitive(),m_Name,m_Type,m_Description,m_SchemaName,m_CatalogName); + pTable->setNew(true); + return pTable; +} + +// XIndexesSupplier +Reference< XNameAccess > SAL_CALL OTable::getIndexes( ) +{ + ::osl::MutexGuard aGuard(m_aMutex); + checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed); + + try + { + if ( !m_xIndexes ) + refreshIndexes(); + } + catch( const RuntimeException& ) + { + // allowed to leave this method + throw; + } + catch( const Exception& ) + { + // allowed + } + + return m_xIndexes.get(); +} + +// XRename +void SAL_CALL OTable::rename( const OUString& newName ) +{ + ::osl::MutexGuard aGuard(m_aMutex); + checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed); + + const OUString sOldComposedName = getName(); + const Reference< XDatabaseMetaData> xMetaData = getMetaData(); + if ( xMetaData.is() ) + ::dbtools::qualifiedNameComponents(xMetaData,newName,m_CatalogName,m_SchemaName,m_Name,::dbtools::EComposeRule::InDataManipulation); + else + m_Name = newName; + + m_pTables->renameObject(sOldComposedName,newName); +} + +Reference< XDatabaseMetaData> OTable::getMetaData() const +{ + return nullptr; +} + +// XAlterTable +void SAL_CALL OTable::alterColumnByName( const OUString& /*colName*/, const Reference< XPropertySet >& /*descriptor*/ ) +{ + throwFeatureNotImplementedSQLException( "XAlterTable::alterColumnByName", *this ); +} + +void SAL_CALL OTable::alterColumnByIndex( sal_Int32 /*index*/, const Reference< XPropertySet >& /*descriptor*/ ) +{ + throwFeatureNotImplementedSQLException( "XAlterTable::alterColumnByIndex", *this ); +} + +css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL OTable::getPropertySetInfo( ) +{ + return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper()); +} + +OUString SAL_CALL OTable::getName() +{ + // this is only correct for tables who haven't a schema or catalog name + OSL_ENSURE(m_CatalogName.isEmpty(),"getName(): forgot to override getName()!"); + OSL_ENSURE(m_SchemaName.isEmpty(),"getName(): forgot to override getName()!"); + return m_Name; +} + +void SAL_CALL OTable::setName( const OUString& /*aName*/ ) +{ +} + +void OTable::refreshColumns() +{ +} + +void OTable::refreshKeys() +{ +} + +void OTable::refreshIndexes() +{ +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/sdbcx/VUser.cxx b/connectivity/source/sdbcx/VUser.cxx new file mode 100644 index 000000000..9cecd7dfd --- /dev/null +++ b/connectivity/source/sdbcx/VUser.cxx @@ -0,0 +1,180 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + + +#include <sdbcx/VUser.hxx> +#include <connectivity/sdbcx/VCollection.hxx> +#include <connectivity/dbexception.hxx> +#include <comphelper/sequence.hxx> + + +using namespace connectivity; +using namespace connectivity::sdbcx; +using namespace ::com::sun::star::sdbc; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::container; +using namespace ::com::sun::star::lang; + +IMPLEMENT_SERVICE_INFO(OUser,"com.sun.star.sdbcx.VUser","com.sun.star.sdbcx.User"); + +OUser::OUser(bool _bCase) : OUser_BASE(m_aMutex) + , ODescriptor(OUser_BASE::rBHelper,_bCase,true) +{ +} + +OUser::OUser(const OUString& Name, bool _bCase) : OUser_BASE(m_aMutex) + ,ODescriptor(OUser_BASE::rBHelper,_bCase) +{ + m_Name = Name; +} + +OUser::~OUser( ) +{ +} + +void OUser::disposing() +{ + OPropertySetHelper::disposing(); + ::osl::MutexGuard aGuard(m_aMutex); + if(m_pGroups) + m_pGroups->disposing(); +} + +Any SAL_CALL OUser::queryInterface( const Type & rType ) +{ + Any aRet = ODescriptor::queryInterface( rType); + return aRet.hasValue() ? aRet : OUser_BASE::queryInterface( rType); +} + +Sequence< Type > SAL_CALL OUser::getTypes( ) +{ + return ::comphelper::concatSequences(ODescriptor::getTypes(),OUser_BASE::getTypes()); +} + +::cppu::IPropertyArrayHelper* OUser::createArrayHelper( ) const +{ + Sequence< Property > aProps; + describeProperties(aProps); + return new ::cppu::OPropertyArrayHelper(aProps); + +} + +::cppu::IPropertyArrayHelper & OUser::getInfoHelper() +{ + return *getArrayHelper(); +} + +// XUser +void SAL_CALL OUser::changePassword( const OUString& /*objPassword*/, const OUString& /*newPassword*/ ) +{ + ::osl::MutexGuard aGuard(m_aMutex); + checkDisposed(OUser_BASE::rBHelper.bDisposed); + ::dbtools::throwFeatureNotImplementedSQLException( "XUser::changePassword", *this ); +} + +// XGroupsSupplier +Reference< XNameAccess > SAL_CALL OUser::getGroups( ) +{ + ::osl::MutexGuard aGuard(m_aMutex); + checkDisposed(OUser_BASE::rBHelper.bDisposed); + + try + { + if ( !m_pGroups ) + refreshGroups(); + } + catch( const RuntimeException& ) + { + // allowed to leave this method + throw; + } + catch( const Exception& ) + { + // allowed + } + + return m_pGroups.get(); +} + + +SAL_WNOUNREACHABLE_CODE_PUSH + +sal_Int32 SAL_CALL OUser::getPrivileges( const OUString& /*objName*/, sal_Int32 /*objType*/ ) +{ + ::osl::MutexGuard aGuard(m_aMutex); + checkDisposed(OUser_BASE::rBHelper.bDisposed); + ::dbtools::throwFeatureNotImplementedSQLException( "XAuthorizable::changePassword", *this ); + return 0; +} + +sal_Int32 SAL_CALL OUser::getGrantablePrivileges( const OUString& /*objName*/, sal_Int32 /*objType*/ ) +{ + ::osl::MutexGuard aGuard(m_aMutex); + checkDisposed(OUser_BASE::rBHelper.bDisposed); + ::dbtools::throwFeatureNotImplementedSQLException( "XAuthorizable::getGrantablePrivileges", *this ); + return 0; +} + +SAL_WNOUNREACHABLE_CODE_POP + + +void SAL_CALL OUser::grantPrivileges( const OUString& /*objName*/, sal_Int32 /*objType*/, sal_Int32 /*objPrivileges*/ ) +{ + ::osl::MutexGuard aGuard(m_aMutex); + checkDisposed(OUser_BASE::rBHelper.bDisposed); + ::dbtools::throwFeatureNotImplementedSQLException( "XAuthorizable::grantPrivileges", *this ); +} + +void SAL_CALL OUser::revokePrivileges( const OUString& /*objName*/, sal_Int32 /*objType*/, sal_Int32 /*objPrivileges*/ ) +{ + ::osl::MutexGuard aGuard(m_aMutex); + checkDisposed(OUser_BASE::rBHelper.bDisposed); + ::dbtools::throwFeatureNotImplementedSQLException( "XAuthorizable::revokePrivileges", *this ); +} + +css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL OUser::getPropertySetInfo( ) +{ + return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper()); +} + +OUString SAL_CALL OUser::getName( ) +{ + return m_Name; +} + +void SAL_CALL OUser::setName( const OUString& /*aName*/ ) +{ + OSL_FAIL( "OUser::setName: not implemented!" ); + // not allowed to throw an SQLException here ... +} + +// XInterface +void SAL_CALL OUser::acquire() throw() +{ + OUser_BASE::acquire(); +} + +void SAL_CALL OUser::release() throw() +{ + OUser_BASE::release(); +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/sdbcx/VView.cxx b/connectivity/source/sdbcx/VView.cxx new file mode 100644 index 000000000..317e985b5 --- /dev/null +++ b/connectivity/source/sdbcx/VView.cxx @@ -0,0 +1,132 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <connectivity/sdbcx/VView.hxx> +#include <com/sun/star/beans/PropertyAttribute.hpp> +#include <comphelper/sequence.hxx> +#include <connectivity/dbtools.hxx> +#include <TConnection.hxx> + + +using namespace connectivity; +using namespace connectivity::sdbcx; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::sdbcx; +using namespace ::com::sun::star::container; +using namespace ::com::sun::star::lang; + +IMPLEMENT_SERVICE_INFO(OView,"com.sun.star.sdbcx.VView","com.sun.star.sdbcx.View"); + +OView::OView(bool _bCase, + const OUString& Name, + const css::uno::Reference< css::sdbc::XDatabaseMetaData >& _xMetaData, + const OUString& Command, + const OUString& SchemaName, + const OUString& CatalogName) : ODescriptor(::comphelper::OMutexAndBroadcastHelper::m_aBHelper,_bCase) + ,m_CatalogName(CatalogName) + ,m_SchemaName(SchemaName) + ,m_Command(Command) + ,m_CheckOption(0) + ,m_xMetaData(_xMetaData) + +{ + m_Name = Name; + construct(); +} + +OView::OView(bool _bCase, const css::uno::Reference< css::sdbc::XDatabaseMetaData >& _xMetaData) + : ODescriptor(::comphelper::OMutexAndBroadcastHelper::m_aBHelper, _bCase, true) + ,m_xMetaData(_xMetaData) +{ + construct(); +} + +OView::~OView() +{ +} + +void OView::construct() +{ + ODescriptor::construct(); + + sal_Int32 nAttrib = isNew() ? 0 : PropertyAttribute::READONLY; + + registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_CATALOGNAME), PROPERTY_ID_CATALOGNAME,nAttrib,&m_CatalogName, ::cppu::UnoType<OUString>::get()); + registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCHEMANAME), PROPERTY_ID_SCHEMANAME, nAttrib,&m_SchemaName, ::cppu::UnoType<OUString>::get()); + registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_COMMAND), PROPERTY_ID_COMMAND, nAttrib,&m_Command, ::cppu::UnoType<OUString>::get()); + registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_CHECKOPTION), PROPERTY_ID_CHECKOPTION,nAttrib,&m_CheckOption, ::cppu::UnoType<sal_Int32>::get()); +} + +Sequence< Type > SAL_CALL OView::getTypes( ) +{ + return ::comphelper::concatSequences(ODescriptor::getTypes(),OView_BASE::getTypes()); +} + +Any SAL_CALL OView::queryInterface( const Type & rType ) +{ + Any aRet = OView_BASE::queryInterface( rType); + return aRet.hasValue() ? aRet : ODescriptor::queryInterface( rType); +} + +::cppu::IPropertyArrayHelper* OView::createArrayHelper( sal_Int32 /*_nId*/ ) const +{ + return doCreateArrayHelper(); +} + +::cppu::IPropertyArrayHelper & OView::getInfoHelper() +{ + return *getArrayHelper(isNew() ? 1 : 0); +} + +OUString SAL_CALL OView::getName() +{ + OUString sComposedName; + if(m_xMetaData.is()) + sComposedName = ::dbtools::composeTableName( m_xMetaData, m_CatalogName, m_SchemaName, m_Name, false, ::dbtools::EComposeRule::InDataManipulation ); + else + { + Any aValue; + getFastPropertyValue(aValue,PROPERTY_ID_NAME); + aValue >>= sComposedName; + } + return sComposedName; +} + +css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL OView::getPropertySetInfo( ) +{ + return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper()); +} + +void SAL_CALL OView::setName( const OUString& ) +{ +} + +void SAL_CALL OView::acquire() throw() +{ + OView_BASE::acquire(); +} + +void SAL_CALL OView::release() throw() +{ + OView_BASE::release(); +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |