Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / connectivity / source / drivers / mork / MQueryHelper.hxx
blob590b27594c702d36225ad5ebd515fd924aa60c9b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MORK_MQUERYHELPER_HXX
21 #define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MORK_MQUERYHELPER_HXX
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>
30 #include <boost/unordered_map.hpp>
32 #include "MErrorResource.hxx"
34 namespace connectivity
36 namespace mork
38 class OConnection;
39 class MQueryHelper;
40 class ErrorDescriptor;
42 namespace MQueryOp {
43 typedef enum {
44 Exists = 0,
45 DoesNotExist = 1,
46 Contains = 2,
47 DoesNotContain = 3,
48 Is = 4,
49 IsNot = 5,
50 BeginsWith = 6,
51 EndsWith = 7,
52 RegExp = 8
53 } cond_type;
56 class MQueryExpressionBase {
57 public:
58 typedef enum {
59 Unknown,
60 StringExpr,
61 Expr
62 } node_type;
64 protected:
65 node_type m_eNodeType;
67 MQueryExpressionBase() : m_eNodeType( Unknown ) {}
68 MQueryExpressionBase( node_type _eNodeType ) : m_eNodeType( _eNodeType ) {}
70 public:
71 bool isUnknown( ) const { return m_eNodeType == Unknown; }
72 bool isStringExpr( ) const { return m_eNodeType == StringExpr; }
73 bool isExpr( ) const { return m_eNodeType == Expr; }
76 class MQueryExpressionString : public MQueryExpressionBase {
77 protected:
78 OUString m_aName; // LHS
79 MQueryOp::cond_type m_aBooleanCondition;
80 OUString m_aValue; // RHS
82 public:
84 MQueryExpressionString( const OUString& lhs,
85 MQueryOp::cond_type cond,
86 const OUString& rhs )
87 : MQueryExpressionBase( MQueryExpressionBase::StringExpr )
88 , m_aName( lhs )
89 , m_aBooleanCondition( cond )
90 , m_aValue( rhs )
94 MQueryExpressionString( const OUString& lhs,
95 MQueryOp::cond_type cond )
96 : MQueryExpressionBase( MQueryExpressionBase::StringExpr )
97 , m_aName( lhs )
98 , m_aBooleanCondition( cond )
99 , m_aValue( OUString() )
103 const OUString& getName() const { return m_aName; }
104 MQueryOp::cond_type getCond() const { return m_aBooleanCondition; }
105 const OUString& getValue() const { return m_aValue; }
108 class MQueryExpression : public MQueryExpressionBase
110 friend class MQueryHelper;
112 public:
113 typedef ::std::vector< MQueryExpressionBase* > ExprVector;
115 typedef enum {
116 AND,
118 } bool_cond;
120 void setExpressions( ExprVector& _exprVector )
121 { m_aExprVector = _exprVector; }
123 // All expressions on a peer level use same condition operator
124 void setExpressionCondition( bool_cond _cond )
125 { m_aExprCondType = _cond; }
127 ExprVector& getExpressions( )
128 { return m_aExprVector; }
130 // All expressions on a peer level use same condition operator
131 bool_cond getExpressionCondition( ) const
132 { return m_aExprCondType; }
134 MQueryExpression() : MQueryExpressionBase( MQueryExpressionBase::Expr ),
135 m_aExprCondType( OR )
136 { m_aExprVector.clear(); }
139 protected:
140 ExprVector m_aExprVector;
141 bool_cond m_aExprCondType;
145 class MQueryHelperResultEntry
147 private:
148 typedef ::boost::unordered_map< OString, OUString, OStringHash > FieldMap;
150 mutable ::osl::Mutex m_aMutex;
151 FieldMap m_Fields;
153 public:
154 MQueryHelperResultEntry();
155 ~MQueryHelperResultEntry();
157 OUString getValue( const OString &key ) const;
158 void setValue( const OString &key, const OUString & rValue);
161 class MQueryHelper
163 private:
164 typedef std::vector< MQueryHelperResultEntry* > resultsArray;
166 mutable ::osl::Mutex m_aMutex;
167 ::osl::Condition m_aCondition;
168 resultsArray m_aResults;
169 sal_uInt32 m_nIndex;
170 bool m_bHasMore;
171 bool m_bAtEnd;
172 void append(MQueryHelperResultEntry* resEnt );
173 void clear_results();
174 OColumnAlias m_rColumnAlias;
175 ErrorDescriptor m_aError;
176 OUString m_aAddressbook;
177 MQueryExpression m_aExpr;
180 void clearResultOrComplete();
181 void notifyResultOrComplete();
182 sal_Bool waitForResultOrComplete( );
183 void getCardValues(nsIAbCard *card,sal_uInt32 rowIndex=0);
186 sal_Int32 doQueryDefaultTable(OConnection* xConnection);
187 sal_Int32 doQueryListTable(OConnection* xConnection, OString& ouStringTable);
189 public:
190 MQueryHelper(const OColumnAlias& _ca);
191 virtual ~MQueryHelper();
193 void reset();
194 MQueryHelperResultEntry* getByIndex( sal_uInt32 nRow );
195 bool isError() const;
196 bool queryComplete() const;
197 sal_Int32 getResultCount() const;
198 bool checkRowAvailable( sal_Int32 nDBRow );
199 bool getRowValue( ORowSetValue& rValue, sal_Int32 nDBRow,const OUString& aDBColumnName, sal_Int32 nType );
200 sal_Int32 executeQuery(OConnection* xConnection);
201 const OColumnAlias& getColumnAlias() const { return m_rColumnAlias; }
202 bool hadError() const { return m_aError.is(); }
203 inline ErrorDescriptor& getError() { return m_aError; }
205 void setAddressbook( OUString&);
206 void setExpression( MQueryExpression &_expr );
212 #endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MORK_MQUERYHELPER_HXX
214 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */