bump product version to 6.3.0.0.beta1
[LibreOffice.git] / connectivity / source / drivers / ado / ATable.cxx
blob09c4c397051d64be3075d00dbf0e4f88bd947c45
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 <ado/ATable.hxx>
21 #include <ado/AIndexes.hxx>
22 #include <ado/AColumns.hxx>
23 #include <ado/AColumn.hxx>
24 #include <ado/AKeys.hxx>
25 #include <ado/AConnection.hxx>
26 #include <com/sun/star/sdbc/XRow.hpp>
27 #include <com/sun/star/sdbc/XResultSet.hpp>
28 #include <com/sun/star/sdbcx/KeyType.hpp>
29 #include <com/sun/star/sdbc/KeyRule.hpp>
30 #include <cppuhelper/typeprovider.hxx>
31 #include <com/sun/star/lang/DisposedException.hpp>
32 #include <com/sun/star/sdbc/ColumnValue.hpp>
33 #include <ado/Awrapado.hxx>
34 #include <TConnection.hxx>
35 #include <comphelper/types.hxx>
37 using namespace ::comphelper;
39 using namespace connectivity;
40 using namespace connectivity::ado;
41 using namespace com::sun::star::uno;
42 using namespace com::sun::star::lang;
43 using namespace com::sun::star::beans;
44 using namespace com::sun::star::sdbc;
45 using namespace com::sun::star::container;
48 OAdoTable::OAdoTable(sdbcx::OCollection* _pTables,bool _bCase,OCatalog* _pCatalog,_ADOTable* _pTable)
49 : OTable_TYPEDEF(_pTables,_bCase)
50 ,m_pCatalog(_pCatalog)
52 construct();
53 m_aTable = WpADOTable(_pTable);
54 // m_aTable.putref_ParentCatalog(_pCatalog->getCatalog());
55 fillPropertyValues();
59 OAdoTable::OAdoTable(sdbcx::OCollection* _pTables,bool _bCase,OCatalog* _pCatalog)
60 : OTable_TYPEDEF(_pTables,_bCase)
61 ,m_pCatalog(_pCatalog)
63 construct();
64 m_aTable.Create();
65 m_aTable.putref_ParentCatalog(_pCatalog->getCatalog());
69 void SAL_CALL OAdoTable::disposing()
71 OTable_TYPEDEF::disposing();
72 m_aTable.clear();
75 void OAdoTable::refreshColumns()
77 ::std::vector< OUString> aVector;
79 WpADOColumns aColumns;
80 if ( m_aTable.IsValid() )
82 aColumns = m_aTable.get_Columns();
83 aColumns.fillElementNames(aVector);
86 if(m_xColumns)
87 m_xColumns->reFill(aVector);
88 else
89 m_xColumns = new OColumns(*this,m_aMutex,aVector,aColumns,isCaseSensitive(),m_pCatalog->getConnection());
92 void OAdoTable::refreshKeys()
94 ::std::vector< OUString> aVector;
96 WpADOKeys aKeys;
97 if(m_aTable.IsValid())
99 aKeys = m_aTable.get_Keys();
100 aKeys.fillElementNames(aVector);
103 if(m_xKeys)
104 m_xKeys->reFill(aVector);
105 else
106 m_xKeys = new OKeys(*this,m_aMutex,aVector,aKeys,isCaseSensitive(),m_pCatalog->getConnection());
109 void OAdoTable::refreshIndexes()
111 ::std::vector< OUString> aVector;
113 WpADOIndexes aIndexes;
114 if(m_aTable.IsValid())
116 aIndexes = m_aTable.get_Indexes();
117 aIndexes.fillElementNames(aVector);
120 if(m_xIndexes)
121 m_xIndexes->reFill(aVector);
122 else
123 m_xIndexes = new OIndexes(*this,m_aMutex,aVector,aIndexes,isCaseSensitive(),m_pCatalog->getConnection());
126 Sequence< sal_Int8 > OAdoTable::getUnoTunnelImplementationId()
128 static ::cppu::OImplementationId implId;
130 return implId.getImplementationId();
133 // css::lang::XUnoTunnel
135 sal_Int64 OAdoTable::getSomething( const Sequence< sal_Int8 > & rId )
137 return (rId.getLength() == 16 && 0 == memcmp(getUnoTunnelImplementationId().getConstArray(), rId.getConstArray(), 16 ) )
138 ? reinterpret_cast< sal_Int64 >( this )
139 : OTable_TYPEDEF::getSomething(rId);
142 // XRename
143 void SAL_CALL OAdoTable::rename( const OUString& newName )
145 ::osl::MutexGuard aGuard(m_aMutex);
146 checkDisposed(OTableDescriptor_BASE_TYPEDEF::rBHelper.bDisposed);
148 m_aTable.put_Name(newName);
149 ADOS::ThrowException(*(m_pCatalog->getConnection()->getConnection()),*this);
151 OTable_TYPEDEF::rename(newName);
154 Reference< XDatabaseMetaData> OAdoTable::getMetaData() const
156 return m_pCatalog->getConnection()->getMetaData();
159 // XAlterTable
160 void SAL_CALL OAdoTable::alterColumnByName( const OUString& colName, const Reference< XPropertySet >& descriptor )
162 ::osl::MutexGuard aGuard(m_aMutex);
163 checkDisposed(OTableDescriptor_BASE_TYPEDEF::rBHelper.bDisposed);
165 bool bError = true;
166 OAdoColumn* pColumn = nullptr;
167 if(::comphelper::getImplementation(pColumn,descriptor) && pColumn != nullptr)
169 WpADOColumns aColumns = m_aTable.get_Columns();
170 bError = !aColumns.Delete(colName);
171 bError = bError || !aColumns.Append(pColumn->getColumnImpl());
173 if(bError)
174 ADOS::ThrowException(*(m_pCatalog->getConnection()->getConnection()),*this);
176 m_xColumns->refresh();
177 refreshColumns();
180 void SAL_CALL OAdoTable::alterColumnByIndex( sal_Int32 index, const Reference< XPropertySet >& descriptor )
182 ::osl::MutexGuard aGuard(m_aMutex);
183 checkDisposed(OTableDescriptor_BASE_TYPEDEF::rBHelper.bDisposed);
185 Reference< XPropertySet > xOld;
186 m_xColumns->getByIndex(index) >>= xOld;
187 if(xOld.is())
188 alterColumnByName(getString(xOld->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME))),descriptor);
191 void OAdoTable::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rValue)
193 if(m_aTable.IsValid())
195 switch(nHandle)
197 case PROPERTY_ID_NAME:
198 m_aTable.put_Name(getString(rValue));
199 break;
201 case PROPERTY_ID_TYPE:
202 OTools::putValue( m_aTable.get_Properties(),
203 OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE),
204 getString(rValue));
205 break;
207 case PROPERTY_ID_DESCRIPTION:
208 OTools::putValue( m_aTable.get_Properties(),
209 OUString("Description"),
210 getString(rValue));
211 break;
213 case PROPERTY_ID_SCHEMANAME:
214 break;
216 default:
217 throw Exception("unknown prop " + OUString::number(nHandle), nullptr);
220 OTable_TYPEDEF::setFastPropertyValue_NoBroadcast(nHandle,rValue);
223 OUString SAL_CALL OAdoTable::getName()
225 return m_aTable.get_Name();
228 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */