Bump for 3.6-28
[LibreOffice.git] / connectivity / source / sdbcx / VTable.cxx
blobb8d84260796e65c5c872da2f9408f7c825d00c31
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)
54 if(isNew())
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);
63 if(isNew())
64 aSupported[0] = ::rtl::OUString("com.sun.star.sdbcx.TableDescriptor");
65 else
66 aSupported[0] = ::rtl::OUString("com.sun.star.sdbcx.Table");
68 return aSupported;
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,
83 sal_Bool _bCase)
84 : OTableDescriptor_BASE(m_aMutex)
85 ,ODescriptor(OTableDescriptor_BASE::rBHelper,_bCase,sal_True)
86 ,m_pKeys(NULL)
87 ,m_pColumns(NULL)
88 ,m_pIndexes(NULL)
89 ,m_pTables(_pTables)
92 // -----------------------------------------------------------------------------
93 OTable::OTable( OCollection* _pTables,
94 sal_Bool _bCase,
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)
102 ,m_Type(_Type)
103 ,m_pKeys(NULL)
104 ,m_pColumns(NULL)
105 ,m_pIndexes(NULL)
106 ,m_pTables(_pTables)
108 m_Name = _Name;
110 // -------------------------------------------------------------------------
111 OTable::~OTable()
113 delete m_pKeys;
114 delete m_pColumns;
115 delete m_pIndexes;
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);
144 if(!aRet.hasValue())
146 if(!isNew())
147 aRet = OTable_BASE::queryInterface( rType);
148 if(isNew() && (rType == getCppuType( (Reference<XIndexesSupplier>*)0)))
149 return Any();
150 if(!aRet.hasValue())
151 aRet = OTableDescriptor_BASE::queryInterface( rType);
153 return aRet;
155 // -------------------------------------------------------------------------
156 Sequence< Type > SAL_CALL OTable::getTypes( ) throw(RuntimeException)
158 if(isNew())
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);
169 if(m_pKeys)
170 m_pKeys->disposing();
171 if(m_pColumns)
172 m_pColumns->disposing();
173 if(m_pIndexes)
174 m_pIndexes->disposing();
176 m_pTables = NULL;
178 // -----------------------------------------------------------------------------
179 // XColumnsSupplier
180 Reference< XNameAccess > SAL_CALL OTable::getColumns( ) throw(RuntimeException)
182 ::osl::MutexGuard aGuard(m_aMutex);
183 checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed);
187 if ( !m_pColumns )
188 refreshColumns();
190 catch( const RuntimeException& )
192 // allowed to leave this method
193 throw;
195 catch( const Exception& )
197 // allowed
200 return m_pColumns;
203 // -------------------------------------------------------------------------
204 // XKeysSupplier
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;
214 if ( !m_pKeys )
215 refreshKeys();
216 xKeys = m_pKeys;
218 catch( const RuntimeException& )
220 // allowed to leave this method
221 throw;
223 catch( const Exception& )
225 // allowed
228 return xKeys;
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);
248 return pTable;
250 // -------------------------------------------------------------------------
251 // XIndexesSupplier
252 Reference< XNameAccess > SAL_CALL OTable::getIndexes( ) throw(RuntimeException)
254 ::osl::MutexGuard aGuard(m_aMutex);
255 checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed);
259 if ( !m_pIndexes )
260 refreshIndexes();
262 catch( const RuntimeException& )
264 // allowed to leave this method
265 throw;
267 catch( const Exception& )
269 // allowed
272 return m_pIndexes;
274 // -------------------------------------------------------------------------
275 // XRename
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);
285 else
286 m_Name = newName;
288 m_pTables->renameObject(sOldComposedName,newName);
290 // -----------------------------------------------------------------------------
291 Reference< XDatabaseMetaData> OTable::getMetaData() const
293 return NULL;
295 // -------------------------------------------------------------------------
296 // XAlterTable
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()!");
317 return m_Name;
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: */