Deprecate ManagedNewTransactionRunner et al.
[genius.git] / mdsalutil / mdsalutil-api / src / main / java / org / opendaylight / genius / infra / Datastore.java
1 /*
2  * Copyright © 2018 Red Hat, Inc. and others.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.genius.infra;
9
10 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
11
12 /**
13  * Strongly-typed representation of a datastore (configuration or operational).
14  *
15  * @deprecated Use {@link org.opendaylight.mdsal.binding.util.Datastore} instead.
16  */
17 @Deprecated(forRemoval = true)
18 public abstract class Datastore {
19
20     /** Class representing the configuration datastore. */
21     public static final Class<Configuration> CONFIGURATION = Configuration.class;
22
23     /** Class representing the operational datastore. */
24     public static final Class<Operational> OPERATIONAL = Operational.class;
25
26     public static final class Configuration extends Datastore {
27
28     }
29
30     public static final class Operational extends Datastore {
31
32     }
33
34     /**
35      * Returns the logical datastore type corresponding to the given datastore class.
36      *
37      * @param datastoreClass The datastore class to convert.
38      * @return The corresponding logical datastore type.
39      * @throws IllegalArgumentException if the provided datastore class isn’t handled.
40      */
41     public static LogicalDatastoreType toType(Class<? extends Datastore> datastoreClass) {
42         if (datastoreClass.equals(Configuration.class)) {
43             return LogicalDatastoreType.CONFIGURATION;
44         } else if (Operational.class.equals(datastoreClass)) {
45             return LogicalDatastoreType.OPERATIONAL;
46         } else {
47             throw new IllegalArgumentException("Unknown datastore class " + datastoreClass);
48         }
49     }
50
51     /**
52      * Returns the datastore class corresponding to the given logical datastore type.
53      * @param datastoreType The logical datastore type to convert.
54      * @return The corresponding datastore class.
55      * @throws IllegalArgumentException if the provided logical datastore type isn’t handled.
56      */
57     public static Class<? extends Datastore> toClass(LogicalDatastoreType datastoreType) {
58         switch (datastoreType) {
59             case CONFIGURATION:
60                 return CONFIGURATION;
61             case OPERATIONAL:
62                 return OPERATIONAL;
63             default:
64                 throw new IllegalArgumentException("Unknown datastore type " + datastoreType);
65         }
66     }
67
68     private Datastore() {
69
70     }
71 }