1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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/.
12 #include "Catalog.hxx"
13 #include <connectivity/dbtools.hxx>
14 #include <comphelper/types.hxx>
15 #include <TConnection.hxx>
17 connectivity::firebird::Views::Views(
18 const css::uno::Reference
<css::sdbc::XConnection
>& _rxConnection
, ::cppu::OWeakObject
& _rParent
,
19 ::osl::Mutex
& _rMutex
, const ::std::vector
<OUString
>& _rVector
)
20 : sdbcx::OCollection(_rParent
, true, _rMutex
, _rVector
)
21 , m_xConnection(_rxConnection
)
22 , m_xMetaData(_rxConnection
->getMetaData())
27 connectivity::sdbcx::ObjectType
connectivity::firebird::Views::createObject(const OUString
& _rName
)
29 OUString sCatalog
, sSchema
, sTable
;
30 ::dbtools::qualifiedNameComponents(m_xMetaData
, _rName
, sCatalog
, sSchema
, sTable
,
31 ::dbtools::EComposeRule::InDataManipulation
);
32 return new View(m_xConnection
, isCaseSensitive(), sSchema
, sTable
);
35 void connectivity::firebird::Views::impl_refresh()
37 static_cast<Catalog
&>(m_rParent
).refreshViews();
40 css::uno::Reference
<css::beans::XPropertySet
> connectivity::firebird::Views::createDescriptor()
42 return new connectivity::sdbcx::OView(true, m_xMetaData
);
46 connectivity::sdbcx::ObjectType
connectivity::firebird::Views::appendObject(
47 const OUString
& _rForName
, const css::uno::Reference
<css::beans::XPropertySet
>& descriptor
)
49 createView(descriptor
);
50 return createObject(_rForName
);
54 void connectivity::firebird::Views::dropObject(sal_Int32 _nPos
, const OUString
& /*_sElementName*/)
59 css::uno::Reference
<XInterface
> xObject(getObject(_nPos
));
60 bool bIsNew
= connectivity::sdbcx::ODescriptor::isNew(xObject
);
63 OUString
aSql("DROP VIEW");
65 css::uno::Reference
<css::beans::XPropertySet
> xProp(xObject
, css::uno::UNO_QUERY
);
66 aSql
+= ::dbtools::composeTableName(m_xMetaData
, xProp
,
67 ::dbtools::EComposeRule::InTableDefinitions
, true);
69 css::uno::Reference
<css::sdbc::XConnection
> xConnection
= m_xMetaData
->getConnection();
70 css::uno::Reference
<css::sdbc::XStatement
> xStmt
= xConnection
->createStatement();
72 ::comphelper::disposeComponent(xStmt
);
76 void connectivity::firebird::Views::dropByNameImpl(const OUString
& elementName
)
79 connectivity::sdbcx::OCollection::dropByName(elementName
);
83 void connectivity::firebird::Views::createView(
84 const css::uno::Reference
<css::beans::XPropertySet
>& descriptor
)
86 css::uno::Reference
<css::sdbc::XConnection
> xConnection
= m_xMetaData
->getConnection();
89 descriptor
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_COMMAND
))
92 OUString aSql
= "CREATE VIEW "
93 + ::dbtools::composeTableName(m_xMetaData
, descriptor
,
94 ::dbtools::EComposeRule::InTableDefinitions
, true)
97 css::uno::Reference
<css::sdbc::XStatement
> xStmt
= xConnection
->createStatement();
100 xStmt
->execute(aSql
);
101 ::comphelper::disposeComponent(xStmt
);
103 connectivity::firebird::Tables
* pTables
= static_cast<connectivity::firebird::Tables
*>(
104 static_cast<connectivity::firebird::Catalog
&>(m_rParent
).getPrivateTables());
107 OUString sName
= ::dbtools::composeTableName(
108 m_xMetaData
, descriptor
, ::dbtools::EComposeRule::InDataManipulation
, false);
109 pTables
->appendNew(sName
);
112 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */