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 "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 <comphelper/sequence.hxx>
35 #include "TConnection.hxx"
36 #include <comphelper/types.hxx>
38 using namespace ::comphelper
;
40 using namespace connectivity
;
41 using namespace connectivity::ado
;
42 using namespace com::sun::star::uno
;
43 using namespace com::sun::star::lang
;
44 using namespace com::sun::star::beans
;
45 using namespace com::sun::star::sdbc
;
46 using namespace com::sun::star::container
;
48 // -------------------------------------------------------------------------
49 OAdoTable::OAdoTable(sdbcx::OCollection
* _pTables
,sal_Bool _bCase
,OCatalog
* _pCatalog
,_ADOTable
* _pTable
)
50 : OTable_TYPEDEF(_pTables
,_bCase
)
51 ,m_pCatalog(_pCatalog
)
54 m_aTable
= WpADOTable(_pTable
);
55 // m_aTable.putref_ParentCatalog(_pCatalog->getCatalog());
59 // -----------------------------------------------------------------------------
60 OAdoTable::OAdoTable(sdbcx::OCollection
* _pTables
,sal_Bool _bCase
,OCatalog
* _pCatalog
)
61 : OTable_TYPEDEF(_pTables
,_bCase
)
62 ,m_pCatalog(_pCatalog
)
66 m_aTable
.putref_ParentCatalog(_pCatalog
->getCatalog());
69 // -----------------------------------------------------------------------------
70 void SAL_CALL
OAdoTable::disposing(void)
72 OTable_TYPEDEF::disposing();
75 // -------------------------------------------------------------------------
76 void OAdoTable::refreshColumns()
78 TStringVector aVector
;
80 WpADOColumns aColumns
;
81 if ( m_aTable
.IsValid() )
83 aColumns
= m_aTable
.get_Columns();
84 aColumns
.fillElementNames(aVector
);
88 m_pColumns
->reFill(aVector
);
90 m_pColumns
= new OColumns(*this,m_aMutex
,aVector
,aColumns
,isCaseSensitive(),m_pCatalog
->getConnection());
92 // -------------------------------------------------------------------------
93 void OAdoTable::refreshKeys()
95 TStringVector aVector
;
98 if(m_aTable
.IsValid())
100 aKeys
= m_aTable
.get_Keys();
101 aKeys
.fillElementNames(aVector
);
105 m_pKeys
->reFill(aVector
);
107 m_pKeys
= new OKeys(*this,m_aMutex
,aVector
,aKeys
,isCaseSensitive(),m_pCatalog
->getConnection());
109 // -------------------------------------------------------------------------
110 void OAdoTable::refreshIndexes()
112 TStringVector aVector
;
114 WpADOIndexes aIndexes
;
115 if(m_aTable
.IsValid())
117 aIndexes
= m_aTable
.get_Indexes();
118 aIndexes
.fillElementNames(aVector
);
122 m_pIndexes
->reFill(aVector
);
124 m_pIndexes
= new OIndexes(*this,m_aMutex
,aVector
,aIndexes
,isCaseSensitive(),m_pCatalog
->getConnection());
126 //--------------------------------------------------------------------------
127 Sequence
< sal_Int8
> OAdoTable::getUnoTunnelImplementationId()
129 static ::cppu::OImplementationId
* pId
= 0;
132 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
135 static ::cppu::OImplementationId aId
;
139 return pId
->getImplementationId();
142 // com::sun::star::lang::XUnoTunnel
143 //------------------------------------------------------------------
144 sal_Int64
OAdoTable::getSomething( const Sequence
< sal_Int8
> & rId
) throw (RuntimeException
)
146 return (rId
.getLength() == 16 && 0 == memcmp(getUnoTunnelImplementationId().getConstArray(), rId
.getConstArray(), 16 ) )
147 ? reinterpret_cast< sal_Int64
>( this )
148 : OTable_TYPEDEF::getSomething(rId
);
150 // -------------------------------------------------------------------------
152 void SAL_CALL
OAdoTable::rename( const OUString
& newName
) throw(SQLException
, ElementExistException
, RuntimeException
)
154 ::osl::MutexGuard
aGuard(m_aMutex
);
155 checkDisposed(OTableDescriptor_BASE_TYPEDEF::rBHelper
.bDisposed
);
157 m_aTable
.put_Name(newName
);
158 ADOS::ThrowException(*(m_pCatalog
->getConnection()->getConnection()),*this);
160 OTable_TYPEDEF::rename(newName
);
162 // -----------------------------------------------------------------------------
163 Reference
< XDatabaseMetaData
> OAdoTable::getMetaData() const
165 return m_pCatalog
->getConnection()->getMetaData();
167 // -------------------------------------------------------------------------
169 void SAL_CALL
OAdoTable::alterColumnByName( const OUString
& colName
, const Reference
< XPropertySet
>& descriptor
) throw(SQLException
, NoSuchElementException
, RuntimeException
)
171 ::osl::MutexGuard
aGuard(m_aMutex
);
172 checkDisposed(OTableDescriptor_BASE_TYPEDEF::rBHelper
.bDisposed
);
174 sal_Bool bError
= sal_True
;
175 OAdoColumn
* pColumn
= NULL
;
176 if(::comphelper::getImplementation(pColumn
,descriptor
) && pColumn
!= NULL
)
178 WpADOColumns aColumns
= m_aTable
.get_Columns();
179 bError
= !aColumns
.Delete(colName
);
180 bError
= bError
|| !aColumns
.Append(pColumn
->getColumnImpl());
183 ADOS::ThrowException(*(m_pCatalog
->getConnection()->getConnection()),*this);
185 m_pColumns
->refresh();
188 // -------------------------------------------------------------------------
189 void SAL_CALL
OAdoTable::alterColumnByIndex( sal_Int32 index
, const Reference
< XPropertySet
>& descriptor
) throw(SQLException
, ::com::sun::star::lang::IndexOutOfBoundsException
, RuntimeException
)
191 ::osl::MutexGuard
aGuard(m_aMutex
);
192 checkDisposed(OTableDescriptor_BASE_TYPEDEF::rBHelper
.bDisposed
);
194 Reference
< XPropertySet
> xOld
;
195 m_pColumns
->getByIndex(index
) >>= xOld
;
197 alterColumnByName(getString(xOld
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME
))),descriptor
);
199 // -------------------------------------------------------------------------
200 void OAdoTable::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle
,const Any
& rValue
)throw (Exception
)
202 if(m_aTable
.IsValid())
206 case PROPERTY_ID_NAME
:
207 m_aTable
.put_Name(getString(rValue
));
210 case PROPERTY_ID_TYPE
:
211 OTools::putValue( m_aTable
.get_Properties(),
212 OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE
),
216 case PROPERTY_ID_DESCRIPTION
:
217 OTools::putValue( m_aTable
.get_Properties(),
218 OUString("Description"),
222 case PROPERTY_ID_SCHEMANAME
:
229 OTable_TYPEDEF::setFastPropertyValue_NoBroadcast(nHandle
,rValue
);
231 // -------------------------------------------------------------------------
232 void SAL_CALL
OAdoTable::acquire() throw()
234 OTable_TYPEDEF::acquire();
236 // -----------------------------------------------------------------------------
237 void SAL_CALL
OAdoTable::release() throw()
239 OTable_TYPEDEF::release();
241 // -----------------------------------------------------------------------------
242 OUString SAL_CALL
OAdoTable::getName() throw(::com::sun::star::uno::RuntimeException
)
244 return m_aTable
.get_Name();
247 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */