LibreOffice Module connectivity (master) 1
pq_xview.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 <rtl/ref.hxx>
38#include <rtl/ustrbuf.hxx>
39
42
43#include <com/sun/star/sdbc/SQLException.hpp>
44
45#include "pq_xview.hxx"
46#include "pq_xviews.hxx"
47#include "pq_statics.hxx"
48#include "pq_tools.hxx"
49
50using osl::MutexGuard;
51
54using com::sun::star::uno::Any;
55using com::sun::star::uno::Type;
56
58
59using com::sun::star::sdbc::XStatement;
60using com::sun::star::sdbc::SQLException;
61
62namespace pq_sdbc_driver
63{
64
65View::View( const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex,
66 const Reference< css::sdbc::XConnection > & connection,
67 ConnectionSettings *pSettings)
68 : ReflectionBase(
69 getStatics().refl.view.implName,
70 getStatics().refl.view.serviceNames,
71 refMutex,
72 connection,
73 pSettings,
74 * getStatics().refl.view.pProps )
75{}
76
77Reference< XPropertySet > View::createDataDescriptor( )
78{
80 m_xMutex, m_conn, m_pSettings );
81 pView->copyValuesFrom( this );
82
83 return Reference< XPropertySet > ( pView );
84}
85
86void View::rename( const OUString& newName )
87{
88 MutexGuard guard( m_xMutex->GetMutex() );
89
90 Statics & st = getStatics();
91
92 OUString oldName = extractStringProperty(this,st.NAME );
93 OUString schema = extractStringProperty(this,st.SCHEMA_NAME );
94 OUString fullOldName = concatQualified( schema, oldName );
95
96 OUString newTableName;
97 OUString newSchemaName;
98 // OOo2.0 passes schema + dot + new-table-name while
99 // OO1.1.x passes new Name without schema
100 // in case name contains a dot, it is interpreted as schema.tablename
101 if( newName.indexOf( '.' ) >= 0 )
102 {
103 splitConcatenatedIdentifier( newName, &newSchemaName, &newTableName );
104 }
105 else
106 {
107 newTableName = newName;
108 newSchemaName = schema;
109 }
110 OUString fullNewName = concatQualified( newSchemaName, newTableName );
111
112 if( schema != newSchemaName )
113 {
114 try
115 {
116 OUStringBuffer buf(128);
117 buf.append( "ALTER TABLE" );
118 bufferQuoteQualifiedIdentifier(buf, schema, oldName, m_pSettings );
119 buf.append( "SET SCHEMA" );
120 bufferQuoteIdentifier( buf, newSchemaName, m_pSettings );
121 Reference< XStatement > statement = m_conn->createStatement();
122 statement->executeUpdate( buf.makeStringAndClear() );
123 setPropertyValue_NoBroadcast_public( st.SCHEMA_NAME, Any(newSchemaName) );
124 disposeNoThrow( statement );
125 schema = newSchemaName;
126 }
127 catch( css::sdbc::SQLException &e )
128 {
129 OUString buf( e.Message + "(NOTE: Only postgresql server >= V8.1 support changing a table's schema)" );
130 e.Message = buf;
131 throw;
132 }
133
134 }
135 if( oldName != newTableName )
136 {
137 OUStringBuffer buf(128);
138 buf.append( "ALTER TABLE" );
139 bufferQuoteQualifiedIdentifier( buf, schema, oldName, m_pSettings );
140 buf.append( "RENAME TO" );
141 bufferQuoteIdentifier( buf, newTableName, m_pSettings );
142 Reference< XStatement > statement = m_conn->createStatement();
143 statement->executeUpdate( buf.makeStringAndClear() );
144 setPropertyValue_NoBroadcast_public( st.NAME, Any(newTableName) );
145 }
146
147 // inform the container of the name change !
148 if( m_pSettings->views.is() )
149 {
150 m_pSettings->pViewsImpl->rename( fullOldName, fullNewName );
151 }
152}
153
154Sequence<Type > View::getTypes()
155{
156 static cppu::OTypeCollection collection(
158 ReflectionBase::getTypes());
159
160 return collection.getTypes();
161}
162
163Sequence< sal_Int8> View::getImplementationId()
164{
165 return css::uno::Sequence<sal_Int8>();
166}
167
168Any View::queryInterface( const Type & reqType )
169{
170 Any ret = ReflectionBase::queryInterface( reqType );
171 if( ! ret.hasValue() )
172 ret = ::cppu::queryInterface(
173 reqType,
174 static_cast< css::sdbcx::XRename * > ( this )
175 );
176 return ret;
177}
178
179OUString View::getName( )
180{
181 Statics & st = getStatics();
182 return concatQualified(
184 extractStringProperty( this, st.NAME ) );
185}
186
187void View::setName( const OUString& aName )
188{
189 rename( aName );
190}
191
192
193ViewDescriptor::ViewDescriptor(
194 const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex,
195 const Reference< css::sdbc::XConnection > & connection,
196 ConnectionSettings *pSettings)
198 getStatics().refl.viewDescriptor.implName,
199 getStatics().refl.viewDescriptor.serviceNames,
200 refMutex,
201 connection,
202 pSettings,
203 * getStatics().refl.viewDescriptor.pProps )
204{}
205
207{
210 pView->copyValuesFrom( this );
211
212 return Reference< XPropertySet > ( pView );
213}
214
215
216}
217
218/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Sequence< css::uno::Type > SAL_CALL getTypes()
css::uno::Reference< css::sdbc::XConnection > m_conn
Definition: pq_xbase.hxx:62
::rtl::Reference< comphelper::RefCountedMutex > m_xMutex
Definition: pq_xbase.hxx:61
ConnectionSettings * m_pSettings
Definition: pq_xbase.hxx:63
ViewDescriptor(const ::rtl::Reference< comphelper::RefCountedMutex > &refMutex, const css::uno::Reference< css::sdbc::XConnection > &connection, ConnectionSettings *pSettings)
virtual css::uno::Reference< css::beans::XPropertySet > SAL_CALL createDataDescriptor() override
Definition: pq_xview.cxx:206
View(const ::rtl::Reference< comphelper::RefCountedMutex > &refMutex, const css::uno::Reference< css::sdbc::XConnection > &connection, ConnectionSettings *pSettings)
OUString aName
class SAL_NO_VTABLE XPropertySet
Type
OUString newName(std::u16string_view aNewPrefix, std::u16string_view aOldPrefix, std::u16string_view old_Name)
Statics & getStatics()
Definition: pq_statics.cxx:112
void bufferQuoteQualifiedIdentifier(OUStringBuffer &buf, std::u16string_view schema, std::u16string_view table, ConnectionSettings *settings)
Definition: pq_tools.cxx:181
OUString concatQualified(std::u16string_view a, std::u16string_view b)
Definition: pq_tools.cxx:90
OUString extractStringProperty(const Reference< XPropertySet > &descriptor, const OUString &name)
Definition: pq_tools.cxx:204
void splitConcatenatedIdentifier(std::u16string_view source, OUString *first, OUString *second)
Definition: pq_tools.cxx:548
void disposeNoThrow(const css::uno::Reference< css::uno::XInterface > &r)
Definition: pq_tools.cxx:235
void bufferQuoteIdentifier(OUStringBuffer &buf, std::u16string_view toQuote, ConnectionSettings *settings)
Definition: pq_tools.cxx:175
rtl::Reference< Connection > m_conn
const char * implName