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 <sdbcx/VIndex.hxx>
21 #include <com/sun/star/beans/PropertyAttribute.hpp>
22 #include <connectivity/dbexception.hxx>
23 #include <comphelper/sequence.hxx>
24 #include <connectivity/sdbcx/VCollection.hxx>
25 #include <cppuhelper/supportsservice.hxx>
26 #include <TConnection.hxx>
27 #include <tools/diagnose_ex.h>
28 
29 using namespace ::connectivity;
30 using namespace ::dbtools;
31 using namespace ::connectivity::sdbcx;
32 using namespace ::cppu;
33 using namespace ::com::sun::star::beans;
34 using namespace ::com::sun::star::uno;
35 using namespace ::com::sun::star::sdbc;
36 using namespace ::com::sun::star::sdbcx;
37 using namespace ::com::sun::star::container;
38 using namespace ::com::sun::star::lang;
39 
40 
getImplementationName()41 OUString SAL_CALL OIndex::getImplementationName(  )
42 {
43     if(isNew())
44         return "com.sun.star.sdbcx.VIndexDescriptor";
45     return "com.sun.star.sdbcx.VIndex";
46 }
47 
getSupportedServiceNames()48 css::uno::Sequence< OUString > SAL_CALL OIndex::getSupportedServiceNames(  )
49 {
50     return { isNew()?OUString("com.sun.star.sdbcx.IndexDescriptor"):OUString("com.sun.star.sdbcx.Index") };
51 }
52 
supportsService(const OUString & _rServiceName)53 sal_Bool SAL_CALL OIndex::supportsService( const OUString& _rServiceName )
54 {
55     return cppu::supportsService(this, _rServiceName);
56 }
57 
OIndex(bool _bCase)58 OIndex::OIndex(bool _bCase) : ODescriptor_BASE(m_aMutex)
59                 ,   ODescriptor(ODescriptor_BASE::rBHelper,_bCase,true)
60                 ,m_IsUnique(false)
61                 ,m_IsPrimaryKeyIndex(false)
62                 ,m_IsClustered(false)
63 {
64 }
65 
OIndex(const OUString & Name,const OUString & Catalog,bool _isUnique,bool _isPrimaryKeyIndex,bool _isClustered,bool _bCase)66 OIndex::OIndex( const OUString& Name,
67                 const OUString& Catalog,
68                 bool _isUnique,
69                 bool _isPrimaryKeyIndex,
70                 bool _isClustered,
71                 bool _bCase) :  ODescriptor_BASE(m_aMutex)
72                         ,ODescriptor(ODescriptor_BASE::rBHelper, _bCase)
73                         ,m_Catalog(Catalog)
74                         ,m_IsUnique(_isUnique)
75                         ,m_IsPrimaryKeyIndex(_isPrimaryKeyIndex)
76                         ,m_IsClustered(_isClustered)
77 {
78     m_Name = Name;
79 }
80 
~OIndex()81 OIndex::~OIndex( )
82 {
83 }
84 
createArrayHelper(sal_Int32) const85 ::cppu::IPropertyArrayHelper* OIndex::createArrayHelper( sal_Int32 /*_nId*/ ) const
86 {
87     return doCreateArrayHelper();
88 }
89 
getInfoHelper()90 ::cppu::IPropertyArrayHelper& SAL_CALL OIndex::getInfoHelper()
91 {
92     return *OIndex_PROP::getArrayHelper(isNew() ? 1 : 0);
93 }
94 
queryInterface(const Type & rType)95 Any SAL_CALL OIndex::queryInterface( const Type & rType )
96 {
97     Any aRet = ODescriptor::queryInterface( rType);
98     if(!aRet.hasValue())
99     {
100         if(!isNew())
101             aRet = OIndex_BASE::queryInterface(rType);
102         if(!aRet.hasValue())
103             aRet = ODescriptor_BASE::queryInterface( rType);
104     }
105     return aRet;
106 }
107 
getTypes()108 Sequence< Type > SAL_CALL OIndex::getTypes(  )
109 {
110     if(isNew())
111         return ::comphelper::concatSequences(ODescriptor::getTypes(),ODescriptor_BASE::getTypes());
112     return ::comphelper::concatSequences(ODescriptor::getTypes(),ODescriptor_BASE::getTypes(),OIndex_BASE::getTypes());
113 }
114 
construct()115 void OIndex::construct()
116 {
117     ODescriptor::construct();
118 
119     sal_Int32 nAttrib = isNew() ? 0 : PropertyAttribute::READONLY;
120 
121     registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_CATALOG),         PROPERTY_ID_CATALOG,            nAttrib,&m_Catalog,         ::cppu::UnoType<OUString>::get());
122     registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISUNIQUE),            PROPERTY_ID_ISUNIQUE,           nAttrib,&m_IsUnique,            cppu::UnoType<bool>::get());
123     registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISPRIMARYKEYINDEX),PROPERTY_ID_ISPRIMARYKEYINDEX, nAttrib,&m_IsPrimaryKeyIndex,   cppu::UnoType<bool>::get());
124     registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISCLUSTERED),     PROPERTY_ID_ISCLUSTERED,        nAttrib,&m_IsClustered,     cppu::UnoType<bool>::get());
125 }
126 
disposing()127 void OIndex::disposing()
128 {
129     OPropertySetHelper::disposing();
130 
131     ::osl::MutexGuard aGuard(m_aMutex);
132 
133     if(m_pColumns)
134         m_pColumns->disposing();
135 }
136 
getColumns()137 Reference< css::container::XNameAccess > SAL_CALL OIndex::getColumns(  )
138 {
139     ::osl::MutexGuard aGuard(m_aMutex);
140     checkDisposed(ODescriptor_BASE::rBHelper.bDisposed);
141 
142     try
143     {
144         if  ( !m_pColumns )
145             refreshColumns();
146     }
147     catch( const RuntimeException& )
148     {
149         // allowed to leave this method
150         throw;
151     }
152     catch( const Exception& )
153     {
154         TOOLS_WARN_EXCEPTION( "connectivity.commontools", "OIndex::getColumns" );
155     }
156 
157     return m_pColumns.get();
158 }
159 
createDataDescriptor()160 Reference< XPropertySet > SAL_CALL OIndex::createDataDescriptor(  )
161 {
162     ::osl::MutexGuard aGuard(m_aMutex);
163     checkDisposed(ODescriptor_BASE::rBHelper.bDisposed);
164 
165 
166     return this;
167 }
168 
getPropertySetInfo()169 css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL OIndex::getPropertySetInfo(  )
170 {
171     return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
172 }
173 
getName()174 OUString SAL_CALL OIndex::getName(  )
175 {
176     return m_Name;
177 }
178 
setName(const OUString &)179 void SAL_CALL OIndex::setName( const OUString& /*aName*/ )
180 {
181 }
182 
183 // XInterface
acquire()184 void SAL_CALL OIndex::acquire() noexcept
185 {
186     ODescriptor_BASE::acquire();
187 }
188 
release()189 void SAL_CALL OIndex::release() noexcept
190 {
191     ODescriptor_BASE::release();
192 }
193 
refreshColumns()194 void OIndex::refreshColumns()
195 {
196 }
197 
198 
199 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
200