xref: /trunk/main/connectivity/source/sdbcx/VIndex.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
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 "connectivity/sdbcx/VIndex.hxx"
31 #include <com/sun/star/lang/DisposedException.hpp>
32 #include "connectivity/sdbcx/VColumn.hxx"
33 #include <connectivity/dbexception.hxx>
34 #include <comphelper/sequence.hxx>
35 #include "connectivity/sdbcx/VCollection.hxx"
36 #include "TConnection.hxx"
37 // -------------------------------------------------------------------------
38 using namespace ::connectivity;
39 using namespace ::connectivity;
40 using namespace ::dbtools;
41 using namespace ::connectivity::sdbcx;
42 using namespace ::cppu;
43 using namespace ::com::sun::star::beans;
44 using namespace ::com::sun::star::uno;
45 using namespace ::com::sun::star::sdbc;
46 using namespace ::com::sun::star::sdbcx;
47 using namespace ::com::sun::star::container;
48 using namespace ::com::sun::star::lang;
49 
50 // -----------------------------------------------------------------------------
51 ::rtl::OUString SAL_CALL OIndex::getImplementationName(  ) throw (::com::sun::star::uno::RuntimeException)
52 {
53     if(isNew())
54         return ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.VIndexDescriptor");
55     return ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.VIndex");
56 }
57 // -----------------------------------------------------------------------------
58 ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL OIndex::getSupportedServiceNames(  ) throw(::com::sun::star::uno::RuntimeException)
59 {
60     ::com::sun::star::uno::Sequence< ::rtl::OUString > aSupported(1);
61     if(isNew())
62         aSupported[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.IndexDescriptor");
63     else
64         aSupported[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.Index");
65 
66     return aSupported;
67 }
68 // -----------------------------------------------------------------------------
69 sal_Bool SAL_CALL OIndex::supportsService( const ::rtl::OUString& _rServiceName ) throw(::com::sun::star::uno::RuntimeException)
70 {
71     Sequence< ::rtl::OUString > aSupported(getSupportedServiceNames());
72     const ::rtl::OUString* pSupported = aSupported.getConstArray();
73     const ::rtl::OUString* pEnd = pSupported + aSupported.getLength();
74     for (;pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported)
75         ;
76 
77     return pSupported != pEnd;
78 }
79 // -------------------------------------------------------------------------
80 OIndex::OIndex(sal_Bool _bCase) :   ODescriptor_BASE(m_aMutex)
81                 ,   ODescriptor(ODescriptor_BASE::rBHelper,_bCase,sal_True)
82                 ,m_IsUnique(sal_False)
83                 ,m_IsPrimaryKeyIndex(sal_False)
84                 ,m_IsClustered(sal_False)
85                 ,m_pColumns(NULL)
86 {
87 }
88 // -------------------------------------------------------------------------
89 OIndex::OIndex( const ::rtl::OUString& _Name,
90                 const ::rtl::OUString& _Catalog,
91                 sal_Bool _isUnique,
92                 sal_Bool _isPrimaryKeyIndex,
93                 sal_Bool _isClustered,
94                 sal_Bool _bCase) :  ODescriptor_BASE(m_aMutex)
95                         ,ODescriptor(ODescriptor_BASE::rBHelper,_bCase)
96                         ,m_Catalog(_Catalog)
97                         ,m_IsUnique(_isUnique)
98                         ,m_IsPrimaryKeyIndex(_isPrimaryKeyIndex)
99                         ,m_IsClustered(_isClustered)
100                         ,m_pColumns(NULL)
101 {
102     m_Name = _Name;
103 }
104 // -------------------------------------------------------------------------
105 OIndex::~OIndex( )
106 {
107     delete m_pColumns;
108 }
109 // -----------------------------------------------------------------------------
110 ::cppu::IPropertyArrayHelper* OIndex::createArrayHelper( sal_Int32 /*_nId*/ ) const
111 {
112     return doCreateArrayHelper();
113 }
114 // -----------------------------------------------------------------------------
115 ::cppu::IPropertyArrayHelper& SAL_CALL OIndex::getInfoHelper()
116 {
117     return *OIndex_PROP::getArrayHelper(isNew() ? 1 : 0);
118 }
119 // -------------------------------------------------------------------------
120 Any SAL_CALL OIndex::queryInterface( const Type & rType ) throw(RuntimeException)
121 {
122     Any aRet = ODescriptor::queryInterface( rType);
123     if(!aRet.hasValue())
124     {
125         if(!isNew())
126             aRet = OIndex_BASE::queryInterface(rType);
127         if(!aRet.hasValue())
128             aRet = ODescriptor_BASE::queryInterface( rType);
129     }
130     return aRet;
131 }
132 // -------------------------------------------------------------------------
133 Sequence< Type > SAL_CALL OIndex::getTypes(  ) throw(RuntimeException)
134 {
135     if(isNew())
136         return ::comphelper::concatSequences(ODescriptor::getTypes(),ODescriptor_BASE::getTypes());
137     return ::comphelper::concatSequences(ODescriptor::getTypes(),ODescriptor_BASE::getTypes(),OIndex_BASE::getTypes());
138 }
139 // -------------------------------------------------------------------------
140 void OIndex::construct()
141 {
142     ODescriptor::construct();
143 
144     sal_Int32 nAttrib = isNew() ? 0 : PropertyAttribute::READONLY;
145 
146     registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_CATALOG),         PROPERTY_ID_CATALOG,            nAttrib,&m_Catalog,         ::getCppuType(reinterpret_cast< ::rtl::OUString*>(NULL)));
147     registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISUNIQUE),            PROPERTY_ID_ISUNIQUE,           nAttrib,&m_IsUnique,            ::getBooleanCppuType());
148     registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISPRIMARYKEYINDEX),PROPERTY_ID_ISPRIMARYKEYINDEX, nAttrib,&m_IsPrimaryKeyIndex,   ::getBooleanCppuType());
149     registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISCLUSTERED),     PROPERTY_ID_ISCLUSTERED,        nAttrib,&m_IsClustered,     ::getBooleanCppuType());
150 }
151 // -------------------------------------------------------------------------
152 void OIndex::disposing(void)
153 {
154     OPropertySetHelper::disposing();
155 
156     ::osl::MutexGuard aGuard(m_aMutex);
157 
158     if(m_pColumns)
159         m_pColumns->disposing();
160 }
161 // -------------------------------------------------------------------------
162 Reference< ::com::sun::star::container::XNameAccess > SAL_CALL OIndex::getColumns(  ) throw(RuntimeException)
163 {
164     ::osl::MutexGuard aGuard(m_aMutex);
165     checkDisposed(ODescriptor_BASE::rBHelper.bDisposed);
166 
167     try
168     {
169         if  ( !m_pColumns )
170             refreshColumns();
171     }
172     catch( const RuntimeException& )
173     {
174         // allowed to leave this method
175         throw;
176     }
177     catch( const Exception& )
178     {
179         OSL_ENSURE( false, "OIndex::getColumns: caught an exception!" );
180     }
181 
182     return const_cast<OIndex*>(this)->m_pColumns;
183 }
184 // -------------------------------------------------------------------------
185 Reference< XPropertySet > SAL_CALL OIndex::createDataDescriptor(  ) throw(RuntimeException)
186 {
187     ::osl::MutexGuard aGuard(m_aMutex);
188     checkDisposed(ODescriptor_BASE::rBHelper.bDisposed);
189 
190 
191     return this;
192 }
193 // -----------------------------------------------------------------------------
194 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL OIndex::getPropertySetInfo(  ) throw(::com::sun::star::uno::RuntimeException)
195 {
196     return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
197 }
198 // -----------------------------------------------------------------------------
199 ::rtl::OUString SAL_CALL OIndex::getName(  ) throw(::com::sun::star::uno::RuntimeException)
200 {
201     return m_Name;
202 }
203 // -----------------------------------------------------------------------------
204 void SAL_CALL OIndex::setName( const ::rtl::OUString& /*aName*/ ) throw(::com::sun::star::uno::RuntimeException)
205 {
206 }
207 // -----------------------------------------------------------------------------
208 // XInterface
209 void SAL_CALL OIndex::acquire() throw()
210 {
211     ODescriptor_BASE::acquire();
212 }
213 // -----------------------------------------------------------------------------
214 void SAL_CALL OIndex::release() throw()
215 {
216     ODescriptor_BASE::release();
217 }
218 // -----------------------------------------------------------------------------
219 void OIndex::refreshColumns()
220 {
221 }
222 // -----------------------------------------------------------------------------
223 
224