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 : * 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/.
34 : *
35 : ************************************************************************/
36 :
37 : #include <rtl/ustrbuf.hxx>
38 :
39 : #include <cppuhelper/typeprovider.hxx>
40 : #include <cppuhelper/queryinterface.hxx>
41 :
42 : #include <com/sun/star/beans/PropertyAttribute.hpp>
43 :
44 : #include <com/sun/star/sdbc/XRow.hpp>
45 : #include <com/sun/star/sdbc/XParameters.hpp>
46 :
47 : #include "pq_xkey.hxx"
48 : #include "pq_xkeycolumns.hxx"
49 : #include "pq_tools.hxx"
50 : #include "pq_statics.hxx"
51 :
52 : using osl::MutexGuard;
53 : using osl::Mutex;
54 :
55 :
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;
60 :
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;
70 :
71 : using com::sun::star::lang::IllegalArgumentException;
72 : using com::sun::star::lang::IndexOutOfBoundsException;
73 :
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;
79 :
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;
86 :
87 : namespace pq_sdbc_driver
88 : {
89 0 : Key::Key( 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 0 : getStatics().refl.key.implName,
96 0 : getStatics().refl.key.serviceNames,
97 : refMutex,
98 : connection,
99 : pSettings,
100 0 : * getStatics().refl.key.pProps ),
101 : m_schemaName( schemaName ),
102 0 : m_tableName( tableName )
103 0 : {}
104 :
105 0 : Reference< XPropertySet > Key::createDataDescriptor( ) throw (RuntimeException, std::exception)
106 : {
107 : KeyDescriptor * pKeyDescriptor = new KeyDescriptor(
108 0 : m_refMutex, m_conn, m_pSettings );
109 0 : pKeyDescriptor->copyValuesFrom( this );
110 :
111 0 : return Reference< XPropertySet > ( pKeyDescriptor );
112 : }
113 :
114 0 : Reference< XNameAccess > Key::getColumns( ) throw (::com::sun::star::uno::RuntimeException, std::exception)
115 : {
116 : // TODO: cash columns object !
117 0 : if( !m_keyColumns.is() )
118 : {
119 0 : Sequence< OUString > columnNames, foreignColumnNames;
120 0 : getPropertyValue( getStatics().PRIVATE_COLUMNS ) >>= columnNames;
121 0 : getPropertyValue( getStatics().PRIVATE_FOREIGN_COLUMNS ) >>= foreignColumnNames;
122 :
123 0 : m_keyColumns = KeyColumns::create(
124 : m_refMutex, m_conn, m_pSettings, m_schemaName,
125 0 : m_tableName, columnNames, foreignColumnNames );
126 : }
127 0 : return m_keyColumns;
128 : }
129 :
130 0 : Sequence<Type > Key::getTypes() throw( RuntimeException, std::exception )
131 : {
132 : static cppu::OTypeCollection *pCollection;
133 0 : if( ! pCollection )
134 : {
135 0 : MutexGuard guard( osl::Mutex::getGlobalMutex() );
136 0 : if( !pCollection )
137 : {
138 : static cppu::OTypeCollection collection(
139 0 : cppu::UnoType<com::sun::star::sdbcx::XColumnsSupplier>::get(),
140 0 : ReflectionBase::getTypes());
141 0 : pCollection = &collection;
142 0 : }
143 : }
144 0 : return pCollection->getTypes();
145 : }
146 :
147 0 : Sequence< sal_Int8> Key::getImplementationId() throw( RuntimeException, std::exception )
148 : {
149 0 : return css::uno::Sequence<sal_Int8>();
150 : }
151 :
152 0 : Any Key::queryInterface( const Type & reqType ) throw (RuntimeException, std::exception)
153 : {
154 0 : Any ret;
155 :
156 0 : ret = ReflectionBase::queryInterface( reqType );
157 0 : if( ! ret.hasValue() )
158 0 : ret = ::cppu::queryInterface(
159 : reqType,
160 0 : static_cast< com::sun::star::sdbcx::XColumnsSupplier * > ( this ) );
161 0 : return ret;
162 : }
163 :
164 :
165 :
166 0 : KeyDescriptor::KeyDescriptor( const ::rtl::Reference< RefCountedMutex > & refMutex,
167 : const Reference< com::sun::star::sdbc::XConnection > & connection,
168 : ConnectionSettings *pSettings )
169 : : ReflectionBase(
170 0 : getStatics().refl.keyDescriptor.implName,
171 0 : getStatics().refl.keyDescriptor.serviceNames,
172 : refMutex,
173 : connection,
174 : pSettings,
175 0 : * getStatics().refl.keyDescriptor.pProps )
176 : {
177 0 : }
178 :
179 0 : Reference< XPropertySet > KeyDescriptor::createDataDescriptor( ) throw (RuntimeException, std::exception)
180 : {
181 : KeyDescriptor * pKeyDescriptor = new KeyDescriptor(
182 0 : m_refMutex, m_conn, m_pSettings );
183 0 : pKeyDescriptor->copyValuesFrom( this );
184 :
185 0 : return Reference< XPropertySet > ( pKeyDescriptor );
186 : }
187 :
188 0 : Reference< XNameAccess > KeyDescriptor::getColumns( ) throw (::com::sun::star::uno::RuntimeException, std::exception)
189 : {
190 : // TODO: cash columns object !
191 0 : if( !m_keyColumns.is() )
192 : {
193 0 : m_keyColumns = new KeyColumnDescriptors( m_refMutex, m_conn, m_pSettings );
194 : }
195 0 : return m_keyColumns;
196 : }
197 :
198 0 : Sequence<Type > KeyDescriptor::getTypes() throw( RuntimeException, std::exception )
199 : {
200 : static cppu::OTypeCollection *pCollection;
201 0 : if( ! pCollection )
202 : {
203 0 : MutexGuard guard( osl::Mutex::getGlobalMutex() );
204 0 : if( !pCollection )
205 : {
206 : static cppu::OTypeCollection collection(
207 0 : cppu::UnoType<com::sun::star::sdbcx::XColumnsSupplier>::get(),
208 0 : ReflectionBase::getTypes());
209 0 : pCollection = &collection;
210 0 : }
211 : }
212 0 : return pCollection->getTypes();
213 : }
214 :
215 0 : Sequence< sal_Int8> KeyDescriptor::getImplementationId() throw( RuntimeException, std::exception )
216 : {
217 0 : return css::uno::Sequence<sal_Int8>();
218 : }
219 :
220 0 : Any KeyDescriptor::queryInterface( const Type & reqType ) throw (RuntimeException, std::exception)
221 : {
222 0 : Any ret;
223 :
224 0 : ret = ReflectionBase::queryInterface( reqType );
225 0 : if( ! ret.hasValue() )
226 0 : ret = ::cppu::queryInterface(
227 : reqType,
228 0 : static_cast< com::sun::star::sdbcx::XColumnsSupplier * > ( this ) );
229 0 : return ret;
230 : }
231 :
232 :
233 : }
234 :
235 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|