Split out TransactionContext classes
[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 org.opendaylight.controller.cluster.datastore.node.NormalizedNodeToNodeCodec;
12 import org.opendaylight.controller.cluster.datastore.node.NormalizedNodeToNodeCodec.Decoded;
13 import org.opendaylight.controller.protobuff.messages.persistent.PersistentMessages;
14 import org.opendaylight.controller.sal.core.spi.data.DOMStoreWriteTransaction;
15 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
16 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
17 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
18
19 /**
20  * MergeModification stores all the parameters required to merge data into the specified path
21  */
22 public class MergeModification extends WriteModification {
23     private static final long serialVersionUID = 1L;
24
25     public MergeModification(final YangInstanceIdentifier path, final NormalizedNode<?, ?> data,
26         final SchemaContext schemaContext) {
27         super(path, data, schemaContext);
28     }
29
30     @Override
31     public void apply(final DOMStoreWriteTransaction transaction) {
32         transaction.merge(path, data);
33     }
34
35     public static MergeModification fromSerializable(final Object serializable, final SchemaContext schemaContext) {
36         PersistentMessages.Modification o = (PersistentMessages.Modification) serializable;
37         Decoded decoded = new NormalizedNodeToNodeCodec(schemaContext).decode(o.getPath(), o.getData());
38         return new MergeModification(decoded.getDecodedPath(), decoded.getDecodedNode(), schemaContext);
39     }
40 }