1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "connectivity/sdbcx/VTable.hxx"
30 #include <com/sun/star/lang/DisposedException.hpp>
31 #include "connectivity/sdbcx/VIndex.hxx"
32 #include <comphelper/sequence.hxx>
33 #include "connectivity/sdbcx/VCollection.hxx"
34 #include "TConnection.hxx"
35 #include "connectivity/sdbcx/VColumn.hxx"
36 #include "connectivity/sdbcx/VKey.hxx"
37 #include "connectivity/dbtools.hxx"
38 #include <connectivity/dbexception.hxx>
40 // -------------------------------------------------------------------------
41 using namespace ::connectivity
;
42 using namespace ::connectivity::sdbcx
;
43 using namespace ::dbtools
;
44 using namespace ::com::sun::star::beans
;
45 using namespace ::com::sun::star::uno
;
46 using namespace ::com::sun::star::sdbc
;
47 using namespace ::com::sun::star::sdbcx
;
48 using namespace ::com::sun::star::container
;
49 using namespace ::com::sun::star::lang
;
51 // -----------------------------------------------------------------------------
52 ::rtl::OUString SAL_CALL
OTable::getImplementationName( ) throw (::com::sun::star::uno::RuntimeException
)
55 return ::rtl::OUString("com.sun.star.sdbcx.VTableDescriptor");
56 return ::rtl::OUString("com.sun.star.sdbcx.Table");
59 // -----------------------------------------------------------------------------
60 ::com::sun::star::uno::Sequence
< ::rtl::OUString
> SAL_CALL
OTable::getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException
)
62 ::com::sun::star::uno::Sequence
< ::rtl::OUString
> aSupported(1);
64 aSupported
[0] = ::rtl::OUString("com.sun.star.sdbcx.TableDescriptor");
66 aSupported
[0] = ::rtl::OUString("com.sun.star.sdbcx.Table");
70 // -----------------------------------------------------------------------------
71 sal_Bool SAL_CALL
OTable::supportsService( const ::rtl::OUString
& _rServiceName
) throw(::com::sun::star::uno::RuntimeException
)
73 Sequence
< ::rtl::OUString
> aSupported(getSupportedServiceNames());
74 const ::rtl::OUString
* pSupported
= aSupported
.getConstArray();
75 const ::rtl::OUString
* pEnd
= pSupported
+ aSupported
.getLength();
76 for (;pSupported
!= pEnd
&& !pSupported
->equals(_rServiceName
); ++pSupported
)
79 return pSupported
!= pEnd
;
81 // -------------------------------------------------------------------------
82 OTable::OTable(OCollection
* _pTables
,
84 : OTableDescriptor_BASE(m_aMutex
)
85 ,ODescriptor(OTableDescriptor_BASE::rBHelper
,_bCase
,sal_True
)
92 // -----------------------------------------------------------------------------
93 OTable::OTable( OCollection
* _pTables
,
95 const ::rtl::OUString
& _Name
, const ::rtl::OUString
& _Type
,
96 const ::rtl::OUString
& _Description
,const ::rtl::OUString
& _SchemaName
,
97 const ::rtl::OUString
& _CatalogName
) : OTableDescriptor_BASE(m_aMutex
)
98 ,ODescriptor(OTableDescriptor_BASE::rBHelper
,_bCase
)
99 ,m_CatalogName(_CatalogName
)
100 ,m_SchemaName(_SchemaName
)
101 ,m_Description(_Description
)
110 // -------------------------------------------------------------------------
117 // -------------------------------------------------------------------------
118 void OTable::construct()
120 ODescriptor::construct();
122 sal_Int32 nAttrib
= isNew() ? 0 : PropertyAttribute::READONLY
;
124 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_CATALOGNAME
), PROPERTY_ID_CATALOGNAME
,nAttrib
,&m_CatalogName
, ::getCppuType(reinterpret_cast< ::rtl::OUString
*>(NULL
)));
125 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCHEMANAME
), PROPERTY_ID_SCHEMANAME
, nAttrib
,&m_SchemaName
, ::getCppuType(reinterpret_cast< ::rtl::OUString
*>(NULL
)));
126 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DESCRIPTION
), PROPERTY_ID_DESCRIPTION
,nAttrib
,&m_Description
, ::getCppuType(reinterpret_cast< ::rtl::OUString
*>(NULL
)));
127 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE
), PROPERTY_ID_TYPE
, nAttrib
,&m_Type
, ::getCppuType(reinterpret_cast< ::rtl::OUString
*>(NULL
)));
129 // -----------------------------------------------------------------------------
130 void SAL_CALL
OTable::acquire() throw()
132 OTableDescriptor_BASE::acquire();
134 // -----------------------------------------------------------------------------
135 void SAL_CALL
OTable::release() throw()
137 OTableDescriptor_BASE::release();
140 // -------------------------------------------------------------------------
141 Any SAL_CALL
OTable::queryInterface( const Type
& rType
) throw(RuntimeException
)
143 Any aRet
= ODescriptor::queryInterface( rType
);
147 aRet
= OTable_BASE::queryInterface( rType
);
148 if(isNew() && (rType
== getCppuType( (Reference
<XIndexesSupplier
>*)0)))
151 aRet
= OTableDescriptor_BASE::queryInterface( rType
);
155 // -------------------------------------------------------------------------
156 Sequence
< Type
> SAL_CALL
OTable::getTypes( ) throw(RuntimeException
)
159 return ::comphelper::concatSequences(ODescriptor::getTypes(),OTableDescriptor_BASE::getTypes());
160 return ::comphelper::concatSequences(ODescriptor::getTypes(),OTableDescriptor_BASE::getTypes(),OTable_BASE::getTypes());
162 // -------------------------------------------------------------------------
163 void SAL_CALL
OTable::disposing(void)
165 ODescriptor::disposing();
167 ::osl::MutexGuard
aGuard(m_aMutex
);
170 m_pKeys
->disposing();
172 m_pColumns
->disposing();
174 m_pIndexes
->disposing();
178 // -----------------------------------------------------------------------------
180 Reference
< XNameAccess
> SAL_CALL
OTable::getColumns( ) throw(RuntimeException
)
182 ::osl::MutexGuard
aGuard(m_aMutex
);
183 checkDisposed(OTableDescriptor_BASE::rBHelper
.bDisposed
);
190 catch( const RuntimeException
& )
192 // allowed to leave this method
195 catch( const Exception
& )
203 // -------------------------------------------------------------------------
205 Reference
< XIndexAccess
> SAL_CALL
OTable::getKeys( ) throw(RuntimeException
)
207 ::osl::MutexGuard
aGuard(m_aMutex
);
208 checkDisposed(OTableDescriptor_BASE::rBHelper
.bDisposed
);
210 Reference
< XIndexAccess
> xKeys
;
218 catch( const RuntimeException
& )
220 // allowed to leave this method
223 catch( const Exception
& )
230 // -----------------------------------------------------------------------------
231 cppu::IPropertyArrayHelper
* OTable::createArrayHelper( sal_Int32
/*_nId*/ ) const
233 return doCreateArrayHelper();
235 // -------------------------------------------------------------------------
236 cppu::IPropertyArrayHelper
& OTable::getInfoHelper()
238 return *const_cast<OTable
*>(this)->getArrayHelper(isNew() ? 1 : 0);
240 // -------------------------------------------------------------------------
241 Reference
< XPropertySet
> SAL_CALL
OTable::createDataDescriptor( ) throw(RuntimeException
)
243 ::osl::MutexGuard
aGuard(m_aMutex
);
244 checkDisposed(OTableDescriptor_BASE::rBHelper
.bDisposed
);
246 OTable
* pTable
= new OTable(m_pTables
,isCaseSensitive(),m_Name
,m_Type
,m_Description
,m_SchemaName
,m_CatalogName
);
247 pTable
->setNew(sal_True
);
250 // -------------------------------------------------------------------------
252 Reference
< XNameAccess
> SAL_CALL
OTable::getIndexes( ) throw(RuntimeException
)
254 ::osl::MutexGuard
aGuard(m_aMutex
);
255 checkDisposed(OTableDescriptor_BASE::rBHelper
.bDisposed
);
262 catch( const RuntimeException
& )
264 // allowed to leave this method
267 catch( const Exception
& )
274 // -------------------------------------------------------------------------
276 void SAL_CALL
OTable::rename( const ::rtl::OUString
& newName
) throw(SQLException
, ElementExistException
, RuntimeException
)
278 ::osl::MutexGuard
aGuard(m_aMutex
);
279 checkDisposed(OTableDescriptor_BASE::rBHelper
.bDisposed
);
281 const ::rtl::OUString sOldComposedName
= getName();
282 const Reference
< XDatabaseMetaData
> xMetaData
= getMetaData();
283 if ( xMetaData
.is() )
284 ::dbtools::qualifiedNameComponents(xMetaData
,newName
,m_CatalogName
,m_SchemaName
,m_Name
,::dbtools::eInDataManipulation
);
288 m_pTables
->renameObject(sOldComposedName
,newName
);
290 // -----------------------------------------------------------------------------
291 Reference
< XDatabaseMetaData
> OTable::getMetaData() const
295 // -------------------------------------------------------------------------
297 void SAL_CALL
OTable::alterColumnByName( const ::rtl::OUString
& /*colName*/, const Reference
< XPropertySet
>& /*descriptor*/ ) throw(SQLException
, NoSuchElementException
, RuntimeException
)
299 throwFeatureNotImplementedException( "XAlterTable::alterColumnByName", *this );
301 // -------------------------------------------------------------------------
302 void SAL_CALL
OTable::alterColumnByIndex( sal_Int32
/*index*/, const Reference
< XPropertySet
>& /*descriptor*/ ) throw(SQLException
, ::com::sun::star::lang::IndexOutOfBoundsException
, RuntimeException
)
304 throwFeatureNotImplementedException( "XAlterTable::alterColumnByIndex", *this );
306 // -------------------------------------------------------------------------
307 ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySetInfo
> SAL_CALL
OTable::getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException
)
309 return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
311 // -----------------------------------------------------------------------------
312 ::rtl::OUString SAL_CALL
OTable::getName() throw(::com::sun::star::uno::RuntimeException
)
314 // this is only correct for tables who haven't a schema or catalog name
315 OSL_ENSURE(m_CatalogName
.isEmpty(),"getName(): forgot to overload getName()!");
316 OSL_ENSURE(m_SchemaName
.isEmpty(),"getName(): forgot to overload getName()!");
319 // -----------------------------------------------------------------------------
320 void SAL_CALL
OTable::setName( const ::rtl::OUString
& /*aName*/ ) throw(::com::sun::star::uno::RuntimeException
)
323 // -----------------------------------------------------------------------------
324 void OTable::refreshColumns()
327 // -----------------------------------------------------------------------------
328 void OTable::refreshKeys()
331 // -----------------------------------------------------------------------------
332 void OTable::refreshIndexes()
335 // -----------------------------------------------------------------------------
337 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */