1*9b5730f6SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*9b5730f6SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*9b5730f6SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*9b5730f6SAndrew Rist  * distributed with this work for additional information
6*9b5730f6SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*9b5730f6SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*9b5730f6SAndrew Rist  * "License"); you may not use this file except in compliance
9*9b5730f6SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*9b5730f6SAndrew Rist  *
11*9b5730f6SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*9b5730f6SAndrew Rist  *
13*9b5730f6SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*9b5730f6SAndrew Rist  * software distributed under the License is distributed on an
15*9b5730f6SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9b5730f6SAndrew Rist  * KIND, either express or implied.  See the License for the
17*9b5730f6SAndrew Rist  * specific language governing permissions and limitations
18*9b5730f6SAndrew Rist  * under the License.
19*9b5730f6SAndrew Rist  *
20*9b5730f6SAndrew Rist  *************************************************************/
21*9b5730f6SAndrew Rist 
22*9b5730f6SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_connectivity.hxx"
26cdf0e10cSrcweir #include "connectivity/sdbcx/VIndex.hxx"
27cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp>
28cdf0e10cSrcweir #include "connectivity/sdbcx/VColumn.hxx"
29cdf0e10cSrcweir #include <connectivity/dbexception.hxx>
30cdf0e10cSrcweir #include <comphelper/sequence.hxx>
31cdf0e10cSrcweir #include "connectivity/sdbcx/VCollection.hxx"
32cdf0e10cSrcweir #include "TConnection.hxx"
33cdf0e10cSrcweir // -------------------------------------------------------------------------
34cdf0e10cSrcweir using namespace ::connectivity;
35cdf0e10cSrcweir using namespace ::connectivity;
36cdf0e10cSrcweir using namespace ::dbtools;
37cdf0e10cSrcweir using namespace ::connectivity::sdbcx;
38cdf0e10cSrcweir using namespace ::cppu;
39cdf0e10cSrcweir using namespace ::com::sun::star::beans;
40cdf0e10cSrcweir using namespace ::com::sun::star::uno;
41cdf0e10cSrcweir using namespace ::com::sun::star::sdbc;
42cdf0e10cSrcweir using namespace ::com::sun::star::sdbcx;
43cdf0e10cSrcweir using namespace ::com::sun::star::container;
44cdf0e10cSrcweir using namespace ::com::sun::star::lang;
45cdf0e10cSrcweir 
46cdf0e10cSrcweir // -----------------------------------------------------------------------------
getImplementationName()47cdf0e10cSrcweir ::rtl::OUString SAL_CALL OIndex::getImplementationName(  ) throw (::com::sun::star::uno::RuntimeException)
48cdf0e10cSrcweir {
49cdf0e10cSrcweir 	if(isNew())
50cdf0e10cSrcweir 		return ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.VIndexDescriptor");
51cdf0e10cSrcweir 	return ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.VIndex");
52cdf0e10cSrcweir }
53cdf0e10cSrcweir // -----------------------------------------------------------------------------
getSupportedServiceNames()54cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL OIndex::getSupportedServiceNames(  ) throw(::com::sun::star::uno::RuntimeException)
55cdf0e10cSrcweir {
56cdf0e10cSrcweir 	::com::sun::star::uno::Sequence< ::rtl::OUString > aSupported(1);
57cdf0e10cSrcweir 	if(isNew())
58cdf0e10cSrcweir 		aSupported[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.IndexDescriptor");
59cdf0e10cSrcweir 	else
60cdf0e10cSrcweir 		aSupported[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.Index");
61cdf0e10cSrcweir 
62cdf0e10cSrcweir 	return aSupported;
63cdf0e10cSrcweir }
64cdf0e10cSrcweir // -----------------------------------------------------------------------------
supportsService(const::rtl::OUString & _rServiceName)65cdf0e10cSrcweir sal_Bool SAL_CALL OIndex::supportsService( const ::rtl::OUString& _rServiceName ) throw(::com::sun::star::uno::RuntimeException)
66cdf0e10cSrcweir {
67cdf0e10cSrcweir 	Sequence< ::rtl::OUString > aSupported(getSupportedServiceNames());
68cdf0e10cSrcweir 	const ::rtl::OUString* pSupported = aSupported.getConstArray();
69cdf0e10cSrcweir 	const ::rtl::OUString* pEnd = pSupported + aSupported.getLength();
70cdf0e10cSrcweir 	for (;pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported)
71cdf0e10cSrcweir 		;
72cdf0e10cSrcweir 
73cdf0e10cSrcweir 	return pSupported != pEnd;
74cdf0e10cSrcweir }
75cdf0e10cSrcweir // -------------------------------------------------------------------------
OIndex(sal_Bool _bCase)76cdf0e10cSrcweir OIndex::OIndex(sal_Bool _bCase) :	ODescriptor_BASE(m_aMutex)
77cdf0e10cSrcweir 				,	ODescriptor(ODescriptor_BASE::rBHelper,_bCase,sal_True)
78cdf0e10cSrcweir 				,m_IsUnique(sal_False)
79cdf0e10cSrcweir                 ,m_IsPrimaryKeyIndex(sal_False)
80cdf0e10cSrcweir 				,m_IsClustered(sal_False)
81cdf0e10cSrcweir                 ,m_pColumns(NULL)
82cdf0e10cSrcweir {
83cdf0e10cSrcweir }
84cdf0e10cSrcweir // -------------------------------------------------------------------------
OIndex(const::rtl::OUString & _Name,const::rtl::OUString & _Catalog,sal_Bool _isUnique,sal_Bool _isPrimaryKeyIndex,sal_Bool _isClustered,sal_Bool _bCase)85cdf0e10cSrcweir OIndex::OIndex(	const ::rtl::OUString& _Name,
86cdf0e10cSrcweir 				const ::rtl::OUString& _Catalog,
87cdf0e10cSrcweir 				sal_Bool _isUnique,
88cdf0e10cSrcweir 				sal_Bool _isPrimaryKeyIndex,
89cdf0e10cSrcweir 				sal_Bool _isClustered,
90cdf0e10cSrcweir 				sal_Bool _bCase) :	ODescriptor_BASE(m_aMutex)
91cdf0e10cSrcweir 						,ODescriptor(ODescriptor_BASE::rBHelper,_bCase)
92cdf0e10cSrcweir 						,m_Catalog(_Catalog)
93cdf0e10cSrcweir 						,m_IsUnique(_isUnique)
94cdf0e10cSrcweir 						,m_IsPrimaryKeyIndex(_isPrimaryKeyIndex)
95cdf0e10cSrcweir 						,m_IsClustered(_isClustered)
96cdf0e10cSrcweir                         ,m_pColumns(NULL)
97cdf0e10cSrcweir {
98cdf0e10cSrcweir 	m_Name = _Name;
99cdf0e10cSrcweir }
100cdf0e10cSrcweir // -------------------------------------------------------------------------
~OIndex()101cdf0e10cSrcweir OIndex::~OIndex( )
102cdf0e10cSrcweir {
103cdf0e10cSrcweir 	delete m_pColumns;
104cdf0e10cSrcweir }
105cdf0e10cSrcweir // -----------------------------------------------------------------------------
createArrayHelper(sal_Int32) const106cdf0e10cSrcweir ::cppu::IPropertyArrayHelper* OIndex::createArrayHelper( sal_Int32 /*_nId*/ ) const
107cdf0e10cSrcweir {
108cdf0e10cSrcweir     return doCreateArrayHelper();
109cdf0e10cSrcweir }
110cdf0e10cSrcweir // -----------------------------------------------------------------------------
getInfoHelper()111cdf0e10cSrcweir ::cppu::IPropertyArrayHelper& SAL_CALL OIndex::getInfoHelper()
112cdf0e10cSrcweir {
113cdf0e10cSrcweir 	return *OIndex_PROP::getArrayHelper(isNew() ? 1 : 0);
114cdf0e10cSrcweir }
115cdf0e10cSrcweir // -------------------------------------------------------------------------
queryInterface(const Type & rType)116cdf0e10cSrcweir Any SAL_CALL OIndex::queryInterface( const Type & rType ) throw(RuntimeException)
117cdf0e10cSrcweir {
118cdf0e10cSrcweir     Any aRet = ODescriptor::queryInterface( rType);
119cdf0e10cSrcweir 	if(!aRet.hasValue())
120cdf0e10cSrcweir 	{
121cdf0e10cSrcweir 		if(!isNew())
122cdf0e10cSrcweir 			aRet = OIndex_BASE::queryInterface(rType);
123cdf0e10cSrcweir 		if(!aRet.hasValue())
124cdf0e10cSrcweir 			aRet = ODescriptor_BASE::queryInterface( rType);
125cdf0e10cSrcweir 	}
126cdf0e10cSrcweir 	return aRet;
127cdf0e10cSrcweir }
128cdf0e10cSrcweir // -------------------------------------------------------------------------
getTypes()129cdf0e10cSrcweir Sequence< Type > SAL_CALL OIndex::getTypes(  ) throw(RuntimeException)
130cdf0e10cSrcweir {
131cdf0e10cSrcweir 	if(isNew())
132cdf0e10cSrcweir 		return ::comphelper::concatSequences(ODescriptor::getTypes(),ODescriptor_BASE::getTypes());
133cdf0e10cSrcweir 	return ::comphelper::concatSequences(ODescriptor::getTypes(),ODescriptor_BASE::getTypes(),OIndex_BASE::getTypes());
134cdf0e10cSrcweir }
135cdf0e10cSrcweir // -------------------------------------------------------------------------
construct()136cdf0e10cSrcweir void OIndex::construct()
137cdf0e10cSrcweir {
138cdf0e10cSrcweir 	ODescriptor::construct();
139cdf0e10cSrcweir 
140cdf0e10cSrcweir 	sal_Int32 nAttrib = isNew() ? 0 : PropertyAttribute::READONLY;
141cdf0e10cSrcweir 
142cdf0e10cSrcweir 	registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_CATALOG),			PROPERTY_ID_CATALOG,			nAttrib,&m_Catalog,			::getCppuType(reinterpret_cast< ::rtl::OUString*>(NULL)));
143cdf0e10cSrcweir 	registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISUNIQUE),			PROPERTY_ID_ISUNIQUE,			nAttrib,&m_IsUnique,			::getBooleanCppuType());
144cdf0e10cSrcweir 	registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISPRIMARYKEYINDEX),PROPERTY_ID_ISPRIMARYKEYINDEX,	nAttrib,&m_IsPrimaryKeyIndex,	::getBooleanCppuType());
145cdf0e10cSrcweir 	registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISCLUSTERED),		PROPERTY_ID_ISCLUSTERED,		nAttrib,&m_IsClustered,		::getBooleanCppuType());
146cdf0e10cSrcweir }
147cdf0e10cSrcweir // -------------------------------------------------------------------------
disposing(void)148cdf0e10cSrcweir void OIndex::disposing(void)
149cdf0e10cSrcweir {
150cdf0e10cSrcweir 	OPropertySetHelper::disposing();
151cdf0e10cSrcweir 
152cdf0e10cSrcweir 	::osl::MutexGuard aGuard(m_aMutex);
153cdf0e10cSrcweir 
154cdf0e10cSrcweir 	if(m_pColumns)
155cdf0e10cSrcweir 		m_pColumns->disposing();
156cdf0e10cSrcweir }
157cdf0e10cSrcweir // -------------------------------------------------------------------------
getColumns()158cdf0e10cSrcweir Reference< ::com::sun::star::container::XNameAccess > SAL_CALL OIndex::getColumns(  ) throw(RuntimeException)
159cdf0e10cSrcweir {
160cdf0e10cSrcweir 	::osl::MutexGuard aGuard(m_aMutex);
161cdf0e10cSrcweir 	checkDisposed(ODescriptor_BASE::rBHelper.bDisposed);
162cdf0e10cSrcweir 
163cdf0e10cSrcweir 	try
164cdf0e10cSrcweir 	{
165cdf0e10cSrcweir 		if	( !m_pColumns )
166cdf0e10cSrcweir 			refreshColumns();
167cdf0e10cSrcweir 	}
168cdf0e10cSrcweir 	catch( const RuntimeException& )
169cdf0e10cSrcweir 	{
170cdf0e10cSrcweir 		// allowed to leave this method
171cdf0e10cSrcweir 		throw;
172cdf0e10cSrcweir 	}
173cdf0e10cSrcweir 	catch( const Exception& )
174cdf0e10cSrcweir 	{
175cdf0e10cSrcweir         OSL_ENSURE( false, "OIndex::getColumns: caught an exception!" );
176cdf0e10cSrcweir 	}
177cdf0e10cSrcweir 
178cdf0e10cSrcweir 	return const_cast<OIndex*>(this)->m_pColumns;
179cdf0e10cSrcweir }
180cdf0e10cSrcweir // -------------------------------------------------------------------------
createDataDescriptor()181cdf0e10cSrcweir Reference< XPropertySet > SAL_CALL OIndex::createDataDescriptor(  ) throw(RuntimeException)
182cdf0e10cSrcweir {
183cdf0e10cSrcweir 	::osl::MutexGuard aGuard(m_aMutex);
184cdf0e10cSrcweir 	checkDisposed(ODescriptor_BASE::rBHelper.bDisposed);
185cdf0e10cSrcweir 
186cdf0e10cSrcweir 
187cdf0e10cSrcweir 	return this;
188cdf0e10cSrcweir }
189cdf0e10cSrcweir // -----------------------------------------------------------------------------
getPropertySetInfo()190cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL OIndex::getPropertySetInfo(  ) throw(::com::sun::star::uno::RuntimeException)
191cdf0e10cSrcweir {
192cdf0e10cSrcweir 	return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
193cdf0e10cSrcweir }
194cdf0e10cSrcweir // -----------------------------------------------------------------------------
getName()195cdf0e10cSrcweir ::rtl::OUString SAL_CALL OIndex::getName(  ) throw(::com::sun::star::uno::RuntimeException)
196cdf0e10cSrcweir {
197cdf0e10cSrcweir 	return m_Name;
198cdf0e10cSrcweir }
199cdf0e10cSrcweir // -----------------------------------------------------------------------------
setName(const::rtl::OUString &)200cdf0e10cSrcweir void SAL_CALL OIndex::setName( const ::rtl::OUString& /*aName*/ ) throw(::com::sun::star::uno::RuntimeException)
201cdf0e10cSrcweir {
202cdf0e10cSrcweir }
203cdf0e10cSrcweir // -----------------------------------------------------------------------------
204cdf0e10cSrcweir // XInterface
acquire()205cdf0e10cSrcweir void SAL_CALL OIndex::acquire() throw()
206cdf0e10cSrcweir {
207cdf0e10cSrcweir 	ODescriptor_BASE::acquire();
208cdf0e10cSrcweir }
209cdf0e10cSrcweir // -----------------------------------------------------------------------------
release()210cdf0e10cSrcweir void SAL_CALL OIndex::release() throw()
211cdf0e10cSrcweir {
212cdf0e10cSrcweir 	ODescriptor_BASE::release();
213cdf0e10cSrcweir }
214cdf0e10cSrcweir // -----------------------------------------------------------------------------
refreshColumns()215cdf0e10cSrcweir void OIndex::refreshColumns()
216cdf0e10cSrcweir {
217cdf0e10cSrcweir }
218cdf0e10cSrcweir // -----------------------------------------------------------------------------
219cdf0e10cSrcweir 
220