]> git.basschouten.com Git - openhab-addons.git/blob
e84f705bba304fb9a8425de5db6d4ee44bfe097e
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.persistence.influxdb.internal;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.core.persistence.FilterCriteria;
17
18 /**
19  * Creates InfluxDB query sentence given an OpenHab persistence {@link FilterCriteria}
20  *
21  * @author Joan Pujol Espinar - Initial contribution
22  */
23 @NonNullByDefault
24 public interface FilterCriteriaQueryCreator {
25     /**
26      * Create query from {@link FilterCriteria}
27      * 
28      * @param criteria Criteria to create query from
29      * @param retentionPolicy Name of the retentionPolicy/bucket to use in query
30      * @return Created query as a String
31      */
32     String createQuery(FilterCriteria criteria, String retentionPolicy);
33
34     default String getOperationSymbol(FilterCriteria.Operator operator, InfluxDBVersion version) {
35         switch (operator) {
36             case EQ:
37                 return "=";
38             case LT:
39                 return "<";
40             case LTE:
41                 return "<=";
42             case GT:
43                 return ">";
44             case GTE:
45                 return ">=";
46             case NEQ:
47                 return version == InfluxDBVersion.V1 ? "<>" : "!=";
48             default:
49                 throw new UnnexpectedConditionException("Not expected operator " + operator);
50         }
51     }
52 }