LCOV - code coverage report
Current view: top level - connectivity/source/drivers/hsqldb - HViews.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 58 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 9 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : 
      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"
      37             : 
      38             : using namespace ::comphelper;
      39             : 
      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;
      51             : 
      52             : 
      53           0 : 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           0 :     ,m_xMetaData( _rxConnection->getMetaData() )
      58           0 :     ,m_bInDrop( false )
      59             : {
      60           0 : }
      61             : 
      62             : 
      63           0 : sdbcx::ObjectType HViews::createObject(const OUString& _rName)
      64             : {
      65           0 :     OUString sCatalog,sSchema,sTable;
      66             :     ::dbtools::qualifiedNameComponents(m_xMetaData,
      67             :                                         _rName,
      68             :                                         sCatalog,
      69             :                                         sSchema,
      70             :                                         sTable,
      71           0 :                                         ::dbtools::eInDataManipulation);
      72           0 :     return new HView( m_xConnection, isCaseSensitive(), sSchema, sTable );
      73             : }
      74             : 
      75             : 
      76           0 : void HViews::impl_refresh(  ) throw(RuntimeException)
      77             : {
      78           0 :     static_cast<OHCatalog&>(m_rParent).refreshTables();
      79           0 : }
      80             : 
      81           0 : void HViews::disposing()
      82             : {
      83           0 : m_xMetaData.clear();
      84           0 :     OCollection::disposing();
      85           0 : }
      86             : 
      87           0 : Reference< XPropertySet > HViews::createDescriptor()
      88             : {
      89           0 :     Reference<XConnection> xConnection = static_cast<OHCatalog&>(m_rParent).getConnection();
      90           0 :     connectivity::sdbcx::OView* pNew = new connectivity::sdbcx::OView(true, xConnection->getMetaData());
      91           0 :     return pNew;
      92             : }
      93             : 
      94             : // XAppend
      95           0 : sdbcx::ObjectType HViews::appendObject( const OUString& _rForName, const Reference< XPropertySet >& descriptor )
      96             : {
      97           0 :     createView(descriptor);
      98           0 :     return createObject( _rForName );
      99             : }
     100             : 
     101             : // XDrop
     102           0 : void HViews::dropObject(sal_Int32 _nPos,const OUString& /*_sElementName*/)
     103             : {
     104           0 :     if ( m_bInDrop )
     105           0 :         return;
     106             : 
     107           0 :     Reference< XInterface > xObject( getObject( _nPos ) );
     108           0 :     bool bIsNew = connectivity::sdbcx::ODescriptor::isNew( xObject );
     109           0 :     if (!bIsNew)
     110             :     {
     111           0 :         OUString aSql(  "DROP VIEW" );
     112             : 
     113           0 :         Reference<XPropertySet> xProp(xObject,UNO_QUERY);
     114           0 :         aSql += ::dbtools::composeTableName( m_xMetaData, xProp, ::dbtools::eInTableDefinitions, false, false, true );
     115             : 
     116           0 :         Reference<XConnection> xConnection = static_cast<OHCatalog&>(m_rParent).getConnection();
     117           0 :         Reference< XStatement > xStmt = xConnection->createStatement(  );
     118           0 :         xStmt->execute(aSql);
     119           0 :         ::comphelper::disposeComponent(xStmt);
     120           0 :     }
     121             : }
     122             : 
     123           0 : void HViews::dropByNameImpl(const OUString& elementName)
     124             : {
     125           0 :     m_bInDrop = true;
     126           0 :     OCollection_TYPE::dropByName(elementName);
     127           0 :     m_bInDrop = false;
     128           0 : }
     129             : 
     130           0 : void HViews::createView( const Reference< XPropertySet >& descriptor )
     131             : {
     132           0 :     Reference<XConnection> xConnection = static_cast<OHCatalog&>(m_rParent).getConnection();
     133             : 
     134           0 :     OUString sCommand;
     135           0 :     descriptor->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_COMMAND)) >>= sCommand;
     136             : 
     137           0 :     OUString aSql = "CREATE VIEW " +
     138           0 :         ::dbtools::composeTableName( m_xMetaData, descriptor, ::dbtools::eInTableDefinitions, false, false, true ) +
     139           0 :         " AS " + sCommand;
     140             : 
     141           0 :     Reference< XStatement > xStmt = xConnection->createStatement(  );
     142           0 :     if ( xStmt.is() )
     143             :     {
     144           0 :         xStmt->execute(aSql);
     145           0 :         ::comphelper::disposeComponent(xStmt);
     146             :     }
     147             : 
     148             :     // insert the new view also in the tables collection
     149           0 :     OTables* pTables = static_cast<OTables*>(static_cast<OHCatalog&>(m_rParent).getPrivateTables());
     150           0 :     if ( pTables )
     151             :     {
     152           0 :         OUString sName = ::dbtools::composeTableName( m_xMetaData, descriptor, ::dbtools::eInDataManipulation, false, false, false );
     153           0 :         pTables->appendNew(sName);
     154           0 :     }
     155           0 : }
     156             : 
     157             : 
     158             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11