Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / connectivity / source / drivers / mozab / mozillasrc / MQuery.hxx
blob08facee24cd5fff8170cb3bf7ca692ff20416b1b
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 .
21 #ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MOZAB_MOZILLASRC_MQUERY_HXX
22 #define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MOZAB_MOZILLASRC_MQUERY_HXX
24 #include "MColumnAlias.hxx"
25 #include "MErrorResource.hxx"
26 #include <connectivity/FValue.hxx>
27 #include "MNSDeclares.hxx"
28 #include <osl/thread.hxx>
29 #include <com/sun/star/mozilla/MozillaProductType.hpp>
31 namespace connectivity
33 namespace mozab
36 class MQueryHelper;
37 struct MQueryDirectory;
39 namespace MQueryOp {
40 typedef enum {
41 Exists = 0,
42 DoesNotExist = 1,
43 Contains = 2,
44 DoesNotContain = 3,
45 Is = 4,
46 IsNot = 5,
47 BeginsWith = 6,
48 EndsWith = 7,
49 SoundsLike = 8,
50 RegExp = 9
51 } cond_type;
54 class MQueryExpressionBase {
55 public:
56 typedef enum {
57 Unknown,
58 StringExpr,
59 Expr
60 } node_type;
62 protected:
63 node_type m_eNodeType;
65 MQueryExpressionBase() : m_eNodeType( Unknown ) {}
66 MQueryExpressionBase( node_type _eNodeType ) : m_eNodeType( _eNodeType ) {}
68 public:
69 sal_Bool isUnknown( ) const { return m_eNodeType == Unknown; }
70 sal_Bool isStringExpr( ) const { return m_eNodeType == StringExpr; }
71 sal_Bool isExpr( ) const { return m_eNodeType == Expr; }
74 class MQueryExpressionString : public MQueryExpressionBase {
75 protected:
76 OUString m_aName; // LHS
77 MQueryOp::cond_type m_aBooleanCondition;
78 OUString m_aValue; // RHS
80 public:
82 MQueryExpressionString( OUString& lhs,
83 MQueryOp::cond_type cond,
84 OUString rhs )
85 : MQueryExpressionBase( MQueryExpressionBase::StringExpr )
86 , m_aName( lhs )
87 , m_aBooleanCondition( cond )
88 , m_aValue( rhs )
92 MQueryExpressionString( OUString& lhs,
93 MQueryOp::cond_type cond )
94 : MQueryExpressionBase( MQueryExpressionBase::StringExpr )
95 , m_aName( lhs )
96 , m_aBooleanCondition( cond )
97 , m_aValue( OUString() )
101 const OUString& getName() const { return m_aName; }
102 MQueryOp::cond_type getCond() const { return m_aBooleanCondition; }
103 const OUString& getValue() const { return m_aValue; }
106 class MQuery;
108 class MQueryExpression : public MQueryExpressionBase
110 friend class MQuery;
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;
146 class MQuery
149 * A query resultset with a maximum limit of
150 * m_nMaxNrOfReturns return items, is created from
151 * the following SQL statement:
153 * -------------------------------------------------
154 * SELECT m_aAttributes FROM m_aAddressbook
155 * WHERE m_aMatchItems SQL_OPR m_aMatchValue
156 * -------------------------------------------------
158 * We are\are not, depending on boolean m_bQuerySubDirs,
159 * interested in querying the sub-directories of the
160 * addressbook directory, if any.
162 * SQL_OPR:
163 * m_aSqlOppr contains the SQL operations for every
164 * attribute in m_aAttributes.
165 * This member must be initialised together with
166 * m_aAttributes.
168 * The SQL operations defined for 'SQL_OPR' are:
169 * matchExists = 0,
170 * matchDoesNotExist = 1,
171 * matchContains = 2,
172 * matchDoesNotContain = 3,
173 * matchIs = 4,
174 * matchIsNot = 5,
175 * matchBeginsWith = 6,
176 * matchEndsWith = 7,
177 * matchSoundsLike = 8,
178 * matchRegExp = 9.
179 * There must be mapping to one of these values.
181 * The following members MUST be initialised before
182 * a query is executed:
183 * m_Attributes, m_aMapAttrOppr, m_aAddressbook,
184 * m_aMatchItems and m_aMatchValue.
186 * m_bQuerySubDirs and m_nMaxNrReturns are set to a
187 * default value in the constructor which can be
188 * overridden. If (element of) m_aSqlOppr is not set,
189 * the default SQL operation is 'matchIs'.
192 private:
193 MQueryDirectory *m_aQueryDirectory;
194 MQueryHelper *m_aQueryHelper;
195 OUString m_aAddressbook;
196 sal_Int32 m_nMaxNrOfReturns;
197 sal_Bool m_bQuerySubDirs;
198 MQueryExpression m_aExpr;
199 const OColumnAlias& m_rColumnAlias;
200 ::com::sun::star::mozilla::MozillaProductType
201 m_Product;
202 OUString m_Profile;
203 ErrorDescriptor m_aError;
205 void construct();
206 protected:
207 ::osl::Mutex m_aMutex;
208 #if OSL_DEBUG_LEVEL > 0
209 oslThreadIdentifier m_oThreadID;
210 #endif
212 public:
214 * - Contains accessors to the members of this class.
215 * - executeQuery() initiates a non-blocking query.
217 sal_Int32 executeQuery(OConnection* _pCon);
218 sal_Int32 executeQueryProxied(OConnection* _pCon); //Used only by MNSMozabProxy
220 sal_Int32 createNewCard(); //return Row count number
221 sal_Int32 deleteRow(const sal_Int32 rowIndex);
222 sal_Int32 commitRow(const sal_Int32 rowIndex);
223 sal_Bool resyncRow(sal_Int32 nDBRow);
225 sal_Bool isWritable(OConnection* _pCon);
227 sal_uInt32 InsertLoginInfo(OConnection* _pCon);
229 void setAddressbook( OUString&);
231 const OColumnAlias& getColumnAlias() const { return m_rColumnAlias; }
233 void setExpression( MQueryExpression &_expr );
235 void setMaxNrOfReturns( const sal_Int32);
237 sal_Int32 getRowCount( void );
238 sal_uInt32 getRealRowCount( void );
239 sal_Bool queryComplete( void );
240 sal_Bool waitForQueryComplete( void );
241 sal_Bool checkRowAvailable( sal_Int32 nDBRow );
242 sal_Bool getRowValue( connectivity::ORowSetValue& rValue,
243 sal_Int32 nDBRow,
244 const OUString& aDBColumnName,
245 sal_Int32 nType ) const;
246 sal_Bool setRowValue( connectivity::ORowSetValue& rValue,
247 sal_Int32 nDBRow,
248 const OUString& aDBColumnName,
249 sal_Int32 nType ) const;
250 sal_Int32 getRowStates(sal_Int32 nDBRow);
251 sal_Bool setRowStates(sal_Int32 nDBRow,sal_Int32 aState);
253 bool hadError() const { return m_aError.is(); }
254 inline const ErrorDescriptor& getError() const { return m_aError; }
256 public:
257 // MQuery();
258 MQuery( const OColumnAlias& _ca );
259 virtual ~MQuery();
260 static MNameMapper* CreateNameMapper();
261 static void FreeNameMapper( MNameMapper* _ptr );
266 #endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MOZAB_MOZILLASRC_MQUERY_HXX
268 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */