]> git.basschouten.com Git - openhab-addons.git/blob
0090d9c6002dd483cbdc9da5aa11654e3e518e88
[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.items.MetadataRegistry;
17 import org.openhab.persistence.influxdb.internal.influx1.Influx1FilterCriteriaQueryCreatorImpl;
18 import org.openhab.persistence.influxdb.internal.influx1.InfluxDB1RepositoryImpl;
19 import org.openhab.persistence.influxdb.internal.influx2.Influx2FilterCriteriaQueryCreatorImpl;
20 import org.openhab.persistence.influxdb.internal.influx2.InfluxDB2RepositoryImpl;
21
22 /**
23  * Factory that returns {@link InfluxDBRepository} and
24  * {@link FilterCriteriaQueryCreator} implementations depending on InfluxDB
25  * version
26  *
27  * @author Joan Pujol Espinar - Initial contribution
28  */
29 @NonNullByDefault
30 public class RepositoryFactory {
31
32     public static InfluxDBRepository createRepository(InfluxDBConfiguration influxDBConfiguration) {
33         switch (influxDBConfiguration.getVersion()) {
34             case V1:
35                 return new InfluxDB1RepositoryImpl(influxDBConfiguration);
36             case V2:
37                 return new InfluxDB2RepositoryImpl(influxDBConfiguration);
38             default:
39                 throw new UnnexpectedConditionException("Not expected version " + influxDBConfiguration.getVersion());
40         }
41     }
42
43     public static FilterCriteriaQueryCreator createQueryCreator(InfluxDBConfiguration influxDBConfiguration,
44             MetadataRegistry metadataRegistry) {
45         switch (influxDBConfiguration.getVersion()) {
46             case V1:
47                 return new Influx1FilterCriteriaQueryCreatorImpl(influxDBConfiguration, metadataRegistry);
48             case V2:
49                 return new Influx2FilterCriteriaQueryCreatorImpl(influxDBConfiguration, metadataRegistry);
50             default:
51                 throw new UnnexpectedConditionException("Not expected version " + influxDBConfiguration.getVersion());
52         }
53     }
54 }