1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: VTable.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_connectivity.hxx"
33 #include "connectivity/sdbcx/VTable.hxx"
34 #include <com/sun/star/lang/DisposedException.hpp>
35 #include "connectivity/sdbcx/VIndex.hxx"
36 #include <comphelper/sequence.hxx>
37 #include "connectivity/sdbcx/VCollection.hxx"
38 #include "TConnection.hxx"
39 #include "connectivity/sdbcx/VColumn.hxx"
40 #include "connectivity/sdbcx/VKey.hxx"
41 #include "connectivity/dbtools.hxx"
42 #include <connectivity/dbexception.hxx>
44 // -------------------------------------------------------------------------
45 using namespace ::connectivity
;
46 using namespace ::connectivity::sdbcx
;
47 using namespace ::dbtools
;
48 using namespace ::com::sun::star::beans
;
49 using namespace ::com::sun::star::uno
;
50 using namespace ::com::sun::star::sdbc
;
51 using namespace ::com::sun::star::sdbcx
;
52 using namespace ::com::sun::star::container
;
53 using namespace ::com::sun::star::lang
;
55 // -----------------------------------------------------------------------------
56 ::rtl::OUString SAL_CALL
OTable::getImplementationName( ) throw (::com::sun::star::uno::RuntimeException
)
59 return ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.VTableDescriptor");
60 return ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.Table");
63 // -----------------------------------------------------------------------------
64 ::com::sun::star::uno::Sequence
< ::rtl::OUString
> SAL_CALL
OTable::getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException
)
66 ::com::sun::star::uno::Sequence
< ::rtl::OUString
> aSupported(1);
68 aSupported
[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.TableDescriptor");
70 aSupported
[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.Table");
74 // -----------------------------------------------------------------------------
75 sal_Bool SAL_CALL
OTable::supportsService( const ::rtl::OUString
& _rServiceName
) throw(::com::sun::star::uno::RuntimeException
)
77 Sequence
< ::rtl::OUString
> aSupported(getSupportedServiceNames());
78 const ::rtl::OUString
* pSupported
= aSupported
.getConstArray();
79 const ::rtl::OUString
* pEnd
= pSupported
+ aSupported
.getLength();
80 for (;pSupported
!= pEnd
&& !pSupported
->equals(_rServiceName
); ++pSupported
)
83 return pSupported
!= pEnd
;
85 // -------------------------------------------------------------------------
86 OTable::OTable(OCollection
* _pTables
,
88 : OTableDescriptor_BASE(m_aMutex
)
89 ,ODescriptor(OTableDescriptor_BASE::rBHelper
,_bCase
,sal_True
)
96 // -----------------------------------------------------------------------------
97 OTable::OTable( OCollection
* _pTables
,
99 const ::rtl::OUString
& _Name
, const ::rtl::OUString
& _Type
,
100 const ::rtl::OUString
& _Description
,const ::rtl::OUString
& _SchemaName
,
101 const ::rtl::OUString
& _CatalogName
) : OTableDescriptor_BASE(m_aMutex
)
102 ,ODescriptor(OTableDescriptor_BASE::rBHelper
,_bCase
)
103 ,m_CatalogName(_CatalogName
)
104 ,m_SchemaName(_SchemaName
)
105 ,m_Description(_Description
)
114 // -------------------------------------------------------------------------
121 // -------------------------------------------------------------------------
122 void OTable::construct()
124 ODescriptor::construct();
126 sal_Int32 nAttrib
= isNew() ? 0 : PropertyAttribute::READONLY
;
128 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_CATALOGNAME
), PROPERTY_ID_CATALOGNAME
,nAttrib
,&m_CatalogName
, ::getCppuType(reinterpret_cast< ::rtl::OUString
*>(NULL
)));
129 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCHEMANAME
), PROPERTY_ID_SCHEMANAME
, nAttrib
,&m_SchemaName
, ::getCppuType(reinterpret_cast< ::rtl::OUString
*>(NULL
)));
130 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DESCRIPTION
), PROPERTY_ID_DESCRIPTION
,nAttrib
,&m_Description
, ::getCppuType(reinterpret_cast< ::rtl::OUString
*>(NULL
)));
131 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE
), PROPERTY_ID_TYPE
, nAttrib
,&m_Type
, ::getCppuType(reinterpret_cast< ::rtl::OUString
*>(NULL
)));
133 // -----------------------------------------------------------------------------
134 void SAL_CALL
OTable::acquire() throw()
136 OTableDescriptor_BASE::acquire();
138 // -----------------------------------------------------------------------------
139 void SAL_CALL
OTable::release() throw()
141 OTableDescriptor_BASE::release();
144 // -------------------------------------------------------------------------
145 Any SAL_CALL
OTable::queryInterface( const Type
& rType
) throw(RuntimeException
)
147 Any aRet
= ODescriptor::queryInterface( rType
);
151 aRet
= OTable_BASE::queryInterface( rType
);
152 if(isNew() && (rType
== getCppuType( (Reference
<XIndexesSupplier
>*)0)))
155 aRet
= OTableDescriptor_BASE::queryInterface( rType
);
159 // -------------------------------------------------------------------------
160 Sequence
< Type
> SAL_CALL
OTable::getTypes( ) throw(RuntimeException
)
163 return ::comphelper::concatSequences(ODescriptor::getTypes(),OTableDescriptor_BASE::getTypes());
164 return ::comphelper::concatSequences(ODescriptor::getTypes(),OTableDescriptor_BASE::getTypes(),OTable_BASE::getTypes());
166 // -------------------------------------------------------------------------
167 void SAL_CALL
OTable::disposing(void)
169 ODescriptor::disposing();
171 ::osl::MutexGuard
aGuard(m_aMutex
);
174 m_pKeys
->disposing();
176 m_pColumns
->disposing();
178 m_pIndexes
->disposing();
182 // -----------------------------------------------------------------------------
184 Reference
< XNameAccess
> SAL_CALL
OTable::getColumns( ) throw(RuntimeException
)
186 ::osl::MutexGuard
aGuard(m_aMutex
);
187 checkDisposed(OTableDescriptor_BASE::rBHelper
.bDisposed
);
194 catch( const RuntimeException
& )
196 // allowed to leave this method
199 catch( const Exception
& )
207 // -------------------------------------------------------------------------
209 Reference
< XIndexAccess
> SAL_CALL
OTable::getKeys( ) throw(RuntimeException
)
211 ::osl::MutexGuard
aGuard(m_aMutex
);
212 checkDisposed(OTableDescriptor_BASE::rBHelper
.bDisposed
);
214 Reference
< XIndexAccess
> xKeys
;
222 catch( const RuntimeException
& )
224 // allowed to leave this method
227 catch( const Exception
& )
234 // -----------------------------------------------------------------------------
235 cppu::IPropertyArrayHelper
* OTable::createArrayHelper( sal_Int32
/*_nId*/ ) const
237 return doCreateArrayHelper();
239 // -------------------------------------------------------------------------
240 cppu::IPropertyArrayHelper
& OTable::getInfoHelper()
242 return *const_cast<OTable
*>(this)->getArrayHelper(isNew() ? 1 : 0);
244 // -------------------------------------------------------------------------
245 Reference
< XPropertySet
> SAL_CALL
OTable::createDataDescriptor( ) throw(RuntimeException
)
247 ::osl::MutexGuard
aGuard(m_aMutex
);
248 checkDisposed(OTableDescriptor_BASE::rBHelper
.bDisposed
);
250 OTable
* pTable
= new OTable(m_pTables
,isCaseSensitive(),m_Name
,m_Type
,m_Description
,m_SchemaName
,m_CatalogName
);
251 pTable
->setNew(sal_True
);
254 // -------------------------------------------------------------------------
256 Reference
< XNameAccess
> SAL_CALL
OTable::getIndexes( ) throw(RuntimeException
)
258 ::osl::MutexGuard
aGuard(m_aMutex
);
259 checkDisposed(OTableDescriptor_BASE::rBHelper
.bDisposed
);
266 catch( const RuntimeException
& )
268 // allowed to leave this method
271 catch( const Exception
& )
278 // -------------------------------------------------------------------------
280 void SAL_CALL
OTable::rename( const ::rtl::OUString
& newName
) throw(SQLException
, ElementExistException
, RuntimeException
)
282 ::osl::MutexGuard
aGuard(m_aMutex
);
283 checkDisposed(OTableDescriptor_BASE::rBHelper
.bDisposed
);
285 const ::rtl::OUString sOldComposedName
= getName();
286 const Reference
< XDatabaseMetaData
> xMetaData
= getMetaData();
287 if ( xMetaData
.is() )
288 ::dbtools::qualifiedNameComponents(xMetaData
,newName
,m_CatalogName
,m_SchemaName
,m_Name
,::dbtools::eInDataManipulation
);
292 m_pTables
->renameObject(sOldComposedName
,newName
);
294 // -----------------------------------------------------------------------------
295 Reference
< XDatabaseMetaData
> OTable::getMetaData() const
299 // -------------------------------------------------------------------------
301 void SAL_CALL
OTable::alterColumnByName( const ::rtl::OUString
& /*colName*/, const Reference
< XPropertySet
>& /*descriptor*/ ) throw(SQLException
, NoSuchElementException
, RuntimeException
)
303 throwFeatureNotImplementedException( "XAlterTable::alterColumnByName", *this );
305 // -------------------------------------------------------------------------
306 void SAL_CALL
OTable::alterColumnByIndex( sal_Int32
/*index*/, const Reference
< XPropertySet
>& /*descriptor*/ ) throw(SQLException
, ::com::sun::star::lang::IndexOutOfBoundsException
, RuntimeException
)
308 throwFeatureNotImplementedException( "XAlterTable::alterColumnByIndex", *this );
310 // -------------------------------------------------------------------------
311 ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySetInfo
> SAL_CALL
OTable::getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException
)
313 return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
315 // -----------------------------------------------------------------------------
316 ::rtl::OUString SAL_CALL
OTable::getName() throw(::com::sun::star::uno::RuntimeException
)
318 // this is only correct for tables who haven't a schema or catalog name
319 OSL_ENSURE(!m_CatalogName
.getLength(),"getName(): forgot to overload getName()!");
320 OSL_ENSURE(!m_SchemaName
.getLength(),"getName(): forgot to overload getName()!");
323 // -----------------------------------------------------------------------------
324 void SAL_CALL
OTable::setName( const ::rtl::OUString
& /*aName*/ ) throw(::com::sun::star::uno::RuntimeException
)
327 // -----------------------------------------------------------------------------
328 void OTable::refreshColumns()
331 // -----------------------------------------------------------------------------
332 void OTable::refreshKeys()
335 // -----------------------------------------------------------------------------
336 void OTable::refreshIndexes()
339 // -----------------------------------------------------------------------------