LCOV - code coverage report
Current view: top level - connectivity/source/drivers/mork - MQueryHelper.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 24 34 70.6 %
Date: 2015-06-13 12:38:46 Functions: 15 23 65.2 %
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             : #ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MORK_MQUERYHELPER_HXX
      21             : #define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MORK_MQUERYHELPER_HXX
      22             : 
      23             : #include <sal/types.h>
      24             : #include <rtl/ustring.hxx>
      25             : #include <osl/mutex.hxx>
      26             : #include <osl/conditn.hxx>
      27             : #include <osl/thread.hxx>
      28             : #include <connectivity/FValue.hxx>
      29             : #include <boost/noncopyable.hpp>
      30             : #include "MErrorResource.hxx"
      31             : #include <unordered_map>
      32             : 
      33             : namespace connectivity
      34             : {
      35             :     namespace mork
      36             :     {
      37             :         class OConnection;
      38             :         class MQueryHelper;
      39             :         class ErrorDescriptor;
      40             : 
      41             :         namespace MQueryOp {
      42             :              typedef enum {
      43             :                  Exists         = 0,
      44             :                  DoesNotExist   = 1,
      45             :                  Contains       = 2,
      46             :                  DoesNotContain = 3,
      47             :                  Is             = 4,
      48             :                  IsNot          = 5,
      49             :                  BeginsWith     = 6,
      50             :                  EndsWith       = 7,
      51             :                  RegExp         = 8
      52             :             } cond_type;
      53             :         }
      54             : 
      55             :         class MQueryExpressionBase {
      56             :         public:
      57             :             typedef enum {
      58             :                 Unknown,
      59             :                 StringExpr,
      60             :                 Expr
      61             :             } node_type;
      62             : 
      63             :         protected:
      64             :             node_type   m_eNodeType;
      65             : 
      66             :             MQueryExpressionBase() : m_eNodeType( Unknown ) {}
      67           3 :             MQueryExpressionBase( node_type _eNodeType ) : m_eNodeType( _eNodeType ) {}
      68             : 
      69             :         public:
      70           3 :             virtual ~MQueryExpressionBase() {}
      71             : 
      72             :             bool   isUnknown( ) const { return m_eNodeType == Unknown; }
      73           5 :             bool   isStringExpr( ) const { return m_eNodeType == StringExpr; }
      74           0 :             bool   isExpr( ) const { return m_eNodeType == Expr; }
      75             :         };
      76             : 
      77           2 :         class MQueryExpressionString : public MQueryExpressionBase {
      78             :         protected:
      79             :             OUString     m_aName;         // LHS
      80             :             MQueryOp::cond_type m_aBooleanCondition;
      81             :             OUString     m_aValue;        // RHS
      82             : 
      83             :         public:
      84             : 
      85           1 :             MQueryExpressionString( const OUString&     lhs,
      86             :                                     MQueryOp::cond_type cond,
      87             :                                     const OUString&     rhs )
      88             :                 : MQueryExpressionBase( MQueryExpressionBase::StringExpr )
      89             :                 , m_aName( lhs )
      90             :                 , m_aBooleanCondition( cond )
      91           1 :                 , m_aValue( rhs )
      92             :             {
      93           1 :             }
      94             : 
      95           0 :             MQueryExpressionString( const OUString&     lhs,
      96             :                                     MQueryOp::cond_type cond )
      97             :                 : MQueryExpressionBase( MQueryExpressionBase::StringExpr )
      98             :                 , m_aName( lhs )
      99             :                 , m_aBooleanCondition( cond )
     100           0 :                 , m_aValue( OUString() )
     101             :             {
     102           0 :             }
     103             : 
     104           5 :             const OUString&    getName() const { return m_aName; }
     105          25 :             MQueryOp::cond_type getCond() const { return m_aBooleanCondition; }
     106           5 :             const OUString&    getValue() const { return m_aValue; }
     107             :         };
     108             : 
     109             :         class MQueryExpression : public MQueryExpressionBase, private boost::noncopyable
     110             :         {
     111             :             friend class MQueryHelper;
     112             : 
     113             :         public:
     114             :             typedef ::std::vector< MQueryExpressionBase* > ExprVector;
     115             : 
     116             :             typedef enum {
     117             :                 AND,
     118             :                 OR
     119             :             } bool_cond;
     120             : 
     121             :             // All expressions on a peer level use same condition operator
     122           0 :             void setExpressionCondition( bool_cond _cond )
     123           0 :                             { m_aExprCondType = _cond; }
     124             : 
     125           1 :             void addExpression(MQueryExpressionBase * expr)
     126           1 :                             { m_aExprVector.push_back(expr); }
     127             : 
     128          35 :             ExprVector const & getExpressions( ) const
     129          35 :                             { return m_aExprVector; }
     130             : 
     131             :             // All expressions on a peer level use same condition operator
     132           0 :             bool_cond getExpressionCondition( ) const
     133           0 :                             { return m_aExprCondType; }
     134             : 
     135           2 :             MQueryExpression() : MQueryExpressionBase( MQueryExpressionBase::Expr ),
     136           2 :                                  m_aExprCondType( OR )
     137           2 :                             {}
     138             : 
     139           4 :             virtual ~MQueryExpression() {
     140           9 :                 for (ExprVector::iterator i(m_aExprVector.begin());
     141           6 :                      i != m_aExprVector.end(); ++i)
     142             :                 {
     143           1 :                     delete *i;
     144             :                 }
     145           2 :             }
     146             : 
     147             :         protected:
     148             :             ExprVector          m_aExprVector;
     149             :             bool_cond           m_aExprCondType;
     150             : 
     151             :         };
     152             : 
     153             :         class MQueryHelperResultEntry
     154             :         {
     155             :         private:
     156             :             typedef std::unordered_map< OString, OUString, OStringHash >  FieldMap;
     157             : 
     158             :             FieldMap                m_Fields;
     159             : 
     160             :         public:
     161             :             MQueryHelperResultEntry();
     162             :             ~MQueryHelperResultEntry();
     163             : 
     164             :             OUString   getValue( const OString &key ) const;
     165             :             void            setValue( const OString &key, const OUString & rValue);
     166             :         };
     167             : 
     168             :         class MQueryHelper
     169             :         {
     170             :         private:
     171             :             typedef std::vector< MQueryHelperResultEntry* > resultsArray;
     172             : 
     173             :             mutable ::osl::Mutex        m_aMutex;
     174             :             ::osl::Condition    m_aCondition;
     175             :             resultsArray        m_aResults;
     176             :             sal_uInt32          m_nIndex;
     177             :             bool            m_bHasMore;
     178             :             bool            m_bAtEnd;
     179             :             void            append(MQueryHelperResultEntry* resEnt );
     180             :             void            clear_results();
     181             :             OColumnAlias        m_rColumnAlias;
     182             :             ErrorDescriptor     m_aError;
     183             :             OUString     m_aAddressbook;
     184             : 
     185             : /*
     186             :             void            clearResultOrComplete();
     187             :             void            notifyResultOrComplete();
     188             :             sal_Bool        waitForResultOrComplete( );
     189             :             void            getCardValues(nsIAbCard  *card,sal_uInt32 rowIndex=0);
     190             : */
     191             : 
     192             :             sal_Int32 doQueryDefaultTable(OConnection* xConnection);
     193             :             sal_Int32 doQueryListTable(OConnection* xConnection, OString& ouStringTable);
     194             : 
     195             :         public:
     196             :                                        MQueryHelper(const OColumnAlias& _ca);
     197             :             virtual                    ~MQueryHelper();
     198             : 
     199             :             void                       reset();
     200             :             MQueryHelperResultEntry*   getByIndex( sal_uInt32 nRow );
     201             :             bool                       isError() const;
     202           0 :             static bool                queryComplete() { return true; }
     203             :             sal_Int32                  getResultCount() const;
     204             :             bool                       checkRowAvailable( sal_Int32 nDBRow );
     205             :             bool                       getRowValue( ORowSetValue& rValue, sal_Int32 nDBRow,const OUString& aDBColumnName, sal_Int32 nType );
     206             :             sal_Int32                  executeQuery(OConnection* xConnection, MQueryExpression & expr);
     207           5 :             const OColumnAlias&        getColumnAlias() const { return m_rColumnAlias; }
     208           2 :             bool                       hadError() const { return m_aError.is(); }
     209           0 :             inline ErrorDescriptor&    getError() { return m_aError; }
     210             : 
     211             :             void                       setAddressbook( OUString&);
     212             :         };
     213             :     }
     214             : }
     215             : 
     216             : #endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MORK_MQUERYHELPER_HXX
     217             : 
     218             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11