1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #include <ado/AIndex.hxx>
21 #include <com/sun/star/sdbc/XRow.hpp>
22 #include <com/sun/star/sdbc/XResultSet.hpp>
23 #include <cppuhelper/typeprovider.hxx>
24 #include <ado/AColumns.hxx>
25 #include <TConnection.hxx>
26 #include <comphelper/servicehelper.hxx>
27 #include <comphelper/types.hxx>
28 
29 using namespace ::comphelper;
30 
31 using namespace connectivity::ado;
32 using namespace com::sun::star::uno;
33 using namespace com::sun::star::lang;
34 using namespace com::sun::star::beans;
35 using namespace com::sun::star::sdbc;
36 
37 
OAdoIndex(bool _bCase,OConnection * _pConnection,ADOIndex * _pIndex)38 OAdoIndex::OAdoIndex(bool _bCase,OConnection* _pConnection,ADOIndex* _pIndex)
39     : sdbcx::OIndex(OUString(),OUString(),false,false,false,_bCase)
40     ,m_pConnection(_pConnection)
41 {
42     construct();
43     m_aIndex = WpADOIndex(_pIndex);
44     fillPropertyValues();
45 }
46 
OAdoIndex(bool _bCase,OConnection * _pConnection)47 OAdoIndex::OAdoIndex(bool _bCase,OConnection* _pConnection)
48     : sdbcx::OIndex(_bCase)
49     ,m_pConnection(_pConnection)
50 {
51     construct();
52     m_aIndex.Create();
53 }
54 
55 
refreshColumns()56 void OAdoIndex::refreshColumns()
57 {
58     ::std::vector< OUString> aVector;
59 
60     WpADOColumns aColumns;
61     if ( m_aIndex.IsValid() )
62     {
63         aColumns = m_aIndex.get_Columns();
64         aColumns.fillElementNames(aVector);
65     }
66 
67     if ( m_pColumns )
68         m_pColumns->reFill(aVector);
69     else
70         m_pColumns.reset(new OColumns(*this, m_aMutex, aVector, aColumns, isCaseSensitive(), m_pConnection));
71 }
72 
73 
getUnoTunnelId()74 Sequence< sal_Int8 > OAdoIndex::getUnoTunnelId()
75 {
76     static ::cppu::OImplementationId implId;
77 
78     return implId.getImplementationId();
79 }
80 
81 // css::lang::XUnoTunnel
82 
getSomething(const Sequence<sal_Int8> & rId)83 sal_Int64 OAdoIndex::getSomething( const Sequence< sal_Int8 > & rId )
84 {
85     return isUnoTunnelId<OAdoIndex>(rId)
86                 ? reinterpret_cast< sal_Int64 >( this )
87                 : sdbcx::OIndex::getSomething(rId);
88 }
89 
setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any & rValue)90 void SAL_CALL OAdoIndex::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rValue)
91 {
92     if(m_aIndex.IsValid())
93     {
94         switch(nHandle)
95         {
96             case PROPERTY_ID_NAME:
97                 {
98                     OUString aVal;
99                     rValue >>= aVal;
100                     m_aIndex.put_Name(aVal);
101                 }
102                 break;
103             case PROPERTY_ID_CATALOG:
104                 {
105                     OUString aVal;
106                     rValue >>= aVal;
107                     m_aIndex.put_Name(aVal);
108                 }
109                 break;
110             case PROPERTY_ID_ISUNIQUE:
111                 m_aIndex.put_Unique(getBOOL(rValue));
112                 break;
113             case PROPERTY_ID_ISPRIMARYKEYINDEX:
114                 m_aIndex.put_PrimaryKey(getBOOL(rValue));
115                 break;
116             case PROPERTY_ID_ISCLUSTERED:
117                 m_aIndex.put_Clustered(getBOOL(rValue));
118                 break;
119         }
120     }
121     sdbcx::OIndex::setFastPropertyValue_NoBroadcast(nHandle,rValue);
122 }
123 
124 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
125