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