1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <connectivity/sdbcx/VTable.hxx>
21 #include <com/sun/star/lang/DisposedException.hpp>
22 #include <connectivity/sdbcx/VIndex.hxx>
23 #include <comphelper/sequence.hxx>
24 #include <connectivity/sdbcx/VCollection.hxx>
25 #include "TConnection.hxx"
26 #include <connectivity/sdbcx/VColumn.hxx>
27 #include <connectivity/sdbcx/VKey.hxx>
28 #include <connectivity/dbtools.hxx>
29 #include <connectivity/dbexception.hxx>
30 #include <cppuhelper/supportsservice.hxx>
32 using namespace ::connectivity
;
33 using namespace ::connectivity::sdbcx
;
34 using namespace ::dbtools
;
35 using namespace ::com::sun::star::beans
;
36 using namespace ::com::sun::star::uno
;
37 using namespace ::com::sun::star::sdbc
;
38 using namespace ::com::sun::star::sdbcx
;
39 using namespace ::com::sun::star::container
;
40 using namespace ::com::sun::star::lang
;
43 OUString SAL_CALL
OTable::getImplementationName( ) throw (::com::sun::star::uno::RuntimeException
, std::exception
)
46 return OUString("com.sun.star.sdbcx.VTableDescriptor");
47 return OUString("com.sun.star.sdbcx.Table");
51 ::com::sun::star::uno::Sequence
< OUString
> SAL_CALL
OTable::getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException
, std::exception
)
53 ::com::sun::star::uno::Sequence
< OUString
> aSupported(1);
55 aSupported
[0] = "com.sun.star.sdbcx.TableDescriptor";
57 aSupported
[0] = "com.sun.star.sdbcx.Table";
62 sal_Bool SAL_CALL
OTable::supportsService( const OUString
& _rServiceName
) throw(::com::sun::star::uno::RuntimeException
, std::exception
)
64 return cppu::supportsService(this, _rServiceName
);
67 OTable::OTable(OCollection
* _pTables
,
69 : OTableDescriptor_BASE(m_aMutex
)
70 ,ODescriptor(OTableDescriptor_BASE::rBHelper
,_bCase
,true)
78 OTable::OTable( OCollection
* _pTables
,
80 const OUString
& _Name
, const OUString
& _Type
,
81 const OUString
& _Description
,const OUString
& _SchemaName
,
82 const OUString
& _CatalogName
) : OTableDescriptor_BASE(m_aMutex
)
83 ,ODescriptor(OTableDescriptor_BASE::rBHelper
,_bCase
)
84 ,m_CatalogName(_CatalogName
)
85 ,m_SchemaName(_SchemaName
)
86 ,m_Description(_Description
)
103 void OTable::construct()
105 ODescriptor::construct();
107 sal_Int32 nAttrib
= isNew() ? 0 : PropertyAttribute::READONLY
;
109 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_CATALOGNAME
), PROPERTY_ID_CATALOGNAME
,nAttrib
,&m_CatalogName
, ::cppu::UnoType
<OUString
>::get());
110 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCHEMANAME
), PROPERTY_ID_SCHEMANAME
, nAttrib
,&m_SchemaName
, ::cppu::UnoType
<OUString
>::get());
111 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DESCRIPTION
), PROPERTY_ID_DESCRIPTION
,nAttrib
,&m_Description
, ::cppu::UnoType
<OUString
>::get());
112 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE
), PROPERTY_ID_TYPE
, nAttrib
,&m_Type
, ::cppu::UnoType
<OUString
>::get());
115 void SAL_CALL
OTable::acquire() throw()
117 OTableDescriptor_BASE::acquire();
120 void SAL_CALL
OTable::release() throw()
122 OTableDescriptor_BASE::release();
126 Any SAL_CALL
OTable::queryInterface( const Type
& rType
) throw(RuntimeException
, std::exception
)
128 Any aRet
= ODescriptor::queryInterface( rType
);
132 aRet
= OTable_BASE::queryInterface( rType
);
133 if(isNew() && (rType
== cppu::UnoType
<XIndexesSupplier
>::get()))
136 aRet
= OTableDescriptor_BASE::queryInterface( rType
);
141 Sequence
< Type
> SAL_CALL
OTable::getTypes( ) throw(RuntimeException
, std::exception
)
144 return ::comphelper::concatSequences(ODescriptor::getTypes(),OTableDescriptor_BASE::getTypes());
145 return ::comphelper::concatSequences(ODescriptor::getTypes(),OTableDescriptor_BASE::getTypes(),OTable_BASE::getTypes());
148 void SAL_CALL
OTable::disposing()
150 ODescriptor::disposing();
152 ::osl::MutexGuard
aGuard(m_aMutex
);
155 m_pKeys
->disposing();
157 m_pColumns
->disposing();
159 m_pIndexes
->disposing();
165 Reference
< XNameAccess
> SAL_CALL
OTable::getColumns( ) throw(RuntimeException
, std::exception
)
167 ::osl::MutexGuard
aGuard(m_aMutex
);
168 checkDisposed(OTableDescriptor_BASE::rBHelper
.bDisposed
);
175 catch( const RuntimeException
& )
177 // allowed to leave this method
180 catch( const Exception
& )
190 Reference
< XIndexAccess
> SAL_CALL
OTable::getKeys( ) throw(RuntimeException
, std::exception
)
192 ::osl::MutexGuard
aGuard(m_aMutex
);
193 checkDisposed(OTableDescriptor_BASE::rBHelper
.bDisposed
);
195 Reference
< XIndexAccess
> xKeys
;
203 catch( const RuntimeException
& )
205 // allowed to leave this method
208 catch( const Exception
& )
216 cppu::IPropertyArrayHelper
* OTable::createArrayHelper( sal_Int32
/*_nId*/ ) const
218 return doCreateArrayHelper();
221 cppu::IPropertyArrayHelper
& OTable::getInfoHelper()
223 return *getArrayHelper(isNew() ? 1 : 0);
226 Reference
< XPropertySet
> SAL_CALL
OTable::createDataDescriptor( ) throw(RuntimeException
, std::exception
)
228 ::osl::MutexGuard
aGuard(m_aMutex
);
229 checkDisposed(OTableDescriptor_BASE::rBHelper
.bDisposed
);
231 OTable
* pTable
= new OTable(m_pTables
,isCaseSensitive(),m_Name
,m_Type
,m_Description
,m_SchemaName
,m_CatalogName
);
232 pTable
->setNew(true);
237 Reference
< XNameAccess
> SAL_CALL
OTable::getIndexes( ) throw(RuntimeException
, std::exception
)
239 ::osl::MutexGuard
aGuard(m_aMutex
);
240 checkDisposed(OTableDescriptor_BASE::rBHelper
.bDisposed
);
247 catch( const RuntimeException
& )
249 // allowed to leave this method
252 catch( const Exception
& )
261 void SAL_CALL
OTable::rename( const OUString
& newName
) throw(SQLException
, ElementExistException
, RuntimeException
, std::exception
)
263 ::osl::MutexGuard
aGuard(m_aMutex
);
264 checkDisposed(OTableDescriptor_BASE::rBHelper
.bDisposed
);
266 const OUString sOldComposedName
= getName();
267 const Reference
< XDatabaseMetaData
> xMetaData
= getMetaData();
268 if ( xMetaData
.is() )
269 ::dbtools::qualifiedNameComponents(xMetaData
,newName
,m_CatalogName
,m_SchemaName
,m_Name
,::dbtools::eInDataManipulation
);
273 m_pTables
->renameObject(sOldComposedName
,newName
);
276 Reference
< XDatabaseMetaData
> OTable::getMetaData() const
282 void SAL_CALL
OTable::alterColumnByName( const OUString
& /*colName*/, const Reference
< XPropertySet
>& /*descriptor*/ ) throw(SQLException
, NoSuchElementException
, RuntimeException
, std::exception
)
284 throwFeatureNotImplementedSQLException( "XAlterTable::alterColumnByName", *this );
287 void SAL_CALL
OTable::alterColumnByIndex( sal_Int32
/*index*/, const Reference
< XPropertySet
>& /*descriptor*/ ) throw(SQLException
, ::com::sun::star::lang::IndexOutOfBoundsException
, RuntimeException
, std::exception
)
289 throwFeatureNotImplementedSQLException( "XAlterTable::alterColumnByIndex", *this );
292 ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySetInfo
> SAL_CALL
OTable::getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException
, std::exception
)
294 return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
297 OUString SAL_CALL
OTable::getName() throw(::com::sun::star::uno::RuntimeException
, std::exception
)
299 // this is only correct for tables who haven't a schema or catalog name
300 OSL_ENSURE(m_CatalogName
.isEmpty(),"getName(): forgot to override getName()!");
301 OSL_ENSURE(m_SchemaName
.isEmpty(),"getName(): forgot to override getName()!");
305 void SAL_CALL
OTable::setName( const OUString
& /*aName*/ ) throw(::com::sun::star::uno::RuntimeException
, std::exception
)
309 void OTable::refreshColumns()
313 void OTable::refreshKeys()
317 void OTable::refreshIndexes()
322 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */