merge the formfield patch from ooo-build
[ooovba.git] / connectivity / source / sdbcx / VTable.cxx
blobf610be3e65ed1904084599e697cb227828f3ee3b
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: VTable.cxx,v $
10 * $Revision: 1.22 $
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)
58 if(isNew())
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);
67 if(isNew())
68 aSupported[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.TableDescriptor");
69 else
70 aSupported[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.Table");
72 return aSupported;
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,
87 sal_Bool _bCase)
88 : OTableDescriptor_BASE(m_aMutex)
89 ,ODescriptor(OTableDescriptor_BASE::rBHelper,_bCase,sal_True)
90 ,m_pKeys(NULL)
91 ,m_pColumns(NULL)
92 ,m_pIndexes(NULL)
93 ,m_pTables(_pTables)
96 // -----------------------------------------------------------------------------
97 OTable::OTable( OCollection* _pTables,
98 sal_Bool _bCase,
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)
106 ,m_Type(_Type)
107 ,m_pKeys(NULL)
108 ,m_pColumns(NULL)
109 ,m_pIndexes(NULL)
110 ,m_pTables(_pTables)
112 m_Name = _Name;
114 // -------------------------------------------------------------------------
115 OTable::~OTable()
117 delete m_pKeys;
118 delete m_pColumns;
119 delete m_pIndexes;
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);
148 if(!aRet.hasValue())
150 if(!isNew())
151 aRet = OTable_BASE::queryInterface( rType);
152 if(isNew() && (rType == getCppuType( (Reference<XIndexesSupplier>*)0)))
153 return Any();
154 if(!aRet.hasValue())
155 aRet = OTableDescriptor_BASE::queryInterface( rType);
157 return aRet;
159 // -------------------------------------------------------------------------
160 Sequence< Type > SAL_CALL OTable::getTypes( ) throw(RuntimeException)
162 if(isNew())
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);
173 if(m_pKeys)
174 m_pKeys->disposing();
175 if(m_pColumns)
176 m_pColumns->disposing();
177 if(m_pIndexes)
178 m_pIndexes->disposing();
180 m_pTables = NULL;
182 // -----------------------------------------------------------------------------
183 // XColumnsSupplier
184 Reference< XNameAccess > SAL_CALL OTable::getColumns( ) throw(RuntimeException)
186 ::osl::MutexGuard aGuard(m_aMutex);
187 checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed);
191 if ( !m_pColumns )
192 refreshColumns();
194 catch( const RuntimeException& )
196 // allowed to leave this method
197 throw;
199 catch( const Exception& )
201 // allowed
204 return m_pColumns;
207 // -------------------------------------------------------------------------
208 // XKeysSupplier
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;
218 if ( !m_pKeys )
219 refreshKeys();
220 xKeys = m_pKeys;
222 catch( const RuntimeException& )
224 // allowed to leave this method
225 throw;
227 catch( const Exception& )
229 // allowed
232 return xKeys;
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);
252 return pTable;
254 // -------------------------------------------------------------------------
255 // XIndexesSupplier
256 Reference< XNameAccess > SAL_CALL OTable::getIndexes( ) throw(RuntimeException)
258 ::osl::MutexGuard aGuard(m_aMutex);
259 checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed);
263 if ( !m_pIndexes )
264 refreshIndexes();
266 catch( const RuntimeException& )
268 // allowed to leave this method
269 throw;
271 catch( const Exception& )
273 // allowed
276 return m_pIndexes;
278 // -------------------------------------------------------------------------
279 // XRename
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);
289 else
290 m_Name = newName;
292 m_pTables->renameObject(sOldComposedName,newName);
294 // -----------------------------------------------------------------------------
295 Reference< XDatabaseMetaData> OTable::getMetaData() const
297 return NULL;
299 // -------------------------------------------------------------------------
300 // XAlterTable
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()!");
321 return m_Name;
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 // -----------------------------------------------------------------------------