1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ATable.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_connectivity.hxx"
33 #include "ado/ATable.hxx"
34 #include "ado/AIndexes.hxx"
35 #include "ado/AColumns.hxx"
36 #include "ado/AColumn.hxx"
37 #include "ado/AKeys.hxx"
38 #include "ado/AConnection.hxx"
39 #include <com/sun/star/sdbc/XRow.hpp>
40 #include <com/sun/star/sdbc/XResultSet.hpp>
41 #include <com/sun/star/sdbcx/KeyType.hpp>
42 #include <com/sun/star/sdbc/KeyRule.hpp>
43 #include <cppuhelper/typeprovider.hxx>
44 #include <com/sun/star/lang/DisposedException.hpp>
45 #include <com/sun/star/sdbc/ColumnValue.hpp>
46 #include "ado/Awrapado.hxx"
47 #include <comphelper/sequence.hxx>
48 #include "TConnection.hxx"
49 #include <comphelper/types.hxx>
51 using namespace ::comphelper
;
53 using namespace connectivity
;
54 using namespace connectivity::ado
;
55 using namespace com::sun::star::uno
;
56 using namespace com::sun::star::lang
;
57 using namespace com::sun::star::beans
;
58 using namespace com::sun::star::sdbc
;
59 using namespace com::sun::star::container
;
60 using namespace com::sun::star::lang
;
62 // -------------------------------------------------------------------------
63 OAdoTable::OAdoTable(sdbcx::OCollection
* _pTables
,sal_Bool _bCase
,OCatalog
* _pCatalog
,_ADOTable
* _pTable
)
64 : OTable_TYPEDEF(_pTables
,_bCase
,::rtl::OUString(),::rtl::OUString())
65 ,m_pCatalog(_pCatalog
)
68 m_aTable
= WpADOTable(_pTable
);
69 // m_aTable.putref_ParentCatalog(_pCatalog->getCatalog());
73 // -----------------------------------------------------------------------------
74 OAdoTable::OAdoTable(sdbcx::OCollection
* _pTables
,sal_Bool _bCase
,OCatalog
* _pCatalog
)
75 : OTable_TYPEDEF(_pTables
,_bCase
)
76 ,m_pCatalog(_pCatalog
)
80 m_aTable
.putref_ParentCatalog(_pCatalog
->getCatalog());
83 // -----------------------------------------------------------------------------
84 void SAL_CALL
OAdoTable::disposing(void)
86 OTable_TYPEDEF::disposing();
89 // -------------------------------------------------------------------------
90 void OAdoTable::refreshColumns()
92 TStringVector aVector
;
94 WpADOColumns aColumns
;
95 if ( m_aTable
.IsValid() )
97 aColumns
= m_aTable
.get_Columns();
98 aColumns
.fillElementNames(aVector
);
102 m_pColumns
->reFill(aVector
);
104 m_pColumns
= new OColumns(*this,m_aMutex
,aVector
,aColumns
,isCaseSensitive(),m_pCatalog
->getConnection());
106 // -------------------------------------------------------------------------
107 void OAdoTable::refreshKeys()
109 TStringVector aVector
;
112 if(m_aTable
.IsValid())
114 aKeys
= m_aTable
.get_Keys();
115 aKeys
.fillElementNames(aVector
);
119 m_pKeys
->reFill(aVector
);
121 m_pKeys
= new OKeys(*this,m_aMutex
,aVector
,aKeys
,isCaseSensitive(),m_pCatalog
->getConnection());
123 // -------------------------------------------------------------------------
124 void OAdoTable::refreshIndexes()
126 TStringVector aVector
;
128 WpADOIndexes aIndexes
;
129 if(m_aTable
.IsValid())
131 aIndexes
= m_aTable
.get_Indexes();
132 aIndexes
.fillElementNames(aVector
);
136 m_pIndexes
->reFill(aVector
);
138 m_pIndexes
= new OIndexes(*this,m_aMutex
,aVector
,aIndexes
,isCaseSensitive(),m_pCatalog
->getConnection());
140 //--------------------------------------------------------------------------
141 Sequence
< sal_Int8
> OAdoTable::getUnoTunnelImplementationId()
143 static ::cppu::OImplementationId
* pId
= 0;
146 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
149 static ::cppu::OImplementationId aId
;
153 return pId
->getImplementationId();
156 // com::sun::star::lang::XUnoTunnel
157 //------------------------------------------------------------------
158 sal_Int64
OAdoTable::getSomething( const Sequence
< sal_Int8
> & rId
) throw (RuntimeException
)
160 return (rId
.getLength() == 16 && 0 == rtl_compareMemory(getUnoTunnelImplementationId().getConstArray(), rId
.getConstArray(), 16 ) )
161 ? reinterpret_cast< sal_Int64
>( this )
162 : OTable_TYPEDEF::getSomething(rId
);
164 // -------------------------------------------------------------------------
166 void SAL_CALL
OAdoTable::rename( const ::rtl::OUString
& newName
) throw(SQLException
, ElementExistException
, RuntimeException
)
168 ::osl::MutexGuard
aGuard(m_aMutex
);
169 checkDisposed(OTableDescriptor_BASE_TYPEDEF::rBHelper
.bDisposed
);
171 m_aTable
.put_Name(newName
);
172 ADOS::ThrowException(*(m_pCatalog
->getConnection()->getConnection()),*this);
174 OTable_TYPEDEF::rename(newName
);
176 // -----------------------------------------------------------------------------
177 Reference
< XDatabaseMetaData
> OAdoTable::getMetaData() const
179 return m_pCatalog
->getConnection()->getMetaData();
181 // -------------------------------------------------------------------------
183 void SAL_CALL
OAdoTable::alterColumnByName( const ::rtl::OUString
& colName
, const Reference
< XPropertySet
>& descriptor
) throw(SQLException
, NoSuchElementException
, RuntimeException
)
185 ::osl::MutexGuard
aGuard(m_aMutex
);
186 checkDisposed(OTableDescriptor_BASE_TYPEDEF::rBHelper
.bDisposed
);
188 sal_Bool bError
= sal_True
;
189 OAdoColumn
* pColumn
= NULL
;
190 if(::comphelper::getImplementation(pColumn
,descriptor
) && pColumn
!= NULL
)
192 WpADOColumns aColumns
= m_aTable
.get_Columns();
193 bError
= !aColumns
.Delete(colName
);
194 bError
= bError
|| !aColumns
.Append(pColumn
->getColumnImpl());
197 ADOS::ThrowException(*(m_pCatalog
->getConnection()->getConnection()),*this);
199 m_pColumns
->refresh();
202 // -------------------------------------------------------------------------
203 void SAL_CALL
OAdoTable::alterColumnByIndex( sal_Int32 index
, const Reference
< XPropertySet
>& descriptor
) throw(SQLException
, ::com::sun::star::lang::IndexOutOfBoundsException
, RuntimeException
)
205 ::osl::MutexGuard
aGuard(m_aMutex
);
206 checkDisposed(OTableDescriptor_BASE_TYPEDEF::rBHelper
.bDisposed
);
208 Reference
< XPropertySet
> xOld
;
209 m_pColumns
->getByIndex(index
) >>= xOld
;
211 alterColumnByName(getString(xOld
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME
))),descriptor
);
213 // -------------------------------------------------------------------------
214 void OAdoTable::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle
,const Any
& rValue
)throw (Exception
)
216 if(m_aTable
.IsValid())
220 case PROPERTY_ID_NAME
:
221 m_aTable
.put_Name(getString(rValue
));
224 case PROPERTY_ID_TYPE
:
225 OTools::putValue( m_aTable
.get_Properties(),
226 OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE
),
230 case PROPERTY_ID_DESCRIPTION
:
231 OTools::putValue( m_aTable
.get_Properties(),
232 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Description")),
236 case PROPERTY_ID_SCHEMANAME
:
243 OTable_TYPEDEF::setFastPropertyValue_NoBroadcast(nHandle
,rValue
);
245 // -------------------------------------------------------------------------
246 void SAL_CALL
OAdoTable::acquire() throw()
248 OTable_TYPEDEF::acquire();
250 // -----------------------------------------------------------------------------
251 void SAL_CALL
OAdoTable::release() throw()
253 OTable_TYPEDEF::release();
255 // -----------------------------------------------------------------------------
256 ::rtl::OUString SAL_CALL
OAdoTable::getName() throw(::com::sun::star::uno::RuntimeException
)
258 return m_aTable
.get_Name();