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_xindex.hxx"
69 : : #include "pq_xindexcolumns.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 : 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 : 0 : getStatics().refl.index.implName,
119 : 0 : getStatics().refl.index.serviceNames,
120 : : refMutex,
121 : : connection,
122 : : pSettings,
123 : 0 : * getStatics().refl.index.pProps ),
124 : : m_schemaName( schemaName ),
125 : 0 : m_tableName( tableName )
126 : 0 : {}
127 : :
128 : 0 : Reference< XPropertySet > Index::createDataDescriptor( ) throw (RuntimeException)
129 : : {
130 : : IndexDescriptor * pIndex = new IndexDescriptor(
131 : 0 : m_refMutex, m_conn, m_pSettings );
132 : 0 : pIndex->copyValuesFrom( this );
133 : :
134 : 0 : return Reference< XPropertySet > ( pIndex );
135 : : }
136 : :
137 : 0 : Reference< XNameAccess > Index::getColumns( ) throw (::com::sun::star::uno::RuntimeException)
138 : : {
139 : 0 : if( ! m_indexColumns.is() )
140 : : {
141 : 0 : Sequence< OUString > columnNames;
142 : 0 : getPropertyValue( getStatics().PRIVATE_COLUMN_INDEXES ) >>= columnNames;
143 : 0 : OUString indexName = extractStringProperty( this, getStatics().NAME );
144 : : m_indexColumns = IndexColumns::create(
145 : : m_refMutex, m_conn, m_pSettings, m_schemaName,
146 : 0 : m_tableName, indexName, columnNames );
147 : : }
148 : 0 : return m_indexColumns;
149 : : }
150 : :
151 : 0 : Sequence<Type > Index::getTypes() throw( RuntimeException )
152 : : {
153 : : static cppu::OTypeCollection *pCollection;
154 : 0 : if( ! pCollection )
155 : : {
156 : 0 : MutexGuard guard( osl::Mutex::getGlobalMutex() );
157 : 0 : if( !pCollection )
158 : : {
159 : : static cppu::OTypeCollection collection(
160 : 0 : getCppuType( (Reference< com::sun::star::sdbcx::XColumnsSupplier> *) 0 ),
161 : 0 : ReflectionBase::getTypes());
162 : 0 : pCollection = &collection;
163 : 0 : }
164 : : }
165 : 0 : return pCollection->getTypes();
166 : : }
167 : :
168 : 0 : Sequence< sal_Int8> Index::getImplementationId() throw( RuntimeException )
169 : : {
170 : 0 : return getStatics().refl.index.implementationId;
171 : : }
172 : :
173 : 0 : Any Index::queryInterface( const Type & reqType ) throw (RuntimeException)
174 : : {
175 : 0 : Any ret;
176 : :
177 : 0 : ret = ReflectionBase::queryInterface( reqType );
178 : 0 : if( ! ret.hasValue() )
179 : : ret = ::cppu::queryInterface(
180 : : reqType,
181 : 0 : static_cast< com::sun::star::sdbcx::XColumnsSupplier * > ( this ) );
182 : 0 : return ret;
183 : : }
184 : :
185 : :
186 : : //___________________________________________________________________________________
187 : 0 : IndexDescriptor::IndexDescriptor(
188 : : const ::rtl::Reference< RefCountedMutex > & refMutex,
189 : : const Reference< com::sun::star::sdbc::XConnection > & connection,
190 : : ConnectionSettings *pSettings )
191 : : : ReflectionBase(
192 : 0 : getStatics().refl.indexDescriptor.implName,
193 : 0 : getStatics().refl.indexDescriptor.serviceNames,
194 : : refMutex,
195 : : connection,
196 : : pSettings,
197 : 0 : * getStatics().refl.indexDescriptor.pProps )
198 : 0 : {}
199 : :
200 : 0 : Reference< XPropertySet > IndexDescriptor::createDataDescriptor( ) throw (RuntimeException)
201 : : {
202 : : IndexDescriptor * pIndex = new IndexDescriptor(
203 : 0 : m_refMutex, m_conn, m_pSettings );
204 : 0 : pIndex->copyValuesFrom( this );
205 : 0 : return Reference< XPropertySet > ( pIndex );
206 : : }
207 : :
208 : 0 : Reference< XNameAccess > IndexDescriptor::getColumns( ) throw (::com::sun::star::uno::RuntimeException)
209 : : {
210 : 0 : if( ! m_indexColumns.is() )
211 : : {
212 : : m_indexColumns = IndexColumnDescriptors::create(
213 : 0 : 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 );
220 : : }
221 : 0 : return m_indexColumns;
222 : : }
223 : :
224 : 0 : Sequence<Type > IndexDescriptor::getTypes() throw( RuntimeException )
225 : : {
226 : : static cppu::OTypeCollection *pCollection;
227 : 0 : if( ! pCollection )
228 : : {
229 : 0 : MutexGuard guard( osl::Mutex::getGlobalMutex() );
230 : 0 : if( !pCollection )
231 : : {
232 : : static cppu::OTypeCollection collection(
233 : 0 : getCppuType( (Reference< com::sun::star::sdbcx::XColumnsSupplier> *) 0 ),
234 : 0 : ReflectionBase::getTypes());
235 : 0 : pCollection = &collection;
236 : 0 : }
237 : : }
238 : 0 : return pCollection->getTypes();
239 : : }
240 : :
241 : 0 : Sequence< sal_Int8> IndexDescriptor::getImplementationId() throw( RuntimeException )
242 : : {
243 : 0 : return getStatics().refl.indexDescriptor.implementationId;
244 : : }
245 : :
246 : 0 : Any IndexDescriptor::queryInterface( const Type & reqType ) throw (RuntimeException)
247 : : {
248 : 0 : Any ret;
249 : :
250 : 0 : ret = ReflectionBase::queryInterface( reqType );
251 : 0 : if( ! ret.hasValue() )
252 : : ret = ::cppu::queryInterface(
253 : : reqType,
254 : 0 : static_cast< com::sun::star::sdbcx::XColumnsSupplier * > ( this ) );
255 : 0 : return ret;
256 : : }
257 : :
258 : :
259 : :
260 : :
261 : : }
|