/**************************************************************************** ** ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the QtAddOn.JsonDb module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and Digia. For licensing terms and ** conditions see http://qt.digia.com/licensing. For further information ** use the contact form at http://qt.digia.com/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser ** General Public License version 2.1 as published by the Free Software ** Foundation and appearing in the file LICENSE.LGPL included in the ** packaging of this file. Please review the following information to ** ensure the GNU Lesser General Public License version 2.1 requirements ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** ** In addition, as a special exception, Digia gives you certain additional ** rights. These rights are described in the Digia Qt LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** ** GNU General Public License Usage ** Alternatively, this file may be used under the terms of the GNU ** General Public License version 3.0 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. Please review the following information to ** ensure the GNU General Public License version 3.0 requirements will be ** met: http://www.gnu.org/copyleft/gpl.html. ** ** ** $QT_END_LICENSE$ ** ****************************************************************************/ #ifndef JSONDB_QUERY_H #define JSONDB_QUERY_H #include #include #include #include #include #include "jsondberrors.h" #include #include #include #include "jsondbobject.h" QT_BEGIN_HEADER QT_BEGIN_NAMESPACE_JSONDB_PARTITION class JsonDbPartition; class Q_JSONDB_PARTITION_EXPORT JsonDbQueryTerm { public: JsonDbQueryTerm(); ~JsonDbQueryTerm(); QString propertyVariable() const { return mPropertyVariable; } void setPropertyVariable(const QString &variable) { mPropertyVariable = variable; } inline bool hasPropertyName() const { return !mPropertyName.isEmpty(); } QString propertyName() const { return mPropertyName; } void setPropertyName(const QString &propertyName) { mPropertyName = propertyName; mFieldPath = propertyName.split(QLatin1Char('.')); } QString op() const { return mOp; } void setOp(QString op) { mOp = op; } QString joinField() const { return mJoinField; } void setJoinField(QString joinField) { mJoinField = joinField; if (!joinField.isEmpty()) { QStringList joinFields = joinField.split(QStringLiteral("->")); mJoinPaths.resize(joinFields.size()); for (int j = 0; j < joinFields.size(); j++) mJoinPaths[j] = joinFields[j].split(QLatin1Char('.')); } } const QVector &joinPaths() const { return mJoinPaths; } QString variable() const { return mVariable; } void setVariable(const QString variable) { mVariable = variable; } inline bool hasValue() const { return !mValue.isUndefined(); } QJsonValue value() const; void setValue(const QJsonValue &v) { mValue = v; } QRegExp ®Exp() { return mRegExp; } void setRegExp(const QRegExp ®Exp) { mRegExp = regExp; } const QRegExp ®ExpConst() const { return mRegExp; } private: QString mPropertyVariable; QString mPropertyName; QString mVariable; QJsonValue mValue; QRegExp mRegExp; QStringList mFieldPath; QString mOp; QString mJoinField; QVector mJoinPaths; }; class Q_JSONDB_PARTITION_EXPORT JsonDbOrQueryTerm { public: JsonDbOrQueryTerm(); JsonDbOrQueryTerm(const JsonDbQueryTerm &term); ~JsonDbOrQueryTerm(); const QList &terms() const { return mTerms; } void addTerm(const JsonDbQueryTerm &term) { mTerms.append(term); } QList propertyNames() const; QList findUnindexablePropertyNames() const; private: QList mTerms; }; class Q_JSONDB_PARTITION_EXPORT JsonDbOrderTerm { public: JsonDbOrderTerm() : ascending(false) { } ~JsonDbOrderTerm() { } bool ascending; QString propertyName; }; class Q_JSONDB_PARTITION_EXPORT JsonDbQuery { public: JsonDbQuery(); ~JsonDbQuery(); QList queryTerms; QList orderTerms; QString query; QStringList mapExpressionList; QStringList mapKeyList; QString aggregateOperation; QMap bindings; inline bool isEmpty() const { return queryTerms.isEmpty() && orderTerms.isEmpty(); } QSet matchedTypes() const { return mMatchedTypes; } bool match(const JsonDbObject &object, QHash *objectCache, JsonDbPartition *partition = 0) const; inline QJsonValue termValue(const JsonDbQueryTerm &term) const { return term.hasValue() ? term.value() : bindings.value(term.variable(), QJsonValue(QJsonValue::Undefined)); } bool isAscending() const; private: QSet mMatchedTypes; friend class JsonDbQueryParserPrivate; }; QT_END_NAMESPACE_JSONDB_PARTITION QT_END_HEADER #endif // JSONDB_QUERY_H