1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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::sdbc
;
37 using namespace dbtools
;
38 typedef connectivity::sdbcx::OCollection OCollection_TYPE
;
41 HViews::HViews( const Reference
< XConnection
>& _rxConnection
, ::cppu::OWeakObject
& _rParent
, ::osl::Mutex
& _rMutex
,
42 const ::std::vector
< OUString
> &_rVector
)
43 :sdbcx::OCollection( _rParent
, true, _rMutex
, _rVector
)
44 ,m_xConnection( _rxConnection
)
45 ,m_xMetaData( _rxConnection
->getMetaData() )
51 sdbcx::ObjectType
HViews::createObject(const OUString
& _rName
)
53 OUString sCatalog
,sSchema
,sTable
;
54 ::dbtools::qualifiedNameComponents(m_xMetaData
,
59 ::dbtools::EComposeRule::InDataManipulation
);
60 return new HView( m_xConnection
, isCaseSensitive(), sSchema
, sTable
);
64 void HViews::impl_refresh( )
66 static_cast<OHCatalog
&>(m_rParent
).refreshTables();
69 void HViews::disposing()
72 OCollection::disposing();
75 Reference
< XPropertySet
> HViews::createDescriptor()
77 Reference
<XConnection
> xConnection
= static_cast<OHCatalog
&>(m_rParent
).getConnection();
78 return new connectivity::sdbcx::OView(true, xConnection
->getMetaData());
82 sdbcx::ObjectType
HViews::appendObject( const OUString
& _rForName
, const Reference
< XPropertySet
>& descriptor
)
84 createView(descriptor
);
85 return createObject( _rForName
);
89 void HViews::dropObject(sal_Int32 _nPos
,const OUString
& /*_sElementName*/)
94 Reference
< XInterface
> xObject( getObject( _nPos
) );
95 bool bIsNew
= connectivity::sdbcx::ODescriptor::isNew( xObject
);
98 OUString
aSql( u
"DROP VIEW"_ustr
);
100 Reference
<XPropertySet
> xProp(xObject
,UNO_QUERY
);
101 aSql
+= ::dbtools::composeTableName( m_xMetaData
, xProp
, ::dbtools::EComposeRule::InTableDefinitions
, true );
103 Reference
<XConnection
> xConnection
= static_cast<OHCatalog
&>(m_rParent
).getConnection();
104 Reference
< XStatement
> xStmt
= xConnection
->createStatement( );
105 xStmt
->execute(aSql
);
106 ::comphelper::disposeComponent(xStmt
);
110 void HViews::dropByNameImpl(const OUString
& elementName
)
113 OCollection_TYPE::dropByName(elementName
);
117 void HViews::createView( const Reference
< XPropertySet
>& descriptor
)
119 Reference
<XConnection
> xConnection
= static_cast<OHCatalog
&>(m_rParent
).getConnection();
122 descriptor
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_COMMAND
)) >>= sCommand
;
124 OUString aSql
= "CREATE VIEW " +
125 ::dbtools::composeTableName( m_xMetaData
, descriptor
, ::dbtools::EComposeRule::InTableDefinitions
, true ) +
128 Reference
< XStatement
> xStmt
= xConnection
->createStatement( );
131 xStmt
->execute(aSql
);
132 ::comphelper::disposeComponent(xStmt
);
135 // insert the new view also in the tables collection
136 OTables
* pTables
= static_cast<OTables
*>(static_cast<OHCatalog
&>(m_rParent
).getPrivateTables());
139 OUString sName
= ::dbtools::composeTableName( m_xMetaData
, descriptor
, ::dbtools::EComposeRule::InDataManipulation
, false );
140 pTables
->appendNew(sName
);
145 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */