Bug 2597: Batch modification operations in TransactionProxy
[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.DataStoreVersions;
14 import org.opendaylight.controller.cluster.datastore.node.NormalizedNodeToNodeCodec;
15 import org.opendaylight.controller.cluster.datastore.node.NormalizedNodeToNodeCodec.Decoded;
16 import org.opendaylight.controller.protobuff.messages.persistent.PersistentMessages;
17 import org.opendaylight.controller.sal.core.spi.data.DOMStoreWriteTransaction;
18 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
19 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
20
21 /**
22  * MergeModification stores all the parameters required to merge data into the specified path
23  */
24 public class MergeModification extends WriteModification {
25     private static final long serialVersionUID = 1L;
26
27     public MergeModification() {
28         this(DataStoreVersions.CURRENT_VERSION);
29     }
30
31     public MergeModification(short version) {
32         super(version);
33     }
34
35     public MergeModification(final YangInstanceIdentifier path, final NormalizedNode<?, ?> data) {
36         super(path, data);
37     }
38
39     @Override
40     public void apply(final DOMStoreWriteTransaction transaction) {
41         transaction.merge(getPath(), getData());
42     }
43
44     @Override
45     public byte getType() {
46         return MERGE;
47     }
48
49     @Deprecated
50     public static MergeModification fromSerializable(final Object serializable) {
51         PersistentMessages.Modification o = (PersistentMessages.Modification) serializable;
52         Decoded decoded = new NormalizedNodeToNodeCodec(null).decode(o.getPath(), o.getData());
53         return new MergeModification(decoded.getDecodedPath(), decoded.getDecodedNode());
54     }
55
56     public static MergeModification fromStream(ObjectInput in, short version)
57             throws ClassNotFoundException, IOException {
58         MergeModification mod = new MergeModification(version);
59         mod.readExternal(in);
60         return mod;
61     }
62 }