bump product version to 5.0.4.1
[LibreOffice.git] / connectivity / source / sdbcx / VTable.cxx
blob7a4d453febb3605a060d18de81e9794d15558622
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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)
45 if(isNew())
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);
54 if(isNew())
55 aSupported[0] = "com.sun.star.sdbcx.TableDescriptor";
56 else
57 aSupported[0] = "com.sun.star.sdbcx.Table";
59 return aSupported;
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,
68 bool _bCase)
69 : OTableDescriptor_BASE(m_aMutex)
70 ,ODescriptor(OTableDescriptor_BASE::rBHelper,_bCase,true)
71 ,m_pKeys(NULL)
72 ,m_pColumns(NULL)
73 ,m_pIndexes(NULL)
74 ,m_pTables(_pTables)
78 OTable::OTable( OCollection* _pTables,
79 bool _bCase,
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)
87 ,m_Type(_Type)
88 ,m_pKeys(NULL)
89 ,m_pColumns(NULL)
90 ,m_pIndexes(NULL)
91 ,m_pTables(_pTables)
93 m_Name = _Name;
96 OTable::~OTable()
98 delete m_pKeys;
99 delete m_pColumns;
100 delete m_pIndexes;
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);
129 if(!aRet.hasValue())
131 if(!isNew())
132 aRet = OTable_BASE::queryInterface( rType);
133 if(isNew() && (rType == cppu::UnoType<XIndexesSupplier>::get()))
134 return Any();
135 if(!aRet.hasValue())
136 aRet = OTableDescriptor_BASE::queryInterface( rType);
138 return aRet;
141 Sequence< Type > SAL_CALL OTable::getTypes( ) throw(RuntimeException, std::exception)
143 if(isNew())
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);
154 if(m_pKeys)
155 m_pKeys->disposing();
156 if(m_pColumns)
157 m_pColumns->disposing();
158 if(m_pIndexes)
159 m_pIndexes->disposing();
161 m_pTables = NULL;
164 // XColumnsSupplier
165 Reference< XNameAccess > SAL_CALL OTable::getColumns( ) throw(RuntimeException, std::exception)
167 ::osl::MutexGuard aGuard(m_aMutex);
168 checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed);
172 if ( !m_pColumns )
173 refreshColumns();
175 catch( const RuntimeException& )
177 // allowed to leave this method
178 throw;
180 catch( const Exception& )
182 // allowed
185 return m_pColumns;
189 // XKeysSupplier
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;
199 if ( !m_pKeys )
200 refreshKeys();
201 xKeys = m_pKeys;
203 catch( const RuntimeException& )
205 // allowed to leave this method
206 throw;
208 catch( const Exception& )
210 // allowed
213 return xKeys;
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);
233 return pTable;
236 // XIndexesSupplier
237 Reference< XNameAccess > SAL_CALL OTable::getIndexes( ) throw(RuntimeException, std::exception)
239 ::osl::MutexGuard aGuard(m_aMutex);
240 checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed);
244 if ( !m_pIndexes )
245 refreshIndexes();
247 catch( const RuntimeException& )
249 // allowed to leave this method
250 throw;
252 catch( const Exception& )
254 // allowed
257 return m_pIndexes;
260 // XRename
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);
270 else
271 m_Name = newName;
273 m_pTables->renameObject(sOldComposedName,newName);
276 Reference< XDatabaseMetaData> OTable::getMetaData() const
278 return NULL;
281 // XAlterTable
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()!");
302 return m_Name;
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: */