Merge "neutron now works with jetty"
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / modification / MergeModification.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
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
9 package org.opendaylight.controller.cluster.datastore.modification;
10
11 import java.io.IOException;
12 import java.io.ObjectInput;
13 import org.opendaylight.controller.cluster.datastore.node.NormalizedNodeToNodeCodec;
14 import org.opendaylight.controller.cluster.datastore.node.NormalizedNodeToNodeCodec.Decoded;
15 import org.opendaylight.controller.protobuff.messages.persistent.PersistentMessages;
16 import org.opendaylight.controller.sal.core.spi.data.DOMStoreWriteTransaction;
17 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
18 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
19
20 /**
21  * MergeModification stores all the parameters required to merge data into the specified path
22  */
23 public class MergeModification extends WriteModification {
24     private static final long serialVersionUID = 1L;
25
26     public MergeModification() {
27     }
28
29     public MergeModification(final YangInstanceIdentifier path, final NormalizedNode<?, ?> data) {
30         super(path, data);
31     }
32
33     @Override
34     public void apply(final DOMStoreWriteTransaction transaction) {
35         transaction.merge(getPath(), getData());
36     }
37
38     @Override
39     public byte getType() {
40         return MERGE;
41     }
42
43     @Deprecated
44     public static MergeModification fromSerializable(final Object serializable) {
45         PersistentMessages.Modification o = (PersistentMessages.Modification) serializable;
46         Decoded decoded = new NormalizedNodeToNodeCodec(null).decode(o.getPath(), o.getData());
47         return new MergeModification(decoded.getDecodedPath(), decoded.getDecodedNode());
48     }
49
50     public static MergeModification fromStream(ObjectInput in) throws ClassNotFoundException, IOException {
51         MergeModification mod = new MergeModification();
52         mod.readExternal(in);
53         return mod;
54     }
55 }