bump product version to 6.3.0.0.beta1
[LibreOffice.git] / connectivity / source / sdbcx / VTable.cxx
blobdb60d4a0e928067504c0ae09f118534ee332a04f
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 <com/sun/star/beans/PropertyAttribute.hpp>
23 #include <connectivity/sdbcx/VIndex.hxx>
24 #include <comphelper/sequence.hxx>
25 #include <connectivity/sdbcx/VCollection.hxx>
26 #include <TConnection.hxx>
27 #include <connectivity/sdbcx/VColumn.hxx>
28 #include <connectivity/sdbcx/VKey.hxx>
29 #include <connectivity/dbtools.hxx>
30 #include <connectivity/dbexception.hxx>
31 #include <cppuhelper/supportsservice.hxx>
33 using namespace ::connectivity;
34 using namespace ::connectivity::sdbcx;
35 using namespace ::dbtools;
36 using namespace ::com::sun::star::beans;
37 using namespace ::com::sun::star::uno;
38 using namespace ::com::sun::star::sdbc;
39 using namespace ::com::sun::star::sdbcx;
40 using namespace ::com::sun::star::container;
41 using namespace ::com::sun::star::lang;
44 OUString SAL_CALL OTable::getImplementationName( )
46 if(isNew())
47 return OUString("com.sun.star.sdbcx.VTableDescriptor");
48 return OUString("com.sun.star.sdbcx.Table");
52 css::uno::Sequence< OUString > SAL_CALL OTable::getSupportedServiceNames( )
54 css::uno::Sequence< OUString > aSupported(1);
55 if(isNew())
56 aSupported[0] = "com.sun.star.sdbcx.TableDescriptor";
57 else
58 aSupported[0] = "com.sun.star.sdbcx.Table";
60 return aSupported;
63 sal_Bool SAL_CALL OTable::supportsService( const OUString& _rServiceName )
65 return cppu::supportsService(this, _rServiceName);
68 OTable::OTable(OCollection* _pTables,
69 bool _bCase)
70 : OTableDescriptor_BASE(m_aMutex)
71 ,ODescriptor(OTableDescriptor_BASE::rBHelper,_bCase,true)
72 ,m_pTables(_pTables)
76 OTable::OTable( OCollection* _pTables,
77 bool _bCase,
78 const OUString& Name, const OUString& Type,
79 const OUString& Description,const OUString& SchemaName,
80 const OUString& CatalogName) : OTableDescriptor_BASE(m_aMutex)
81 ,ODescriptor(OTableDescriptor_BASE::rBHelper,_bCase)
82 ,m_CatalogName(CatalogName)
83 ,m_SchemaName(SchemaName)
84 ,m_Description(Description)
85 ,m_Type(Type)
86 ,m_pTables(_pTables)
88 m_Name = Name;
91 OTable::~OTable()
95 void OTable::construct()
97 ODescriptor::construct();
99 sal_Int32 nAttrib = isNew() ? 0 : PropertyAttribute::READONLY;
101 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_CATALOGNAME), PROPERTY_ID_CATALOGNAME,nAttrib,&m_CatalogName, ::cppu::UnoType<OUString>::get());
102 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCHEMANAME), PROPERTY_ID_SCHEMANAME, nAttrib,&m_SchemaName, ::cppu::UnoType<OUString>::get());
103 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DESCRIPTION), PROPERTY_ID_DESCRIPTION,nAttrib,&m_Description, ::cppu::UnoType<OUString>::get());
104 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE), PROPERTY_ID_TYPE, nAttrib,&m_Type, ::cppu::UnoType<OUString>::get());
107 void SAL_CALL OTable::acquire() throw()
109 OTableDescriptor_BASE::acquire();
112 void SAL_CALL OTable::release() throw()
114 OTableDescriptor_BASE::release();
118 Any SAL_CALL OTable::queryInterface( const Type & rType )
120 Any aRet = ODescriptor::queryInterface( rType);
121 if(!aRet.hasValue())
123 if(!isNew())
124 aRet = OTable_BASE::queryInterface( rType);
125 if(isNew() && (rType == cppu::UnoType<XIndexesSupplier>::get()))
126 return Any();
127 if(!aRet.hasValue())
128 aRet = OTableDescriptor_BASE::queryInterface( rType);
130 return aRet;
133 Sequence< Type > SAL_CALL OTable::getTypes( )
135 if(isNew())
136 return ::comphelper::concatSequences(ODescriptor::getTypes(),OTableDescriptor_BASE::getTypes());
137 return ::comphelper::concatSequences(ODescriptor::getTypes(),OTableDescriptor_BASE::getTypes(),OTable_BASE::getTypes());
140 void SAL_CALL OTable::disposing()
142 ODescriptor::disposing();
144 ::osl::MutexGuard aGuard(m_aMutex);
146 if(m_xKeys)
147 m_xKeys->disposing();
148 if(m_xColumns)
149 m_xColumns->disposing();
150 if(m_xIndexes)
151 m_xIndexes->disposing();
153 m_pTables = nullptr;
156 // XColumnsSupplier
157 Reference< XNameAccess > SAL_CALL OTable::getColumns( )
159 ::osl::MutexGuard aGuard(m_aMutex);
160 checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed);
164 if ( !m_xColumns )
165 refreshColumns();
167 catch( const RuntimeException& )
169 // allowed to leave this method
170 throw;
172 catch( const Exception& )
174 // allowed
177 return m_xColumns.get();
181 // XKeysSupplier
182 Reference< XIndexAccess > SAL_CALL OTable::getKeys( )
184 ::osl::MutexGuard aGuard(m_aMutex);
185 checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed);
187 Reference< XIndexAccess > xKeys;
191 if ( !m_xKeys )
192 refreshKeys();
193 xKeys = m_xKeys.get();
195 catch( const RuntimeException& )
197 // allowed to leave this method
198 throw;
200 catch( const Exception& )
202 // allowed
205 return xKeys;
208 cppu::IPropertyArrayHelper* OTable::createArrayHelper( sal_Int32 /*_nId*/ ) const
210 return doCreateArrayHelper();
213 cppu::IPropertyArrayHelper & OTable::getInfoHelper()
215 return *getArrayHelper(isNew() ? 1 : 0);
218 Reference< XPropertySet > SAL_CALL OTable::createDataDescriptor( )
220 ::osl::MutexGuard aGuard(m_aMutex);
221 checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed);
223 OTable* pTable = new OTable(m_pTables,isCaseSensitive(),m_Name,m_Type,m_Description,m_SchemaName,m_CatalogName);
224 pTable->setNew(true);
225 return pTable;
228 // XIndexesSupplier
229 Reference< XNameAccess > SAL_CALL OTable::getIndexes( )
231 ::osl::MutexGuard aGuard(m_aMutex);
232 checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed);
236 if ( !m_xIndexes )
237 refreshIndexes();
239 catch( const RuntimeException& )
241 // allowed to leave this method
242 throw;
244 catch( const Exception& )
246 // allowed
249 return m_xIndexes.get();
252 // XRename
253 void SAL_CALL OTable::rename( const OUString& newName )
255 ::osl::MutexGuard aGuard(m_aMutex);
256 checkDisposed(OTableDescriptor_BASE::rBHelper.bDisposed);
258 const OUString sOldComposedName = getName();
259 const Reference< XDatabaseMetaData> xMetaData = getMetaData();
260 if ( xMetaData.is() )
261 ::dbtools::qualifiedNameComponents(xMetaData,newName,m_CatalogName,m_SchemaName,m_Name,::dbtools::EComposeRule::InDataManipulation);
262 else
263 m_Name = newName;
265 m_pTables->renameObject(sOldComposedName,newName);
268 Reference< XDatabaseMetaData> OTable::getMetaData() const
270 return nullptr;
273 // XAlterTable
274 void SAL_CALL OTable::alterColumnByName( const OUString& /*colName*/, const Reference< XPropertySet >& /*descriptor*/ )
276 throwFeatureNotImplementedSQLException( "XAlterTable::alterColumnByName", *this );
279 void SAL_CALL OTable::alterColumnByIndex( sal_Int32 /*index*/, const Reference< XPropertySet >& /*descriptor*/ )
281 throwFeatureNotImplementedSQLException( "XAlterTable::alterColumnByIndex", *this );
284 css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL OTable::getPropertySetInfo( )
286 return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
289 OUString SAL_CALL OTable::getName()
291 // this is only correct for tables who haven't a schema or catalog name
292 OSL_ENSURE(m_CatalogName.isEmpty(),"getName(): forgot to override getName()!");
293 OSL_ENSURE(m_SchemaName.isEmpty(),"getName(): forgot to override getName()!");
294 return m_Name;
297 void SAL_CALL OTable::setName( const OUString& /*aName*/ )
301 void OTable::refreshColumns()
305 void OTable::refreshKeys()
309 void OTable::refreshIndexes()
314 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */