Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / connectivity / source / drivers / postgresql / pq_xindex.cxx
blob9c81b6ce47f59cd91686a694af7ff0a5d1dac748
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * Effective License of whole file:
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License version 2.1, as published by the Free Software Foundation.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
18 * MA 02111-1307 USA
20 * Parts "Copyright by Sun Microsystems, Inc" prior to August 2011:
22 * The Contents of this file are made available subject to the terms of
23 * the GNU Lesser General Public License Version 2.1
25 * Copyright: 2000 by Sun Microsystems, Inc.
27 * Contributor(s): Joerg Budischewski
29 * All parts contributed on or after August 2011:
31 * This Source Code Form is subject to the terms of the Mozilla Public
32 * License, v. 2.0. If a copy of the MPL was not distributed with this
33 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
35 ************************************************************************/
37 #include <rtl/ustrbuf.hxx>
39 #include <cppuhelper/typeprovider.hxx>
40 #include <cppuhelper/queryinterface.hxx>
42 #include <com/sun/star/beans/PropertyAttribute.hpp>
44 #include <com/sun/star/sdbc/XRow.hpp>
45 #include <com/sun/star/sdbc/XParameters.hpp>
47 #include "pq_xindex.hxx"
48 #include "pq_xindexcolumns.hxx"
49 #include "pq_tools.hxx"
50 #include "pq_statics.hxx"
52 using osl::MutexGuard;
53 using osl::Mutex;
56 using com::sun::star::container::XNameAccess;
57 using com::sun::star::container::XIndexAccess;
58 using com::sun::star::container::ElementExistException;
59 using com::sun::star::container::NoSuchElementException;
61 using com::sun::star::uno::Reference;
62 using com::sun::star::uno::Exception;
63 using com::sun::star::uno::UNO_QUERY;
64 using com::sun::star::uno::XInterface;
65 using com::sun::star::uno::Sequence;
66 using com::sun::star::uno::Any;
67 using com::sun::star::uno::makeAny;
68 using com::sun::star::uno::Type;
69 using com::sun::star::uno::RuntimeException;
71 using com::sun::star::lang::IllegalArgumentException;
72 using com::sun::star::lang::IndexOutOfBoundsException;
74 using com::sun::star::beans::XPropertySetInfo;
75 using com::sun::star::beans::XFastPropertySet;
76 using com::sun::star::beans::XMultiPropertySet;
77 using com::sun::star::beans::XPropertySet;
78 using com::sun::star::beans::Property;
80 using com::sun::star::sdbc::XResultSet;
81 using com::sun::star::sdbc::XPreparedStatement;
82 using com::sun::star::sdbc::XStatement;
83 using com::sun::star::sdbc::XParameters;
84 using com::sun::star::sdbc::XRow;
85 using com::sun::star::sdbc::SQLException;
87 namespace pq_sdbc_driver
89 Index::Index( const ::rtl::Reference< RefCountedMutex > & refMutex,
90 const Reference< com::sun::star::sdbc::XConnection > & connection,
91 ConnectionSettings *pSettings,
92 const OUString & schemaName,
93 const OUString & tableName )
94 : ReflectionBase(
95 getStatics().refl.index.implName,
96 getStatics().refl.index.serviceNames,
97 refMutex,
98 connection,
99 pSettings,
100 * getStatics().refl.index.pProps ),
101 m_schemaName( schemaName ),
102 m_tableName( tableName )
105 Reference< XPropertySet > Index::createDataDescriptor( ) throw (RuntimeException, std::exception)
107 IndexDescriptor * pIndex = new IndexDescriptor(
108 m_refMutex, m_conn, m_pSettings );
109 pIndex->copyValuesFrom( this );
111 return Reference< XPropertySet > ( pIndex );
114 Reference< XNameAccess > Index::getColumns( ) throw (::com::sun::star::uno::RuntimeException, std::exception)
116 if( ! m_indexColumns.is() )
118 Sequence< OUString > columnNames;
119 getPropertyValue( getStatics().PRIVATE_COLUMN_INDEXES ) >>= columnNames;
120 OUString indexName = extractStringProperty( this, getStatics().NAME );
121 m_indexColumns = IndexColumns::create(
122 m_refMutex, m_conn, m_pSettings, m_schemaName,
123 m_tableName, indexName, columnNames );
125 return m_indexColumns;
128 Sequence<Type > Index::getTypes() throw( RuntimeException, std::exception )
130 static cppu::OTypeCollection *pCollection;
131 if( ! pCollection )
133 MutexGuard guard( osl::Mutex::getGlobalMutex() );
134 if( !pCollection )
136 static cppu::OTypeCollection collection(
137 getCppuType( (Reference< com::sun::star::sdbcx::XColumnsSupplier> *) 0 ),
138 ReflectionBase::getTypes());
139 pCollection = &collection;
142 return pCollection->getTypes();
145 Sequence< sal_Int8> Index::getImplementationId() throw( RuntimeException, std::exception )
147 return css::uno::Sequence<sal_Int8>();
150 Any Index::queryInterface( const Type & reqType ) throw (RuntimeException, std::exception)
152 Any ret;
154 ret = ReflectionBase::queryInterface( reqType );
155 if( ! ret.hasValue() )
156 ret = ::cppu::queryInterface(
157 reqType,
158 static_cast< com::sun::star::sdbcx::XColumnsSupplier * > ( this ) );
159 return ret;
164 IndexDescriptor::IndexDescriptor(
165 const ::rtl::Reference< RefCountedMutex > & refMutex,
166 const Reference< com::sun::star::sdbc::XConnection > & connection,
167 ConnectionSettings *pSettings )
168 : ReflectionBase(
169 getStatics().refl.indexDescriptor.implName,
170 getStatics().refl.indexDescriptor.serviceNames,
171 refMutex,
172 connection,
173 pSettings,
174 * getStatics().refl.indexDescriptor.pProps )
177 Reference< XPropertySet > IndexDescriptor::createDataDescriptor( ) throw (RuntimeException, std::exception)
179 IndexDescriptor * pIndex = new IndexDescriptor(
180 m_refMutex, m_conn, m_pSettings );
181 pIndex->copyValuesFrom( this );
182 return Reference< XPropertySet > ( pIndex );
185 Reference< XNameAccess > IndexDescriptor::getColumns( ) throw (::com::sun::star::uno::RuntimeException, std::exception)
187 if( ! m_indexColumns.is() )
189 m_indexColumns = IndexColumnDescriptors::create(
190 m_refMutex, m_conn, m_pSettings );
191 // Sequence< OUString > columnNames;
192 // getPropertyValue( getStatics().PRIVATE_COLUMN_INDEXES ) >>= columnNames;
193 // OUString indexName = extractStringProperty( this, getStatics().NAME );
194 // m_indexColumns = IndexColumns::create(
195 // m_refMutex, m_conn, m_pSettings, m_schemaName,
196 // m_tableName, indexName, columnNames );
198 return m_indexColumns;
201 Sequence<Type > IndexDescriptor::getTypes() throw( RuntimeException, std::exception )
203 static cppu::OTypeCollection *pCollection;
204 if( ! pCollection )
206 MutexGuard guard( osl::Mutex::getGlobalMutex() );
207 if( !pCollection )
209 static cppu::OTypeCollection collection(
210 getCppuType( (Reference< com::sun::star::sdbcx::XColumnsSupplier> *) 0 ),
211 ReflectionBase::getTypes());
212 pCollection = &collection;
215 return pCollection->getTypes();
218 Sequence< sal_Int8> IndexDescriptor::getImplementationId() throw( RuntimeException, std::exception )
220 return css::uno::Sequence<sal_Int8>();
223 Any IndexDescriptor::queryInterface( const Type & reqType ) throw (RuntimeException, std::exception)
225 Any ret;
227 ret = ReflectionBase::queryInterface( reqType );
228 if( ! ret.hasValue() )
229 ret = ::cppu::queryInterface(
230 reqType,
231 static_cast< com::sun::star::sdbcx::XColumnsSupplier * > ( this ) );
232 return ret;
240 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */