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 public class QueryBuilderExamples {
21 private QueryFactory factory;
24 * Return all of /foo. Equivalent to a read() of the same identifier.
26 public QueryExpression<Foo> selectFoo() {
28 .querySubtree(InstanceIdentifier.create(Foo.class))
33 * Read all of /foo/system[name="some"]. Equivalent to a read() of the same identifier.
35 public QueryExpression<System> selectFooSystemSome() {
37 .querySubtree(InstanceIdentifier.create(Foo.class).child(System.class, new SystemKey("some")))
42 * Read all entries in /foo/system. Equivalent to a read(/foo).get().nonnullSystem().
44 public QueryExpression<System> selectFooSystem() {
46 .querySubtree(InstanceIdentifier.create(Foo.class))
47 .extractChild(System.class)
52 * Read all entries in /foo/system, which have 'alias' set to 'some'.
54 public QueryExpression<System> selectFooSystemAliasSome() {
56 .querySubtree(InstanceIdentifier.create(Foo.class))
57 .extractChild(System.class)
59 .leaf(System::getAlias)
65 * Read all entries in /foo/system, which have 'alias' containing the string 'needle'.
67 public QueryExpression<System> selectFooSystemAliasWithNeedle() {
69 .querySubtree(InstanceIdentifier.create(Foo.class))
70 .extractChild(System.class)
72 .leaf(System::getAlias)
78 * Read all entries in /foo/system/alarms, which have 'critical' leaf present.
80 public QueryExpression<Alarms> selectFooSystemAlarmsCritical() {
82 .querySubtree(InstanceIdentifier.create(Foo.class))
83 .extractChild(System.class)
84 .extractChild(Alarms.class)
86 .leaf(Alarms::getCritical)
92 * Read all entries in /foo/system/alarms, which have 'critical' leaf present and have an entry in 'affected-users'
93 * with 'uid' larger than 10.
95 * Note this is the same expression as selectFooSystemCriticalUid(), but selects Alarms objects.
97 public QueryExpression<Alarms> selectFooSystemAlarmsCriticalUid() {
99 .querySubtree(InstanceIdentifier.create(Foo.class))
100 .extractChild(System.class)
101 .extractChild(Alarms.class)
103 .leaf(Alarms::getCritical)
106 .childObject(AffectedUsers.class)
107 .leaf(AffectedUsers::getUid)
108 .greaterThan(Uint64.TEN)
114 * Read all entries in /foo/system, which have 'critical' leaf present and have an entry in 'affected-users'
115 * with 'uid' larger than 10.
117 * Note this is the same expression as selectFooSystemAlarmsCriticalUid(), but selects System objects.
119 public QueryExpression<System> selectFooSystemCriticalUid() {
121 .querySubtree(InstanceIdentifier.create(Foo.class))
122 .extractChild(System.class)
124 .childObject(Alarms.class)
125 .leaf(Alarms::getCritical)
128 .childObject(Alarms.class)
129 .childObject(AffectedUsers.class)
130 .leaf(AffectedUsers::getUid)
131 .greaterThan(Uint64.TEN)