2 * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others. All rights reserved.
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
8 package org.opendaylight.mdsal.binding.api.query;
10 import org.mockito.Mock;
11 import org.opendaylight.yang.gen.v1.mdsal.query.norev.Foo;
12 import org.opendaylight.yang.gen.v1.mdsal.query.norev.first.grp.System;
13 import org.opendaylight.yang.gen.v1.mdsal.query.norev.first.grp.SystemKey;
14 import org.opendaylight.yang.gen.v1.mdsal.query.norev.second.grp.Alarms;
15 import org.opendaylight.yang.gen.v1.mdsal.query.norev.third.grp.AffectedUsers;
16 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
17 import org.opendaylight.yangtools.yang.common.Uint64;
19 @SuppressWarnings("exports")
20 public class QueryBuilderExamples {
22 private QueryFactory factory;
25 * Return all of /foo. Equivalent to a read() of the same identifier.
27 public QueryExpression<Foo> selectFoo() {
29 .querySubtree(InstanceIdentifier.create(Foo.class))
34 * Read all of /foo/system[name="some"]. Equivalent to a read() of the same identifier.
36 public QueryExpression<System> selectFooSystemSome() {
38 .querySubtree(InstanceIdentifier.create(Foo.class).child(System.class, new SystemKey("some")))
43 * Read all entries in /foo/system. Equivalent to a read(/foo).get().nonnullSystem().
45 public QueryExpression<System> selectFooSystem() {
47 .querySubtree(InstanceIdentifier.create(Foo.class))
48 .extractChild(System.class)
53 * Read all entries in /foo/system, which have 'alias' set to 'some'.
55 public QueryExpression<System> selectFooSystemAliasSome() {
57 .querySubtree(InstanceIdentifier.create(Foo.class))
58 .extractChild(System.class)
60 .leaf(System::getAlias)
66 * Read all entries in /foo/system, which have 'alias' containing the string 'needle'.
68 public QueryExpression<System> selectFooSystemAliasWithNeedle() {
70 .querySubtree(InstanceIdentifier.create(Foo.class))
71 .extractChild(System.class)
73 .leaf(System::getAlias)
79 * Read all entries in /foo/system/alarms, which have 'critical' leaf present.
81 public QueryExpression<Alarms> selectFooSystemAlarmsCritical() {
83 .querySubtree(InstanceIdentifier.create(Foo.class))
84 .extractChild(System.class)
85 .extractChild(Alarms.class)
87 .leaf(Alarms::getCritical)
93 * Read all entries in /foo/system/alarms, which have 'critical' leaf present and have an entry in 'affected-users'
94 * with 'uid' larger than 10.
96 * Note this is the same expression as selectFooSystemCriticalUid(), but selects Alarms objects.
98 public QueryExpression<Alarms> selectFooSystemAlarmsCriticalUid() {
100 .querySubtree(InstanceIdentifier.create(Foo.class))
101 .extractChild(System.class)
102 .extractChild(Alarms.class)
104 .leaf(Alarms::getCritical)
107 .childObject(AffectedUsers.class)
108 .leaf(AffectedUsers::getUid)
109 .greaterThan(Uint64.TEN)
115 * Read all entries in /foo/system, which have 'critical' leaf present and have an entry in 'affected-users'
116 * with 'uid' larger than 10.
118 * Note this is the same expression as selectFooSystemAlarmsCriticalUid(), but selects System objects.
120 public QueryExpression<System> selectFooSystemCriticalUid() {
122 .querySubtree(InstanceIdentifier.create(Foo.class))
123 .extractChild(System.class)
125 .childObject(Alarms.class)
126 .leaf(Alarms::getCritical)
129 .childObject(Alarms.class)
130 .childObject(AffectedUsers.class)
131 .leaf(AffectedUsers::getUid)
132 .greaterThan(Uint64.TEN)