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