xref: /trunk/main/connectivity/source/drivers/adabas/BIndex.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_connectivity.hxx"
30 #include "adabas/BIndex.hxx"
31 #ifndef _CONNECTIVITY_ADABAS_INDEXCOLUMNS_HXX_
32 #include "adabas/BIndexColumns.hxx"
33 #endif
34 #include <com/sun/star/sdbc/XRow.hpp>
35 #include <com/sun/star/sdbc/XResultSet.hpp>
36 #include "adabas/BTable.hxx"
37 #include <comphelper/types.hxx>
38 
39 using namespace connectivity::adabas;
40 using namespace ::com::sun::star::uno;
41 using namespace ::com::sun::star::beans;
42 //  using namespace ::com::sun::star::sdbcx;
43 using namespace ::com::sun::star::sdbc;
44 using namespace ::com::sun::star::container;
45 using namespace ::com::sun::star::lang;
46 // -------------------------------------------------------------------------
47 OAdabasIndex::OAdabasIndex( OAdabasTable* _pTable,
48                 const ::rtl::OUString& _Name,
49                 const ::rtl::OUString& _Catalog,
50                 sal_Bool _isUnique,
51                 sal_Bool _isPrimaryKeyIndex,
52                 sal_Bool _isClustered
53                 ) : connectivity::sdbcx::OIndex(_Name,
54                                   _Catalog,
55                                   _isUnique,
56                                   _isPrimaryKeyIndex,
57                                   _isClustered,sal_True)
58                 ,m_pTable(_pTable)
59 {
60     construct();
61     refreshColumns();
62 }
63 // -------------------------------------------------------------------------
64 OAdabasIndex::OAdabasIndex(OAdabasTable* _pTable)
65     : connectivity::sdbcx::OIndex(sal_True)
66     ,m_pTable(_pTable)
67 {
68     construct();
69 }
70 // -----------------------------------------------------------------------------
71 
72 void OAdabasIndex::refreshColumns()
73 {
74     if(!m_pTable)
75         return;
76 
77     TStringVector aVector;
78     if(!isNew())
79     {
80         Reference< XResultSet > xResult = m_pTable->getMetaData()->getIndexInfo(Any(),
81         m_pTable->getSchema(),m_pTable->getTableName(),sal_False,sal_False);
82 
83         if(xResult.is())
84         {
85                     Reference< XRow > xRow(xResult,UNO_QUERY);
86             ::rtl::OUString aColName;
87             while(xResult->next())
88             {
89                 if(xRow->getString(6) == m_Name)
90                 {
91                     aColName = xRow->getString(9);
92                     if(!xRow->wasNull())
93                         aVector.push_back(aColName);
94                 }
95             }
96             ::comphelper::disposeComponent(xResult);
97         }
98     }
99     if(m_pColumns)
100         m_pColumns->reFill(aVector);
101     else
102         m_pColumns  = new OIndexColumns(this,m_aMutex,aVector);
103 }
104 // -----------------------------------------------------------------------------
105 
106 
107