fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / connectivity / source / drivers / hsqldb / HViews.cxx
blob265981fda0ffa22c0e8290dd041a230dc4d97e18
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 ::com::sun::star::uno;
44 using namespace ::com::sun::star::beans;
45 using namespace ::com::sun::star::sdbcx;
46 using namespace ::com::sun::star::sdbc;
47 using namespace ::com::sun::star::container;
48 using namespace ::com::sun::star::lang;
49 using namespace dbtools;
50 typedef connectivity::sdbcx::OCollection OCollection_TYPE;
52 // -------------------------------------------------------------------------
53 HViews::HViews( const Reference< XConnection >& _rxConnection, ::cppu::OWeakObject& _rParent, ::osl::Mutex& _rMutex,
54 const TStringVector &_rVector )
55 :sdbcx::OCollection( _rParent, sal_True, _rMutex, _rVector )
56 ,m_xConnection( _rxConnection )
57 ,m_xMetaData( _rxConnection->getMetaData() )
58 ,m_bInDrop( sal_False )
62 // -------------------------------------------------------------------------
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::eInDataManipulation);
72 return new HView( m_xConnection, isCaseSensitive(), sSchema, sTable );
75 // -------------------------------------------------------------------------
76 void HViews::impl_refresh( ) throw(RuntimeException)
78 static_cast<OHCatalog&>(m_rParent).refreshTables();
80 // -------------------------------------------------------------------------
81 void HViews::disposing(void)
83 m_xMetaData.clear();
84 OCollection::disposing();
86 // -------------------------------------------------------------------------
87 Reference< XPropertySet > HViews::createDescriptor()
89 Reference<XConnection> xConnection = static_cast<OHCatalog&>(m_rParent).getConnection();
90 connectivity::sdbcx::OView* pNew = new connectivity::sdbcx::OView(sal_True,xConnection->getMetaData());
91 return pNew;
93 // -------------------------------------------------------------------------
94 // XAppend
95 sdbcx::ObjectType HViews::appendObject( const OUString& _rForName, const Reference< XPropertySet >& descriptor )
97 createView(descriptor);
98 return createObject( _rForName );
100 // -------------------------------------------------------------------------
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 sal_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::eInTableDefinitions, 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);
122 // -----------------------------------------------------------------------------
123 void HViews::dropByNameImpl(const OUString& elementName)
125 m_bInDrop = sal_True;
126 OCollection_TYPE::dropByName(elementName);
127 m_bInDrop = sal_False;
129 // -----------------------------------------------------------------------------
130 void HViews::createView( const Reference< XPropertySet >& descriptor )
132 Reference<XConnection> xConnection = static_cast<OHCatalog&>(m_rParent).getConnection();
134 OUString aSql( "CREATE VIEW " );
135 OUString sCommand;
137 aSql += ::dbtools::composeTableName( m_xMetaData, descriptor, ::dbtools::eInTableDefinitions, false, false, true );
139 aSql += OUString(" AS ");
140 descriptor->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_COMMAND)) >>= sCommand;
141 aSql += sCommand;
143 Reference< XStatement > xStmt = xConnection->createStatement( );
144 if ( xStmt.is() )
146 xStmt->execute(aSql);
147 ::comphelper::disposeComponent(xStmt);
150 // insert the new view also in the tables collection
151 OTables* pTables = static_cast<OTables*>(static_cast<OHCatalog&>(m_rParent).getPrivateTables());
152 if ( pTables )
154 OUString sName = ::dbtools::composeTableName( m_xMetaData, descriptor, ::dbtools::eInDataManipulation, false, false, false );
155 pTables->appendNew(sName);
158 // -----------------------------------------------------------------------------
160 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */