LibreOffice Module connectivity (master) 1
pq_xindexcolumns.cxx
Go to the documentation of this file.
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 <sal/log.hxx>
38
39#include <string_view>
40#include <utility>
41#include <vector>
42
43#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
44#include <com/sun/star/sdbc/SQLException.hpp>
45#include <com/sun/star/sdbc/XRow.hpp>
47#include <rtl/ref.hxx>
48
49#include "pq_xcolumns.hxx"
50#include "pq_xindexcolumns.hxx"
51#include "pq_xindexcolumn.hxx"
52#include "pq_statics.hxx"
53#include "pq_tools.hxx"
54
55using osl::MutexGuard;
56
58
59using com::sun::star::uno::Any;
60using com::sun::star::uno::UNO_QUERY;
63
64using com::sun::star::sdbc::XRow;
65using com::sun::star::sdbc::XResultSet;
66using com::sun::star::sdbc::XDatabaseMetaData;
67using com::sun::star::sdbc::SQLException;
68
69namespace pq_sdbc_driver
70{
71
73 const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex,
74 const css::uno::Reference< css::sdbc::XConnection > & origin,
75 ConnectionSettings *pSettings,
76 OUString schemaName,
77 OUString tableName,
78 OUString indexName,
79 const css::uno::Sequence< OUString > &columns )
80 : Container( refMutex, origin, pSettings, "INDEX_COLUMN" ),
81 m_schemaName(std::move( schemaName )),
82 m_tableName(std::move( tableName )),
83 m_indexName(std::move( indexName )),
84 m_columns( columns )
85{}
86
88{}
89
90static sal_Int32 findInSequence( const Sequence< OUString > & seq , std::u16string_view str)
91{
92 int index;
93 for( index = 0 ; index < seq.getLength() ; index ++ )
94 {
95 if( str == seq[index] )
96 break;
97 }
98 return index;
99}
100
102{
103 try
104 {
105 SAL_INFO("connectivity.postgresql", "sdbcx.IndexColumns get refreshed for index " << m_indexName);
106
107 osl::MutexGuard guard( m_xMutex->GetMutex() );
108
109 Statics &st = getStatics();
110 Reference< XDatabaseMetaData > meta = m_origin->getMetaData();
111
113 meta->getColumns( Any(), m_schemaName, m_tableName, st.cPERCENT );
114
115 DisposeGuard disposeIt( rs );
116 Reference< XRow > xRow( rs , UNO_QUERY );
117 m_values.clear();
118 m_values.resize( m_columns.getLength() );
119
120 while( rs->next() )
121 {
122 OUString columnName = xRow->getString( 4 );
123
125 if( index >= m_columns.getLength() )
126 continue;
127
128 rtl::Reference<IndexColumn> pIndexColumn =
130 Reference< css::beans::XPropertySet > prop = pIndexColumn;
131
132 columnMetaData2SDBCX( pIndexColumn.get(), xRow );
133 pIndexColumn->setPropertyValue_NoBroadcast_public(
134 st.IS_ASCENDING , Any( false ) );
135
136 m_values[ index ] <<= prop;
138 }
139 }
140 catch ( css::sdbc::SQLException & e )
141 {
142 css::uno::Any anyEx = cppu::getCaughtException();
143 throw css::lang::WrappedTargetRuntimeException( e.Message,
144 e.Context, anyEx );
145 }
146
147 fire( RefreshedBroadcaster( *this ) );
148}
149
150
152 const css::uno::Reference< css::beans::XPropertySet >& /*future*/ )
153{
154 throw css::sdbc::SQLException(
155 "SDBC-POSTGRESQL: IndexesColumns.appendByDescriptor not yet implemented",
156 *this, OUString(), 1, Any() );
157// osl::MutexGuard guard( m_xMutex->GetMutex() );
158// Statics & st = getStatics();
159// Reference< XPropertySet > past = createDataDescriptor();
160// past->setPropertyValue( st.IS_NULLABLE, makeAny( css::sdbc::ColumnValue::NULLABLE ) );
161// alterColumnByDescriptor(
162// m_schemaName, m_tableName, m_pSettings->encoding, m_origin->createStatement() , past, future );
163
164}
165
166void IndexColumns::dropByName( const OUString& )
167{
168 throw css::sdbc::SQLException(
169 "SDBC-POSTGRESQL: IndexesColumns.dropByName not yet implemented",
170 *this, OUString(), 1, Any() );
171// String2IntMap::const_iterator ii = m_name2index.find( elementName );
172// if( ii == m_name2index.end() )
173// {
174// OUStringBuffer buf( 128 );
175// buf.appendAscii( "Column " );
176// buf.append( elementName );
177// buf.appendAscii( " is unknown in table " );
178// buf.append( m_schemaName );
179// buf.appendAscii( "." );
180// buf.append( m_tableName );
181// buf.appendAscii( ", so it can't be dropped" );
182// throw css::container::NoSuchElementException(
183// buf.makeStringAndClear(), *this );
184// }
185// dropByIndex( ii->second );
186}
187
189{
190 throw css::sdbc::SQLException(
191 "SDBC-POSTGRESQL: IndexesColumns.dropByIndex not yet implemented",
192 *this, OUString(), 1, Any() );
193// osl::MutexGuard guard( m_xMutex->GetMutex() );
194// if( index < 0 || index >= m_values.getLength() )
195// {
196// OUStringBuffer buf( 128 );
197// buf.appendAscii( "COLUMNS: Index out of range (allowed 0 to " );
198// buf.append((sal_Int32)(m_values.getLength() -1) );
199// buf.appendAscii( ", got " );
200// buf.append( index );
201// buf.appendAscii( ")" );
202// throw css::lang::IndexOutOfBoundsException(
203// buf.makeStringAndClear(), *this );
204// }
205
206// Reference< XPropertySet > set;
207// m_values[index] >>= set;
208// Statics &st = getStatics();
209// OUString name;
210// set->getPropertyValue( st.NAME ) >>= name;
211
212// OUStringBuffer update( 128 );
213// update.appendAscii( "ALTER TABLE ONLY");
214// bufferQuoteQualifiedIdentifier( update, m_schemaName, m_tableName );
215// update.appendAscii( "DROP COLUMN" );
216// bufferQuoteIdentifier( update, name );
217// Reference< XStatement > stmt = m_origin->createStatement( );
218// DisposeGuard disposeIt( stmt );
219// stmt->executeUpdate( update.makeStringAndClear() );
220
221}
222
223
225{
227}
228
230 const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex,
231 const css::uno::Reference< css::sdbc::XConnection > & origin,
232 ConnectionSettings *pSettings,
233 const OUString &schemaName,
234 const OUString &tableName,
235 const OUString &indexName,
236 const Sequence< OUString > &columns )
237{
238 rtl::Reference<IndexColumns> pIndexColumns = new IndexColumns(
239 refMutex, origin, pSettings, schemaName, tableName, indexName, columns );
240 pIndexColumns->refresh();
241
242 return pIndexColumns;
243}
244
245
247 const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex,
248 const css::uno::Reference< css::sdbc::XConnection > & origin,
249 ConnectionSettings *pSettings)
250 : Container( refMutex, origin, pSettings, getStatics().INDEX_COLUMN )
251{}
252
254 const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex,
255 const css::uno::Reference< css::sdbc::XConnection > & origin,
256 ConnectionSettings *pSettings)
257{
258 return new IndexColumnDescriptors( refMutex, origin, pSettings );
259}
260
261css::uno::Reference< css::beans::XPropertySet > IndexColumnDescriptors::createDataDescriptor()
262{
264}
265
266};
267
268/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ConnectionSettings * m_pSettings
void fire(const EventBroadcastHelper &helper)
css::uno::Reference< css::sdbc::XConnection > m_origin
::rtl::Reference< comphelper::RefCountedMutex > m_xMutex
std::vector< css::uno::Any > m_values
virtual css::uno::Reference< css::beans::XPropertySet > SAL_CALL createDataDescriptor() override
IndexColumnDescriptors(const ::rtl::Reference< comphelper::RefCountedMutex > &refMutex, const css::uno::Reference< css::sdbc::XConnection > &origin, ConnectionSettings *pSettings)
static css::uno::Reference< css::container::XNameAccess > create(const ::rtl::Reference< comphelper::RefCountedMutex > &refMutex, const css::uno::Reference< css::sdbc::XConnection > &origin, ConnectionSettings *pSettings)
virtual void SAL_CALL dropByName(const OUString &elementName) override
IndexColumns(const ::rtl::Reference< comphelper::RefCountedMutex > &refMutex, const css::uno::Reference< css::sdbc::XConnection > &origin, ConnectionSettings *pSettings, OUString schemaName, OUString tableName, OUString indexName, const css::uno::Sequence< OUString > &columns)
virtual void SAL_CALL dropByIndex(sal_Int32 index) override
virtual ~IndexColumns() override
virtual css::uno::Reference< css::beans::XPropertySet > SAL_CALL createDataDescriptor() override
virtual void SAL_CALL refresh() override
virtual void SAL_CALL appendByDescriptor(const css::uno::Reference< css::beans::XPropertySet > &descriptor) override
css::uno::Sequence< OUString > m_columns
static css::uno::Reference< css::container::XNameAccess > create(const ::rtl::Reference< comphelper::RefCountedMutex > &refMutex, const css::uno::Reference< css::sdbc::XConnection > &origin, ConnectionSettings *pSettings, const OUString &schemaName, const OUString &tableName, const OUString &indexName, const css::uno::Sequence< OUString > &columns)
#define SAL_INFO(area, stream)
class SAL_NO_VTABLE XPropertySet
Any SAL_CALL getCaughtException()
index
Statics & getStatics()
Definition: pq_statics.cxx:112
OUString columnMetaData2SDBCX(ReflectionBase *pBase, const css::uno::Reference< css::sdbc::XRow > &xRow)
static sal_Int32 findInSequence(const Sequence< OUString > &seq, std::u16string_view str)
const char * columnName
Definition: pq_statics.cxx:56
const char * tableName
Definition: pq_statics.cxx:57