LibreOffice Module connectivity (master) 1
ATable.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <sal/config.h>
21
22#include <string_view>
23
24#include <ado/ATable.hxx>
25#include <ado/AIndexes.hxx>
26#include <ado/AColumns.hxx>
27#include <ado/AColumn.hxx>
28#include <ado/AKeys.hxx>
29#include <ado/AConnection.hxx>
30#include <com/sun/star/sdbc/XRow.hpp>
31#include <com/sun/star/sdbc/XResultSet.hpp>
32#include <com/sun/star/sdbcx/KeyType.hpp>
33#include <com/sun/star/sdbc/KeyRule.hpp>
34#include <com/sun/star/lang/DisposedException.hpp>
35#include <com/sun/star/sdbc/ColumnValue.hpp>
36#include <ado/Awrapado.hxx>
37#include <TConnection.hxx>
39#include <comphelper/types.hxx>
40
41using namespace ::comphelper;
42
43using namespace connectivity;
44using namespace connectivity::ado;
45using namespace com::sun::star::uno;
46using namespace com::sun::star::lang;
47using namespace com::sun::star::beans;
48using namespace com::sun::star::sdbc;
49using namespace com::sun::star::container;
50
51
52OAdoTable::OAdoTable(sdbcx::OCollection* _pTables,bool _bCase,OCatalog* _pCatalog,_ADOTable* _pTable)
53 : OTable_TYPEDEF(_pTables,_bCase)
54 ,m_pCatalog(_pCatalog)
55{
56 construct();
57 m_aTable.set(_pTable);
58 // m_aTable.putref_ParentCatalog(_pCatalog->getCatalog());
60
61}
62
63OAdoTable::OAdoTable(sdbcx::OCollection* _pTables,bool _bCase,OCatalog* _pCatalog)
64 : OTable_TYPEDEF(_pTables,_bCase)
65 ,m_pCatalog(_pCatalog)
66{
67 construct();
70
71}
72
73void SAL_CALL OAdoTable::disposing()
74{
77}
78
80{
81 ::std::vector< OUString> aVector;
82
83 WpADOColumns aColumns;
84 if ( m_aTable.IsValid() )
85 {
86 aColumns = m_aTable.get_Columns();
87 aColumns.fillElementNames(aVector);
88 }
89
90 if(m_xColumns)
91 m_xColumns->reFill(aVector);
92 else
93 m_xColumns.reset(new OColumns(*this,m_aMutex,aVector,aColumns,isCaseSensitive(),m_pCatalog->getConnection()));
94}
95
97{
98 ::std::vector< OUString> aVector;
99
100 WpADOKeys aKeys;
101 if(m_aTable.IsValid())
102 {
103 aKeys = m_aTable.get_Keys();
104 aKeys.fillElementNames(aVector);
105 }
106
107 if(m_xKeys)
108 m_xKeys->reFill(aVector);
109 else
110 m_xKeys.reset(new OKeys(*this,m_aMutex,aVector,aKeys,isCaseSensitive(),m_pCatalog->getConnection()));
111}
112
114{
115 ::std::vector< OUString> aVector;
116
117 WpADOIndexes aIndexes;
118 if(m_aTable.IsValid())
119 {
120 aIndexes = m_aTable.get_Indexes();
121 aIndexes.fillElementNames(aVector);
122 }
123
124 if(m_xIndexes)
125 m_xIndexes->reFill(aVector);
126 else
127 m_xIndexes.reset(new OIndexes(*this,m_aMutex,aVector,aIndexes,isCaseSensitive(),m_pCatalog->getConnection()));
128}
129
130// XRename
131void SAL_CALL OAdoTable::rename( const OUString& newName )
132{
133 ::osl::MutexGuard aGuard(m_aMutex);
134 checkDisposed(OTableDescriptor_BASE_TYPEDEF::rBHelper.bDisposed);
135
138
140}
141
143{
145}
146
147// XAlterTable
148void SAL_CALL OAdoTable::alterColumnByName( const OUString& colName, const Reference< XPropertySet >& descriptor )
149{
150 ::osl::MutexGuard aGuard(m_aMutex);
151 checkDisposed(OTableDescriptor_BASE_TYPEDEF::rBHelper.bDisposed);
152
153 bool bError = true;
154 OAdoColumn* pColumn = dynamic_cast<OAdoColumn*>(descriptor.get());
155 if(pColumn != nullptr)
156 {
157 WpADOColumns aColumns = m_aTable.get_Columns();
158 bError = !aColumns.Delete(colName);
159 bError = bError || !aColumns.Append(pColumn->getColumnImpl());
160 }
161 if(bError)
163
164 m_xColumns->refresh();
166}
167
168void SAL_CALL OAdoTable::alterColumnByIndex( sal_Int32 index, const Reference< XPropertySet >& descriptor )
169{
170 ::osl::MutexGuard aGuard(m_aMutex);
171 checkDisposed(OTableDescriptor_BASE_TYPEDEF::rBHelper.bDisposed);
172
174 m_xColumns->getByIndex(index) >>= xOld;
175 if(xOld.is())
177}
178
179void OAdoTable::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rValue)
180{
181 if(m_aTable.IsValid())
182 {
183 switch(nHandle)
184 {
185 case PROPERTY_ID_NAME:
186 m_aTable.put_Name(getString(rValue));
187 break;
188
189 case PROPERTY_ID_TYPE:
192 getString(rValue));
193 break;
194
197 std::u16string_view(u"Description"),
198 getString(rValue));
199 break;
200
202 break;
203
204 default:
205 throw Exception("unknown prop " + OUString::number(nHandle), nullptr);
206 }
207 }
209}
210
211OUString SAL_CALL OAdoTable::getName()
212{
213 return m_aTable.get_Name();
214}
215
216/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void SAL_CALL setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const css::uno::Any &rValue) override
::dbtools::OPropertyMap & getPropMap()
Definition: TConnection.cxx:68
static void ThrowException(ADOConnection *_pAdoCon, const css::uno::Reference< css::uno::XInterface > &_xInterface)
Definition: ADriver.cxx:207
WpADOColumn getColumnImpl() const
Definition: AColumn.cxx:229
virtual void SAL_CALL disposing() override
Definition: ATable.cxx:73
virtual css::uno::Reference< css::sdbc::XDatabaseMetaData > getMetaData() const override
Definition: ATable.cxx:142
virtual void refreshColumns() override
Definition: ATable.cxx:79
virtual void SAL_CALL alterColumnByName(const OUString &colName, const css::uno::Reference< css::beans::XPropertySet > &descriptor) override
Definition: ATable.cxx:148
virtual void SAL_CALL rename(const OUString &newName) override
Definition: ATable.cxx:131
virtual void refreshKeys() override
Definition: ATable.cxx:96
virtual OUString SAL_CALL getName() override
Definition: ATable.cxx:211
OAdoTable(sdbcx::OCollection *_pTables, bool _bCase, OCatalog *_pCatalog, _ADOTable *_pTable)
Definition: ATable.cxx:52
virtual void SAL_CALL alterColumnByIndex(sal_Int32 index, const css::uno::Reference< css::beans::XPropertySet > &descriptor) override
Definition: ATable.cxx:168
virtual void SAL_CALL setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const css::uno::Any &rValue) override
Definition: ATable.cxx:179
virtual void refreshIndexes() override
Definition: ATable.cxx:113
WpADOCatalog getCatalog() const
Definition: ACatalog.hxx:45
OConnection * getConnection() const
Definition: ACatalog.hxx:43
virtual css::uno::Reference< css::sdbc::XDatabaseMetaData > SAL_CALL getMetaData() override
WpADOConnection & getConnection()
static void putValue(const WpADOProperties &_rProps, const OLEVariant &_aPosition, const OLEVariant &_aValVar)
putValue set the property value at the ado column
Definition: Awrapado.cxx:1992
void put_Name(std::u16string_view _rName)
Definition: Awrapado.cxx:1291
WpADOKeys get_Keys() const
Definition: Awrapado.cxx:1322
WpADOProperties get_Properties() const
Definition: Awrapado.cxx:1338
WpADOIndexes get_Indexes() const
Definition: Awrapado.cxx:1314
void putref_ParentCatalog(_ADOCatalog __RPC_FAR *ppvObject)
Definition: Awrapado.cxx:1985
WpADOColumns get_Columns() const
Definition: Awrapado.cxx:1306
bool Append(const WrapT &aWrapT)
Definition: Aolewrap.hxx:160
bool Delete(const OUString &sName)
Definition: Aolewrap.hxx:165
void fillElementNames(::std::vector< OUString > &_rVector)
Definition: Aolewrap.hxx:129
std::unique_ptr< OCollection > m_xIndexes
Definition: VTable.hxx:78
std::unique_ptr< OCollection > m_xKeys
Definition: VTable.hxx:76
std::unique_ptr< OCollection > m_xColumns
Definition: VTable.hxx:77
virtual void SAL_CALL rename(const OUString &newName) override
Definition: VTable.cxx:244
virtual void construct() override
Definition: VTable.cxx:86
virtual void SAL_CALL disposing() override
Definition: VTable.cxx:131
mutable::osl::Mutex m_aMutex
const OUString & getNameByIndex(sal_Int32 _nIndex) const
Definition: propertyids.cxx:95
float u
@ Exception
OUString getString(const Any &_rAny)
void checkDisposed(bool _bThrow)
Definition: dbtools.cxx:1951
OUString newName(std::u16string_view aNewPrefix, std::u16string_view aOldPrefix, std::u16string_view old_Name)
index
#define PROPERTY_ID_NAME
Definition: propertyids.hxx:50
#define PROPERTY_ID_TYPE
Definition: propertyids.hxx:51
#define PROPERTY_ID_DESCRIPTION
Definition: propertyids.hxx:58
#define PROPERTY_ID_SCHEMANAME
Definition: propertyids.hxx:69
sal_Int32 nHandle