Refator names & imports (frsync)
[openflowplugin.git] / applications / forwardingrules-sync / src / main / java / org / opendaylight / openflowplugin / applications / frsync / dao / FlowCapableNodeCachedDao.java
1 /**\r
2  * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.\r
3  *\r
4  * This program and the accompanying materials are made available under the\r
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
6  * and is available at http://www.eclipse.org/legal/epl-v10.html\r
7  */\r
8 \r
9 package org.opendaylight.openflowplugin.applications.frsync.dao;\r
10 \r
11 import com.google.common.base.Optional;\r
12 import javax.annotation.Nonnull;\r
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;\r
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;\r
15 \r
16 /**\r
17  * Implementation of data access object for {@link FlowCapableNode}.\r
18  * Contains pair of snapshot and odl DAOs.\r
19  */\r
20 public class FlowCapableNodeCachedDao implements FlowCapableNodeDao {\r
21 \r
22     private final FlowCapableNodeDao snapshotDao;\r
23     private final FlowCapableNodeDao odlDao;\r
24 \r
25     public FlowCapableNodeCachedDao(FlowCapableNodeDao snapshotDao, FlowCapableNodeDao odlDao) {\r
26         this.snapshotDao = snapshotDao;\r
27         this.odlDao = odlDao;\r
28     }\r
29 \r
30     public Optional<FlowCapableNode> loadByNodeId(@Nonnull NodeId nodeId) {\r
31         final Optional<FlowCapableNode> node = snapshotDao.loadByNodeId(nodeId);\r
32 \r
33         if (node.isPresent()) {\r
34             return node;\r
35         }\r
36 \r
37         return odlDao.loadByNodeId(nodeId);\r
38     }\r
39 \r
40 }\r