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,
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 * 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/.
35 ************************************************************************/
37 #include <rtl/ustrbuf.hxx>
39 #include <cppuhelper/typeprovider.hxx>
40 #include <cppuhelper/queryinterface.hxx>
42 #include <com/sun/star/beans/PropertyAttribute.hpp>
44 #include <com/sun/star/sdbc/XRow.hpp>
45 #include <com/sun/star/sdbc/XParameters.hpp>
47 #include "pq_xindex.hxx"
48 #include "pq_xindexcolumns.hxx"
49 #include "pq_tools.hxx"
50 #include "pq_statics.hxx"
52 using osl::MutexGuard
;
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
;
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
;
71 using com::sun::star::lang::IllegalArgumentException
;
72 using com::sun::star::lang::IndexOutOfBoundsException
;
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
;
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
;
87 namespace pq_sdbc_driver
89 Index::Index( 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
)
95 getStatics().refl
.index
.implName
,
96 getStatics().refl
.index
.serviceNames
,
100 * getStatics().refl
.index
.pProps
),
101 m_schemaName( schemaName
),
102 m_tableName( tableName
)
105 Reference
< XPropertySet
> Index::createDataDescriptor( ) throw (RuntimeException
, std::exception
)
107 IndexDescriptor
* pIndex
= new IndexDescriptor(
108 m_refMutex
, m_conn
, m_pSettings
);
109 pIndex
->copyValuesFrom( this );
111 return Reference
< XPropertySet
> ( pIndex
);
114 Reference
< XNameAccess
> Index::getColumns( ) throw (::com::sun::star::uno::RuntimeException
, std::exception
)
116 if( ! m_indexColumns
.is() )
118 Sequence
< OUString
> columnNames
;
119 getPropertyValue( getStatics().PRIVATE_COLUMN_INDEXES
) >>= columnNames
;
120 OUString indexName
= extractStringProperty( this, getStatics().NAME
);
121 m_indexColumns
= IndexColumns::create(
122 m_refMutex
, m_conn
, m_pSettings
, m_schemaName
,
123 m_tableName
, indexName
, columnNames
);
125 return m_indexColumns
;
128 Sequence
<Type
> Index::getTypes() throw( RuntimeException
, std::exception
)
130 static cppu::OTypeCollection
*pCollection
;
133 MutexGuard
guard( osl::Mutex::getGlobalMutex() );
136 static cppu::OTypeCollection
collection(
137 getCppuType( (Reference
< com::sun::star::sdbcx::XColumnsSupplier
> *) 0 ),
138 ReflectionBase::getTypes());
139 pCollection
= &collection
;
142 return pCollection
->getTypes();
145 Sequence
< sal_Int8
> Index::getImplementationId() throw( RuntimeException
, std::exception
)
147 return css::uno::Sequence
<sal_Int8
>();
150 Any
Index::queryInterface( const Type
& reqType
) throw (RuntimeException
, std::exception
)
154 ret
= ReflectionBase::queryInterface( reqType
);
155 if( ! ret
.hasValue() )
156 ret
= ::cppu::queryInterface(
158 static_cast< com::sun::star::sdbcx::XColumnsSupplier
* > ( this ) );
164 IndexDescriptor::IndexDescriptor(
165 const ::rtl::Reference
< RefCountedMutex
> & refMutex
,
166 const Reference
< com::sun::star::sdbc::XConnection
> & connection
,
167 ConnectionSettings
*pSettings
)
169 getStatics().refl
.indexDescriptor
.implName
,
170 getStatics().refl
.indexDescriptor
.serviceNames
,
174 * getStatics().refl
.indexDescriptor
.pProps
)
177 Reference
< XPropertySet
> IndexDescriptor::createDataDescriptor( ) throw (RuntimeException
, std::exception
)
179 IndexDescriptor
* pIndex
= new IndexDescriptor(
180 m_refMutex
, m_conn
, m_pSettings
);
181 pIndex
->copyValuesFrom( this );
182 return Reference
< XPropertySet
> ( pIndex
);
185 Reference
< XNameAccess
> IndexDescriptor::getColumns( ) throw (::com::sun::star::uno::RuntimeException
, std::exception
)
187 if( ! m_indexColumns
.is() )
189 m_indexColumns
= IndexColumnDescriptors::create(
190 m_refMutex
, m_conn
, m_pSettings
);
191 // Sequence< OUString > columnNames;
192 // getPropertyValue( getStatics().PRIVATE_COLUMN_INDEXES ) >>= columnNames;
193 // OUString indexName = extractStringProperty( this, getStatics().NAME );
194 // m_indexColumns = IndexColumns::create(
195 // m_refMutex, m_conn, m_pSettings, m_schemaName,
196 // m_tableName, indexName, columnNames );
198 return m_indexColumns
;
201 Sequence
<Type
> IndexDescriptor::getTypes() throw( RuntimeException
, std::exception
)
203 static cppu::OTypeCollection
*pCollection
;
206 MutexGuard
guard( osl::Mutex::getGlobalMutex() );
209 static cppu::OTypeCollection
collection(
210 getCppuType( (Reference
< com::sun::star::sdbcx::XColumnsSupplier
> *) 0 ),
211 ReflectionBase::getTypes());
212 pCollection
= &collection
;
215 return pCollection
->getTypes();
218 Sequence
< sal_Int8
> IndexDescriptor::getImplementationId() throw( RuntimeException
, std::exception
)
220 return css::uno::Sequence
<sal_Int8
>();
223 Any
IndexDescriptor::queryInterface( const Type
& reqType
) throw (RuntimeException
, std::exception
)
227 ret
= ReflectionBase::queryInterface( reqType
);
228 if( ! ret
.hasValue() )
229 ret
= ::cppu::queryInterface(
231 static_cast< com::sun::star::sdbcx::XColumnsSupplier
* > ( this ) );
240 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */