Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * Effective License of whole file:
5 : : *
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.
9 : : *
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.
14 : : *
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
19 : : *
20 : : * Parts "Copyright by Sun Microsystems, Inc" prior to August 2011:
21 : : *
22 : : * The Contents of this file are made available subject to the terms of
23 : : * the GNU Lesser General Public License Version 2.1
24 : : *
25 : : * Copyright: 2000 by Sun Microsystems, Inc.
26 : : *
27 : : * Contributor(s): Joerg Budischewski
28 : : *
29 : : * All parts contributed on or after August 2011:
30 : : *
31 : : * Version: MPL 1.1 / GPLv3+ / LGPLv2.1+
32 : : *
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/
37 : : *
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.
42 : : *
43 : : * Major Contributor(s):
44 : : * [ Copyright (C) 2011 Lionel Elie Mamane <lionel@mamane.lu> ]
45 : : *
46 : : * All Rights Reserved.
47 : : *
48 : : * For minor contributions see the git repository.
49 : : *
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.
55 : : *
56 : : ************************************************************************/
57 : :
58 : : #include <rtl/ustrbuf.hxx>
59 : :
60 : : #include <cppuhelper/typeprovider.hxx>
61 : : #include <cppuhelper/queryinterface.hxx>
62 : :
63 : : #include <com/sun/star/beans/PropertyAttribute.hpp>
64 : :
65 : : #include <com/sun/star/sdbc/XRow.hpp>
66 : : #include <com/sun/star/sdbc/XParameters.hpp>
67 : :
68 : : #include "pq_xkey.hxx"
69 : : #include "pq_xkeycolumns.hxx"
70 : : #include "pq_tools.hxx"
71 : : #include "pq_statics.hxx"
72 : :
73 : : using osl::MutexGuard;
74 : : using osl::Mutex;
75 : :
76 : : using rtl::OUString;
77 : : using rtl::OUStringBuffer;
78 : :
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;
83 : :
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;
93 : :
94 : : using com::sun::star::lang::IllegalArgumentException;
95 : : using com::sun::star::lang::IndexOutOfBoundsException;
96 : :
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;
102 : :
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;
109 : :
110 : : namespace pq_sdbc_driver
111 : : {
112 : 0 : 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 : 0 : getStatics().refl.key.implName,
119 : 0 : getStatics().refl.key.serviceNames,
120 : : refMutex,
121 : : connection,
122 : : pSettings,
123 : 0 : * getStatics().refl.key.pProps ),
124 : : m_schemaName( schemaName ),
125 : 0 : m_tableName( tableName )
126 : 0 : {}
127 : :
128 : 0 : Reference< XPropertySet > Key::createDataDescriptor( ) throw (RuntimeException)
129 : : {
130 : : KeyDescriptor * pKeyDescriptor = new KeyDescriptor(
131 : 0 : m_refMutex, m_conn, m_pSettings );
132 : 0 : pKeyDescriptor->copyValuesFrom( this );
133 : :
134 : 0 : return Reference< XPropertySet > ( pKeyDescriptor );
135 : : }
136 : :
137 : 0 : Reference< XNameAccess > Key::getColumns( ) throw (::com::sun::star::uno::RuntimeException)
138 : : {
139 : : // TODO: cash columns object !
140 : 0 : if( !m_keyColumns.is() )
141 : : {
142 : 0 : Sequence< OUString > columnNames, foreignColumnNames;
143 : 0 : getPropertyValue( getStatics().PRIVATE_COLUMNS ) >>= columnNames;
144 : 0 : getPropertyValue( getStatics().PRIVATE_FOREIGN_COLUMNS ) >>= foreignColumnNames;
145 : :
146 : : m_keyColumns = KeyColumns::create(
147 : : m_refMutex, m_conn, m_pSettings, m_schemaName,
148 : 0 : m_tableName, columnNames, foreignColumnNames );
149 : : }
150 : 0 : return m_keyColumns;
151 : : }
152 : :
153 : 0 : Sequence<Type > Key::getTypes() throw( RuntimeException )
154 : : {
155 : : static cppu::OTypeCollection *pCollection;
156 : 0 : if( ! pCollection )
157 : : {
158 : 0 : MutexGuard guard( osl::Mutex::getGlobalMutex() );
159 : 0 : if( !pCollection )
160 : : {
161 : : static cppu::OTypeCollection collection(
162 : 0 : getCppuType( (Reference< com::sun::star::sdbcx::XColumnsSupplier> *) 0 ),
163 : 0 : ReflectionBase::getTypes());
164 : 0 : pCollection = &collection;
165 : 0 : }
166 : : }
167 : 0 : return pCollection->getTypes();
168 : : }
169 : :
170 : 0 : Sequence< sal_Int8> Key::getImplementationId() throw( RuntimeException )
171 : : {
172 : 0 : return getStatics().refl.key.implementationId;
173 : : }
174 : :
175 : 0 : Any Key::queryInterface( const Type & reqType ) throw (RuntimeException)
176 : : {
177 : 0 : Any ret;
178 : :
179 : 0 : ret = ReflectionBase::queryInterface( reqType );
180 : 0 : if( ! ret.hasValue() )
181 : : ret = ::cppu::queryInterface(
182 : : reqType,
183 : 0 : static_cast< com::sun::star::sdbcx::XColumnsSupplier * > ( this ) );
184 : 0 : return ret;
185 : : }
186 : :
187 : :
188 : : //_____________________________________________________________________________
189 : 0 : KeyDescriptor::KeyDescriptor( const ::rtl::Reference< RefCountedMutex > & refMutex,
190 : : const Reference< com::sun::star::sdbc::XConnection > & connection,
191 : : ConnectionSettings *pSettings )
192 : : : ReflectionBase(
193 : 0 : getStatics().refl.keyDescriptor.implName,
194 : 0 : getStatics().refl.keyDescriptor.serviceNames,
195 : : refMutex,
196 : : connection,
197 : : pSettings,
198 : 0 : * getStatics().refl.keyDescriptor.pProps )
199 : : {
200 : 0 : }
201 : :
202 : 0 : Reference< XPropertySet > KeyDescriptor::createDataDescriptor( ) throw (RuntimeException)
203 : : {
204 : : KeyDescriptor * pKeyDescriptor = new KeyDescriptor(
205 : 0 : m_refMutex, m_conn, m_pSettings );
206 : 0 : pKeyDescriptor->copyValuesFrom( this );
207 : :
208 : 0 : return Reference< XPropertySet > ( pKeyDescriptor );
209 : : }
210 : :
211 : 0 : Reference< XNameAccess > KeyDescriptor::getColumns( ) throw (::com::sun::star::uno::RuntimeException)
212 : : {
213 : : // TODO: cash columns object !
214 : 0 : if( !m_keyColumns.is() )
215 : : {
216 : 0 : m_keyColumns = new KeyColumnDescriptors( m_refMutex, m_conn, m_pSettings );
217 : : }
218 : 0 : return m_keyColumns;
219 : : }
220 : :
221 : 0 : Sequence<Type > KeyDescriptor::getTypes() throw( RuntimeException )
222 : : {
223 : : static cppu::OTypeCollection *pCollection;
224 : 0 : if( ! pCollection )
225 : : {
226 : 0 : MutexGuard guard( osl::Mutex::getGlobalMutex() );
227 : 0 : if( !pCollection )
228 : : {
229 : : static cppu::OTypeCollection collection(
230 : 0 : getCppuType( (Reference< com::sun::star::sdbcx::XColumnsSupplier> *) 0 ),
231 : 0 : ReflectionBase::getTypes());
232 : 0 : pCollection = &collection;
233 : 0 : }
234 : : }
235 : 0 : return pCollection->getTypes();
236 : : }
237 : :
238 : 0 : Sequence< sal_Int8> KeyDescriptor::getImplementationId() throw( RuntimeException )
239 : : {
240 : 0 : return getStatics().refl.keyDescriptor.implementationId;
241 : : }
242 : :
243 : 0 : Any KeyDescriptor::queryInterface( const Type & reqType ) throw (RuntimeException)
244 : : {
245 : 0 : Any ret;
246 : :
247 : 0 : ret = ReflectionBase::queryInterface( reqType );
248 : 0 : if( ! ret.hasValue() )
249 : : ret = ::cppu::queryInterface(
250 : : reqType,
251 : 0 : static_cast< com::sun::star::sdbcx::XColumnsSupplier * > ( this ) );
252 : 0 : return ret;
253 : : }
254 : :
255 : :
256 : : }
|