Bump for 3.6-28
[LibreOffice.git] / connectivity / source / drivers / postgresql / pq_xindex.cxx
blob11d7b421de1261f92f97e3e0d70e1fa688d4ac5c
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 * Version: MPL 1.1 / GPLv3+ / LGPLv2.1+
33 * The contents of this file are subject to the Mozilla Public License Version
34 * 1.1 (the "License"); you may not use this file except in compliance with
35 * the License or as specified alternatively below. You may obtain a copy of
36 * the License at http://www.mozilla.org/MPL/
38 * Software distributed under the License is distributed on an "AS IS" basis,
39 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
40 * for the specific language governing rights and limitations under the
41 * License.
43 * Major Contributor(s):
44 * [ Copyright (C) 2011 Lionel Elie Mamane <lionel@mamane.lu> ]
46 * All Rights Reserved.
48 * For minor contributions see the git repository.
50 * Alternatively, the contents of this file may be used under the terms of
51 * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
52 * the GNU Lesser General Public License Version 2.1 or later (the "LGPLv2.1+"),
53 * in which case the provisions of the GPLv3+ or the LGPLv2.1+ are applicable
54 * instead of those above.
56 ************************************************************************/
58 #include <rtl/ustrbuf.hxx>
60 #include <cppuhelper/typeprovider.hxx>
61 #include <cppuhelper/queryinterface.hxx>
63 #include <com/sun/star/beans/PropertyAttribute.hpp>
65 #include <com/sun/star/sdbc/XRow.hpp>
66 #include <com/sun/star/sdbc/XParameters.hpp>
68 #include "pq_xindex.hxx"
69 #include "pq_xindexcolumns.hxx"
70 #include "pq_tools.hxx"
71 #include "pq_statics.hxx"
73 using osl::MutexGuard;
74 using osl::Mutex;
76 using rtl::OUString;
77 using rtl::OUStringBuffer;
79 using com::sun::star::container::XNameAccess;
80 using com::sun::star::container::XIndexAccess;
81 using com::sun::star::container::ElementExistException;
82 using com::sun::star::container::NoSuchElementException;
84 using com::sun::star::uno::Reference;
85 using com::sun::star::uno::Exception;
86 using com::sun::star::uno::UNO_QUERY;
87 using com::sun::star::uno::XInterface;
88 using com::sun::star::uno::Sequence;
89 using com::sun::star::uno::Any;
90 using com::sun::star::uno::makeAny;
91 using com::sun::star::uno::Type;
92 using com::sun::star::uno::RuntimeException;
94 using com::sun::star::lang::IllegalArgumentException;
95 using com::sun::star::lang::IndexOutOfBoundsException;
97 using com::sun::star::beans::XPropertySetInfo;
98 using com::sun::star::beans::XFastPropertySet;
99 using com::sun::star::beans::XMultiPropertySet;
100 using com::sun::star::beans::XPropertySet;
101 using com::sun::star::beans::Property;
103 using com::sun::star::sdbc::XResultSet;
104 using com::sun::star::sdbc::XPreparedStatement;
105 using com::sun::star::sdbc::XStatement;
106 using com::sun::star::sdbc::XParameters;
107 using com::sun::star::sdbc::XRow;
108 using com::sun::star::sdbc::SQLException;
110 namespace pq_sdbc_driver
112 Index::Index( const ::rtl::Reference< RefCountedMutex > & refMutex,
113 const Reference< com::sun::star::sdbc::XConnection > & connection,
114 ConnectionSettings *pSettings,
115 const rtl::OUString & schemaName,
116 const rtl::OUString & tableName )
117 : ReflectionBase(
118 getStatics().refl.index.implName,
119 getStatics().refl.index.serviceNames,
120 refMutex,
121 connection,
122 pSettings,
123 * getStatics().refl.index.pProps ),
124 m_schemaName( schemaName ),
125 m_tableName( tableName )
128 Reference< XPropertySet > Index::createDataDescriptor( ) throw (RuntimeException)
130 IndexDescriptor * pIndex = new IndexDescriptor(
131 m_refMutex, m_conn, m_pSettings );
132 pIndex->copyValuesFrom( this );
134 return Reference< XPropertySet > ( pIndex );
137 Reference< XNameAccess > Index::getColumns( ) throw (::com::sun::star::uno::RuntimeException)
139 if( ! m_indexColumns.is() )
141 Sequence< OUString > columnNames;
142 getPropertyValue( getStatics().PRIVATE_COLUMN_INDEXES ) >>= columnNames;
143 OUString indexName = extractStringProperty( this, getStatics().NAME );
144 m_indexColumns = IndexColumns::create(
145 m_refMutex, m_conn, m_pSettings, m_schemaName,
146 m_tableName, indexName, columnNames );
148 return m_indexColumns;
151 Sequence<Type > Index::getTypes() throw( RuntimeException )
153 static cppu::OTypeCollection *pCollection;
154 if( ! pCollection )
156 MutexGuard guard( osl::Mutex::getGlobalMutex() );
157 if( !pCollection )
159 static cppu::OTypeCollection collection(
160 getCppuType( (Reference< com::sun::star::sdbcx::XColumnsSupplier> *) 0 ),
161 ReflectionBase::getTypes());
162 pCollection = &collection;
165 return pCollection->getTypes();
168 Sequence< sal_Int8> Index::getImplementationId() throw( RuntimeException )
170 return getStatics().refl.index.implementationId;
173 Any Index::queryInterface( const Type & reqType ) throw (RuntimeException)
175 Any ret;
177 ret = ReflectionBase::queryInterface( reqType );
178 if( ! ret.hasValue() )
179 ret = ::cppu::queryInterface(
180 reqType,
181 static_cast< com::sun::star::sdbcx::XColumnsSupplier * > ( this ) );
182 return ret;
186 //___________________________________________________________________________________
187 IndexDescriptor::IndexDescriptor(
188 const ::rtl::Reference< RefCountedMutex > & refMutex,
189 const Reference< com::sun::star::sdbc::XConnection > & connection,
190 ConnectionSettings *pSettings )
191 : ReflectionBase(
192 getStatics().refl.indexDescriptor.implName,
193 getStatics().refl.indexDescriptor.serviceNames,
194 refMutex,
195 connection,
196 pSettings,
197 * getStatics().refl.indexDescriptor.pProps )
200 Reference< XPropertySet > IndexDescriptor::createDataDescriptor( ) throw (RuntimeException)
202 IndexDescriptor * pIndex = new IndexDescriptor(
203 m_refMutex, m_conn, m_pSettings );
204 pIndex->copyValuesFrom( this );
205 return Reference< XPropertySet > ( pIndex );
208 Reference< XNameAccess > IndexDescriptor::getColumns( ) throw (::com::sun::star::uno::RuntimeException)
210 if( ! m_indexColumns.is() )
212 m_indexColumns = IndexColumnDescriptors::create(
213 m_refMutex, m_conn, m_pSettings );
214 // Sequence< OUString > columnNames;
215 // getPropertyValue( getStatics().PRIVATE_COLUMN_INDEXES ) >>= columnNames;
216 // OUString indexName = extractStringProperty( this, getStatics().NAME );
217 // m_indexColumns = IndexColumns::create(
218 // m_refMutex, m_conn, m_pSettings, m_schemaName,
219 // m_tableName, indexName, columnNames );
221 return m_indexColumns;
224 Sequence<Type > IndexDescriptor::getTypes() throw( RuntimeException )
226 static cppu::OTypeCollection *pCollection;
227 if( ! pCollection )
229 MutexGuard guard( osl::Mutex::getGlobalMutex() );
230 if( !pCollection )
232 static cppu::OTypeCollection collection(
233 getCppuType( (Reference< com::sun::star::sdbcx::XColumnsSupplier> *) 0 ),
234 ReflectionBase::getTypes());
235 pCollection = &collection;
238 return pCollection->getTypes();
241 Sequence< sal_Int8> IndexDescriptor::getImplementationId() throw( RuntimeException )
243 return getStatics().refl.indexDescriptor.implementationId;
246 Any IndexDescriptor::queryInterface( const Type & reqType ) throw (RuntimeException)
248 Any ret;
250 ret = ReflectionBase::queryInterface( reqType );
251 if( ! ret.hasValue() )
252 ret = ::cppu::queryInterface(
253 reqType,
254 static_cast< com::sun::star::sdbcx::XColumnsSupplier * > ( this ) );
255 return ret;