Switch CDS frontend internals to use MD-SAL APIs
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / modification / DeleteModification.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 java.io.ObjectOutput;
14 import org.opendaylight.controller.cluster.datastore.DataStoreVersions;
15 import org.opendaylight.controller.cluster.datastore.node.utils.stream.SerializationUtils;
16 import org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction;
17 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
18 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
19
20 /**
21  * DeleteModification store all the parameters required to delete a path from the data tree.
22  */
23 public class DeleteModification extends AbstractModification {
24     private static final long serialVersionUID = 1L;
25
26     public DeleteModification() {
27         this(DataStoreVersions.CURRENT_VERSION);
28     }
29
30     public DeleteModification(short version) {
31         super(version);
32     }
33
34     public DeleteModification(YangInstanceIdentifier path) {
35         super(path);
36     }
37
38     @Override
39     public void apply(DOMStoreWriteTransaction transaction) {
40         transaction.delete(getPath());
41     }
42
43     @Override
44     public void apply(DataTreeModification transaction) {
45         transaction.delete(getPath());
46     }
47
48     @Override
49     public byte getType() {
50         return DELETE;
51     }
52
53     @Override
54     public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
55         setPath(SerializationUtils.deserializePath(in));
56     }
57
58     @Override
59     public void writeExternal(ObjectOutput out) throws IOException {
60         SerializationUtils.serializePath(getPath(), out);
61     }
62
63     public static DeleteModification fromStream(ObjectInput in, short version)
64             throws ClassNotFoundException, IOException {
65         DeleteModification mod = new DeleteModification(version);
66         mod.readExternal(in);
67         return mod;
68     }
69 }