1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <sal/config.h>
22 #include <string_view>
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>
38 #include <comphelper/servicehelper.hxx>
39 #include <comphelper/types.hxx>
41 using namespace ::comphelper
;
43 using namespace connectivity
;
44 using namespace connectivity::ado
;
45 using namespace com::sun::star::uno
;
46 using namespace com::sun::star::lang
;
47 using namespace com::sun::star::beans
;
48 using namespace com::sun::star::sdbc
;
49 using namespace com::sun::star::container
;
52 OAdoTable::OAdoTable(sdbcx::OCollection
* _pTables
,bool _bCase
,OCatalog
* _pCatalog
,_ADOTable
* _pTable
)
53 : OTable_TYPEDEF(_pTables
,_bCase
)
54 ,m_pCatalog(_pCatalog
)
57 m_aTable
.set(_pTable
);
58 // m_aTable.putref_ParentCatalog(_pCatalog->getCatalog());
63 OAdoTable::OAdoTable(sdbcx::OCollection
* _pTables
,bool _bCase
,OCatalog
* _pCatalog
)
64 : OTable_TYPEDEF(_pTables
,_bCase
)
65 ,m_pCatalog(_pCatalog
)
69 m_aTable
.putref_ParentCatalog(_pCatalog
->getCatalog());
73 void SAL_CALL
OAdoTable::disposing()
75 OTable_TYPEDEF::disposing();
79 void OAdoTable::refreshColumns()
81 ::std::vector
< OUString
> aVector
;
83 WpADOColumns aColumns
;
84 if ( m_aTable
.IsValid() )
86 aColumns
= m_aTable
.get_Columns();
87 aColumns
.fillElementNames(aVector
);
91 m_xColumns
->reFill(aVector
);
93 m_xColumns
.reset(new OColumns(*this,m_aMutex
,aVector
,aColumns
,isCaseSensitive(),m_pCatalog
->getConnection()));
96 void OAdoTable::refreshKeys()
98 ::std::vector
< OUString
> aVector
;
101 if(m_aTable
.IsValid())
103 aKeys
= m_aTable
.get_Keys();
104 aKeys
.fillElementNames(aVector
);
108 m_xKeys
->reFill(aVector
);
110 m_xKeys
.reset(new OKeys(*this,m_aMutex
,aVector
,aKeys
,isCaseSensitive(),m_pCatalog
->getConnection()));
113 void OAdoTable::refreshIndexes()
115 ::std::vector
< OUString
> aVector
;
117 WpADOIndexes aIndexes
;
118 if(m_aTable
.IsValid())
120 aIndexes
= m_aTable
.get_Indexes();
121 aIndexes
.fillElementNames(aVector
);
125 m_xIndexes
->reFill(aVector
);
127 m_xIndexes
.reset(new OIndexes(*this,m_aMutex
,aVector
,aIndexes
,isCaseSensitive(),m_pCatalog
->getConnection()));
131 void SAL_CALL
OAdoTable::rename( const OUString
& newName
)
133 ::osl::MutexGuard
aGuard(m_aMutex
);
134 checkDisposed(OTableDescriptor_BASE_TYPEDEF::rBHelper
.bDisposed
);
136 m_aTable
.put_Name(newName
);
137 ADOS::ThrowException(m_pCatalog
->getConnection()->getConnection(),*this);
139 OTable_TYPEDEF::rename(newName
);
142 Reference
< XDatabaseMetaData
> OAdoTable::getMetaData() const
144 return m_pCatalog
->getConnection()->getMetaData();
148 void SAL_CALL
OAdoTable::alterColumnByName( const OUString
& colName
, const Reference
< XPropertySet
>& descriptor
)
150 ::osl::MutexGuard
aGuard(m_aMutex
);
151 checkDisposed(OTableDescriptor_BASE_TYPEDEF::rBHelper
.bDisposed
);
154 OAdoColumn
* pColumn
= dynamic_cast<OAdoColumn
*>(descriptor
.get());
155 if(pColumn
!= nullptr)
157 WpADOColumns aColumns
= m_aTable
.get_Columns();
158 bError
= !aColumns
.Delete(colName
);
159 bError
= bError
|| !aColumns
.Append(pColumn
->getColumnImpl());
162 ADOS::ThrowException(m_pCatalog
->getConnection()->getConnection(),*this);
164 m_xColumns
->refresh();
168 void SAL_CALL
OAdoTable::alterColumnByIndex( sal_Int32 index
, const Reference
< XPropertySet
>& descriptor
)
170 ::osl::MutexGuard
aGuard(m_aMutex
);
171 checkDisposed(OTableDescriptor_BASE_TYPEDEF::rBHelper
.bDisposed
);
173 Reference
< XPropertySet
> xOld
;
174 m_xColumns
->getByIndex(index
) >>= xOld
;
176 alterColumnByName(getString(xOld
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME
))),descriptor
);
179 void OAdoTable::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle
,const Any
& rValue
)
181 if(m_aTable
.IsValid())
185 case PROPERTY_ID_NAME
:
186 m_aTable
.put_Name(getString(rValue
));
189 case PROPERTY_ID_TYPE
:
190 OTools::putValue( m_aTable
.get_Properties(),
191 OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE
),
195 case PROPERTY_ID_DESCRIPTION
:
196 OTools::putValue( m_aTable
.get_Properties(),
197 std::u16string_view(u
"Description"),
201 case PROPERTY_ID_SCHEMANAME
:
205 throw Exception("unknown prop " + OUString::number(nHandle
), nullptr);
208 OTable_TYPEDEF::setFastPropertyValue_NoBroadcast(nHandle
,rValue
);
211 OUString SAL_CALL
OAdoTable::getName()
213 return m_aTable
.get_Name();
216 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */