bump product version to 7.2.5.1
[LibreOffice.git] / connectivity / source / drivers / hsqldb / HViews.cxx
blob1f4b807484e55b55993e35c88c84b7754fae1119
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <hsqldb/HTables.hxx>
22 #include <hsqldb/HViews.hxx>
23 #include <hsqldb/HView.hxx>
24 #include <hsqldb/HCatalog.hxx>
25 #include <connectivity/dbtools.hxx>
26 #include <comphelper/types.hxx>
27 #include <TConnection.hxx>
29 using namespace ::comphelper;
31 using namespace ::cppu;
32 using namespace connectivity;
33 using namespace connectivity::hsqldb;
34 using namespace css::uno;
35 using namespace css::beans;
36 using namespace css::sdbcx;
37 using namespace css::sdbc;
38 using namespace css::container;
39 using namespace css::lang;
40 using namespace dbtools;
41 typedef connectivity::sdbcx::OCollection OCollection_TYPE;
44 HViews::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 )
54 sdbcx::ObjectType HViews::createObject(const OUString& _rName)
56 OUString sCatalog,sSchema,sTable;
57 ::dbtools::qualifiedNameComponents(m_xMetaData,
58 _rName,
59 sCatalog,
60 sSchema,
61 sTable,
62 ::dbtools::EComposeRule::InDataManipulation);
63 return new HView( m_xConnection, isCaseSensitive(), sSchema, sTable );
67 void HViews::impl_refresh( )
69 static_cast<OHCatalog&>(m_rParent).refreshTables();
72 void HViews::disposing()
74 m_xMetaData.clear();
75 OCollection::disposing();
78 Reference< XPropertySet > HViews::createDescriptor()
80 Reference<XConnection> xConnection = static_cast<OHCatalog&>(m_rParent).getConnection();
81 return new connectivity::sdbcx::OView(true, xConnection->getMetaData());
84 // XAppend
85 sdbcx::ObjectType HViews::appendObject( const OUString& _rForName, const Reference< XPropertySet >& descriptor )
87 createView(descriptor);
88 return createObject( _rForName );
91 // XDrop
92 void HViews::dropObject(sal_Int32 _nPos,const OUString& /*_sElementName*/)
94 if ( m_bInDrop )
95 return;
97 Reference< XInterface > xObject( getObject( _nPos ) );
98 bool bIsNew = connectivity::sdbcx::ODescriptor::isNew( xObject );
99 if (!bIsNew)
101 OUString aSql( "DROP VIEW" );
103 Reference<XPropertySet> xProp(xObject,UNO_QUERY);
104 aSql += ::dbtools::composeTableName( m_xMetaData, xProp, ::dbtools::EComposeRule::InTableDefinitions, true );
106 Reference<XConnection> xConnection = static_cast<OHCatalog&>(m_rParent).getConnection();
107 Reference< XStatement > xStmt = xConnection->createStatement( );
108 xStmt->execute(aSql);
109 ::comphelper::disposeComponent(xStmt);
113 void HViews::dropByNameImpl(const OUString& elementName)
115 m_bInDrop = true;
116 OCollection_TYPE::dropByName(elementName);
117 m_bInDrop = false;
120 void HViews::createView( const Reference< XPropertySet >& descriptor )
122 Reference<XConnection> xConnection = static_cast<OHCatalog&>(m_rParent).getConnection();
124 OUString sCommand;
125 descriptor->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_COMMAND)) >>= sCommand;
127 OUString aSql = "CREATE VIEW " +
128 ::dbtools::composeTableName( m_xMetaData, descriptor, ::dbtools::EComposeRule::InTableDefinitions, true ) +
129 " AS " + sCommand;
131 Reference< XStatement > xStmt = xConnection->createStatement( );
132 if ( xStmt.is() )
134 xStmt->execute(aSql);
135 ::comphelper::disposeComponent(xStmt);
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 )
142 OUString sName = ::dbtools::composeTableName( m_xMetaData, descriptor, ::dbtools::EComposeRule::InDataManipulation, false );
143 pTables->appendNew(sName);
148 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */