build fix
[LibreOffice.git] / connectivity / source / drivers / hsqldb / HViews.cxx
blobdc0dd69de886e64a8a8375ebb96694a18aac51c5
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 <com/sun/star/sdbc/XRow.hpp>
25 #include <com/sun/star/sdbc/XResultSet.hpp>
26 #include <com/sun/star/sdbc/ColumnValue.hpp>
27 #include <com/sun/star/sdbc/KeyRule.hpp>
28 #include <com/sun/star/sdbcx/KeyType.hpp>
29 #include <com/sun/star/sdbcx/CheckOption.hpp>
30 #include "hsqldb/HCatalog.hxx"
31 #include <comphelper/extract.hxx>
32 #include <connectivity/dbtools.hxx>
33 #include <connectivity/dbexception.hxx>
34 #include <cppuhelper/interfacecontainer.h>
35 #include <comphelper/types.hxx>
36 #include "TConnection.hxx"
38 using namespace ::comphelper;
40 using namespace ::cppu;
41 using namespace connectivity;
42 using namespace connectivity::hsqldb;
43 using namespace css::uno;
44 using namespace css::beans;
45 using namespace css::sdbcx;
46 using namespace css::sdbc;
47 using namespace css::container;
48 using namespace css::lang;
49 using namespace dbtools;
50 typedef connectivity::sdbcx::OCollection OCollection_TYPE;
53 HViews::HViews( const Reference< XConnection >& _rxConnection, ::cppu::OWeakObject& _rParent, ::osl::Mutex& _rMutex,
54 const TStringVector &_rVector )
55 :sdbcx::OCollection( _rParent, true, _rMutex, _rVector )
56 ,m_xConnection( _rxConnection )
57 ,m_xMetaData( _rxConnection->getMetaData() )
58 ,m_bInDrop( false )
63 sdbcx::ObjectType HViews::createObject(const OUString& _rName)
65 OUString sCatalog,sSchema,sTable;
66 ::dbtools::qualifiedNameComponents(m_xMetaData,
67 _rName,
68 sCatalog,
69 sSchema,
70 sTable,
71 ::dbtools::EComposeRule::InDataManipulation);
72 return new HView( m_xConnection, isCaseSensitive(), sSchema, sTable );
76 void HViews::impl_refresh( ) throw(RuntimeException)
78 static_cast<OHCatalog&>(m_rParent).refreshTables();
81 void HViews::disposing()
83 m_xMetaData.clear();
84 OCollection::disposing();
87 Reference< XPropertySet > HViews::createDescriptor()
89 Reference<XConnection> xConnection = static_cast<OHCatalog&>(m_rParent).getConnection();
90 connectivity::sdbcx::OView* pNew = new connectivity::sdbcx::OView(true, xConnection->getMetaData());
91 return pNew;
94 // XAppend
95 sdbcx::ObjectType HViews::appendObject( const OUString& _rForName, const Reference< XPropertySet >& descriptor )
97 createView(descriptor);
98 return createObject( _rForName );
101 // XDrop
102 void HViews::dropObject(sal_Int32 _nPos,const OUString& /*_sElementName*/)
104 if ( m_bInDrop )
105 return;
107 Reference< XInterface > xObject( getObject( _nPos ) );
108 bool bIsNew = connectivity::sdbcx::ODescriptor::isNew( xObject );
109 if (!bIsNew)
111 OUString aSql( "DROP VIEW" );
113 Reference<XPropertySet> xProp(xObject,UNO_QUERY);
114 aSql += ::dbtools::composeTableName( m_xMetaData, xProp, ::dbtools::EComposeRule::InTableDefinitions, false, false, true );
116 Reference<XConnection> xConnection = static_cast<OHCatalog&>(m_rParent).getConnection();
117 Reference< XStatement > xStmt = xConnection->createStatement( );
118 xStmt->execute(aSql);
119 ::comphelper::disposeComponent(xStmt);
123 void HViews::dropByNameImpl(const OUString& elementName)
125 m_bInDrop = true;
126 OCollection_TYPE::dropByName(elementName);
127 m_bInDrop = false;
130 void HViews::createView( const Reference< XPropertySet >& descriptor )
132 Reference<XConnection> xConnection = static_cast<OHCatalog&>(m_rParent).getConnection();
134 OUString sCommand;
135 descriptor->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_COMMAND)) >>= sCommand;
137 OUString aSql = "CREATE VIEW " +
138 ::dbtools::composeTableName( m_xMetaData, descriptor, ::dbtools::EComposeRule::InTableDefinitions, false, false, true ) +
139 " AS " + sCommand;
141 Reference< XStatement > xStmt = xConnection->createStatement( );
142 if ( xStmt.is() )
144 xStmt->execute(aSql);
145 ::comphelper::disposeComponent(xStmt);
148 // insert the new view also in the tables collection
149 OTables* pTables = static_cast<OTables*>(static_cast<OHCatalog&>(m_rParent).getPrivateTables());
150 if ( pTables )
152 OUString sName = ::dbtools::composeTableName( m_xMetaData, descriptor, ::dbtools::EComposeRule::InDataManipulation, false, false, false );
153 pTables->appendNew(sName);
158 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */