blob: 326bbb7fa65b35fa30928897453af6a721b1bdf4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
#ifndef _QmfEngineQueryImpl_
#define _QmfEngineQueryImpl_
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
#include "qmf/engine/Query.h"
#include <qpid/messaging/Variant.h>
#include <qpid/messaging/MapView.h>
#include <qpid/messaging/ListView.h>
#include <string>
#include <boost/shared_ptr.hpp>
namespace qmf {
namespace engine {
struct QueryImpl {
QueryImpl(const char* _target) : target(_target), resultLimit(0) {}
QueryImpl(const char* _target, const qpid::messaging::Variant::List& _predicate) :
target(_target), predicate(_predicate), resultLimit(0) {}
QueryImpl(const char* _target, const char* expression) :
target(_target), resultLimit(0) { parsePredicate(expression); }
QueryImpl(const qpid::messaging::MapView& map);
QueryImpl(const qpid::messaging::ListView& pred);
~QueryImpl() {}
static Query* factory(const qpid::messaging::MapView& map);
static Query* factory(const qpid::messaging::ListView& pred);
void where(const qpid::messaging::Variant::List& _predicate) { predicate = _predicate; }
void where(const char* expression) { parsePredicate(expression); }
void limit(uint32_t maxResults) { resultLimit = maxResults; }
void orderBy(const char* attrName, bool decreasing) { sortAttr = attrName; orderDecreasing = decreasing; }
bool havePredicate() const { return !predicate.empty(); }
bool haveLimit() const { return resultLimit != 0; }
bool haveOrderBy() const { return !sortAttr.empty(); }
const qpid::messaging::Variant::List& getPredicate() const { return predicate; }
uint32_t getLimit() const { return resultLimit; }
const char* getOrderBy() const { return sortAttr.c_str(); }
bool getDecreasing() const { return orderDecreasing; }
bool matches(const qpid::messaging::Variant::Map& data) const;
void parsePredicate(const std::string& expression);
const std::string target;
qpid::messaging::Variant::List predicate;
uint32_t resultLimit;
std::string sortAttr;
bool orderDecreasing;
};
}
}
#endif
|