diff options
Diffstat (limited to 'connectivity/source/sdbcx')
-rw-r--r-- | connectivity/source/sdbcx/VCatalog.cxx | 241 | ||||
-rw-r--r-- | connectivity/source/sdbcx/VCollection.cxx | 603 | ||||
-rw-r--r-- | connectivity/source/sdbcx/VColumn.cxx | 229 | ||||
-rw-r--r-- | connectivity/source/sdbcx/VDescriptor.cxx | 155 | ||||
-rw-r--r-- | connectivity/source/sdbcx/VGroup.cxx | 183 | ||||
-rw-r--r-- | connectivity/source/sdbcx/VIndex.cxx | 223 | ||||
-rw-r--r-- | connectivity/source/sdbcx/VIndexColumn.cxx | 120 | ||||
-rw-r--r-- | connectivity/source/sdbcx/VKey.cxx | 228 | ||||
-rw-r--r-- | connectivity/source/sdbcx/VKeyColumn.cxx | 125 | ||||
-rw-r--r-- | connectivity/source/sdbcx/VTable.cxx | 336 | ||||
-rw-r--r-- | connectivity/source/sdbcx/VUser.cxx | 194 | ||||
-rw-r--r-- | connectivity/source/sdbcx/VView.cxx | 150 | ||||
-rw-r--r-- | connectivity/source/sdbcx/makefile.mk | 63 |
13 files changed, 2850 insertions, 0 deletions
diff --git a/connectivity/source/sdbcx/VCatalog.cxx b/connectivity/source/sdbcx/VCatalog.cxx new file mode 100644 index 000000000000..c9576d5b3d35 --- /dev/null +++ b/connectivity/source/sdbcx/VCatalog.cxx @@ -0,0 +1,241 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_connectivity.hxx" +#include "connectivity/sdbcx/VCatalog.hxx" +#include "connectivity/sdbcx/VCollection.hxx" +#include <com/sun/star/lang/DisposedException.hpp> +#include "connectivity/sdbcx/VCollection.hxx" +#include "connectivity/sdbcx/VDescriptor.hxx" +#include "TConnection.hxx" +#include <comphelper/uno3.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) + ,connectivity::OSubComponent<OCatalog, OCatalog_BASE>(_xConnection, this) + ,m_pTables(NULL) + ,m_pViews(NULL) + ,m_pGroups(NULL) + ,m_pUsers(NULL) +{ + try + { + m_xMetaData = _xConnection->getMetaData(); + } + catch(const Exception&) + { + OSL_ENSURE(0,"No Metadata available!"); + } +} +//----------------------------------------------------------------------------- +OCatalog::~OCatalog() +{ + delete m_pTables; + delete m_pViews; + delete m_pGroups; + delete m_pUsers; +} +//----------------------------------------------------------------------------- +void SAL_CALL OCatalog::acquire() throw() +{ + OCatalog_BASE::acquire(); +} +//------------------------------------------------------------------------------ +void SAL_CALL OCatalog::release() throw() +{ + relase_ChildImpl(); +} + +//------------------------------------------------------------------------------ +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(); + + dispose_ChildImpl(); + OCatalog_BASE::disposing(); +} +//------------------------------------------------------------------------------ +// XTablesSupplier +Reference< XNameAccess > SAL_CALL OCatalog::getTables( ) throw(RuntimeException) +{ + ::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 const_cast<OCatalog*>(this)->m_pTables; +} +// ------------------------------------------------------------------------- +// XViewsSupplier +Reference< XNameAccess > SAL_CALL OCatalog::getViews( ) throw(RuntimeException) +{ + ::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 const_cast<OCatalog*>(this)->m_pViews; +} +// ------------------------------------------------------------------------- +// XUsersSupplier +Reference< XNameAccess > SAL_CALL OCatalog::getUsers( ) throw(RuntimeException) +{ + ::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 const_cast<OCatalog*>(this)->m_pUsers; +} +// ------------------------------------------------------------------------- +// XGroupsSupplier +Reference< XNameAccess > SAL_CALL OCatalog::getGroups( ) throw(RuntimeException) +{ + ::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 const_cast<OCatalog*>(this)->m_pGroups; +} +// ----------------------------------------------------------------------------- +::rtl::OUString OCatalog::buildName(const Reference< XRow >& _xRow) +{ + ::rtl::OUString sCatalog = _xRow->getString(1); + if ( _xRow->wasNull() ) + sCatalog = ::rtl::OUString(); + ::rtl::OUString sSchema = _xRow->getString(2); + if ( _xRow->wasNull() ) + sSchema = ::rtl::OUString(); + ::rtl::OUString sTable = _xRow->getString(3); + if ( _xRow->wasNull() ) + sTable = ::rtl::OUString(); + + ::rtl::OUString sComposedName( + ::dbtools::composeTableName( m_xMetaData, sCatalog, sSchema, sTable, sal_False, ::dbtools::eInDataManipulation ) ); + return sComposedName; +} +// ----------------------------------------------------------------------------- +void OCatalog::fillNames(Reference< XResultSet >& _xResult,TStringVector& _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 : ::com::sun::star::beans::PropertyAttribute::READONLY; + registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME), PROPERTY_ID_NAME ,nAttrib,&m_Name,::getCppuType(reinterpret_cast< ::rtl::OUString*>(NULL))); +} +// ------------------------------------------------------------------------- +ODescriptor::~ODescriptor() +{ +} +// ----------------------------------------------------------------------------- + diff --git a/connectivity/source/sdbcx/VCollection.cxx b/connectivity/source/sdbcx/VCollection.cxx new file mode 100644 index 000000000000..46ecc3f134d7 --- /dev/null +++ b/connectivity/source/sdbcx/VCollection.cxx @@ -0,0 +1,603 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_connectivity.hxx" + +#include <algorithm> +#include <stdio.h> +#include "connectivity/sdbcx/VCollection.hxx" +#include "connectivity/sdbcx/VDescriptor.hxx" +#include "connectivity/dbexception.hxx" +#include <comphelper/enumhelper.hxx> +#include <comphelper/container.hxx> +#include <comphelper/types.hxx> +#include <comphelper/property.hxx> +#include "TConnection.hxx" +#include <rtl/ustrbuf.hxx> +#include "resource/common_res.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< ::rtl::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(sal_Bool _bCase) + : m_aNameMap(_bCase ? true : false) + { + } + virtual ~OHardRefMap() + { + } + + 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(); + } + // ----------------------------------------------------------------------------- + virtual void insert(const ::rtl::OUString& _sName,const ObjectType& _xObject) + { + m_aElements.push_back(m_aNameMap.insert(m_aNameMap.begin(), ObjectEntry(_sName,_xObject))); + } + // ----------------------------------------------------------------------------- + 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) + m_aElements.push_back(m_aNameMap.insert(m_aNameMap.begin(), ObjectEntry(*i,ObjectType()))); + } + // ----------------------------------------------------------------------------- + virtual bool rename(const ::rtl::OUString _sOldName,const ::rtl::OUString _sNewName) + { + 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() + { + return static_cast<sal_Int32>(m_aNameMap.size()); + } + // ----------------------------------------------------------------------------- + virtual Sequence< ::rtl::OUString > getElementNames() + { + Sequence< ::rtl::OUString > aNameList(m_aElements.size()); + + ::rtl::OUString* pStringArray = aNameList.getArray(); + 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) + *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; + } + // ----------------------------------------------------------------------------- + virtual ObjectType getObject(sal_Int32 _nIndex) + { + OSL_ENSURE(_nIndex >= 0 && _nIndex < static_cast<sal_Int32>(m_aElements.size()),"Illegal argument!"); + return m_aElements[_nIndex]->second; + } + // ----------------------------------------------------------------------------- + virtual ObjectType getObject(const ::rtl::OUString& columnName) + { + return m_aNameMap.find(columnName)->second; + } + // ----------------------------------------------------------------------------- + virtual void setObject(sal_Int32 _nIndex,const ObjectType& _xObject) + { + 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(); + } + // ----------------------------------------------------------------------------- + }; +} +// ----------------------------------------------------------------------------- + +IMPLEMENT_SERVICE_INFO(OCollection,"com.sun.star.sdbcx.VContainer" , "com.sun.star.sdbcx.Container") + +OCollection::OCollection(::cppu::OWeakObject& _rParent + , sal_Bool _bCase + , ::osl::Mutex& _rMutex + , const TStringVector &_rVector + , sal_Bool _bUseIndexOnly + , sal_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 ) 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(); + + ::std::vector<Type> aOwnTypes; + aOwnTypes.reserve(aTypes.getLength()); + Type aType = ::getCppuType(static_cast< Reference<XNameAccess> *>(NULL)); + for(;pBegin != pEnd; ++pBegin) + { + if ( *pBegin != aType ) + aOwnTypes.push_back(*pBegin); + } + Type* pTypes = aOwnTypes.empty() ? 0 : &aOwnTypes[0]; + return Sequence< Type >(pTypes,aOwnTypes.size()); + } + return OCollectionBase::getTypes( ); +} +// ------------------------------------------------------------------------- +void OCollection::clear_NoDispose() +{ + ::osl::MutexGuard aGuard(m_rMutex); + + m_pElements->clear(); + m_pElements->swapAll(); +} + +// ------------------------------------------------------------------------- +void OCollection::disposing(void) +{ + 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 ) throw(IndexOutOfBoundsException, WrappedTargetException, RuntimeException) +{ + ::osl::MutexGuard aGuard(m_rMutex); + if (Index < 0 || Index >= m_pElements->size() ) + throw IndexOutOfBoundsException(::rtl::OUString::valueOf(Index),static_cast<XTypeProvider*>(this)); + + return makeAny(getObject(Index)); +} +// ------------------------------------------------------------------------- +Any SAL_CALL OCollection::getByName( const ::rtl::OUString& aName ) throw(NoSuchElementException, WrappedTargetException, RuntimeException) +{ + ::osl::MutexGuard aGuard(m_rMutex); + + if ( !m_pElements->exists(aName) ) + { + ::connectivity::SharedResources aResources; + const ::rtl::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< ::rtl::OUString > SAL_CALL OCollection::getElementNames( ) throw(RuntimeException) +{ + ::osl::MutexGuard aGuard(m_rMutex); + return m_pElements->getElementNames(); +} +// ------------------------------------------------------------------------- +void SAL_CALL OCollection::refresh( ) throw(RuntimeException) +{ + ::osl::MutexGuard aGuard(m_rMutex); + + disposeElements(); + + impl_refresh(); + EventObject aEvt(static_cast<XTypeProvider*>(this)); + m_aRefreshListeners.notifyEach( &XRefreshListener::refreshed, aEvt ); +} +// ----------------------------------------------------------------------------- +void OCollection::reFill(const TStringVector &_rVector) +{ + m_pElements->reFill(_rVector); +} +// ------------------------------------------------------------------------- +// XDataDescriptorFactory +Reference< XPropertySet > SAL_CALL OCollection::createDataDescriptor( ) throw(RuntimeException) +{ + ::osl::MutexGuard aGuard(m_rMutex); + + return createDescriptor(); +} +// ----------------------------------------------------------------------------- +::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; +} +// ------------------------------------------------------------------------- +// XAppend +void SAL_CALL OCollection::appendByDescriptor( const Reference< XPropertySet >& descriptor ) throw(SQLException, ElementExistException, RuntimeException) +{ + ::osl::ClearableMutexGuard aGuard(m_rMutex); + + ::rtl::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 = ODescriptor::getImplementation( xNewlyCreated ); + if ( pDescriptor ) + pDescriptor->setNew( sal_False ); + + sName = getNameForObject( xNewlyCreated ); + if ( !m_pElements->exists( sName ) ) // this may happen when the drived 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 ::rtl::OUString& elementName ) throw(SQLException, NoSuchElementException, RuntimeException) +{ + ::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 ) throw(SQLException, IndexOutOfBoundsException, RuntimeException) +{ + ::osl::MutexGuard aGuard(m_rMutex); + if(index <0 || index >= getCount()) + throw IndexOutOfBoundsException(::rtl::OUString::valueOf(index),static_cast<XTypeProvider*>(this)); + + dropImpl(index); +} +// ----------------------------------------------------------------------------- +void OCollection::dropImpl(sal_Int32 _nIndex,sal_Bool _bReallyDrop) +{ + ::rtl::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 ::rtl::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 + OInterfaceIteratorHelper aListenerLoop(m_aContainerListeners); + while (aListenerLoop.hasMoreElements()) + static_cast<XContainerListener*>(aListenerLoop.next())->elementRemoved(aEvent); +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL OCollection::findColumn( const ::rtl::OUString& columnName ) throw(SQLException, RuntimeException) +{ + if ( !m_pElements->exists(columnName) ) + { + ::connectivity::SharedResources aResources; + const ::rtl::OUString sError( aResources.getResourceStringWithSubstitution( + STR_UNKNOWN_COLUMN_NAME, + "$columnname$", columnName + ) ); + ::dbtools::throwGenericSQLException(sError,static_cast< XIndexAccess*>(this)); + } + + return m_pElements->findColumn(columnName) + 1; // because columns start at one +} +// ------------------------------------------------------------------------- +Reference< XEnumeration > SAL_CALL OCollection::createEnumeration( ) throw(RuntimeException) +{ + ::osl::MutexGuard aGuard(m_rMutex); + return new OEnumerationByIndex( static_cast< XIndexAccess*>(this)); +} +// ----------------------------------------------------------------------------- +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); +} +// ----------------------------------------------------------------------------- +void SAL_CALL OCollection::acquire() throw() +{ + m_rParent.acquire(); +} +// ----------------------------------------------------------------------------- +void SAL_CALL OCollection::release() throw() +{ + m_rParent.release(); +} +// ----------------------------------------------------------------------------- +Type SAL_CALL OCollection::getElementType( ) throw(RuntimeException) +{ + return::getCppuType(static_cast< Reference< XPropertySet>*>(NULL)); +} +// ----------------------------------------------------------------------------- +sal_Bool SAL_CALL OCollection::hasElements( ) throw(RuntimeException) +{ + ::osl::MutexGuard aGuard(m_rMutex); + return !m_pElements->empty(); +} +// ----------------------------------------------------------------------------- +sal_Int32 SAL_CALL OCollection::getCount( ) throw(RuntimeException) +{ + ::osl::MutexGuard aGuard(m_rMutex); + return m_pElements->size(); +} +// ----------------------------------------------------------------------------- +sal_Bool SAL_CALL OCollection::hasByName( const ::rtl::OUString& aName ) throw(RuntimeException) +{ + ::osl::MutexGuard aGuard(m_rMutex); + return m_pElements->exists(aName); +} +// ----------------------------------------------------------------------------- +void SAL_CALL OCollection::addRefreshListener( const Reference< XRefreshListener >& l ) throw(RuntimeException) +{ + m_aRefreshListeners.addInterface(l); +} +// ----------------------------------------------------------------------------- +void SAL_CALL OCollection::removeRefreshListener( const Reference< XRefreshListener >& l ) throw(RuntimeException) +{ + m_aRefreshListeners.removeInterface(l); +} +// ----------------------------------------------------------------------------- +void OCollection::insertElement(const ::rtl::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 ::rtl::OUString _sOldName,const ::rtl::OUString _sNewName) +{ + OSL_ENSURE(m_pElements->exists(_sOldName),"Element doesn't exist"); + OSL_ENSURE(!m_pElements->exists(_sNewName),"Element already exists"); + OSL_ENSURE(_sNewName.getLength(),"New name must not be empty!"); + OSL_ENSURE(_sOldName.getLength(),"New 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 + OInterfaceIteratorHelper 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) + { + try + { + dropImpl(_nIndex,sal_False); + } + catch(const Exception& ) + { + } + throw WrappedTargetException(e.Message,static_cast<XTypeProvider*>(this),makeAny(e)); + } + m_pElements->setObject(_nIndex,xName); + } + return xName; +} +// ----------------------------------------------------------------------------- +void OCollection::disposeElements() +{ + m_pElements->disposeElements(); +} +// ----------------------------------------------------------------------------- +Reference< XPropertySet > OCollection::createDescriptor() +{ + OSL_ASSERT(!"Need to be overloaded when used!"); + throw SQLException(); +} +// ----------------------------------------------------------------------------- +ObjectType OCollection::cloneDescriptor( const ObjectType& _descriptor ) +{ + ObjectType xNewDescriptor( createDescriptor() ); + ::comphelper::copyProperties( _descriptor, xNewDescriptor ); + return xNewDescriptor; +} +// ----------------------------------------------------------------------------- +ObjectType OCollection::appendObject( const ::rtl::OUString& /*_rForName*/, const Reference< XPropertySet >& descriptor ) +{ + return cloneDescriptor( descriptor ); +} +// ----------------------------------------------------------------------------- +void OCollection::dropObject(sal_Int32 /*_nPos*/,const ::rtl::OUString /*_sElementName*/) +{ +} +// ----------------------------------------------------------------------------- diff --git a/connectivity/source/sdbcx/VColumn.cxx b/connectivity/source/sdbcx/VColumn.cxx new file mode 100644 index 000000000000..65bc1b368b1e --- /dev/null +++ b/connectivity/source/sdbcx/VColumn.cxx @@ -0,0 +1,229 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_connectivity.hxx" +#include "connectivity/sdbcx/VColumn.hxx" +#include <com/sun/star/lang/DisposedException.hpp> +#include <comphelper/sequence.hxx> +#include "TConnection.hxx" +#include <com/sun/star/sdbc/ColumnValue.hpp> +// ------------------------------------------------------------------------- +using namespace connectivity; +using namespace connectivity::sdbcx; +using namespace cppu; +using namespace connectivity; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::sdbc; + +// ----------------------------------------------------------------------------- +::rtl::OUString SAL_CALL OColumn::getImplementationName( ) throw (::com::sun::star::uno::RuntimeException) +{ + if(isNew()) + return ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.VColumnDescription"); + return ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.VColumn"); +} +// ----------------------------------------------------------------------------- +::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL OColumn::getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException) +{ + ::com::sun::star::uno::Sequence< ::rtl::OUString > aSupported(1); + if(isNew()) + aSupported[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.ColumnDescription"); + else + aSupported[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.Column"); + + return aSupported; +} +// ----------------------------------------------------------------------------- +sal_Bool SAL_CALL OColumn::supportsService( const ::rtl::OUString& _rServiceName ) throw(::com::sun::star::uno::RuntimeException) +{ + Sequence< ::rtl::OUString > aSupported(getSupportedServiceNames()); + const ::rtl::OUString* pSupported = aSupported.getConstArray(); + const ::rtl::OUString* pEnd = pSupported + aSupported.getLength(); + for (;pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported) + ; + + return pSupported != pEnd; +} +// ------------------------------------------------------------------------- +OColumn::OColumn(sal_Bool _bCase) + :OColumnDescriptor_BASE(m_aMutex) + ,ODescriptor(OColumnDescriptor_BASE::rBHelper,_bCase,sal_True) + ,m_IsNullable(ColumnValue::NULLABLE) + ,m_Precision(0) + ,m_Scale(0) + ,m_Type(0) + ,m_IsAutoIncrement(sal_False) + ,m_IsRowVersion(sal_False) + ,m_IsCurrency(sal_False) +{ + construct(); +} +// ------------------------------------------------------------------------- +OColumn::OColumn( const ::rtl::OUString& _Name, + const ::rtl::OUString& _TypeName, + const ::rtl::OUString& _DefaultValue, + const ::rtl::OUString& _Description, + sal_Int32 _IsNullable, + sal_Int32 _Precision, + sal_Int32 _Scale, + sal_Int32 _Type, + sal_Bool _IsAutoIncrement, + sal_Bool _IsRowVersion, + sal_Bool _IsCurrency, + sal_Bool _bCase) + :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_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 ) throw(RuntimeException) +{ + 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( ) throw(RuntimeException) +{ + 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, ::getCppuType(reinterpret_cast< ::rtl::OUString*>(NULL))); + registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DESCRIPTION), PROPERTY_ID_DESCRIPTION, nAttrib,&m_Description, ::getCppuType(reinterpret_cast< ::rtl::OUString*>(NULL))); + registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DEFAULTVALUE), PROPERTY_ID_DEFAULTVALUE, nAttrib,&m_DefaultValue, ::getCppuType(reinterpret_cast< ::rtl::OUString*>(NULL))); + registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PRECISION), PROPERTY_ID_PRECISION, nAttrib,&m_Precision, ::getCppuType(reinterpret_cast<sal_Int32*>(NULL))); + registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE), PROPERTY_ID_TYPE, nAttrib,&m_Type, ::getCppuType(reinterpret_cast<sal_Int32*>(NULL))); + registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE), PROPERTY_ID_SCALE, nAttrib,&m_Scale, ::getCppuType(reinterpret_cast<sal_Int32*>(NULL))); + registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISNULLABLE), PROPERTY_ID_ISNULLABLE, nAttrib,&m_IsNullable, ::getCppuType(reinterpret_cast<sal_Int32*>(NULL))); + registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISAUTOINCREMENT), PROPERTY_ID_ISAUTOINCREMENT, nAttrib,&m_IsAutoIncrement, ::getBooleanCppuType()); + registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISROWVERSION), PROPERTY_ID_ISROWVERSION, nAttrib,&m_IsRowVersion, ::getBooleanCppuType()); + registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISCURRENCY), PROPERTY_ID_ISCURRENCY, nAttrib,&m_IsCurrency, ::getBooleanCppuType()); +} +// ------------------------------------------------------------------------- +void OColumn::disposing(void) +{ + OPropertySetHelper::disposing(); + + ::osl::MutexGuard aGuard(m_aMutex); + checkDisposed(OColumnDescriptor_BASE::rBHelper.bDisposed); + +} +// ------------------------------------------------------------------------- +Reference< XPropertySet > SAL_CALL OColumn::createDataDescriptor( ) throw(RuntimeException) +{ + ::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()); + pNewColumn->setNew(sal_True); + return pNewColumn; +} +// ----------------------------------------------------------------------------- +::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL OColumn::getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException) +{ + return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper()); +} +// ----------------------------------------------------------------------------- +// XNamed +::rtl::OUString SAL_CALL OColumn::getName( ) throw(::com::sun::star::uno::RuntimeException) +{ + return m_Name; +} +// ----------------------------------------------------------------------------- +void SAL_CALL OColumn::setName( const ::rtl::OUString& aName ) throw(::com::sun::star::uno::RuntimeException) +{ + m_Name = aName; +} +// ----------------------------------------------------------------------------- + diff --git a/connectivity/source/sdbcx/VDescriptor.cxx b/connectivity/source/sdbcx/VDescriptor.cxx new file mode 100644 index 000000000000..539726339809 --- /dev/null +++ b/connectivity/source/sdbcx/VDescriptor.cxx @@ -0,0 +1,155 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_connectivity.hxx" +#include <connectivity/sdbcx/VDescriptor.hxx> +#include <cppuhelper/queryinterface.hxx> + +#include <functional> +#include <algorithm> + +namespace connectivity +{ + namespace 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,sal_Bool _bCase, sal_Bool _bNew) + :ODescriptor_PBASE(_rBHelper) + ,m_aCase(_bCase) + ,m_bNew(_bNew) + { + } + + // ------------------------------------------------------------------------- + // com::sun::star::lang::XUnoTunnel + sal_Int64 SAL_CALL ODescriptor::getSomething( const Sequence< sal_Int8 >& rId ) throw(RuntimeException) + { + return (rId.getLength() == 16 && 0 == rtl_compareMemory(getUnoTunnelImplementationId().getConstArray(), rId.getConstArray(), 16 ) ) + ? reinterpret_cast< sal_Int64 >( this ) + : 0; + } + + // ----------------------------------------------------------------------------- + ODescriptor* ODescriptor::getImplementation( const Reference< XInterface >& _rxSomeComp ) + { + Reference< XUnoTunnel > xTunnel( _rxSomeComp, UNO_QUERY ); + if ( xTunnel.is() ) + return reinterpret_cast< ODescriptor* >( xTunnel->getSomething( getUnoTunnelImplementationId() ) ); + return NULL; + } + + // ----------------------------------------------------------------------------- + namespace + { + struct ResetROAttribute : public ::std::unary_function< Property, void > + { + void operator ()( Property& _rProperty ) const + { + _rProperty.Attributes &= ~PropertyAttribute::READONLY; + } + }; + struct SetROAttribute : public ::std::unary_function< Property, void > + { + 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.getArray(), aProperties.getArray() + aProperties.getLength(), ResetROAttribute() ); + else + ::std::for_each( aProperties.getArray(), aProperties.getArray() + aProperties.getLength(), SetROAttribute() ); + + return new ::cppu::OPropertyArrayHelper( aProperties ); + } + + // ----------------------------------------------------------------------------- + sal_Bool ODescriptor::isNew( const Reference< XInterface >& _rxDescriptor ) + { + ODescriptor* pImplementation = getImplementation( _rxDescriptor ); + return pImplementation != NULL ? pImplementation->isNew() : sal_False; + } + + // ----------------------------------------------------------------------------- + Sequence< sal_Int8 > ODescriptor::getUnoTunnelImplementationId() + { + static ::cppu::OImplementationId * pId = 0; + if (! pId) + { + ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + if (! pId) + { + static ::cppu::OImplementationId aId; + pId = &aId; + } + } + return pId->getImplementationId(); + } + + // ----------------------------------------------------------------------------- + Any SAL_CALL ODescriptor::queryInterface( const Type & rType ) throw(RuntimeException) + { + Any aRet = ::cppu::queryInterface(rType,static_cast< XUnoTunnel*> (this)); + return aRet.hasValue() ? aRet : ODescriptor_PBASE::queryInterface(rType); + } + + // ----------------------------------------------------------------------------- + void ODescriptor::setNew(sal_Bool _bNew) + { + m_bNew = _bNew; + } + + // ----------------------------------------------------------------------------- + Sequence< Type > SAL_CALL ODescriptor::getTypes( ) throw(RuntimeException) + { + ::cppu::OTypeCollection aTypes( ::getCppuType( (const Reference< XMultiPropertySet > *)0 ), + ::getCppuType( (const Reference< XFastPropertySet > *)0 ), + ::getCppuType( (const Reference< XPropertySet > *)0 ), + ::getCppuType( (const Reference< XUnoTunnel > *)0 )); + return aTypes.getTypes(); + } + + } +} + + diff --git a/connectivity/source/sdbcx/VGroup.cxx b/connectivity/source/sdbcx/VGroup.cxx new file mode 100644 index 000000000000..bb8d49bb7499 --- /dev/null +++ b/connectivity/source/sdbcx/VGroup.cxx @@ -0,0 +1,183 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_connectivity.hxx" + +#include <stdio.h> +#include "connectivity/sdbcx/VGroup.hxx" +#include <com/sun/star/lang/DisposedException.hpp> +#include <com/sun/star/sdbcx/Privilege.hpp> +#include <com/sun/star/sdbcx/PrivilegeObject.hpp> +#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(sal_Bool _bCase) : OGroup_BASE(m_aMutex) + , ODescriptor(OGroup_BASE::rBHelper,_bCase) + , m_pUsers(NULL) +{ +} +// ------------------------------------------------------------------------- +OGroup::OGroup(const ::rtl::OUString& _Name,sal_Bool _bCase) : OGroup_BASE(m_aMutex) + ,ODescriptor(OGroup_BASE::rBHelper,_bCase) + ,m_pUsers(NULL) +{ + m_Name = _Name; +} +// ------------------------------------------------------------------------- +OGroup::~OGroup() +{ + delete m_pUsers; +} +// ------------------------------------------------------------------------- +Any SAL_CALL OGroup::queryInterface( const Type & rType ) throw(RuntimeException) +{ + Any aRet = ODescriptor::queryInterface( rType); + return aRet.hasValue() ? aRet : OGroup_BASE::queryInterface( rType); +} +// ------------------------------------------------------------------------- +Sequence< Type > SAL_CALL OGroup::getTypes( ) throw(RuntimeException) +{ + return ::comphelper::concatSequences(ODescriptor::getTypes(),OGroup_BASE::getTypes()); +} +// ------------------------------------------------------------------------- +void OGroup::disposing(void) +{ + 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 *const_cast<OGroup*>(this)->getArrayHelper(); +} +// ------------------------------------------------------------------------- +Reference< XNameAccess > SAL_CALL OGroup::getUsers( ) throw(RuntimeException) +{ + ::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 const_cast<OGroup*>(this)->m_pUsers; +} +// ------------------------------------------------------------------------- + +sal_Int32 SAL_CALL OGroup::getPrivileges( const ::rtl::OUString& /*objName*/, sal_Int32 /*objType*/ ) throw(::com::sun::star::sdbc::SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard(m_aMutex); + checkDisposed(OGroup_BASE::rBHelper.bDisposed); + + return 0; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL OGroup::getGrantablePrivileges( const ::rtl::OUString& /*objName*/, sal_Int32 /*objType*/ ) throw(::com::sun::star::sdbc::SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard(m_aMutex); + checkDisposed(OGroup_BASE::rBHelper.bDisposed); + + return 0; +} +// ------------------------------------------------------------------------- +void SAL_CALL OGroup::grantPrivileges( const ::rtl::OUString& /*objName*/, sal_Int32 /*objType*/, sal_Int32 /*objPrivileges*/ ) throw(::com::sun::star::sdbc::SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard(m_aMutex); + checkDisposed(OGroup_BASE::rBHelper.bDisposed); + throwFeatureNotImplementedException( "XAuthorizable::grantPrivileges", *this ); +} +// ------------------------------------------------------------------------- +void SAL_CALL OGroup::revokePrivileges( const ::rtl::OUString& /*objName*/, sal_Int32 /*objType*/, sal_Int32 /*objPrivileges*/ ) throw(::com::sun::star::sdbc::SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard(m_aMutex); + checkDisposed(OGroup_BASE::rBHelper.bDisposed); + throwFeatureNotImplementedException( "XAuthorizable::revokePrivileges", *this ); +} +// ----------------------------------------------------------------------------- +::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL OGroup::getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException) +{ + return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper()); +} +// ----------------------------------------------------------------------------- +::rtl::OUString SAL_CALL OGroup::getName( ) throw(::com::sun::star::uno::RuntimeException) +{ + return m_Name; +} +// ----------------------------------------------------------------------------- +void SAL_CALL OGroup::setName( const ::rtl::OUString& /*aName*/ ) throw(::com::sun::star::uno::RuntimeException) +{ + throwFeatureNotImplementedException( "XNamed::setName", *this ); +} +// ----------------------------------------------------------------------------- +// XInterface +void SAL_CALL OGroup::acquire() throw() +{ + OGroup_BASE::acquire(); +} +// ----------------------------------------------------------------------------- +void SAL_CALL OGroup::release() throw() +{ + OGroup_BASE::release(); +} +// ----------------------------------------------------------------------------- + + diff --git a/connectivity/source/sdbcx/VIndex.cxx b/connectivity/source/sdbcx/VIndex.cxx new file mode 100644 index 000000000000..a9ae6eaa1538 --- /dev/null +++ b/connectivity/source/sdbcx/VIndex.cxx @@ -0,0 +1,223 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_connectivity.hxx" +#include "connectivity/sdbcx/VIndex.hxx" +#include <com/sun/star/lang/DisposedException.hpp> +#include "connectivity/sdbcx/VColumn.hxx" +#include <connectivity/dbexception.hxx> +#include <comphelper/sequence.hxx> +#include "connectivity/sdbcx/VCollection.hxx" +#include "TConnection.hxx" +// ------------------------------------------------------------------------- +using namespace ::connectivity; +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; + +// ----------------------------------------------------------------------------- +::rtl::OUString SAL_CALL OIndex::getImplementationName( ) throw (::com::sun::star::uno::RuntimeException) +{ + if(isNew()) + return ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.VIndexDescriptor"); + return ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.VIndex"); +} +// ----------------------------------------------------------------------------- +::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL OIndex::getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException) +{ + ::com::sun::star::uno::Sequence< ::rtl::OUString > aSupported(1); + if(isNew()) + aSupported[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.IndexDescriptor"); + else + aSupported[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.Index"); + + return aSupported; +} +// ----------------------------------------------------------------------------- +sal_Bool SAL_CALL OIndex::supportsService( const ::rtl::OUString& _rServiceName ) throw(::com::sun::star::uno::RuntimeException) +{ + Sequence< ::rtl::OUString > aSupported(getSupportedServiceNames()); + const ::rtl::OUString* pSupported = aSupported.getConstArray(); + const ::rtl::OUString* pEnd = pSupported + aSupported.getLength(); + for (;pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported) + ; + + return pSupported != pEnd; +} +// ------------------------------------------------------------------------- +OIndex::OIndex(sal_Bool _bCase) : ODescriptor_BASE(m_aMutex) + , ODescriptor(ODescriptor_BASE::rBHelper,_bCase,sal_True) + ,m_IsUnique(sal_False) + ,m_IsPrimaryKeyIndex(sal_False) + ,m_IsClustered(sal_False) + ,m_pColumns(NULL) +{ +} +// ------------------------------------------------------------------------- +OIndex::OIndex( const ::rtl::OUString& _Name, + const ::rtl::OUString& _Catalog, + sal_Bool _isUnique, + sal_Bool _isPrimaryKeyIndex, + sal_Bool _isClustered, + sal_Bool _bCase) : ODescriptor_BASE(m_aMutex) + ,ODescriptor(ODescriptor_BASE::rBHelper,_bCase) + ,m_Catalog(_Catalog) + ,m_IsUnique(_isUnique) + ,m_IsPrimaryKeyIndex(_isPrimaryKeyIndex) + ,m_IsClustered(_isClustered) + ,m_pColumns(NULL) +{ + m_Name = _Name; +} +// ------------------------------------------------------------------------- +OIndex::~OIndex( ) +{ + delete m_pColumns; +} +// ----------------------------------------------------------------------------- +::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 ) throw(RuntimeException) +{ + 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( ) throw(RuntimeException) +{ + 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, ::getCppuType(reinterpret_cast< ::rtl::OUString*>(NULL))); + registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISUNIQUE), PROPERTY_ID_ISUNIQUE, nAttrib,&m_IsUnique, ::getBooleanCppuType()); + registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISPRIMARYKEYINDEX),PROPERTY_ID_ISPRIMARYKEYINDEX, nAttrib,&m_IsPrimaryKeyIndex, ::getBooleanCppuType()); + registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISCLUSTERED), PROPERTY_ID_ISCLUSTERED, nAttrib,&m_IsClustered, ::getBooleanCppuType()); +} +// ------------------------------------------------------------------------- +void OIndex::disposing(void) +{ + OPropertySetHelper::disposing(); + + ::osl::MutexGuard aGuard(m_aMutex); + + if(m_pColumns) + m_pColumns->disposing(); +} +// ------------------------------------------------------------------------- +Reference< ::com::sun::star::container::XNameAccess > SAL_CALL OIndex::getColumns( ) throw(RuntimeException) +{ + ::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& ) + { + OSL_ENSURE( false, "OIndex::getColumns: caught an exception!" ); + } + + return const_cast<OIndex*>(this)->m_pColumns; +} +// ------------------------------------------------------------------------- +Reference< XPropertySet > SAL_CALL OIndex::createDataDescriptor( ) throw(RuntimeException) +{ + ::osl::MutexGuard aGuard(m_aMutex); + checkDisposed(ODescriptor_BASE::rBHelper.bDisposed); + + + return this; +} +// ----------------------------------------------------------------------------- +::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL OIndex::getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException) +{ + return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper()); +} +// ----------------------------------------------------------------------------- +::rtl::OUString SAL_CALL OIndex::getName( ) throw(::com::sun::star::uno::RuntimeException) +{ + return m_Name; +} +// ----------------------------------------------------------------------------- +void SAL_CALL OIndex::setName( const ::rtl::OUString& /*aName*/ ) throw(::com::sun::star::uno::RuntimeException) +{ +} +// ----------------------------------------------------------------------------- +// XInterface +void SAL_CALL OIndex::acquire() throw() +{ + ODescriptor_BASE::acquire(); +} +// ----------------------------------------------------------------------------- +void SAL_CALL OIndex::release() throw() +{ + ODescriptor_BASE::release(); +} +// ----------------------------------------------------------------------------- +void OIndex::refreshColumns() +{ +} +// ----------------------------------------------------------------------------- + diff --git a/connectivity/source/sdbcx/VIndexColumn.cxx b/connectivity/source/sdbcx/VIndexColumn.cxx new file mode 100644 index 000000000000..ca1649b06384 --- /dev/null +++ b/connectivity/source/sdbcx/VIndexColumn.cxx @@ -0,0 +1,120 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_connectivity.hxx" +#include "connectivity/sdbcx/VIndexColumn.hxx" +#include "TConnection.hxx" + +using namespace connectivity; +using namespace connectivity::sdbcx; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::uno; +// ----------------------------------------------------------------------------- +::rtl::OUString SAL_CALL OIndexColumn::getImplementationName( ) throw (::com::sun::star::uno::RuntimeException) +{ + if(isNew()) + return ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.VIndexColumnDescription"); + return ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.VIndex"); +} +// ----------------------------------------------------------------------------- +::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL OIndexColumn::getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException) +{ + ::com::sun::star::uno::Sequence< ::rtl::OUString > aSupported(1); + if(isNew()) + aSupported[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.IndexDescription"); + else + aSupported[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.Index"); + + return aSupported; +} +// ----------------------------------------------------------------------------- +sal_Bool SAL_CALL OIndexColumn::supportsService( const ::rtl::OUString& _rServiceName ) throw(::com::sun::star::uno::RuntimeException) +{ + Sequence< ::rtl::OUString > aSupported(getSupportedServiceNames()); + const ::rtl::OUString* pSupported = aSupported.getConstArray(); + const ::rtl::OUString* pEnd = pSupported + aSupported.getLength(); + for (;pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported) + ; + + return pSupported != pEnd; +} +// ----------------------------------------------------------------------------- +OIndexColumn::OIndexColumn(sal_Bool _bCase) : OColumn(_bCase), m_IsAscending(sal_True) +{ + construct(); +} + +// ------------------------------------------------------------------------- +OIndexColumn::OIndexColumn( sal_Bool _IsAscending, + const ::rtl::OUString& _Name, + const ::rtl::OUString& _TypeName, + const ::rtl::OUString& _DefaultValue, + sal_Int32 _IsNullable, + sal_Int32 _Precision, + sal_Int32 _Scale, + sal_Int32 _Type, + sal_Bool _IsAutoIncrement, + sal_Bool _IsRowVersion, + sal_Bool _IsCurrency, + sal_Bool _bCase + ) : OColumn(_Name, + _TypeName, + _DefaultValue, + ::rtl::OUString(), + _IsNullable, + _Precision, + _Scale, + _Type, + _IsAutoIncrement, + _IsRowVersion, + _IsCurrency, + _bCase) + , 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, ::getBooleanCppuType()); +} +// ----------------------------------------------------------------------------- + + + diff --git a/connectivity/source/sdbcx/VKey.cxx b/connectivity/source/sdbcx/VKey.cxx new file mode 100644 index 000000000000..b73d8721f88e --- /dev/null +++ b/connectivity/source/sdbcx/VKey.cxx @@ -0,0 +1,228 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_connectivity.hxx" + + +#include "connectivity/sdbcx/VKey.hxx" +#include <com/sun/star/lang/DisposedException.hpp> +#include <com/sun/star/sdbc/KeyRule.hpp> +#include <comphelper/sequence.hxx> +#include "connectivity/sdbcx/VColumn.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; + +// ----------------------------------------------------------------------------- +::rtl::OUString SAL_CALL OKey::getImplementationName( ) throw (::com::sun::star::uno::RuntimeException) +{ + if(isNew()) + return ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.VKeyDescription"); + return ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.VKey"); +} +// ----------------------------------------------------------------------------- +::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL OKey::getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException) +{ + ::com::sun::star::uno::Sequence< ::rtl::OUString > aSupported(1); + if(isNew()) + aSupported[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.KeyDescription"); + else + aSupported[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.Key"); + + return aSupported; +} +// ----------------------------------------------------------------------------- +sal_Bool SAL_CALL OKey::supportsService( const ::rtl::OUString& _rServiceName ) throw(::com::sun::star::uno::RuntimeException) +{ + Sequence< ::rtl::OUString > aSupported(getSupportedServiceNames()); + const ::rtl::OUString* pSupported = aSupported.getConstArray(); + const ::rtl::OUString* pEnd = pSupported + aSupported.getLength(); + for (;pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported) + ; + + return pSupported != pEnd; +} +// ------------------------------------------------------------------------- +OKey::OKey(sal_Bool _bCase) : ODescriptor_BASE(m_aMutex) + , ODescriptor(ODescriptor_BASE::rBHelper,_bCase,sal_True) + , m_aProps(new KeyProperties()) + , m_pColumns(NULL) +{ +} +// ------------------------------------------------------------------------- +OKey::OKey(const ::rtl::OUString& _Name,const TKeyProperties& _rProps,sal_Bool _bCase) +: ODescriptor_BASE(m_aMutex) + ,ODescriptor(ODescriptor_BASE::rBHelper,_bCase) + ,m_aProps(_rProps) + ,m_pColumns(NULL) +{ + m_Name = _Name; +} +//OKey::OKey( const ::rtl::OUString& _Name, +// const ::rtl::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( ) +{ + delete m_pColumns; +} +// ------------------------------------------------------------------------- +Any SAL_CALL OKey::queryInterface( const Type & rType ) throw(RuntimeException) +{ + 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( ) throw(RuntimeException) +{ + 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, ::getCppuType(reinterpret_cast< ::rtl::OUString*>(NULL))); + registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE), PROPERTY_ID_TYPE, nAttrib,&m_aProps->m_Type, ::getCppuType(reinterpret_cast<sal_Int32*>(NULL))); + registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_UPDATERULE), PROPERTY_ID_UPDATERULE, nAttrib,&m_aProps->m_UpdateRule, ::getCppuType(reinterpret_cast<sal_Int32*>(NULL))); + registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DELETERULE), PROPERTY_ID_DELETERULE, nAttrib,&m_aProps->m_DeleteRule, ::getCppuType(reinterpret_cast<sal_Int32*>(NULL))); +} +// ------------------------------------------------------------------------- +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 *const_cast<OKey*>(this)->getArrayHelper(isNew() ? 1 : 0); +} +// ------------------------------------------------------------------------- +Reference< ::com::sun::star::container::XNameAccess > SAL_CALL OKey::getColumns( ) throw(RuntimeException) +{ + ::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 const_cast<OKey*>(this)->m_pColumns; +} +// ------------------------------------------------------------------------- +Reference< XPropertySet > SAL_CALL OKey::createDataDescriptor( ) throw(RuntimeException) +{ + ::osl::MutexGuard aGuard(m_aMutex); + checkDisposed(ODescriptor_BASE::rBHelper.bDisposed); + + + return this; +} +// ----------------------------------------------------------------------------- +::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL OKey::getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException) +{ + return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper()); +} +// ----------------------------------------------------------------------------- +::rtl::OUString SAL_CALL OKey::getName( ) throw(::com::sun::star::uno::RuntimeException) +{ + return m_Name; +} +// ----------------------------------------------------------------------------- +void SAL_CALL OKey::setName( const ::rtl::OUString& /*aName*/ ) throw(::com::sun::star::uno::RuntimeException) +{ +} +// ----------------------------------------------------------------------------- +// XInterface +void SAL_CALL OKey::acquire() throw() +{ + ODescriptor_BASE::acquire(); +} +// ----------------------------------------------------------------------------- +void SAL_CALL OKey::release() throw() +{ + ODescriptor_BASE::release(); +} +// ----------------------------------------------------------------------------- + diff --git a/connectivity/source/sdbcx/VKeyColumn.cxx b/connectivity/source/sdbcx/VKeyColumn.cxx new file mode 100644 index 000000000000..97e83f5c633a --- /dev/null +++ b/connectivity/source/sdbcx/VKeyColumn.cxx @@ -0,0 +1,125 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_connectivity.hxx" +#include "connectivity/sdbcx/VKeyColumn.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; +// ----------------------------------------------------------------------------- +::rtl::OUString SAL_CALL OKeyColumn::getImplementationName( ) throw (::com::sun::star::uno::RuntimeException) +{ + if(isNew()) + return ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.VKeyColumnDescription"); + return ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.VKeyColumn"); +} +// ----------------------------------------------------------------------------- +::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL OKeyColumn::getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException) +{ + ::com::sun::star::uno::Sequence< ::rtl::OUString > aSupported(1); + if(isNew()) + aSupported[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.KeyColumnDescription"); + else + aSupported[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.KeyColumn"); + + return aSupported; +} +// ----------------------------------------------------------------------------- +sal_Bool SAL_CALL OKeyColumn::supportsService( const ::rtl::OUString& _rServiceName ) throw(::com::sun::star::uno::RuntimeException) +{ + Sequence< ::rtl::OUString > aSupported(getSupportedServiceNames()); + const ::rtl::OUString* pSupported = aSupported.getConstArray(); + const ::rtl::OUString* pEnd = pSupported + aSupported.getLength(); + for (;pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported) + ; + + return pSupported != pEnd; +} +// ------------------------------------------------------------------------- +OKeyColumn::OKeyColumn(sal_Bool _bCase) : OColumn(_bCase) +{ + construct(); +} +// ------------------------------------------------------------------------- +OKeyColumn::OKeyColumn( const ::rtl::OUString& _ReferencedColumn, + const ::rtl::OUString& _Name, + const ::rtl::OUString& _TypeName, + const ::rtl::OUString& _DefaultValue, + sal_Int32 _IsNullable, + sal_Int32 _Precision, + sal_Int32 _Scale, + sal_Int32 _Type, + sal_Bool _IsAutoIncrement, + sal_Bool _IsRowVersion, + sal_Bool _IsCurrency, + sal_Bool _bCase + ) : OColumn(_Name, + _TypeName, + _DefaultValue, + ::rtl::OUString(), + _IsNullable, + _Precision, + _Scale, + _Type, + _IsAutoIncrement, + _IsRowVersion, + _IsCurrency, + _bCase) + , 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, ::getCppuType(reinterpret_cast< ::rtl::OUString*>(NULL))); +} +// ----------------------------------------------------------------------------- + + + + diff --git a/connectivity/source/sdbcx/VTable.cxx b/connectivity/source/sdbcx/VTable.cxx new file mode 100644 index 000000000000..743980a345ce --- /dev/null +++ b/connectivity/source/sdbcx/VTable.cxx @@ -0,0 +1,336 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_connectivity.hxx" +#include "connectivity/sdbcx/VTable.hxx" +#include <com/sun/star/lang/DisposedException.hpp> +#include "connectivity/sdbcx/VIndex.hxx" +#include <comphelper/sequence.hxx> +#include "connectivity/sdbcx/VCollection.hxx" +#include "TConnection.hxx" +#include "connectivity/sdbcx/VColumn.hxx" +#include "connectivity/sdbcx/VKey.hxx" +#include "connectivity/dbtools.hxx" +#include <connectivity/dbexception.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; + +// ----------------------------------------------------------------------------- +::rtl::OUString SAL_CALL OTable::getImplementationName( ) throw (::com::sun::star::uno::RuntimeException) +{ + if(isNew()) + return ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.VTableDescriptor"); + return ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.Table"); +} + +// ----------------------------------------------------------------------------- +::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL OTable::getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException) +{ + ::com::sun::star::uno::Sequence< ::rtl::OUString > aSupported(1); + if(isNew()) + aSupported[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.TableDescriptor"); + else + aSupported[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.Table"); + + return aSupported; +} +// ----------------------------------------------------------------------------- +sal_Bool SAL_CALL OTable::supportsService( const ::rtl::OUString& _rServiceName ) throw(::com::sun::star::uno::RuntimeException) +{ + Sequence< ::rtl::OUString > aSupported(getSupportedServiceNames()); + const ::rtl::OUString* pSupported = aSupported.getConstArray(); + const ::rtl::OUString* pEnd = pSupported + aSupported.getLength(); + for (;pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported) + ; + + return pSupported != pEnd; +} +// ------------------------------------------------------------------------- +OTable::OTable(OCollection* _pTables, + sal_Bool _bCase) + : OTableDescriptor_BASE(m_aMutex) + ,ODescriptor(OTableDescriptor_BASE::rBHelper,_bCase,sal_True) + ,m_pKeys(NULL) + ,m_pColumns(NULL) + ,m_pIndexes(NULL) + ,m_pTables(_pTables) +{ +} +// ----------------------------------------------------------------------------- +OTable::OTable( OCollection* _pTables, + sal_Bool _bCase, + const ::rtl::OUString& _Name, const ::rtl::OUString& _Type, + const ::rtl::OUString& _Description,const ::rtl::OUString& _SchemaName, + const ::rtl::OUString& _CatalogName) : OTableDescriptor_BASE(m_aMutex) + ,ODescriptor(OTableDescriptor_BASE::rBHelper,_bCase) + ,m_CatalogName(_CatalogName) + ,m_SchemaName(_SchemaName) + ,m_Description(_Description) + ,m_Type(_Type) + ,m_pKeys(NULL) + ,m_pColumns(NULL) + ,m_pIndexes(NULL) + ,m_pTables(_pTables) +{ + m_Name = _Name; +} +// ------------------------------------------------------------------------- +OTable::~OTable() +{ + delete m_pKeys; + delete m_pColumns; + delete m_pIndexes; +} +// ------------------------------------------------------------------------- +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, ::getCppuType(reinterpret_cast< ::rtl::OUString*>(NULL))); + registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCHEMANAME), PROPERTY_ID_SCHEMANAME, nAttrib,&m_SchemaName, ::getCppuType(reinterpret_cast< ::rtl::OUString*>(NULL))); + registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DESCRIPTION), PROPERTY_ID_DESCRIPTION,nAttrib,&m_Description, ::getCppuType(reinterpret_cast< ::rtl::OUString*>(NULL))); + registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE), PROPERTY_ID_TYPE, nAttrib,&m_Type, ::getCppuType(reinterpret_cast< ::rtl::OUString*>(NULL))); +} +// ----------------------------------------------------------------------------- +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 ) throw(RuntimeException) +{ + Any aRet = ODescriptor::queryInterface( rType); + if(!aRet.hasValue()) + { + if(!isNew()) + aRet = OTable_BASE::queryInterface( rType); + if(isNew() && (rType == getCppuType( (Reference<XIndexesSupplier>*)0))) + return Any(); + if(!aRet.hasValue()) + aRet = OTableDescriptor_BASE::queryInterface( rType); + } + return aRet; +} +// ------------------------------------------------------------------------- +Sequence< Type > SAL_CALL OTable::getTypes( ) throw(RuntimeException) +{ + 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(void) +{ + ODescriptor::disposing(); + + ::osl::MutexGuard aGuard(m_aMutex); + + if(m_pKeys) + m_pKeys->disposing(); + if(m_pColumns) + m_pColumns->disposing(); + if(m_pIndexes) + m_pIndexes->disposing(); + + m_pTables = NULL; +} +// ----------------------------------------------------------------------------- +// XColumnsSupplier +Reference< XNameAccess > SAL_CALL OTable::getColumns( ) throw(RuntimeException) +{ + ::osl::MutexGuard aGuard(m_aMutex); + checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed); + + try + { + if ( !m_pColumns ) + refreshColumns(); + } + catch( const RuntimeException& ) + { + // allowed to leave this method + throw; + } + catch( const Exception& ) + { + // allowed + } + + return m_pColumns; +} + +// ------------------------------------------------------------------------- +// XKeysSupplier +Reference< XIndexAccess > SAL_CALL OTable::getKeys( ) throw(RuntimeException) +{ + ::osl::MutexGuard aGuard(m_aMutex); + checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed); + + Reference< XIndexAccess > xKeys; + + try + { + if ( !m_pKeys ) + refreshKeys(); + xKeys = m_pKeys; + } + 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 *const_cast<OTable*>(this)->getArrayHelper(isNew() ? 1 : 0); +} +// ------------------------------------------------------------------------- +Reference< XPropertySet > SAL_CALL OTable::createDataDescriptor( ) throw(RuntimeException) +{ + ::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(sal_True); + return pTable; +} +// ------------------------------------------------------------------------- +// XIndexesSupplier +Reference< XNameAccess > SAL_CALL OTable::getIndexes( ) throw(RuntimeException) +{ + ::osl::MutexGuard aGuard(m_aMutex); + checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed); + + try + { + if ( !m_pIndexes ) + refreshIndexes(); + } + catch( const RuntimeException& ) + { + // allowed to leave this method + throw; + } + catch( const Exception& ) + { + // allowed + } + + return m_pIndexes; +} +// ------------------------------------------------------------------------- +// XRename +void SAL_CALL OTable::rename( const ::rtl::OUString& newName ) throw(SQLException, ElementExistException, RuntimeException) +{ + ::osl::MutexGuard aGuard(m_aMutex); + checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed); + + const ::rtl::OUString sOldComposedName = getName(); + const Reference< XDatabaseMetaData> xMetaData = getMetaData(); + if ( xMetaData.is() ) + ::dbtools::qualifiedNameComponents(xMetaData,newName,m_CatalogName,m_SchemaName,m_Name,::dbtools::eInDataManipulation); + else + m_Name = newName; + + m_pTables->renameObject(sOldComposedName,newName); +} +// ----------------------------------------------------------------------------- +Reference< XDatabaseMetaData> OTable::getMetaData() const +{ + return NULL; +} +// ------------------------------------------------------------------------- +// XAlterTable +void SAL_CALL OTable::alterColumnByName( const ::rtl::OUString& /*colName*/, const Reference< XPropertySet >& /*descriptor*/ ) throw(SQLException, NoSuchElementException, RuntimeException) +{ + throwFeatureNotImplementedException( "XAlterTable::alterColumnByName", *this ); +} +// ------------------------------------------------------------------------- +void SAL_CALL OTable::alterColumnByIndex( sal_Int32 /*index*/, const Reference< XPropertySet >& /*descriptor*/ ) throw(SQLException, ::com::sun::star::lang::IndexOutOfBoundsException, RuntimeException) +{ + throwFeatureNotImplementedException( "XAlterTable::alterColumnByIndex", *this ); +} +// ------------------------------------------------------------------------- +::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL OTable::getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException) +{ + return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper()); +} +// ----------------------------------------------------------------------------- +::rtl::OUString SAL_CALL OTable::getName() throw(::com::sun::star::uno::RuntimeException) +{ + // this is only correct for tables who haven't a schema or catalog name + OSL_ENSURE(!m_CatalogName.getLength(),"getName(): forgot to overload getName()!"); + OSL_ENSURE(!m_SchemaName.getLength(),"getName(): forgot to overload getName()!"); + return m_Name; +} +// ----------------------------------------------------------------------------- +void SAL_CALL OTable::setName( const ::rtl::OUString& /*aName*/ ) throw(::com::sun::star::uno::RuntimeException) +{ +} +// ----------------------------------------------------------------------------- +void OTable::refreshColumns() +{ +} +// ----------------------------------------------------------------------------- +void OTable::refreshKeys() +{ +} +// ----------------------------------------------------------------------------- +void OTable::refreshIndexes() +{ +} +// ----------------------------------------------------------------------------- diff --git a/connectivity/source/sdbcx/VUser.cxx b/connectivity/source/sdbcx/VUser.cxx new file mode 100644 index 000000000000..ee05eb1b2139 --- /dev/null +++ b/connectivity/source/sdbcx/VUser.cxx @@ -0,0 +1,194 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_connectivity.hxx" + +#include <stdio.h> +#include "connectivity/sdbcx/VUser.hxx" +#include <com/sun/star/lang/DisposedException.hpp> +#include <com/sun/star/sdbcx/Privilege.hpp> +#include <com/sun/star/sdbcx/PrivilegeObject.hpp> +#include "TConnection.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(sal_Bool _bCase) : OUser_BASE(m_aMutex) + , ODescriptor(OUser_BASE::rBHelper,_bCase,sal_True) + , m_pGroups(NULL) +{ +} +// ------------------------------------------------------------------------- +OUser::OUser(const ::rtl::OUString& _Name,sal_Bool _bCase) : OUser_BASE(m_aMutex) + ,ODescriptor(OUser_BASE::rBHelper,_bCase) + ,m_pGroups(NULL) +{ + m_Name = _Name; +} +// ------------------------------------------------------------------------- +OUser::~OUser( ) +{ + delete m_pGroups; +} +// ------------------------------------------------------------------------- +void OUser::disposing(void) +{ + OPropertySetHelper::disposing(); + ::osl::MutexGuard aGuard(m_aMutex); + if(m_pGroups) + m_pGroups->disposing(); +} +// ------------------------------------------------------------------------- +Any SAL_CALL OUser::queryInterface( const Type & rType ) throw(RuntimeException) +{ + Any aRet = ODescriptor::queryInterface( rType); + return aRet.hasValue() ? aRet : OUser_BASE::queryInterface( rType); +} +// ------------------------------------------------------------------------- +Sequence< Type > SAL_CALL OUser::getTypes( ) throw(RuntimeException) +{ + 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 *const_cast<OUser*>(this)->getArrayHelper(); +} +// ------------------------------------------------------------------------- +// XUser +void SAL_CALL OUser::changePassword( const ::rtl::OUString& /*objPassword*/, const ::rtl::OUString& /*newPassword*/ ) throw(::com::sun::star::sdbc::SQLException, RuntimeException) +{ + ::osl::MutexGuard aGuard(m_aMutex); + checkDisposed(OUser_BASE::rBHelper.bDisposed); + ::dbtools::throwFeatureNotImplementedException( "XUser::changePassword", *this ); +} +// ------------------------------------------------------------------------- +// XGroupsSupplier +Reference< XNameAccess > SAL_CALL OUser::getGroups( ) throw(RuntimeException) +{ + ::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 const_cast<OUser*>(this)->m_pGroups; +} +// ------------------------------------------------------------------------- +// ------------------------------------------------------------------------- + +sal_Int32 SAL_CALL OUser::getPrivileges( const ::rtl::OUString& /*objName*/, sal_Int32 /*objType*/ ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + ::osl::MutexGuard aGuard(m_aMutex); + checkDisposed(OUser_BASE::rBHelper.bDisposed); + ::dbtools::throwFeatureNotImplementedException( "XAuthorizable::changePassword", *this ); + return 0; +} +// ------------------------------------------------------------------------- +sal_Int32 SAL_CALL OUser::getGrantablePrivileges( const ::rtl::OUString& /*objName*/, sal_Int32 /*objType*/ ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + ::osl::MutexGuard aGuard(m_aMutex); + checkDisposed(OUser_BASE::rBHelper.bDisposed); + ::dbtools::throwFeatureNotImplementedException( "XAuthorizable::getGrantablePrivileges", *this ); + return 0; +} +// ------------------------------------------------------------------------- +void SAL_CALL OUser::grantPrivileges( const ::rtl::OUString& /*objName*/, sal_Int32 /*objType*/, sal_Int32 /*objPrivileges*/ ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + ::osl::MutexGuard aGuard(m_aMutex); + checkDisposed(OUser_BASE::rBHelper.bDisposed); + ::dbtools::throwFeatureNotImplementedException( "XAuthorizable::grantPrivileges", *this ); +} +// ------------------------------------------------------------------------- +void SAL_CALL OUser::revokePrivileges( const ::rtl::OUString& /*objName*/, sal_Int32 /*objType*/, sal_Int32 /*objPrivileges*/ ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) +{ + ::osl::MutexGuard aGuard(m_aMutex); + checkDisposed(OUser_BASE::rBHelper.bDisposed); + ::dbtools::throwFeatureNotImplementedException( "XAuthorizable::revokePrivileges", *this ); +} +// ----------------------------------------------------------------------------- +::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL OUser::getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException) +{ + return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper()); +} +// ----------------------------------------------------------------------------- +::rtl::OUString SAL_CALL OUser::getName( ) throw(::com::sun::star::uno::RuntimeException) +{ + return m_Name; +} +// ----------------------------------------------------------------------------- +void SAL_CALL OUser::setName( const ::rtl::OUString& /*aName*/ ) throw(::com::sun::star::uno::RuntimeException) +{ + OSL_ENSURE( false, "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(); +} +// ----------------------------------------------------------------------------- + + diff --git a/connectivity/source/sdbcx/VView.cxx b/connectivity/source/sdbcx/VView.cxx new file mode 100644 index 000000000000..281566162db7 --- /dev/null +++ b/connectivity/source/sdbcx/VView.cxx @@ -0,0 +1,150 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_connectivity.hxx" +#include "connectivity/sdbcx/VView.hxx" +#include <com/sun/star/lang/DisposedException.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(sal_Bool _bCase, + const ::rtl::OUString& _Name, + const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDatabaseMetaData >& _xMetaData, + sal_Int32 _CheckOption, + const ::rtl::OUString& _Command, + const ::rtl::OUString& _SchemaName, + const ::rtl::OUString& _CatalogName) : ODescriptor(::comphelper::OMutexAndBroadcastHelper::m_aBHelper,_bCase) + ,m_CatalogName(_CatalogName) + ,m_SchemaName(_SchemaName) + ,m_Command(_Command) + ,m_CheckOption(_CheckOption) + ,m_xMetaData(_xMetaData) + +{ + m_Name = _Name; + construct(); +} +// ------------------------------------------------------------------------- +OView::OView(sal_Bool _bCase,const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDatabaseMetaData >& _xMetaData) + : ODescriptor(::comphelper::OMutexAndBroadcastHelper::m_aBHelper,_bCase,sal_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, ::getCppuType(reinterpret_cast< ::rtl::OUString*>(NULL))); + registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCHEMANAME), PROPERTY_ID_SCHEMANAME, nAttrib,&m_SchemaName, ::getCppuType(reinterpret_cast< ::rtl::OUString*>(NULL))); + registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_COMMAND), PROPERTY_ID_COMMAND, nAttrib,&m_Command, ::getCppuType(reinterpret_cast< ::rtl::OUString*>(NULL))); + registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_CHECKOPTION), PROPERTY_ID_CHECKOPTION,nAttrib,&m_CheckOption, ::getCppuType(reinterpret_cast< sal_Int32*>(NULL))); +} +// ------------------------------------------------------------------------- +void OView::disposing(void) +{ + OPropertySetHelper::disposing(); + + ::osl::MutexGuard aGuard(m_aMutex); +} +// ------------------------------------------------------------------------- +Sequence< Type > SAL_CALL OView::getTypes( ) throw(RuntimeException) +{ + return ::comphelper::concatSequences(ODescriptor::getTypes(),OView_BASE::getTypes()); +} +// ------------------------------------------------------------------------- +Any SAL_CALL OView::queryInterface( const Type & rType ) throw(RuntimeException) +{ + 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 *const_cast<OView*>(this)->getArrayHelper(isNew() ? 1 : 0); +} +// ----------------------------------------------------------------------------- +::rtl::OUString SAL_CALL OView::getName() throw(::com::sun::star::uno::RuntimeException) +{ + ::rtl::OUString sComposedName; + if(m_xMetaData.is()) + sComposedName = ::dbtools::composeTableName( m_xMetaData, m_CatalogName, m_SchemaName, m_Name, sal_False, ::dbtools::eInDataManipulation ); + else + { + Any aValue; + getFastPropertyValue(aValue,PROPERTY_ID_NAME); + aValue >>= sComposedName; + } + return sComposedName; +} +// ----------------------------------------------------------------------------- +::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL OView::getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException) +{ + return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper()); +} +// ----------------------------------------------------------------------------- +void SAL_CALL OView::setName( const ::rtl::OUString& ) throw(::com::sun::star::uno::RuntimeException) +{ +} +// ----------------------------------------------------------------------------- +void SAL_CALL OView::acquire() throw() +{ + OView_BASE::acquire(); +} +// ----------------------------------------------------------------------------- +void SAL_CALL OView::release() throw() +{ + OView_BASE::release(); +} +// ----------------------------------------------------------------------------- + + diff --git a/connectivity/source/sdbcx/makefile.mk b/connectivity/source/sdbcx/makefile.mk new file mode 100644 index 000000000000..c036e83db58b --- /dev/null +++ b/connectivity/source/sdbcx/makefile.mk @@ -0,0 +1,63 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org 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 version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/.. +PRJINC=.. +PRJNAME=connectivity +TARGET=sdbcx + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ---------------------------------- +.IF "$(DBGUTIL_OJ)"!="" +ENVCFLAGS+=/FR$(SLO)$/ +.ENDIF + +.INCLUDE : settings.mk +.INCLUDE : $(PRJ)$/dbtools.pmk + +# --- Files ------------------------------------- + +SLOFILES=\ + $(SLO)$/VDescriptor.obj \ + $(SLO)$/VCollection.obj \ + $(SLO)$/VColumn.obj \ + $(SLO)$/VIndexColumn.obj \ + $(SLO)$/VKeyColumn.obj \ + $(SLO)$/VUser.obj \ + $(SLO)$/VGroup.obj \ + $(SLO)$/VTable.obj \ + $(SLO)$/VKey.obj \ + $(SLO)$/VIndex.obj \ + $(SLO)$/VCatalog.obj \ + $(SLO)$/VView.obj + +# --- Targets ---------------------------------- + +.INCLUDE : target.mk + + |