]> git.basschouten.com Git - openhab-addons.git/blob
1f72a470e3b99e4e774f70dac350739517505c23
[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         return switch (operator) {
36             case EQ -> "=";
37             case LT -> "<";
38             case LTE -> "<=";
39             case GT -> ">";
40             case GTE -> ">=";
41             case NEQ -> version == InfluxDBVersion.V1 ? "<>" : "!=";
42         };
43     }
44 }