Bump for 3.6-28
[LibreOffice.git] / connectivity / source / drivers / postgresql / pq_xkey.cxx
bloba89dc114e478f2278ee3f4fb7c39e972687862d4
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_xkey.hxx"
69 #include "pq_xkeycolumns.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 Key::Key( 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.key.implName,
119 getStatics().refl.key.serviceNames,
120 refMutex,
121 connection,
122 pSettings,
123 * getStatics().refl.key.pProps ),
124 m_schemaName( schemaName ),
125 m_tableName( tableName )
128 Reference< XPropertySet > Key::createDataDescriptor( ) throw (RuntimeException)
130 KeyDescriptor * pKeyDescriptor = new KeyDescriptor(
131 m_refMutex, m_conn, m_pSettings );
132 pKeyDescriptor->copyValuesFrom( this );
134 return Reference< XPropertySet > ( pKeyDescriptor );
137 Reference< XNameAccess > Key::getColumns( ) throw (::com::sun::star::uno::RuntimeException)
139 // TODO: cash columns object !
140 if( !m_keyColumns.is() )
142 Sequence< OUString > columnNames, foreignColumnNames;
143 getPropertyValue( getStatics().PRIVATE_COLUMNS ) >>= columnNames;
144 getPropertyValue( getStatics().PRIVATE_FOREIGN_COLUMNS ) >>= foreignColumnNames;
146 m_keyColumns = KeyColumns::create(
147 m_refMutex, m_conn, m_pSettings, m_schemaName,
148 m_tableName, columnNames, foreignColumnNames );
150 return m_keyColumns;
153 Sequence<Type > Key::getTypes() throw( RuntimeException )
155 static cppu::OTypeCollection *pCollection;
156 if( ! pCollection )
158 MutexGuard guard( osl::Mutex::getGlobalMutex() );
159 if( !pCollection )
161 static cppu::OTypeCollection collection(
162 getCppuType( (Reference< com::sun::star::sdbcx::XColumnsSupplier> *) 0 ),
163 ReflectionBase::getTypes());
164 pCollection = &collection;
167 return pCollection->getTypes();
170 Sequence< sal_Int8> Key::getImplementationId() throw( RuntimeException )
172 return getStatics().refl.key.implementationId;
175 Any Key::queryInterface( const Type & reqType ) throw (RuntimeException)
177 Any ret;
179 ret = ReflectionBase::queryInterface( reqType );
180 if( ! ret.hasValue() )
181 ret = ::cppu::queryInterface(
182 reqType,
183 static_cast< com::sun::star::sdbcx::XColumnsSupplier * > ( this ) );
184 return ret;
188 //_____________________________________________________________________________
189 KeyDescriptor::KeyDescriptor( const ::rtl::Reference< RefCountedMutex > & refMutex,
190 const Reference< com::sun::star::sdbc::XConnection > & connection,
191 ConnectionSettings *pSettings )
192 : ReflectionBase(
193 getStatics().refl.keyDescriptor.implName,
194 getStatics().refl.keyDescriptor.serviceNames,
195 refMutex,
196 connection,
197 pSettings,
198 * getStatics().refl.keyDescriptor.pProps )
202 Reference< XPropertySet > KeyDescriptor::createDataDescriptor( ) throw (RuntimeException)
204 KeyDescriptor * pKeyDescriptor = new KeyDescriptor(
205 m_refMutex, m_conn, m_pSettings );
206 pKeyDescriptor->copyValuesFrom( this );
208 return Reference< XPropertySet > ( pKeyDescriptor );
211 Reference< XNameAccess > KeyDescriptor::getColumns( ) throw (::com::sun::star::uno::RuntimeException)
213 // TODO: cash columns object !
214 if( !m_keyColumns.is() )
216 m_keyColumns = new KeyColumnDescriptors( m_refMutex, m_conn, m_pSettings );
218 return m_keyColumns;
221 Sequence<Type > KeyDescriptor::getTypes() throw( RuntimeException )
223 static cppu::OTypeCollection *pCollection;
224 if( ! pCollection )
226 MutexGuard guard( osl::Mutex::getGlobalMutex() );
227 if( !pCollection )
229 static cppu::OTypeCollection collection(
230 getCppuType( (Reference< com::sun::star::sdbcx::XColumnsSupplier> *) 0 ),
231 ReflectionBase::getTypes());
232 pCollection = &collection;
235 return pCollection->getTypes();
238 Sequence< sal_Int8> KeyDescriptor::getImplementationId() throw( RuntimeException )
240 return getStatics().refl.keyDescriptor.implementationId;
243 Any KeyDescriptor::queryInterface( const Type & reqType ) throw (RuntimeException)
245 Any ret;
247 ret = ReflectionBase::queryInterface( reqType );
248 if( ! ret.hasValue() )
249 ret = ::cppu::queryInterface(
250 reqType,
251 static_cast< com::sun::star::sdbcx::XColumnsSupplier * > ( this ) );
252 return ret;