LibreOffice Module connectivity (master) 1
HViews.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20
21#include <hsqldb/HTables.hxx>
22#include <hsqldb/HViews.hxx>
23#include <hsqldb/HView.hxx>
24#include <hsqldb/HCatalog.hxx>
26#include <comphelper/types.hxx>
27#include <TConnection.hxx>
28
29using namespace ::comphelper;
30
31using namespace ::cppu;
32using namespace connectivity;
33using namespace connectivity::hsqldb;
34using namespace css::uno;
35using namespace css::beans;
36using namespace css::sdbcx;
37using namespace css::sdbc;
38using namespace css::container;
39using namespace css::lang;
40using namespace dbtools;
42
43
44HViews::HViews( const Reference< XConnection >& _rxConnection, ::cppu::OWeakObject& _rParent, ::osl::Mutex& _rMutex,
45 const ::std::vector< OUString> &_rVector )
46 :sdbcx::OCollection( _rParent, true, _rMutex, _rVector )
47 ,m_xConnection( _rxConnection )
48 ,m_xMetaData( _rxConnection->getMetaData() )
49 ,m_bInDrop( false )
50{
51}
52
53
55{
56 OUString sCatalog,sSchema,sTable;
58 _rName,
60 sSchema,
61 sTable,
62 ::dbtools::EComposeRule::InDataManipulation);
63 return new HView( m_xConnection, isCaseSensitive(), sSchema, sTable );
64}
65
66
68{
69 static_cast<OHCatalog&>(m_rParent).refreshTables();
70}
71
73{
74 m_xMetaData.clear();
76}
77
78Reference< XPropertySet > HViews::createDescriptor()
79{
80 Reference<XConnection> xConnection = static_cast<OHCatalog&>(m_rParent).getConnection();
81 return new connectivity::sdbcx::OView(true, xConnection->getMetaData());
82}
83
84// XAppend
85sdbcx::ObjectType HViews::appendObject( const OUString& _rForName, const Reference< XPropertySet >& descriptor )
86{
87 createView(descriptor);
88 return createObject( _rForName );
89}
90
91// XDrop
92void HViews::dropObject(sal_Int32 _nPos,const OUString& /*_sElementName*/)
93{
94 if ( m_bInDrop )
95 return;
96
97 Reference< XInterface > xObject( getObject( _nPos ) );
98 bool bIsNew = connectivity::sdbcx::ODescriptor::isNew( xObject );
99 if (!bIsNew)
100 {
101 OUString aSql( "DROP VIEW" );
102
103 Reference<XPropertySet> xProp(xObject,UNO_QUERY);
104 aSql += ::dbtools::composeTableName( m_xMetaData, xProp, ::dbtools::EComposeRule::InTableDefinitions, true );
105
106 Reference<XConnection> xConnection = static_cast<OHCatalog&>(m_rParent).getConnection();
107 Reference< XStatement > xStmt = xConnection->createStatement( );
108 xStmt->execute(aSql);
109 ::comphelper::disposeComponent(xStmt);
110 }
111}
112
113void HViews::dropByNameImpl(const OUString& elementName)
114{
115 m_bInDrop = true;
116 OCollection_TYPE::dropByName(elementName);
117 m_bInDrop = false;
118}
119
120void HViews::createView( const Reference< XPropertySet >& descriptor )
121{
122 Reference<XConnection> xConnection = static_cast<OHCatalog&>(m_rParent).getConnection();
123
124 OUString sCommand;
125 descriptor->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_COMMAND)) >>= sCommand;
126
127 OUString aSql = "CREATE VIEW " +
128 ::dbtools::composeTableName( m_xMetaData, descriptor, ::dbtools::EComposeRule::InTableDefinitions, true ) +
129 " AS " + sCommand;
130
131 Reference< XStatement > xStmt = xConnection->createStatement( );
132 if ( xStmt.is() )
133 {
134 xStmt->execute(aSql);
135 ::comphelper::disposeComponent(xStmt);
136 }
137
138 // insert the new view also in the tables collection
139 OTables* pTables = static_cast<OTables*>(static_cast<OHCatalog&>(m_rParent).getPrivateTables());
140 if ( pTables )
141 {
142 OUString sName = ::dbtools::composeTableName( m_xMetaData, descriptor, ::dbtools::EComposeRule::InDataManipulation, false );
143 pTables->appendNew(sName);
144 }
145}
146
147
148/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OptionalString sSchema
OptionalString sCatalog
connectivity::sdbcx::OCollection OCollection_TYPE
Definition: HViews.cxx:41
::dbtools::OPropertyMap & getPropMap()
Definition: TConnection.cxx:68
virtual void impl_refresh() override
Definition: HViews.cxx:67
virtual css::uno::Reference< css::beans::XPropertySet > createDescriptor() override
Definition: HViews.cxx:78
css::uno::Reference< css::sdbc::XConnection > m_xConnection
Definition: HViews.hxx:27
virtual void disposing() override
Definition: HViews.cxx:72
css::uno::Reference< css::sdbc::XDatabaseMetaData > m_xMetaData
Definition: HViews.hxx:28
virtual sdbcx::ObjectType createObject(const OUString &_rName) override
Definition: HViews.cxx:54
virtual sdbcx::ObjectType appendObject(const OUString &_rForName, const css::uno::Reference< css::beans::XPropertySet > &descriptor) override
appends an object described by a descriptor, under a given name
Definition: HViews.cxx:85
virtual void dropObject(sal_Int32 _nPos, const OUString &_sElementName) override
Definition: HViews.cxx:92
void createView(const css::uno::Reference< css::beans::XPropertySet > &descriptor)
Definition: HViews.cxx:120
void dropByNameImpl(const OUString &elementName)
Definition: HViews.cxx:113
void appendNew(const OUString &_rsNewTable)
Definition: HTables.cxx:158
virtual void SAL_CALL dropByName(const OUString &elementName) override
ObjectType getObject(sal_Int32 _nIndex)
return the object, if not existent it creates it.
::cppu::OWeakObject & m_rParent
Definition: VCollection.hxx:97
const OUString & getNameByIndex(sal_Int32 _nIndex) const
Definition: propertyids.cxx:95
OUString sName
css::uno::Reference< css::beans::XPropertySet > ObjectType
Definition: VCollection.hxx:59
OUString composeTableName(const Reference< XDatabaseMetaData > &_rxMetaData, const OUString &_rCatalog, const OUString &_rSchema, const OUString &_rName, bool _bQuote, EComposeRule _eComposeRule)
Definition: dbtools.cxx:1286
Reference< XConnection > getConnection(const Reference< XRowSet > &_rxRowSet)
Definition: dbtools.cxx:348
void qualifiedNameComponents(const Reference< XDatabaseMetaData > &_rxConnMetaData, const OUString &_rQualifiedName, OUString &_rCatalog, OUString &_rSchema, OUString &_rName, EComposeRule _eComposeRule)
Definition: dbtools.cxx:862
Reference< XConnection > m_xConnection
#define PROPERTY_ID_COMMAND
Definition: propertyids.hxx:72
sal_Int32 _nPos