LCOV - code coverage report
Current view: top level - connectivity/source/drivers/hsqldb - HTables.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 29 79 36.7 %
Date: 2015-06-13 12:38:46 Functions: 3 9 33.3 %
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             : #include "hsqldb/HTables.hxx"
      21             : #include "hsqldb/HViews.hxx"
      22             : #include "hsqldb/HTable.hxx"
      23             : #include <com/sun/star/sdbc/XRow.hpp>
      24             : #include <com/sun/star/sdbc/XResultSet.hpp>
      25             : #include <com/sun/star/sdbc/ColumnValue.hpp>
      26             : #include <com/sun/star/sdbcx/Privilege.hpp>
      27             : #include <com/sun/star/sdbc/KeyRule.hpp>
      28             : #include <com/sun/star/sdbcx/KeyType.hpp>
      29             : #include "hsqldb/HCatalog.hxx"
      30             : #include <comphelper/extract.hxx>
      31             : #include <connectivity/dbtools.hxx>
      32             : #include <connectivity/dbexception.hxx>
      33             : #include <cppuhelper/interfacecontainer.h>
      34             : #include <comphelper/types.hxx>
      35             : #include "TConnection.hxx"
      36             : 
      37             : using namespace ::comphelper;
      38             : using namespace connectivity;
      39             : using namespace ::cppu;
      40             : using namespace connectivity::hsqldb;
      41             : using namespace ::com::sun::star::uno;
      42             : using namespace ::com::sun::star::beans;
      43             : using namespace ::com::sun::star::sdbcx;
      44             : using namespace ::com::sun::star::sdbc;
      45             : using namespace ::com::sun::star::container;
      46             : using namespace ::com::sun::star::lang;
      47             : using namespace dbtools;
      48             : 
      49           9 : sdbcx::ObjectType OTables::createObject(const OUString& _rName)
      50             : {
      51          18 :     OUString sCatalog,sSchema,sTable;
      52           9 :     ::dbtools::qualifiedNameComponents(m_xMetaData,_rName,sCatalog,sSchema,sTable,::dbtools::eInDataManipulation);
      53             : 
      54             :     static const char s_sTableTypeView[] = "VIEW";
      55             :     static const char s_sTableTypeTable[] = "TABLE";
      56             :     static const char s_sAll[] = "%";
      57             : 
      58          18 :     Sequence< OUString > sTableTypes(3);
      59           9 :     sTableTypes[0] = s_sTableTypeView;
      60           9 :     sTableTypes[1] = s_sTableTypeTable;
      61           9 :     sTableTypes[2] = s_sAll;    // just to be sure to include anything else ....
      62             : 
      63          18 :     Any aCatalog;
      64           9 :     if ( !sCatalog.isEmpty() )
      65           0 :         aCatalog <<= sCatalog;
      66          18 :     Reference< XResultSet > xResult = m_xMetaData->getTables(aCatalog,sSchema,sTable,sTableTypes);
      67             : 
      68           9 :     sdbcx::ObjectType xRet = NULL;
      69           9 :     if ( xResult.is() )
      70             :     {
      71           9 :         Reference< XRow > xRow(xResult,UNO_QUERY);
      72           9 :         if ( xResult->next() ) // there can be only one table with this name
      73             :         {
      74           9 :             sal_Int32 nPrivileges = ::dbtools::getTablePrivileges( m_xMetaData, sCatalog, sSchema, sTable );
      75           9 :             if ( m_xMetaData->isReadOnly() )
      76           0 :                 nPrivileges &= ~( Privilege::INSERT | Privilege::UPDATE | Privilege::DELETE | Privilege::CREATE | Privilege::ALTER | Privilege::DROP );
      77             : 
      78             :             // obtain privileges
      79             :             OHSQLTable* pRet = new OHSQLTable( this
      80             :                                                 ,static_cast<OHCatalog&>(m_rParent).getConnection()
      81             :                                                 ,sTable
      82           9 :                                                 ,xRow->getString(4)
      83           9 :                                                 ,xRow->getString(5)
      84             :                                                 ,sSchema
      85             :                                                 ,sCatalog
      86          27 :                                                 ,nPrivileges);
      87           9 :             xRet = pRet;
      88             :         }
      89           9 :         ::comphelper::disposeComponent(xResult);
      90             :     }
      91             : 
      92          18 :     return xRet;
      93             : }
      94             : 
      95          12 : void OTables::impl_refresh(  ) throw(RuntimeException)
      96             : {
      97          12 :     static_cast<OHCatalog&>(m_rParent).refreshTables();
      98          12 : }
      99             : 
     100           9 : void OTables::disposing()
     101             : {
     102           9 : m_xMetaData.clear();
     103           9 :     OCollection::disposing();
     104           9 : }
     105             : 
     106           0 : Reference< XPropertySet > OTables::createDescriptor()
     107             : {
     108           0 :     return new OHSQLTable(this,static_cast<OHCatalog&>(m_rParent).getConnection());
     109             : }
     110             : 
     111             : // XAppend
     112           0 : sdbcx::ObjectType OTables::appendObject( const OUString& _rForName, const Reference< XPropertySet >& descriptor )
     113             : {
     114           0 :     createTable(descriptor);
     115           0 :     return createObject( _rForName );
     116             : }
     117             : 
     118             : // XDrop
     119           0 : void OTables::dropObject(sal_Int32 _nPos,const OUString& _sElementName)
     120             : {
     121           0 :     Reference< XInterface > xObject( getObject( _nPos ) );
     122           0 :     bool bIsNew = connectivity::sdbcx::ODescriptor::isNew( xObject );
     123           0 :     if (!bIsNew)
     124             :     {
     125           0 :         Reference< XConnection > xConnection = static_cast<OHCatalog&>(m_rParent).getConnection();
     126             : 
     127             : 
     128           0 :         OUString sCatalog,sSchema,sTable;
     129           0 :         ::dbtools::qualifiedNameComponents(m_xMetaData,_sElementName,sCatalog,sSchema,sTable,::dbtools::eInDataManipulation);
     130             : 
     131           0 :         OUString aSql(  "DROP " );
     132             : 
     133           0 :         Reference<XPropertySet> xProp(xObject,UNO_QUERY);
     134             :         bool bIsView;
     135           0 :         if((bIsView = (xProp.is() && ::comphelper::getString(xProp->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE))) == "VIEW"))) // here we have a view
     136           0 :             aSql += "VIEW ";
     137             :         else
     138           0 :             aSql += "TABLE ";
     139             : 
     140             :         OUString sComposedName(
     141           0 :             ::dbtools::composeTableName( m_xMetaData, sCatalog, sSchema, sTable, true, ::dbtools::eInDataManipulation ) );
     142           0 :         aSql += sComposedName;
     143           0 :         Reference< XStatement > xStmt = xConnection->createStatement(  );
     144           0 :         if ( xStmt.is() )
     145             :         {
     146           0 :             xStmt->execute(aSql);
     147           0 :             ::comphelper::disposeComponent(xStmt);
     148             :         }
     149             :         // if no exception was thrown we must delete it from the views
     150           0 :         if ( bIsView )
     151             :         {
     152           0 :             HViews* pViews = static_cast<HViews*>(static_cast<OHCatalog&>(m_rParent).getPrivateViews());
     153           0 :             if ( pViews && pViews->hasByName(_sElementName) )
     154           0 :                 pViews->dropByNameImpl(_sElementName);
     155           0 :         }
     156           0 :     }
     157           0 : }
     158             : 
     159           0 : void OTables::createTable( const Reference< XPropertySet >& descriptor )
     160             : {
     161           0 :     Reference< XConnection > xConnection = static_cast<OHCatalog&>(m_rParent).getConnection();
     162           0 :     OUString aSql = ::dbtools::createSqlCreateTableStatement(descriptor,xConnection);
     163             : 
     164           0 :     Reference< XStatement > xStmt = xConnection->createStatement(  );
     165           0 :     if ( xStmt.is() )
     166             :     {
     167           0 :         xStmt->execute(aSql);
     168           0 :         ::comphelper::disposeComponent(xStmt);
     169           0 :     }
     170           0 : }
     171             : 
     172           0 : void OTables::appendNew(const OUString& _rsNewTable)
     173             : {
     174           0 :     insertElement(_rsNewTable,NULL);
     175             : 
     176             :     // notify our container listeners
     177           0 :     ContainerEvent aEvent(static_cast<XContainer*>(this), makeAny(_rsNewTable), Any(), Any());
     178           0 :     OInterfaceIteratorHelper aListenerLoop(m_aContainerListeners);
     179           0 :     while (aListenerLoop.hasMoreElements())
     180           0 :         static_cast<XContainerListener*>(aListenerLoop.next())->elementInserted(aEvent);
     181           0 : }
     182             : 
     183           0 : OUString OTables::getNameForObject(const sdbcx::ObjectType& _xObject)
     184             : {
     185             :     OSL_ENSURE(_xObject.is(),"OTables::getNameForObject: Object is NULL!");
     186           0 :     return ::dbtools::composeTableName( m_xMetaData, _xObject, ::dbtools::eInDataManipulation, false, false, false );
     187             : }
     188             : 
     189             : 
     190             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11